优化购买流程

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"> <!-- <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>
@ -33,8 +40,13 @@
<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,7 +57,12 @@
value: 1, value: 1,
id: '', id: '',
detail: null, 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'], coinType: ['BNB', 'ETH', 'BTC'],
balabces: {}, balabces: {},
userInfo: {}, userInfo: {},
@ -55,8 +72,11 @@
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;
@ -71,6 +91,19 @@
uni.removeStorageSync(this.id) uni.removeStorageSync(this.id)
}, },
methods: { 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() { isTrue() {
let val = this.balabces.USDT let val = this.balabces.USDT
if (this.detail.optionType === 'CALL') { if (this.detail.optionType === 'CALL') {
@ -82,14 +115,19 @@
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({
mask: true,
title: '正在檢測數據...'
})
const arr = JSON.parse(buyInfos) const arr = JSON.parse(buyInfos)
let pall = [] let pall = []
arr.map(item => { arr.map(item => {
pall.push(_pushBuyInfo(item)) pall.push(_pushBuyInfo(item))
}) })
Promise.all(pall).then(res => { 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.setStorageSync('bInfo', JSON.stringify(noSave))
}) })
uni.hideLoading() uni.hideLoading()
@ -155,7 +193,9 @@
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,
@ -164,40 +204,23 @@
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',
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, duration: 3000,
message:'當前產品火熱搶購中,下單失敗,請選擇其他產品購買.', message: "購買成功"
// message: `${error.code},${error.msg}`, }
if (res.code === 0) {
toast.type = 'error'
toast.message = res.data.hasOwnProperty('error') ? '當前產品火熱搶購中,下單失敗,請選擇其他產品購買.' : res.msg
}
this.$refs.uToast.show({
...toast,
complete: () => { complete: () => {
uni.$emit('updateView', {}) uni.$emit('updateView', {})
uni.hideLoading() uni.hideLoading()
@ -206,7 +229,6 @@
} }
}); });
}) })
}, },
} }
} }
@ -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,6 +288,7 @@
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%;
@ -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