优化购买流程

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

@ -13,19 +13,26 @@
<!-- <view class="uni-flex-item" v-for="coin in coinType" :key="coin">
{{coin}}&nbsp;:&nbsp;&nbsp;<label class="coinB">{{balabces[coin]}}</label>
</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-else class="uni-flex-item">USDT&nbsp;:&nbsp;&nbsp;<label class="coinB">{{Number(balabces.USDT)}}</label></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-else class="uni-flex-item">USDT&nbsp;:&nbsp;&nbsp;<label
class="coinB">{{Number(balabces.USDT)}}</label></view>
</view>
</view>
<view class="uni-flex-item name">交易數量</view>
<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 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>
<u-toast ref="uToast"></u-toast>
</view>
@ -33,8 +40,13 @@
<script>
import item from '@/components/smarttrading/item.vue';
import { _buy } from "@/request/aiInvestApi.js"
import { _pushBuyInfo } from "@/request/api.js"
import {
_buy
} from "@/request/aiInvestApi.js"
import {
_pushBuyInfo,
_getcharge
} from "@/request/api.js"
export default {
components: {
@ -45,7 +57,12 @@
value: 1,
id: '',
detail: null,
min:{'BNB':'0.2','ETH':'0.01','BTC':'0.001','USDT':100},
min: {
'BNB': '0.2',
'ETH': '0.01',
'BTC': '0.001',
'USDT': 100
},
coinType: ['BNB', 'ETH', 'BTC'],
balabces: {},
userInfo: {},
@ -55,8 +72,11 @@
async onLoad(options) {
await this.syncBuyInfos()
uni.showLoading({mask: true})
this.balabces = JSON.parse(uni.getStorageSync('balabces'))
await this.loadMoney()
uni.showLoading({
mask: true
})
// this.balabces = JSON.parse(uni.getStorageSync('balabces'))
this.userInfo = JSON.parse(uni.getStorageSync('infos'))
//
this.id = options.id;
@ -71,6 +91,19 @@
uni.removeStorageSync(this.id)
},
methods: {
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') {
@ -82,14 +115,19 @@
const buyInfos = uni.getStorageSync('bInfo') || null
if (buyInfos) {
uni.removeStorageSync('bInfo')
uni.showLoading({ mask: true ,title:'正在檢測數據...'})
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})
const noSave = res.filter(r => {
return r.code !== 1
})
uni.setStorageSync('bInfo', JSON.stringify(noSave))
})
uni.hideLoading()
@ -155,7 +193,9 @@
this.loading = false
return
}
uni.showLoading({ mask: true })
uni.showLoading({
mask: true
})
const data = {
id: this.detail.id,
orderId: this.detail.orderId,
@ -164,40 +204,23 @@
money: this.value,
money_wallet: this.userInfo.wallet.address
}
_buy(data).then( (res)=>{
if(res.status === 200){
let _res = res.data
_res.id = data.id
_res.money = data.money
_res.createTimes = this.$moment().valueOf()
this.$refs.uToast.show({
_pushBuyInfo({
'buyinfo': data,
money: this.value,
...this.detail
}).then((res) => {
let toast = {
type: "success",
position: 'bottom',
message: "購買成功",
});
_pushBuyInfo(_res).then().catch(err=>{
let buyInfos = uni.getStorageSync('bInfo') || null
if(buyInfos){
buyInfos.push(_res)
uni.setStorageSync('bInfo',JSON.stringify(buyInfos))
}
}).finally(e=>{
uni.$emit('updateView',{})
uni.hideLoading()
this.loading = false
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}`,
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()
@ -206,7 +229,6 @@
}
});
})
},
}
}
@ -224,12 +246,14 @@
margin-top: 12px;
text-indent: 12px;
line-height: 48px;
.coinB {
display: inline-block;
color: #1ABA84;
line-height: 48px;
}
}
background-color: #000033;
height: 100vh;
padding: 32rpx;
@ -264,6 +288,7 @@
text-align: center;
margin-bottom: 24rpx;
}
.buy-box {
box-sizing: border-box;
width: 100%;
@ -280,4 +305,3 @@
}
}
</style>

View File

@ -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