index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <div class="payment">
  3. <!-- 选择支付方式 -->
  4. <template v-if="step === 1">
  5. <div class="moneyInfo">
  6. <div class="tips">You Neet to Pay</div>
  7. <div class="money" v-if="salePlans">
  8. <FontZoom width="320">
  9. <template v-if="salePlans && salePlans.currencyCode && salePlans.currencyCode !== 'USD'">
  10. <img class="icon" :src="salePlans.currencyInfo.iconPath" /><span class="info"> {{ salePlans.price }} {{ salePlans.currencyInfo.tokenSymbol }} (${{salePlans.usdPrice}})</span>
  11. </template>
  12. <template v-else>
  13. <span class="info usd">${{salePlans.usdPrice}}</span>
  14. </template>
  15. </FontZoom>
  16. </div>
  17. </div>
  18. <div class="payList">
  19. <div class="detail" v-if="salePlans && salePlans.currencyCode && salePlans.currencyCode !== 'USD'">
  20. <div class="title">Crypto Wallet</div>
  21. <div class="item denet">
  22. <div>
  23. <img src="../../static/payment/icon_wallet.png" />
  24. <span>DeNet Pay</span>
  25. </div>
  26. <div class="wallet">
  27. Balance:150 SHIB
  28. </div>
  29. </div>
  30. <div class="item">
  31. <img src="../../static/payment/icon_meta_mask.png" />
  32. <span>MetaMask</span>
  33. </div>
  34. <div class="item">
  35. <img src="../../static/payment/icon_coinbase_wallet.png" />
  36. <span>Coinbase Wallet</span>
  37. </div>
  38. </div>
  39. <div class="detail" v-if="salePlans && salePlans.currencyCode && salePlans.currencyCode === 'USD'">
  40. <div class="title">Credit/Debit Card</div>
  41. <div class="item denet">
  42. <div>
  43. <img src="../../static/payment/icon_wallet.png" />
  44. <span>DeNet Pay</span>
  45. </div>
  46. <div class="wallet">
  47. Balance:150 SHIB
  48. </div>
  49. </div>
  50. <div class="item">
  51. <img src="../../static/payment/icon_master_card.png" />
  52. <span>MasterCard</span>
  53. </div>
  54. <div class="item">
  55. <img src="../../static/payment/icon_visa.png" />
  56. <span>VISA</span>
  57. </div>
  58. </div>
  59. <div class="detail">
  60. <div class="title">Redemption Code</div>
  61. <div class="item" @click="showRedeem">
  62. <img src="../../static/payment/icon_enter_code.png" />
  63. <span>Enter Code</span>
  64. </div>
  65. </div>
  66. </div>
  67. </template>
  68. <!-- 成功支付 -->
  69. <template v-if="step === 4">
  70. <div class="payInfo">
  71. <div class="picShow" v-if="buyData">
  72. <div class="tip">Wow, NFT in the Mystery box is</div>
  73. <img class="pic" :src="buyData.imagePath" />
  74. <div class="name">{{buyData.nftItemName}}</div>
  75. </div>
  76. </div>
  77. <div class="payBtn">
  78. <button class="btn" @click="jumpGuide">Done</button>
  79. </div>
  80. </template>
  81. <!-- loading -->
  82. <div class="loading" v-if="loading">
  83. <van-loading color="#1D9BF0"></van-loading>
  84. </div>
  85. <div class="loadingBg" v-if="loading"></div>
  86. <!-- redeem -->
  87. <van-popup
  88. round
  89. v-model="redeemLayer"
  90. position="bottom">
  91. <div class="redeem">
  92. <div class="tips">Enter Redemption Code</div>
  93. <div class="footer">
  94. <div class="input">
  95. <input
  96. type="text"
  97. ref="input"
  98. v-model="redeemStr"
  99. @input="textInput"
  100. @blur="textBlur"
  101. @focus="textFocus"
  102. @keydown.enter="redeemPayment" />
  103. </div>
  104. <button
  105. class="enter"
  106. :class="{ disabled: !redeemNext }"
  107. @click="redeemPayment">
  108. Redeem
  109. </button>
  110. </div>
  111. </div>
  112. </van-popup>
  113. </div>
  114. </template>
  115. <script>
  116. import FontZoom from '../../components/FontZoom.vue';
  117. import { postRequest } from '../../http/index';
  118. import { Dialog } from 'vant';
  119. import Api from '../../http/api';
  120. export default {
  121. name: 'payment',
  122. data() {
  123. return {
  124. step: 1, // 1: 支付方式列表 2: 余额支付 3: 充值支付 4: 支付完成
  125. loading: true,
  126. salePlans: null,
  127. redeemStr: '',
  128. redeemNext: false,
  129. redeemLayer: false,
  130. buyData: {},
  131. }
  132. },
  133. head() {
  134. return {
  135. title: 'Buy NFT Mystery Box',
  136. }
  137. },
  138. components: {
  139. FontZoom,
  140. },
  141. mounted() {
  142. this.saleInfo()
  143. },
  144. methods : {
  145. saleInfo () {
  146. postRequest(Api.getNftMysteryBoxSaleInfo, {
  147. params: {
  148. nftProjectId: this.$route.query.nftProjectId
  149. }
  150. }).then(res => {
  151. let { code, data } = res;
  152. if (code === 0) {
  153. this.salePlans = data.salePlans[0];
  154. }
  155. }).finally(() => {
  156. this.loading = false;
  157. })
  158. },
  159. showRedeem() {
  160. this.redeemStr = '';
  161. this.redeemLayer = true;
  162. this.$nextTick(() => {
  163. this.$refs.input.focus();
  164. })
  165. },
  166. textInput(e) {
  167. let len = 16
  168. let str = this.redeemStr.replace(/[^a-zA-Z0-9]/g, '')
  169. str = str.toUpperCase();
  170. str = str.slice(0, len);
  171. // set
  172. this.redeemStr = str;
  173. this.redeemNext = str !== '' && str.length === len;
  174. },
  175. textBlur(e) {
  176. let isiOS = !!window.navigator.userAgent.match(/\(i\[^;]+;( U;)? CPU.+Mac OS X/)
  177. if (isiOS) {
  178. setTimeout(() => {
  179. const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0
  180. window.scrollTo(0, Math.max(scrollHeight - 1, 0))
  181. }, 100)
  182. }
  183. },
  184. textFocus(e) {
  185. let isiOS = !!window.navigator.userAgent.match(/\(i\[^;]+;( U;)? CPU.+Mac OS X/)
  186. if (isiOS) {
  187. setTimeout(() => {
  188. const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0
  189. window.scrollTo(0, Math.max(scrollHeight - 1, 0))
  190. }, 100)
  191. }
  192. },
  193. redeemPayment() {
  194. if (!this.redeemNext) return;
  195. let params = {
  196. redeemCode: this.redeemStr,
  197. nftProjectId: this.$route.query.nftProjectId,
  198. }
  199. this.redeemNext = false;
  200. postRequest(Api.redeemNft, {
  201. params
  202. }).then(res => {
  203. let { code, data } = res;
  204. if (code === 0) {
  205. this.redeemLayer = false;
  206. if (data.length > 0) {
  207. this.buyData = data[0];
  208. }
  209. // 购买成功
  210. this.step = 4;
  211. } else {
  212. let msg;
  213. switch (code.toString()) {
  214. case '5001':
  215. msg = 'nft project not exist'
  216. break;
  217. case '5002':
  218. msg = 'nft project not available'
  219. break
  220. case '5101':
  221. msg = 'nft sale plan not exist'
  222. break
  223. case '5102':
  224. msg = 'nft sold out'
  225. break
  226. case '5103':
  227. msg = 'Purchase limit reached'
  228. break
  229. case '5104':
  230. case '5105':
  231. case '5106':
  232. msg = 'Invalid redemption code'
  233. break;
  234. default:
  235. msg = 'Invalid redemption code, please try again'
  236. break;
  237. }
  238. // Dialog
  239. Dialog({
  240. message: msg,
  241. confirmButtonText: 'OK',
  242. confirmButtonColor: '#1D9BF0',
  243. });
  244. }
  245. }).finally(() => {
  246. this.redeemNext = true;
  247. })
  248. },
  249. jumpGuide() {
  250. this.$router.push({
  251. path: `/nft/${this.$route.query.nftProjectId}/${this.$route.query.account}/show`,
  252. })
  253. },
  254. }
  255. }
  256. </script>
  257. <style lang="scss">
  258. html,
  259. body,
  260. #__nuxt,
  261. #__layout {
  262. width: 100%;
  263. height: 100%;
  264. padding: 0;
  265. margin: 0;
  266. }
  267. .payment {
  268. width: 100%;
  269. height: 100%;
  270. }
  271. .moneyInfo {
  272. display: flex;
  273. align-items: center;
  274. justify-content: center;
  275. flex-direction: column;
  276. height: 90px;
  277. border-bottom: solid 8px rgba($color: #f5f5f5, $alpha: .6);
  278. .tips {
  279. font-size: 12px;
  280. font-weight: 500;
  281. }
  282. .money {
  283. display: flex;
  284. align-items: center;
  285. justify-content: center;
  286. margin-top: 10px;
  287. .icon {
  288. overflow: hidden;
  289. width: 26px;
  290. height: 26px;
  291. border-radius: 50%;
  292. margin-right: 10px;
  293. vertical-align: middle;
  294. background-color: #f5f5f5;
  295. }
  296. .info {
  297. color: #000;
  298. font-size: 20px;
  299. font-weight: 700;
  300. &.usd {
  301. margin-top: -5px;
  302. }
  303. }
  304. }
  305. }
  306. .payList {
  307. overflow-y: auto;
  308. height: calc(100% - 90px);
  309. .detail {
  310. padding: 18px 16px;
  311. .title {
  312. color: #ADADAD;
  313. height: 26px;
  314. font-size: 12px;
  315. font-weight: 500;
  316. }
  317. .item {
  318. display: flex;
  319. align-items: center;
  320. justify-content: center;
  321. font-weight: 500;
  322. font-size: 16px;
  323. height: 50px;
  324. margin-bottom: 14px;
  325. border-radius: 100px;
  326. border: 1px solid #ECECEC;
  327. &:last-child {
  328. margin-bottom: 0;
  329. }
  330. img {
  331. width: 24px;
  332. height: 24px;
  333. margin-right: 4px;
  334. }
  335. &.denet {
  336. flex-direction: column;
  337. img {
  338. margin-top: -6px;
  339. }
  340. }
  341. .wallet {
  342. width: 100%;
  343. color: #ADADAD;
  344. font-size: 11px;
  345. text-align: center;
  346. margin-top: -2px;
  347. }
  348. }
  349. }
  350. }
  351. .loading {
  352. position: absolute;
  353. z-index: 3;
  354. display: flex;
  355. align-items: center;
  356. justify-content: center;
  357. top: 0;
  358. left: 0;
  359. width: 100%;
  360. height: 100%;
  361. }
  362. .loadingBg {
  363. position: absolute;
  364. z-index: 2;
  365. top: 0;
  366. left: 0;
  367. width: 100%;
  368. height: 100%;
  369. background-color: rgba($color: #ffffff, $alpha: .1);
  370. }
  371. .redeem {
  372. padding: 18px 16px 38px;
  373. .tips {
  374. height: 31px;
  375. font-size: 15px;
  376. font-weight: 500;
  377. }
  378. .footer {
  379. display: flex;
  380. justify-content: space-between;
  381. .input {
  382. display: flex;
  383. align-items: center;
  384. justify-content: center;
  385. width: calc(100% - 93px);
  386. height: 45px;
  387. border-radius: 5px;
  388. border: 1px solid #E0E0E0;
  389. input {
  390. width: 94%;
  391. border: 0;
  392. outline: 0;
  393. }
  394. }
  395. .enter {
  396. width: 83px;
  397. height: 45px;
  398. border: 0;
  399. color: #ffffff;
  400. font-size: 17px;
  401. font-weight: 500;
  402. border-radius: 5px;
  403. background: #1D9BF0;
  404. &.disabled {
  405. background: #DEDEDE;
  406. }
  407. }
  408. }
  409. }
  410. .payInfo {
  411. width: 100%;
  412. height: calc(100% - 88px);
  413. .picShow {
  414. padding: 54px 48px;
  415. .tip {
  416. height: 44px;
  417. font-size: 18px;
  418. font-weight: 600;
  419. text-align: center;
  420. }
  421. .pic {
  422. width: 280px;
  423. height: 280px;
  424. border-radius: 3px;
  425. margin-bottom: 20px;
  426. }
  427. .name {
  428. font-size: 18px;
  429. font-weight: 600;
  430. line-height: 21px;
  431. text-align: center;
  432. }
  433. }
  434. }
  435. .payBtn {
  436. padding: 0 16px 38px;
  437. .btn {
  438. width: 100%;
  439. height: 50px;
  440. color: #FFFFFF;
  441. font-size: 18px;
  442. font-weight: 700;
  443. border-radius: 50px;
  444. background: #1D9BF0;
  445. }
  446. }
  447. </style>