From 5f55a31e30d31d1227b4af3e5dc5059852b2ac5d Mon Sep 17 00:00:00 2001 From: zhongshilong Date: Tue, 29 Apr 2025 10:22:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B4=AD=E4=B9=B0=E6=B5=81?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/smarttrading/buy.vue | 586 +++++++++++++++++++------------------ request/servies.js | 2 +- 2 files changed, 306 insertions(+), 282 deletions(-) diff --git a/pages/smarttrading/buy.vue b/pages/smarttrading/buy.vue index b1cf94b..0ca34b5 100644 --- a/pages/smarttrading/buy.vue +++ b/pages/smarttrading/buy.vue @@ -1,283 +1,307 @@ - - - - - - + async loadMoney() { + const Money = await _getcharge() + this.balabces = { + 'BNB': '0.00', + 'ETH': '0.00', + 'BTC': '0.00', + 'USDT': '0.00' + } + Money.data.map(item => { + this.balabces[item.coin] = item.amount + }) + uni.setStorageSync('balabces', JSON.stringify(this.balabces)) + }, + isTrue() { + let val = this.balabces.USDT + if (this.detail.optionType === 'CALL') { + val = this.balabces[this.detail.investCoin] + } + return Number(val) > 0 && Number(val) >= this.value + }, + async syncBuyInfos() { + const buyInfos = uni.getStorageSync('bInfo') || null + if (buyInfos) { + uni.removeStorageSync('bInfo') + uni.showLoading({ + mask: true, + title: '正在檢測數據...' + }) + const arr = JSON.parse(buyInfos) + let pall = [] + arr.map(item => { + pall.push(_pushBuyInfo(item)) + }) + Promise.all(pall).then(res => { + const noSave = res.filter(r => { + return r.code !== 1 + }) + uni.setStorageSync('bInfo', JSON.stringify(noSave)) + }) + uni.hideLoading() + } + }, + checkTypeAndValue(type, value) { + let obj = { + message: "", + isCross: false + }; + switch (type) { + case "BNB": + if (value >= 0.2) { + obj.isCross = true + } else { + obj.message = "BNB類型最低購買0.2"; + obj.isCross = false; + } + break; + case "ETH": + if (value >= 0.01) { + obj.isCross = true + } else { + obj.message = "ETH類型最低購買0.01"; + obj.isCross = false; + } + break; + case "BTC": + if (value >= 0.001) { + obj.isCross = true + } else { + obj.message = "BTC類型最低購買0.001"; + obj.isCross = false; + } + break; + case "USDT": + if (value >= 100) { + obj.isCross = true + } else { + obj.message = "USDT類型最低購買100"; + obj.isCross = false; + } + break; + } + return obj + }, + async buy() { + this.loading = true + if(!Number(this.userInfo.miner_G) >= 1){ + uni.showToast({ + title: '購買1G以上算力才可交易', + icon:"none" + }) + this.loading = false + return + } + let cobj = this.checkTypeAndValue(this.detail.investCoin,this.value) + if(!cobj.isCross){ + uni.showToast({ + title: cobj.message, + icon:"none" + }) + this.loading = false + return + } + uni.showLoading({ + mask: true + }) + const data = { + id: this.detail.id, + orderId: this.detail.orderId, + type: this.detail.optionType, + name: this.userInfo.email, + money: this.value, + money_wallet: this.userInfo.wallet.address + } + _pushBuyInfo({ + 'buyinfo': data, + money: this.value, + ...this.detail + }).then((res) => { + let toast = { + type: "success", + position: 'bottom', + duration: 3000, + message: "購買成功" + } + if (res.code === 0) { + toast.type = 'error' + toast.message = res.data.hasOwnProperty('error') ? '當前產品火熱搶購中,下單失敗,請選擇其他產品購買.' : res.msg + } + this.$refs.uToast.show({ + ...toast, + complete: () => { + uni.$emit('updateView', {}) + uni.hideLoading() + this.loading = false + uni.navigateBack() + } + }); + }) + }, + } + } + + + \ No newline at end of file diff --git a/request/servies.js b/request/servies.js index 0e95cb8..683cff6 100644 --- a/request/servies.js +++ b/request/servies.js @@ -15,7 +15,7 @@ request.defaults.headers.post['content-type'] = 'application/json';//发送请 request.interceptors.request.use((request) => { let token = uni.getStorageSync('token'); if(process.env.NODE_ENV === 'development' && !token){ - token = '06b8c5ed-120d-4533-a3f9-9d50735bf341' + token = 'a91c32b7-f3a1-4900-8c55-ece1e1d4696c' } // console.log("token",token); // 请求头是否携带token