pay.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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 router from "@/router/buy-nft.js";
  87. import { ref, onMounted, inject, reactive } from 'vue'
  88. import topUp2 from "@/view/iframe/publish/components/top-up2.vue";
  89. import { getCurrencyInfoByCode } from "@/http/publishApi";
  90. import PreviewBalance from "@/view/components/preview-balance.vue";
  91. import BtnLoading from '../components/btn-loading.vue'
  92. import { payNftMysteryBoxWithBalance } from "@/http/pay";
  93. import { getChromeStorage } from "@/uilts/chromeExtension"
  94. import { ElMessage } from 'element-plus'
  95. import "element-plus/es/components/message/style/css";
  96. import { sendChromeTabMessage } from '@/uilts/chromeExtension.js';
  97. let pay_info = inject('pay_info');
  98. let state = reactive({
  99. loading: {
  100. show: false
  101. },
  102. is_btn_grey: true
  103. })
  104. let currentCurrencyInfo = reactive({
  105. currencyCode: "",
  106. currencyName: "",
  107. balance: "",
  108. });
  109. let dialogStyle = reactive({
  110. height: '800'
  111. })
  112. const updateData = (obj_data) => {
  113. if (Number(obj_data.balance) >= Number(pay_info.home.sale_plan.price)) {
  114. state.is_btn_grey = false
  115. }
  116. }
  117. const clickBack = () => {
  118. router.back()
  119. }
  120. const clickPlay = () => {
  121. state.loading.show = true
  122. payNftMysteryBoxWithBalance({
  123. params: {
  124. nftProjectId: pay_info.home.nftProjectId,
  125. salePlanId: pay_info.home.sale_plan.salePlanId,
  126. nftGroupId: pay_info.nft_group_Id
  127. }
  128. }).then((res) => {
  129. state.loading.show = false
  130. if (res.code == 0) {
  131. pay_info.buy_items = res.data.buyItems
  132. sendChromeTabMessage({ actionType: "FINISH_GROUP_BANNNER" }, () => { })
  133. router.push({ path: '/open_box' });
  134. } else {
  135. let msg = ''
  136. switch (res.code.toString()) {
  137. case '5001':
  138. msg = 'nft project not exist'
  139. break;
  140. case '5002':
  141. msg = 'nft project not available'
  142. break
  143. case '5101':
  144. msg = 'nft sale plan not exist'
  145. break
  146. case '5102':
  147. msg = 'nft sold out'
  148. break
  149. case '5103':
  150. msg = 'Purchase limit reached'
  151. break
  152. default:
  153. console.log(res.msg)
  154. }
  155. ElMessage({
  156. message: msg,
  157. grouping: true,
  158. type: 'warning',
  159. offset: -16,
  160. appendTo: document.body
  161. })
  162. }
  163. }).catch(() => {
  164. state.loading.show = false
  165. })
  166. }
  167. // 余额是否同步中
  168. let asyncIng = ref(false);
  169. //临时货币信息
  170. let tempCurrentCurrencyInfo = ref({});
  171. const getLocalCurrencyInfoByCode = () => {
  172. if (currentCurrencyInfo.currencyCode) {
  173. getCurrencyInfo();
  174. }
  175. }
  176. const getCurrencyInfo = async () => {
  177. let { accessToken = '' } = await getChromeStorage('userInfo') || {};
  178. if (accessToken) {
  179. getCurrencyInfoByCode({
  180. params: {
  181. currencyCode: currentCurrencyInfo.currencyCode
  182. }
  183. }).then(res => {
  184. if (res.code == 0 && res.data) {
  185. currentCurrencyInfo = res.data;
  186. tempCurrentCurrencyInfo.value = res.data;
  187. }
  188. });
  189. }
  190. }
  191. const setDialogStyle = () => {
  192. let clientHeight = window.innerHeight;
  193. if(clientHeight >= 840) {
  194. dialogStyle.height = 800;
  195. } else {
  196. dialogStyle.height = clientHeight - 40;
  197. }
  198. }
  199. onMounted(() => {
  200. currentCurrencyInfo.currencyCode = pay_info.home.sale_plan.currencyCode
  201. getLocalCurrencyInfoByCode();
  202. setDialogStyle()
  203. })
  204. </script>
  205. <style lang="scss" scoped>
  206. .dialog {
  207. background: #fff;
  208. border-radius: 25px;
  209. max-width: 1000px;
  210. min-width: 800px;
  211. max-height: 90%;
  212. z-index: 23;
  213. display: flex;
  214. flex-direction: column;
  215. .area-title {
  216. width: 100%;
  217. height: 48px;
  218. display: flex;
  219. align-items: center;
  220. border-bottom: 1px solid #D9D9D9;
  221. font-weight: 500;
  222. font-size: 16px;
  223. letter-spacing: 0.3px;
  224. color: #000000;
  225. img {
  226. width: 24p;
  227. height: 24px;
  228. margin-left: 14px;
  229. margin-right: 12px;
  230. cursor: pointer;
  231. }
  232. }
  233. .area-content {
  234. display: flex;
  235. overflow-y: auto;
  236. flex: 1;
  237. .left {
  238. width: 400px;
  239. margin: 40px 56px 0 56px;
  240. img {
  241. max-width: 400px;
  242. max-height: 400px;
  243. width: 100%;
  244. height: auto;
  245. }
  246. p {
  247. margin: 0;
  248. padding: 0;
  249. }
  250. .tip {
  251. margin-top: 15px;
  252. font-size: 16px;
  253. display: flex;
  254. justify-content: space-between;
  255. div {
  256. display: flex;
  257. align-items: center;
  258. }
  259. img {
  260. margin-right: 4px;
  261. width: 14px;
  262. height: 14px;
  263. }
  264. }
  265. }
  266. .right {
  267. margin: 30px 56px 0px 30px;
  268. .card-content {
  269. float: right;
  270. width: 430px;
  271. padding-bottom: 22px;
  272. .card-title {
  273. margin-bottom: 12px;
  274. display: flex;
  275. align-items: center;
  276. .img {
  277. width: 20px;
  278. height: 20px;
  279. margin-right: 8px;
  280. }
  281. .font {
  282. font-size: 17px;
  283. font-weight: 500;
  284. span {
  285. color: #0091e9;
  286. }
  287. }
  288. }
  289. .card-list {
  290. padding: 20px;
  291. border-radius: 20px;
  292. border: 1px solid #E6E6E6;
  293. .item {
  294. display: flex;
  295. justify-content: space-between;
  296. align-items: center;
  297. height: 47px;
  298. font-size: 14px;
  299. font-weight: 500;
  300. box-shadow: inset 0px -1px 0px #EAEAEA;
  301. }
  302. }
  303. }
  304. }
  305. }
  306. .pay {
  307. width: 200px;
  308. height: 50px;
  309. font-weight: 700;
  310. font-size: 18px;
  311. margin-right: 30px;
  312. color: #FFFFFF;
  313. background: #1D9BF0;
  314. border-radius: 10000px;
  315. text-align: center;
  316. line-height: 50px;
  317. cursor: pointer;
  318. p {
  319. margin: 0;
  320. padding: 0;
  321. }
  322. }
  323. .footer {
  324. border-top: 1px solid #D9D9D9;
  325. height: 80px;
  326. width: 100%;
  327. display: flex;
  328. align-items: center;
  329. justify-content: flex-end;
  330. position: relative;
  331. .sold {
  332. position: absolute;
  333. left: 20px;
  334. }
  335. .limit {
  336. color: #AF934E;
  337. margin-right: 25px;
  338. }
  339. .buy5 {
  340. border: 1px solid #1D9BF0;
  341. background: rgba(29, 155, 240, 0.01);
  342. border-radius: 100px;
  343. color: #1D9BF0;
  344. width: 217px;
  345. height: 50px;
  346. display: flex;
  347. justify-content: space-between;
  348. align-items: center;
  349. padding: 0 15px 0 20px;
  350. font-weight: 700;
  351. font-size: 18px;
  352. cursor: pointer;
  353. margin-right: 12px;
  354. .off {
  355. color: #AF934E;
  356. font-weight: 700;
  357. font-size: 14px;
  358. letter-spacing: 0.3px;
  359. }
  360. .usdt {
  361. color: #1D9BF0;
  362. font-size: 14px;
  363. font-weight: 700;
  364. }
  365. }
  366. .buy1 {
  367. cursor: pointer;
  368. background: #1D9BF0;
  369. color: #fff;
  370. border-radius: 100px;
  371. min-width: 217px;
  372. min-height: 50px;
  373. display: flex;
  374. align-items: center;
  375. font-size: 14px;
  376. font-weight: 700;
  377. justify-content: space-between;
  378. padding: 0 15px 0 20px;
  379. margin-right: 25px;
  380. .left {
  381. margin-right: 20px;
  382. }
  383. .right {
  384. text-align: right;
  385. p {
  386. margin: 0;
  387. padding: 0;
  388. line-height: 17px;
  389. }
  390. }
  391. }
  392. .grey {
  393. background: #CDCDCD;
  394. cursor: not-allowed;
  395. }
  396. }
  397. }
  398. </style>