popup.vue 24 KB

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