pay.vue 12 KB

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