pay.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <template>
  2. <div class="dialog" :style="{'height': dialogStyle.height + 'px'}">
  3. <!-- home -->
  4. <div class="area-title">
  5. <img :src="require('@/assets/svg/icon-back.svg')" @click="clickBack" />
  6. <div class="title">Payment</div>
  7. </div>
  8. <!-- 内容 -->
  9. <div class="area-content">
  10. <div class="left">
  11. <img :src="require('@/assets/img/img-box5.png')" v-show="pay_info.home.sale_plan.itemCount == 5"
  12. alt="" />
  13. <img :src="require('@/assets/img/img-box1.png')" v-show="pay_info.home.sale_plan.itemCount == 1"
  14. alt="" />
  15. <div class="tip">
  16. <span>Mystery box*{{ pay_info.home.sale_plan.itemCount }}</span>
  17. <div>
  18. <img :src="pay_info.home.sale_plan.currencyInfo.iconPath" alt="" />
  19. <span>{{ pay_info.home.sale_plan.price }}</span>
  20. </div>
  21. </div>
  22. </div>
  23. <div class="right">
  24. <div class="card-content">
  25. <template v-if="tempCurrentCurrencyInfo.currencyCode">
  26. <div class="card-title">
  27. <img class="img" :src="require('@/assets/subject/top-01.svg')" />
  28. <div class="font">Deposit to Send Giveaway</div>
  29. </div>
  30. <top-up2 v-if="tempCurrentCurrencyInfo.currencyCode" :asyncIng="asyncIng"
  31. :currentCurrencyInfo="tempCurrentCurrencyInfo" @topUpDone="topUpDone">
  32. </top-up2>
  33. <div class="card-title">
  34. <img class="img" :src="require('@/assets/subject/top-02.svg')" />
  35. <div class="font">Wait for the amount to arrive</div>
  36. </div>
  37. <preview-balance v-if="tempCurrentCurrencyInfo.currencyCode"
  38. :currencyCode="tempCurrentCurrencyInfo.currencyCode"
  39. :tokenSymbol="tempCurrentCurrencyInfo.tokenSymbol" @updateData="updateData">
  40. </preview-balance>
  41. </template>
  42. </div>
  43. </div>
  44. </div>
  45. <!-- 底部 -->
  46. <div class="footer">
  47. <div class="buy1" @click="clickPlay" v-if="state.is_btn_grey == false">
  48. <btn-loading :color="'while'" v-if="state.loading.show"></btn-loading>
  49. <template
  50. v-else-if="(pay_info.home.sale_plan.price.length + pay_info.home.sale_plan.currencyInfo.tokenSymbol.length) > 30">
  51. <div class="left">Pay</div>
  52. <div class="right">
  53. <p>{{ pay_info.home.sale_plan.price }}</p>
  54. <p>{{ pay_info.home.sale_plan.currencyInfo.tokenSymbol }}</p>
  55. </div>
  56. </template>
  57. <template v-else>
  58. <div class="left">Pay</div>
  59. <div class="right">
  60. {{ pay_info.home.sale_plan.price }}
  61. {{ pay_info.home.sale_plan.currencyInfo.tokenSymbol }}
  62. </div>
  63. </template>
  64. </div>
  65. <div class="buy1 grey" v-else>
  66. <template
  67. v-if="(pay_info.home.sale_plan.price.length + pay_info.home.sale_plan.currencyInfo.tokenSymbol.length) > 30">
  68. <div class="left">Pay</div>
  69. <div class="right">
  70. <p>{{ pay_info.home.sale_plan.price }}</p>
  71. <p>{{ pay_info.home.sale_plan.currencyInfo.tokenSymbol }}</p>
  72. </div>
  73. </template>
  74. <template v-else>
  75. <div class="left">Pay</div>
  76. <div class="right">
  77. {{ pay_info.home.sale_plan.price }}
  78. {{ pay_info.home.sale_plan.currencyInfo.tokenSymbol }}
  79. </div>
  80. </template>
  81. </div>
  82. </div>
  83. </div>
  84. </template>
  85. <script setup >
  86. import Report from "@/log-center/log"
  87. import router from "@/router/buy-nft.js";
  88. import { ref, onMounted, inject, reactive } from 'vue'
  89. import topUp2 from "@/view/iframe/publish/components/top-up2.vue";
  90. import { getCurrencyInfoByCode } from "@/http/publishApi";
  91. import PreviewBalance from "@/view/components/preview-balance.vue";
  92. import BtnLoading from '../components/btn-loading.vue'
  93. import { payNftMysteryBoxWithBalance } from "@/http/pay";
  94. import { getChromeStorage } from "@/uilts/chromeExtension"
  95. import { ElMessage } from 'element-plus'
  96. import "element-plus/es/components/message/style/css";
  97. import { sendChromeTabMessage } from '@/uilts/chromeExtension.js';
  98. let pay_info = inject('pay_info');
  99. let postId = inject('post_Id');
  100. let state = reactive({
  101. loading: {
  102. show: false
  103. },
  104. is_btn_grey: true
  105. })
  106. let currentCurrencyInfo = reactive({
  107. currencyCode: "",
  108. currencyName: "",
  109. balance: "",
  110. });
  111. let dialogStyle = reactive({
  112. height: '800'
  113. })
  114. const updateData = (obj_data) => {
  115. if (Number(obj_data.balance) >= Number(pay_info.home.sale_plan.price)) {
  116. state.is_btn_grey = false
  117. }
  118. }
  119. const clickBack = () => {
  120. router.back()
  121. }
  122. const clickPlay = () => {
  123. state.loading.show = true
  124. payNftMysteryBoxWithBalance({
  125. params: {
  126. nftProjectId: pay_info.home.nftProjectId,
  127. salePlanId: pay_info.home.sale_plan.salePlanId,
  128. nftGroupId: pay_info.nft_group_Id
  129. }
  130. }).then((res) => {
  131. state.loading.show = false
  132. if (res.code == 0) {
  133. pay_info.buy_items = res.data.buyItems
  134. sendChromeTabMessage({ actionType: "FINISH_GROUP_BANNNER" }, () => { })
  135. router.push({ path: '/open_box' });
  136. Report.reportLog({
  137. pageSource: Report.pageSource.nftShopPage,
  138. businessType: Report.businessType.buttonClick,
  139. objectType: Report.objectType.buy_button,
  140. nftProjectId: pay_info.home.nftProjectId,
  141. postEditorPostId: postId.value,
  142. }, {
  143. 'buy-number': pay_info.home?.sale_plan?.itemCount,
  144. result: 'success'
  145. })
  146. } else {
  147. let msg = ''
  148. switch (res.code.toString()) {
  149. case '5001':
  150. msg = 'nft project not exist'
  151. break;
  152. case '5002':
  153. msg = 'nft project not available'
  154. break
  155. case '5101':
  156. msg = 'nft sale plan not exist'
  157. break
  158. case '5102':
  159. msg = 'nft sold out'
  160. break
  161. case '5103':
  162. msg = 'Purchase limit reached'
  163. break
  164. default:
  165. console.log(res.msg)
  166. }
  167. ElMessage({
  168. message: msg,
  169. grouping: true,
  170. type: 'warning',
  171. offset: -16,
  172. appendTo: document.body
  173. })
  174. Report.reportLog({
  175. pageSource: Report.pageSource.nftShopPage,
  176. businessType: Report.businessType.buttonClick,
  177. objectType: Report.objectType.buy_button,
  178. nftProjectId: pay_info.home.nftProjectId,
  179. postEditorPostId: postId.value,
  180. }, {
  181. 'buy-number': pay_info.home?.sale_plan?.itemCount,
  182. result: 'fail'
  183. })
  184. }
  185. }).catch(() => {
  186. state.loading.show = false
  187. })
  188. // report
  189. Report.reportLog({
  190. pageSource: Report.pageSource.nftPreviewPage,
  191. businessType: Report.businessType.buttonClick,
  192. objectType: Report.objectType.confirmButton,
  193. nftProjectId: pay_info.home.nftProjectId,
  194. postEditorPostId: postId.value,
  195. })
  196. }
  197. // 余额是否同步中
  198. let asyncIng = ref(false);
  199. //临时货币信息
  200. let tempCurrentCurrencyInfo = ref({});
  201. const getLocalCurrencyInfoByCode = () => {
  202. if (currentCurrencyInfo.currencyCode) {
  203. getCurrencyInfo();
  204. }
  205. }
  206. const getCurrencyInfo = async () => {
  207. let { accessToken = '' } = await getChromeStorage('userInfo') || {};
  208. if (accessToken) {
  209. getCurrencyInfoByCode({
  210. params: {
  211. currencyCode: currentCurrencyInfo.currencyCode
  212. }
  213. }).then(res => {
  214. if (res.code == 0 && res.data) {
  215. currentCurrencyInfo = res.data;
  216. tempCurrentCurrencyInfo.value = res.data;
  217. }
  218. });
  219. }
  220. }
  221. const setDialogStyle = () => {
  222. let clientHeight = window.innerHeight;
  223. if(clientHeight >= 840) {
  224. dialogStyle.height = 800;
  225. } else {
  226. dialogStyle.height = clientHeight - 40;
  227. }
  228. }
  229. onMounted(() => {
  230. currentCurrencyInfo.currencyCode = pay_info.home.sale_plan.currencyCode
  231. getLocalCurrencyInfoByCode();
  232. setDialogStyle()
  233. // report
  234. Report.reportLog({
  235. pageSource: Report.pageSource.nftPreviewPage,
  236. businessType: Report.businessType.pageView,
  237. nftProjectId: pay_info.home.nftProjectId,
  238. postEditorPostId: postId.value,
  239. })
  240. })
  241. </script>
  242. <style lang="scss" scoped>
  243. .dialog {
  244. background: #fff;
  245. border-radius: 25px;
  246. max-width: 1000px;
  247. min-width: 800px;
  248. max-height: 90%;
  249. z-index: 23;
  250. display: flex;
  251. flex-direction: column;
  252. .area-title {
  253. width: 100%;
  254. height: 48px;
  255. display: flex;
  256. align-items: center;
  257. border-bottom: 1px solid #D9D9D9;
  258. font-weight: 500;
  259. font-size: 16px;
  260. letter-spacing: 0.3px;
  261. color: #000000;
  262. img {
  263. width: 24p;
  264. height: 24px;
  265. margin-left: 14px;
  266. margin-right: 12px;
  267. cursor: pointer;
  268. }
  269. }
  270. .area-content {
  271. display: flex;
  272. overflow-y: auto;
  273. flex: 1;
  274. .left {
  275. width: 400px;
  276. margin: 40px 56px 0 56px;
  277. img {
  278. max-width: 400px;
  279. max-height: 400px;
  280. width: 100%;
  281. height: auto;
  282. }
  283. p {
  284. margin: 0;
  285. padding: 0;
  286. }
  287. .tip {
  288. margin-top: 15px;
  289. font-size: 16px;
  290. display: flex;
  291. justify-content: space-between;
  292. div {
  293. display: flex;
  294. align-items: center;
  295. }
  296. img {
  297. margin-right: 4px;
  298. width: 14px;
  299. height: 14px;
  300. }
  301. }
  302. }
  303. .right {
  304. margin: 30px 56px 0px 30px;
  305. .card-content {
  306. float: right;
  307. width: 430px;
  308. padding-bottom: 22px;
  309. .card-title {
  310. margin-bottom: 12px;
  311. display: flex;
  312. align-items: center;
  313. .img {
  314. width: 20px;
  315. height: 20px;
  316. margin-right: 8px;
  317. }
  318. .font {
  319. font-size: 17px;
  320. font-weight: 500;
  321. span {
  322. color: #0091e9;
  323. }
  324. }
  325. }
  326. .card-list {
  327. padding: 20px;
  328. border-radius: 20px;
  329. border: 1px solid #E6E6E6;
  330. .item {
  331. display: flex;
  332. justify-content: space-between;
  333. align-items: center;
  334. height: 47px;
  335. font-size: 14px;
  336. font-weight: 500;
  337. box-shadow: inset 0px -1px 0px #EAEAEA;
  338. }
  339. }
  340. }
  341. }
  342. }
  343. .pay {
  344. width: 200px;
  345. height: 50px;
  346. font-weight: 700;
  347. font-size: 18px;
  348. margin-right: 30px;
  349. color: #FFFFFF;
  350. background: #1D9BF0;
  351. border-radius: 10000px;
  352. text-align: center;
  353. line-height: 50px;
  354. cursor: pointer;
  355. p {
  356. margin: 0;
  357. padding: 0;
  358. }
  359. }
  360. .footer {
  361. border-top: 1px solid #D9D9D9;
  362. height: 80px;
  363. width: 100%;
  364. display: flex;
  365. align-items: center;
  366. justify-content: flex-end;
  367. position: relative;
  368. .sold {
  369. position: absolute;
  370. left: 20px;
  371. }
  372. .limit {
  373. color: #AF934E;
  374. margin-right: 25px;
  375. }
  376. .buy5 {
  377. border: 1px solid #1D9BF0;
  378. background: rgba(29, 155, 240, 0.01);
  379. border-radius: 100px;
  380. color: #1D9BF0;
  381. width: 217px;
  382. height: 50px;
  383. display: flex;
  384. justify-content: space-between;
  385. align-items: center;
  386. padding: 0 15px 0 20px;
  387. font-weight: 700;
  388. font-size: 18px;
  389. cursor: pointer;
  390. margin-right: 12px;
  391. .off {
  392. color: #AF934E;
  393. font-weight: 700;
  394. font-size: 14px;
  395. letter-spacing: 0.3px;
  396. }
  397. .usdt {
  398. color: #1D9BF0;
  399. font-size: 14px;
  400. font-weight: 700;
  401. }
  402. }
  403. .buy1 {
  404. cursor: pointer;
  405. background: #1D9BF0;
  406. color: #fff;
  407. border-radius: 100px;
  408. min-width: 217px;
  409. min-height: 50px;
  410. display: flex;
  411. align-items: center;
  412. font-size: 14px;
  413. font-weight: 700;
  414. justify-content: space-between;
  415. padding: 0 15px 0 20px;
  416. margin-right: 25px;
  417. .left {
  418. margin-right: 20px;
  419. }
  420. .right {
  421. text-align: right;
  422. p {
  423. margin: 0;
  424. padding: 0;
  425. line-height: 17px;
  426. }
  427. }
  428. }
  429. .grey {
  430. background: #CDCDCD;
  431. cursor: not-allowed;
  432. }
  433. }
  434. }
  435. </style>