优化购买流程

This commit is contained in:
zhongshilong 2025-04-29 10:22:35 +08:00
parent c4fee3f5c5
commit 5f55a31e30
2 changed files with 306 additions and 282 deletions

View File

@ -5,36 +5,48 @@
<view class="info"> <view class="info">
<view class="uni-flex-item name">產品信息</view> <view class="uni-flex-item name">產品信息</view>
<item :detail="detail" /> <item :detail="detail" />
<view class="uni-flex-item name"> <view class="uni-flex-item name">
{{detail.optionType === 'PUT'?'可用餘額':'可交易數量'}} {{detail.optionType === 'PUT'?'可用餘額':'可交易數量'}}
</view> </view>
<view class="balance"> <view class="balance">
<view class="uni-flex uni-column"> <view class="uni-flex uni-column">
<!-- <view class="uni-flex-item" v-for="coin in coinType" :key="coin"> <!-- <view class="uni-flex-item" v-for="coin in coinType" :key="coin">
{{coin}}&nbsp;:&nbsp;&nbsp;<label class="coinB">{{balabces[coin]}}</label> {{coin}}&nbsp;:&nbsp;&nbsp;<label class="coinB">{{balabces[coin]}}</label>
</view> --> </view> -->
<view v-if="detail.optionType !== 'PUT'" class="uni-flex-item">{{detail.investCoin}}&nbsp;:&nbsp;&nbsp;<label class="coinB">{{Number(balabces[detail.investCoin])}}</label></view> <view v-if="detail.optionType !== 'PUT'" class="uni-flex-item">
<view v-else class="uni-flex-item">USDT&nbsp;:&nbsp;&nbsp;<label class="coinB">{{Number(balabces.USDT)}}</label></view> {{detail.investCoin}}&nbsp;:&nbsp;&nbsp;<label
class="coinB">{{Number(balabces[detail.investCoin])}}</label>
</view>
<view v-else class="uni-flex-item">USDT&nbsp;:&nbsp;&nbsp;<label
class="coinB">{{Number(balabces.USDT)}}</label></view>
</view> </view>
</view> </view>
<view class="uni-flex-item name">交易數量</view> <view class="uni-flex-item name">交易數量</view>
<view class="uni-flex-item"> <view class="uni-flex-item">
<input :class="{'disabled' :!detail.canPurchase || !isTrue() || loading}" :disabled="!detail.canPurchase || !isTrue() || loading" v-model="value" class="input" placeholder="請輸入" /> <input :class="{'disabled' :!detail.canPurchase || !isTrue() || loading}"
:disabled="!detail.canPurchase || !isTrue() || loading" v-model="value" class="input"
placeholder="請輸入" />
</view> </view>
</view> </view>
</view> </view>
</view> </view>
<view style="margin-top: 32px;" v-if="detail.canPurchase"> <view style="margin-top: 32px;" v-if="detail.canPurchase">
<button type="primary" :disabled="!detail.canPurchase || !isTrue() || loading" @click="buy" class="btn" :class="{'disabled' :!detail.canPurchase || !isTrue() || loading}" >{{loading?'处 理 中':'確 定 交 易'}}</button> <button type="primary" @click="buy" class="btn" :disabled="!detail.canPurchase || !isTrue() || loading"
:class="{'disabled' :!detail.canPurchase || !isTrue() || loading}">{{loading?'处 理 中':'確 定 交 易'}}</button>
</view> </view>
<u-toast ref="uToast"></u-toast> <u-toast ref="uToast"></u-toast>
</view> </view>
</template> </template>
<script> <script>
import item from '@/components/smarttrading/item.vue'; import item from '@/components/smarttrading/item.vue';
import { _buy } from "@/request/aiInvestApi.js" import {
import { _pushBuyInfo } from "@/request/api.js" _buy
} from "@/request/aiInvestApi.js"
import {
_pushBuyInfo,
_getcharge
} from "@/request/api.js"
export default { export default {
components: { components: {
@ -45,24 +57,32 @@
value: 1, value: 1,
id: '', id: '',
detail: null, detail: null,
min:{'BNB':'0.2','ETH':'0.01','BTC':'0.001','USDT':100}, min: {
coinType:['BNB','ETH','BTC'], 'BNB': '0.2',
balabces:{}, 'ETH': '0.01',
userInfo:{}, 'BTC': '0.001',
loading:false, 'USDT': 100
},
coinType: ['BNB', 'ETH', 'BTC'],
balabces: {},
userInfo: {},
loading: false,
} }
}, },
async onLoad(options) { async onLoad(options) {
await this.syncBuyInfos() await this.syncBuyInfos()
uni.showLoading({mask: true}) await this.loadMoney()
this.balabces = JSON.parse(uni.getStorageSync('balabces')) uni.showLoading({
mask: true
})
// this.balabces = JSON.parse(uni.getStorageSync('balabces'))
this.userInfo = JSON.parse(uni.getStorageSync('infos')) this.userInfo = JSON.parse(uni.getStorageSync('infos'))
// //
this.id = options.id; this.id = options.id;
setTimeout(() => { setTimeout(() => {
const obj = JSON.parse(uni.getStorageSync(this.id)) const obj = JSON.parse(uni.getStorageSync(this.id))
this.value = obj.optionType === 'PUT'? this.min.USDT: this.min[obj.investCoin] this.value = obj.optionType === 'PUT' ? this.min.USDT : this.min[obj.investCoin]
this.detail = {...obj} this.detail = {...obj}
uni.hideLoading() uni.hideLoading()
}, 600) }, 600)
@ -71,142 +91,144 @@
uni.removeStorageSync(this.id) uni.removeStorageSync(this.id)
}, },
methods: { methods: {
isTrue(){ 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 let val = this.balabces.USDT
if(this.detail.optionType === 'CALL'){ if (this.detail.optionType === 'CALL') {
val = this.balabces[this.detail.investCoin] val = this.balabces[this.detail.investCoin]
} }
return Number(val) > 0 && Number(val) >= this.value return Number(val) > 0 && Number(val) >= this.value
}, },
async syncBuyInfos(){ async syncBuyInfos() {
const buyInfos = uni.getStorageSync('bInfo') || null const buyInfos = uni.getStorageSync('bInfo') || null
if(buyInfos){ if (buyInfos) {
uni.removeStorageSync('bInfo') uni.removeStorageSync('bInfo')
uni.showLoading({ mask: true ,title:'正在檢測數據...'}) uni.showLoading({
const arr = JSON.parse(buyInfos) mask: true,
let pall = [] title: '正在檢測數據...'
arr.map(item =>{ })
pall.push(_pushBuyInfo(item)) const arr = JSON.parse(buyInfos)
}) let pall = []
Promise.all(pall).then(res =>{ arr.map(item => {
const noSave = res.filter(r => {return r.code !== 1}) pall.push(_pushBuyInfo(item))
uni.setStorageSync('bInfo',JSON.stringify(noSave)) })
}) Promise.all(pall).then(res => {
uni.hideLoading() 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
}, },
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() { async buy() {
this.loading = true this.loading = true
if(!Number(this.userInfo.miner_G) >= 1){ if(!Number(this.userInfo.miner_G) >= 1){
uni.showToast({ uni.showToast({
title: '購買1G以上算力才可交易', title: '購買1G以上算力才可交易',
icon:"none" icon:"none"
}) })
this.loading = false this.loading = false
return return
} }
let cobj = this.checkTypeAndValue(this.detail.investCoin,this.value) let cobj = this.checkTypeAndValue(this.detail.investCoin,this.value)
if(!cobj.isCross){ if(!cobj.isCross){
uni.showToast({ uni.showToast({
title: cobj.message, title: cobj.message,
icon:"none" icon:"none"
}) })
this.loading = false this.loading = false
return return
} }
uni.showLoading({ mask: true }) uni.showLoading({
mask: true
})
const data = { const data = {
id: this.detail.id, id: this.detail.id,
orderId: this.detail.orderId, orderId: this.detail.orderId,
type: this.detail.optionType, type: this.detail.optionType,
name:this.userInfo.email, name: this.userInfo.email,
money:this.value, money: this.value,
money_wallet:this.userInfo.wallet.address money_wallet: this.userInfo.wallet.address
} }
_buy(data).then( (res)=>{ _pushBuyInfo({
if(res.status === 200){ 'buyinfo': data,
let _res = res.data money: this.value,
_res.id = data.id ...this.detail
_res.money = data.money }).then((res) => {
_res.createTimes = this.$moment().valueOf() let toast = {
this.$refs.uToast.show({ type: "success",
type: "success", position: 'bottom',
position:'bottom', duration: 3000,
message: "購買成功", message: "購買成功"
}); }
_pushBuyInfo(_res).then().catch(err=>{ if (res.code === 0) {
let buyInfos = uni.getStorageSync('bInfo') || null toast.type = 'error'
if(buyInfos){ toast.message = res.data.hasOwnProperty('error') ? '當前產品火熱搶購中,下單失敗,請選擇其他產品購買.' : res.msg
buyInfos.push(_res) }
uni.setStorageSync('bInfo',JSON.stringify(buyInfos)) this.$refs.uToast.show({
} ...toast,
complete: () => {
}).finally(e=>{ uni.$emit('updateView', {})
uni.$emit('updateView',{}) uni.hideLoading()
uni.hideLoading() this.loading = false
this.loading = false uni.navigateBack()
uni.navigateBack() }
}) });
}
}).catch(err => {
// const error = JSON.parse(err.response.data.error.replace("HTTP :",""))
this.$refs.uToast.show({
type: "error",
position:'bottom',
duration:3000,
message:'當前產品火熱搶購中,下單失敗,請選擇其他產品購買.',
// message: `${error.code},${error.msg}`,
complete:()=>{
uni.$emit('updateView',{})
uni.hideLoading()
this.loading = false
uni.navigateBack()
}
});
}) })
}, },
} }
} }
@ -214,7 +236,7 @@
<style lang="scss" scoped> <style lang="scss" scoped>
.box { .box {
.balance{ .balance {
background-color: rgba(0, 0, 0, .1); background-color: rgba(0, 0, 0, .1);
border-radius: 8px; border-radius: 8px;
color: #666; color: #666;
@ -224,12 +246,14 @@
margin-top: 12px; margin-top: 12px;
text-indent: 12px; text-indent: 12px;
line-height: 48px; line-height: 48px;
.coinB{
.coinB {
display: inline-block; display: inline-block;
color: #1ABA84; color: #1ABA84;
line-height: 48px; line-height: 48px;
} }
} }
background-color: #000033; background-color: #000033;
height: 100vh; height: 100vh;
padding: 32rpx; padding: 32rpx;
@ -264,13 +288,14 @@
text-align: center; text-align: center;
margin-bottom: 24rpx; margin-bottom: 24rpx;
} }
.buy-box { .buy-box {
box-sizing: border-box; box-sizing: border-box;
width: 100%; width: 100%;
min-height: 20vh; min-height: 20vh;
background-color: #fff; background-color: #fff;
border-radius: 12px; border-radius: 12px;
padding:24rpx; padding: 24rpx;
.info { .info {
background-color: #F4F6F8; background-color: #F4F6F8;
@ -280,4 +305,3 @@
} }
} }
</style> </style>

View File

@ -15,7 +15,7 @@ request.defaults.headers.post['content-type'] = 'application/json';//发送请
request.interceptors.request.use((request) => { request.interceptors.request.use((request) => {
let token = uni.getStorageSync('token'); let token = uni.getStorageSync('token');
if(process.env.NODE_ENV === 'development' && !token){ if(process.env.NODE_ENV === 'development' && !token){
token = '06b8c5ed-120d-4533-a3f9-9d50735bf341' token = 'a91c32b7-f3a1-4900-8c55-ece1e1d4696c'
} }
// console.log("token",token); // console.log("token",token);
// 请求头是否携带token // 请求头是否携带token