pay.vue 12 KB

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