popup.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. <template>
  2. <div class="page-wrapper" ref="pageWrapperDom" @scroll="pageScroll">
  3. <template v-if="isLogin && homeVisibility">
  4. <!-- <div class="nav-bar">
  5. <div class="item left">
  6. <img :src="require('@/assets/svg/icon-denet-logo.svg')" />
  7. DeNet
  8. </div>
  9. <div class="item right" @click="showTransactions">
  10. <img :src="require('@/assets/svg/icon-option-list.svg')" />
  11. Transactions
  12. </div>
  13. </div> -->
  14. <v-head :show_more="true" :show_state="'home'"></v-head>
  15. <div class="content">
  16. <img :src="require('@/assets/svg/icon-money.svg')" class="icon-money" />
  17. <div class="msg" v-show="walletWithdrawConfig.withdrawUSDPaypalFeeDesc">
  18. ({{ walletWithdrawConfig.withdrawUSDPaypalFeeDesc }})</div>
  19. <div class="amount">${{ canWithdrawBalance / 100 }}</div>
  20. <div class="area-btn">
  21. <div class="withdraw-btn" @click="clickWithdraw">Withdraw</div>
  22. <div class="top-up-btn" @click="clickTopUp">Top Up</div>
  23. </div>
  24. </div>
  25. <div class="tab-bar">
  26. <div class="tab-item" :class="{ active: currentTabIndex == index }" v-for="(item, index) in tabList"
  27. :key="index" @click="clickTab(item, index)">
  28. <img :src="item.icon" class="icon" />
  29. {{ item.label }}
  30. </div>
  31. </div>
  32. <div class="list-wrapper" ref="pageGiveListDom">
  33. <div class="give-list" v-if="currentTabIndex == 0">
  34. <template v-if="giveList.length">
  35. <div class="cell" v-for="(item, index) in giveList" :key="index"
  36. @click="clickListItem(item, index)">
  37. <div class="img-wrapper">
  38. <!-- 收到红包 -->
  39. <template v-if="item.type == 1">
  40. <img class="icon-avatar" :src="item.userInfo.avatarUrl" />
  41. <img class="icon-give" :src="
  42. require('@/assets/svg/icon-giveaways.svg')
  43. " />
  44. </template>
  45. <!-- 发出去红包 -->
  46. <template v-else-if="2">
  47. <img :src="
  48. require('@/assets/svg/icon-list-big-give.svg')
  49. " />
  50. </template>
  51. </div>
  52. <div class="info-wrapper">
  53. <div class="left">
  54. <div class="nickname">
  55. {{
  56. item.type == 1
  57. ? item.userInfo.nickName
  58. : "Giveaways"
  59. }}
  60. </div>
  61. <div class="time">
  62. {{
  63. moment(item.timestamp).format(
  64. "MM-DD HH:mm:ss"
  65. )
  66. }}
  67. </div>
  68. </div>
  69. <div class="right">
  70. <div class="msg">
  71. <div class="bold">
  72. <!-- 收到的 -->
  73. <template v-if="item.type == 1">
  74. <!-- 进行中-->
  75. <template v-if="item.status == 0">
  76. in progress
  77. </template>
  78. <!-- 已完成 -->
  79. <template v-else-if="item.status == 1">
  80. ${{ item.amount / 100 }}
  81. </template>
  82. <!-- 已过期 -->
  83. <template v-else-if="item.status == 2">
  84. Timeout
  85. </template>
  86. </template>
  87. <!-- 发出去的 -->
  88. <template v-else-if="item.type == 2">
  89. -${{ item.amount / 100 }}
  90. </template>
  91. </div>
  92. <!-- 发出的红包显示 -->
  93. <div class="desc" v-if="item.type == 2">
  94. <!-- 未发送-->
  95. <template v-if="item.postTaskLuckdrop.reSendAvailable">
  96. Unpublished
  97. </template>
  98. <!-- 进行中 -->
  99. <template v-else-if="item.status == 1">
  100. {{
  101. item.postTaskLuckdrop
  102. .receivedCount
  103. }}/{{
  104. item.postTaskLuckdrop
  105. .totalCount
  106. }}
  107. </template>
  108. <!-- 已结束 -->
  109. <template v-else-if="item.status == 2">
  110. (Time expired)
  111. {{
  112. item.postTaskLuckdrop
  113. .receivedCount
  114. }}/{{
  115. item.postTaskLuckdrop
  116. .totalCount
  117. }}
  118. </template>
  119. <!-- 红包未发出显示 -->
  120. <div v-if="item.postTaskLuckdrop.reSendAvailable" class="send-btn"
  121. @click.stop="sendTwitter(item)">
  122. Send
  123. </div>
  124. </div>
  125. </div>
  126. <!-- 发红包,红包未发出隐藏-->
  127. <img v-if="
  128. !(
  129. item.type == 2 &&
  130. item.postTaskLuckdrop.reSendAvailable
  131. )
  132. " class="icon" :src="
  133. require('@/assets/svg/icon-cell-arrow-right.svg')
  134. " />
  135. </div>
  136. </div>
  137. </div>
  138. </template>
  139. <template v-else>
  140. <img class="icon-empty" :src="require('@/assets/svg/icon-empty-list.svg')" />
  141. </template>
  142. </div>
  143. <div class="more-list" v-else>
  144. <div class="cell" v-for="(item, index) in moreTabList" :key="index">
  145. <img class="icon" :src="item.icon" />
  146. <div class="info-wrapper">
  147. <div class="left">
  148. {{ item.label }}
  149. </div>
  150. <div class="right">
  151. <img class="icon" :src="
  152. require('@/assets/svg/icon-cell-arrow-right.svg')
  153. " />
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. </div>
  159. </template>
  160. <!-- login -->
  161. <option-login v-if="!isLogin" @loginAction="loginAction" />
  162. <template v-if="isLogin && !homeVisibility">
  163. <!-- 交易列表 -->
  164. <option-transactions v-if="transactionsVisibility" @back="transactionsBack" />
  165. <!-- 提现页 -->
  166. <option-withdraw :amountValue="canWithdrawBalance" :walletWithdrawConfig="walletWithdrawConfig"
  167. v-if="withdrawVisibility" @back="withdrawBack" />
  168. </template>
  169. </div>
  170. </template>
  171. <script setup>
  172. import { ref, onMounted } from "vue";
  173. import optionTransactions from "@/view/components/options-transactions";
  174. import optionLogin from "@/view/components/option-login.vue";
  175. import optionWithdraw from "@/view/components/option-withdraw.vue";
  176. import {
  177. getChromeStorage,
  178. } from "@/uilts/chromeExtension";
  179. import { getBalance, getMineLuckdropRecords, getWithdrawConfig } from "@/http/account";
  180. import router from "@/router/popup.js";
  181. import VHead from '@/view/popup/components/head.vue'
  182. var moment = require("moment");
  183. let pageWrapperDom = ref(null);
  184. let pageGiveListDom = ref(null);
  185. let isLogin = ref(false);
  186. let homeVisibility = ref(false);
  187. let transactionsVisibility = ref(false);
  188. let withdrawVisibility = ref(false);
  189. let userInfo = ref({});
  190. let canWithdrawBalance = ref(0);
  191. let isRequestWithdrawBalance = ref(false);
  192. let currentTabIndex = ref(0);
  193. let giveList = ref([]);
  194. let giveReqParams = {
  195. params: {
  196. pageNum: 1,
  197. pageSize: 10,
  198. },
  199. loadMore: false,
  200. };
  201. let walletWithdrawConfig = ref({
  202. withdrawUSDPaypalFee: 0,
  203. withdrawUSDPreMinAmount: 100,
  204. withdrawUSDSwitch: "",
  205. withdrawUSDPaypalFeeDesc: ''
  206. });
  207. let moreTabList = ref([
  208. {
  209. icon: require("@/assets/svg/icon-twitter.svg"),
  210. label: "Twitter contact",
  211. },
  212. {
  213. icon: require("@/assets/svg/icon-about.svg"),
  214. label: "About",
  215. },
  216. ]);
  217. let tabList = ref([
  218. {
  219. icon: require("@/assets/svg/icon-giveaways.svg"),
  220. label: "Giveaways",
  221. },
  222. {
  223. icon: require("@/assets/svg/icon-more.svg"),
  224. label: "More",
  225. },
  226. ]);
  227. onMounted(() => {
  228. checkLoginState(() => {
  229. if (isLogin.value) {
  230. getAccountBalance();
  231. getLuckdropRecordsList();
  232. queryWithdrawConfig();
  233. }
  234. });
  235. });
  236. /**
  237. * 获取提现配置
  238. */
  239. const queryWithdrawConfig = () => {
  240. getWithdrawConfig({
  241. params: {},
  242. }).then((res) => {
  243. console.log(res);
  244. if (res.code == 0) {
  245. walletWithdrawConfig.value = res.data;
  246. }
  247. });
  248. };
  249. /**
  250. * 获取账户余额
  251. */
  252. const getAccountBalance = () => {
  253. isRequestWithdrawBalance.value = false;
  254. getBalance({
  255. params: {
  256. currencyCode: "USD",
  257. },
  258. }).then((res) => {
  259. isRequestWithdrawBalance.value = true;
  260. if (res.code == 0) {
  261. if (res.data) {
  262. canWithdrawBalance.value = res.data.canWithdrawBalance;
  263. }
  264. }
  265. });
  266. };
  267. const getUserInfo = (cb) => {
  268. getChromeStorage("userInfo", (res) => {
  269. cb && cb(res);
  270. });
  271. };
  272. /**
  273. * 检查登录状态
  274. */
  275. const checkLoginState = (cb) => {
  276. getUserInfo((res) => {
  277. if (res && res.accessToken) {
  278. userInfo.value = res;
  279. isLogin.value = true;
  280. homeVisibility.value = true;
  281. } else {
  282. userInfo.value = {};
  283. isLogin.value = false;
  284. }
  285. cb && cb();
  286. });
  287. };
  288. const pageScroll = (e) => {
  289. let wrapperHeight = pageWrapperDom.value.offsetHeight;
  290. let pageGiveListHeight = pageGiveListDom.value.offsetHeight;
  291. let scrollTop = e.target.scrollTop || 0;
  292. if (currentTabIndex.value != 0) {
  293. return;
  294. }
  295. if (
  296. giveReqParams.loadMore === false &&
  297. wrapperHeight + scrollTop >= pageGiveListHeight
  298. ) {
  299. giveReqParams.loadMore = true;
  300. giveReqParams.params.pageNum++;
  301. getLuckdropRecordsList();
  302. }
  303. };
  304. /**
  305. * 获取红包列表
  306. */
  307. const getLuckdropRecordsList = () => {
  308. getMineLuckdropRecords({
  309. params: giveReqParams.params,
  310. }).then((res) => {
  311. if (res.data && res.data.length) {
  312. if (giveReqParams.params.pageNum < 2) {
  313. giveList.value = res.data;
  314. } else {
  315. let data = giveList.value;
  316. data = data.concat(res.data);
  317. giveList.value = data;
  318. }
  319. giveReqParams.loadMore = false;
  320. }
  321. });
  322. };
  323. const clickTab = (params, index) => {
  324. currentTabIndex.value = index;
  325. console.log(params, index);
  326. };
  327. /**
  328. * 点击列表跳转到推文
  329. */
  330. const clickListItem = (params) => {
  331. if (!params.srcContentId) {
  332. return;
  333. }
  334. let url = "";
  335. let twitterUrl = "https://twitter.com/";
  336. let nickName = "";
  337. if (params.type == 1) {
  338. nickName = params.userInfo.nickName;
  339. } else if (params.type == 2) {
  340. nickName = userInfo.value.nickName;
  341. }
  342. url = twitterUrl + nickName + "/status/" + params.srcContentId;
  343. chrome.tabs.create({
  344. url,
  345. });
  346. };
  347. /**
  348. * 交易列表返回
  349. */
  350. const transactionsBack = () => {
  351. if (!homeVisibility.value) {
  352. if (transactionsVisibility.value) {
  353. transactionsVisibility.value = false;
  354. }
  355. homeVisibility.value = true;
  356. }
  357. };
  358. /**
  359. * 提现返回
  360. */
  361. const withdrawBack = () => {
  362. if (!homeVisibility.value) {
  363. if (withdrawVisibility.value) {
  364. withdrawVisibility.value = false;
  365. }
  366. homeVisibility.value = true;
  367. getAccountBalance();
  368. giveReqParams.params.pageNum = 1;
  369. getLuckdropRecordsList();
  370. }
  371. };
  372. // const showTransactions = () => {
  373. // // homeVisibility.value = false;
  374. // // transactionsVisibility.value = true;
  375. // router.push('/transactions')
  376. // };
  377. // const clickWithdraw = () => {
  378. // if (isRequestWithdrawBalance.value) {
  379. // homeVisibility.value = false;
  380. // withdrawVisibility.value = true;
  381. // }
  382. // };
  383. const loginAction = () => {
  384. login();
  385. };
  386. const login = () => {
  387. callEventPageMethod("POPUP_LOGIN", "", function (response) {
  388. console.log("res", response);
  389. });
  390. };
  391. /**
  392. * sendMessage
  393. */
  394. const callEventPageMethod = (method, data, callback) => {
  395. chrome.runtime.sendMessage(
  396. { method: method, data: data },
  397. function (response) {
  398. if (typeof callback === "function") callback(response);
  399. }
  400. );
  401. };
  402. /**
  403. * 点击发送,去发推
  404. */
  405. const sendTwitter = (params) => {
  406. console.log(params)
  407. callEventPageMethod(
  408. "POPUP_PUBLISH_TWITTER_RED_PACK",
  409. { srcContent: params.postTaskLuckdrop.srcContent, postId: params.postTaskLuckdrop.postId },
  410. function (response) {
  411. console.log("res", response);
  412. }
  413. );
  414. };
  415. // 点击提现
  416. const clickWithdraw = ()=>{
  417. router.push('/withdraw/home');
  418. }
  419. const clickTopUp = ()=>{
  420. router.push('/top-up/home');
  421. }
  422. </script>
  423. <style lang="scss">
  424. html,
  425. body {
  426. padding: 0 !important;
  427. margin: 0 !important;
  428. }
  429. .page-wrapper {
  430. width: 375px;
  431. height: 600px;
  432. box-sizing: border-box;
  433. overflow-y: scroll;
  434. .nav-bar {
  435. padding: 14px;
  436. box-sizing: border-box;
  437. display: flex;
  438. align-items: center;
  439. justify-content: space-between;
  440. .item {
  441. display: flex;
  442. align-items: center;
  443. font-size: 13px;
  444. cursor: pointer;
  445. img {
  446. width: 16px;
  447. height: 16px;
  448. margin-right: 4px;
  449. }
  450. }
  451. .left {
  452. font-weight: 500;
  453. }
  454. .right {
  455. color: #b6b6b6;
  456. }
  457. }
  458. .content {
  459. margin-top: 30px;
  460. text-align: center;
  461. .icon-money {
  462. width: 70px;
  463. height: 70px;
  464. }
  465. .amount {
  466. margin-top: 16px;
  467. margin-bottom: 20px;
  468. font-weight: 700;
  469. font-size: 42px;
  470. }
  471. .area-btn {
  472. display: flex;
  473. justify-content: center;
  474. font-weight: 600;
  475. font-size: 15px;
  476. .top-up-btn {
  477. border: 1px solid #ffb443;
  478. color: #fff;
  479. background: #FFB443;
  480. border-radius: 100px;
  481. width: 110px;
  482. height: 38px;
  483. margin-left: 8px;
  484. line-height: 38px;
  485. }
  486. .withdraw-btn {
  487. background: rgba(56, 154, 255, 0.01);
  488. border: 1px solid #ffb443;
  489. box-sizing: border-box;
  490. width: 110px;
  491. font-size: 15px;
  492. height: 38px;
  493. text-align: center;
  494. line-height: 38px;
  495. border-radius: 100px;
  496. color: #ffb443;
  497. display: inline-block;
  498. cursor: pointer;
  499. }
  500. }
  501. .msg {
  502. margin-top: 10px;
  503. font-size: 13px;
  504. color: #b6b6b6;
  505. }
  506. }
  507. .tab-bar {
  508. display: flex;
  509. align-items: center;
  510. margin-top: 25px;
  511. position: sticky;
  512. position: -webkit-sticky;
  513. top: 0px;
  514. z-index: 1000;
  515. background-color: #fff;
  516. .tab-item {
  517. flex: 1;
  518. display: flex;
  519. align-items: center;
  520. justify-content: center;
  521. padding: 17px 0;
  522. box-sizing: border-box;
  523. border-bottom: 1px solid #d1d1d1;
  524. cursor: pointer;
  525. .icon {
  526. width: 16px;
  527. height: 16px;
  528. margin-right: 5px;
  529. font-weight: 500;
  530. font-size: 16px;
  531. }
  532. }
  533. .active {
  534. border-bottom: 2px solid #000;
  535. }
  536. }
  537. .list-wrapper {
  538. min-height: 202px;
  539. .give-list {
  540. min-height: 202px;
  541. position: relative;
  542. .cell {
  543. display: flex;
  544. justify-content: space-between;
  545. align-items: center;
  546. height: 66px;
  547. box-sizing: border-box;
  548. padding-left: 20px;
  549. cursor: pointer;
  550. .img-wrapper {
  551. position: relative;
  552. margin-right: 16px;
  553. box-sizing: border-box;
  554. .icon-avatar {
  555. width: 34px;
  556. height: 34px;
  557. border-radius: 50%;
  558. }
  559. .icon-give {
  560. position: absolute;
  561. right: -4px;
  562. bottom: 2px;
  563. }
  564. }
  565. .info-wrapper {
  566. flex: 1;
  567. height: 100%;
  568. display: flex;
  569. justify-content: space-between;
  570. align-items: center;
  571. border-bottom: 1px solid #d1d1d1;
  572. box-sizing: border-box;
  573. padding-right: 16px;
  574. .left {
  575. .nickname {
  576. font-weight: 500;
  577. font-size: 14px;
  578. margin-bottom: 5px;
  579. }
  580. .time {
  581. font-size: 12px;
  582. color: #b6b6b6;
  583. }
  584. }
  585. .right {
  586. display: flex;
  587. align-items: center;
  588. cursor: pointer;
  589. .msg {
  590. .bold {
  591. font-weight: 500;
  592. font-size: 14px;
  593. text-align: right;
  594. }
  595. .desc {
  596. font-size: 12px;
  597. color: #b6b6b6;
  598. display: flex;
  599. align-items: center;
  600. justify-content: end;
  601. margin-top: 5px;
  602. .send-btn {
  603. height: 24px;
  604. width: 54px;
  605. line-height: 24px;
  606. text-align: center;
  607. border-radius: 100px;
  608. border: 1px solid #389aff;
  609. color: #389aff;
  610. font-weight: 500;
  611. font-size: 14px;
  612. cursor: pointer;
  613. margin-left: 8px;
  614. }
  615. }
  616. }
  617. .icon {
  618. width: 18px;
  619. height: 24px;
  620. margin-left: 4px;
  621. }
  622. }
  623. }
  624. }
  625. .icon-empty {
  626. position: absolute;
  627. left: 50%;
  628. top: 50%;
  629. transform: translate(-50%, -50%);
  630. }
  631. }
  632. .more-list {
  633. .cell {
  634. display: flex;
  635. justify-content: space-between;
  636. align-items: center;
  637. height: 66px;
  638. box-sizing: border-box;
  639. padding-left: 20px;
  640. .icon {
  641. width: 42px;
  642. height: 42px;
  643. border-radius: 50%;
  644. }
  645. .info-wrapper {
  646. flex: 1;
  647. height: 100%;
  648. display: flex;
  649. justify-content: space-between;
  650. align-items: center;
  651. border-bottom: 1px solid #d1d1d1;
  652. box-sizing: border-box;
  653. padding-right: 16px;
  654. .left {
  655. font-weight: 500;
  656. font-size: 16px;
  657. }
  658. .right {
  659. display: flex;
  660. align-items: center;
  661. cursor: pointer;
  662. .icon {
  663. width: 18px;
  664. height: 24px;
  665. }
  666. }
  667. }
  668. }
  669. }
  670. }
  671. }
  672. .page-wrapper::-webkit-scrollbar {
  673. display: none;
  674. }
  675. </style>