优化购买流程
This commit is contained in:
parent
c4fee3f5c5
commit
5f55a31e30
@ -5,36 +5,48 @@
|
||||
<view class="info">
|
||||
<view class="uni-flex-item name">產品信息</view>
|
||||
<item :detail="detail" />
|
||||
<view class="uni-flex-item name">
|
||||
{{detail.optionType === 'PUT'?'可用餘額':'可交易數量'}}
|
||||
</view>
|
||||
<view class="uni-flex-item name">
|
||||
{{detail.optionType === 'PUT'?'可用餘額':'可交易數量'}}
|
||||
</view>
|
||||
<view class="balance">
|
||||
<view class="uni-flex uni-column">
|
||||
<!-- <view class="uni-flex-item" v-for="coin in coinType" :key="coin">
|
||||
{{coin}} : <label class="coinB">{{balabces[coin]}}</label>
|
||||
</view> -->
|
||||
<view v-if="detail.optionType !== 'PUT'" class="uni-flex-item">{{detail.investCoin}} : <label class="coinB">{{Number(balabces[detail.investCoin])}}</label></view>
|
||||
<view v-else class="uni-flex-item">USDT : <label class="coinB">{{Number(balabces.USDT)}}</label></view>
|
||||
<view v-if="detail.optionType !== 'PUT'" class="uni-flex-item">
|
||||
{{detail.investCoin}} : <label
|
||||
class="coinB">{{Number(balabces[detail.investCoin])}}</label>
|
||||
</view>
|
||||
<view v-else class="uni-flex-item">USDT : <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>
|
||||
<u-toast ref="uToast"></u-toast>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<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,24 +57,32 @@
|
||||
value: 1,
|
||||
id: '',
|
||||
detail: null,
|
||||
min:{'BNB':'0.2','ETH':'0.01','BTC':'0.001','USDT':100},
|
||||
coinType:['BNB','ETH','BTC'],
|
||||
balabces:{},
|
||||
userInfo:{},
|
||||
loading:false,
|
||||
min: {
|
||||
'BNB': '0.2',
|
||||
'ETH': '0.01',
|
||||
'BTC': '0.001',
|
||||
'USDT': 100
|
||||
},
|
||||
coinType: ['BNB', 'ETH', 'BTC'],
|
||||
balabces: {},
|
||||
userInfo: {},
|
||||
loading: false,
|
||||
}
|
||||
},
|
||||
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;
|
||||
setTimeout(() => {
|
||||
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}
|
||||
uni.hideLoading()
|
||||
}, 600)
|
||||
@ -71,142 +91,144 @@
|
||||
uni.removeStorageSync(this.id)
|
||||
},
|
||||
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
|
||||
if(this.detail.optionType === 'CALL'){
|
||||
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()
|
||||
}
|
||||
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
|
||||
},
|
||||
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 })
|
||||
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
|
||||
name: this.userInfo.email,
|
||||
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({
|
||||
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}`,
|
||||
complete:()=>{
|
||||
uni.$emit('updateView',{})
|
||||
uni.hideLoading()
|
||||
this.loading = false
|
||||
uni.navigateBack()
|
||||
}
|
||||
});
|
||||
_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()
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -214,7 +236,7 @@
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.box {
|
||||
.balance{
|
||||
.balance {
|
||||
background-color: rgba(0, 0, 0, .1);
|
||||
border-radius: 8px;
|
||||
color: #666;
|
||||
@ -224,12 +246,14 @@
|
||||
margin-top: 12px;
|
||||
text-indent: 12px;
|
||||
line-height: 48px;
|
||||
.coinB{
|
||||
|
||||
.coinB {
|
||||
display: inline-block;
|
||||
color: #1ABA84;
|
||||
line-height: 48px;
|
||||
}
|
||||
}
|
||||
|
||||
background-color: #000033;
|
||||
height: 100vh;
|
||||
padding: 32rpx;
|
||||
@ -264,13 +288,14 @@
|
||||
text-align: center;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.buy-box {
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
min-height: 20vh;
|
||||
background-color: #fff;
|
||||
border-radius: 12px;
|
||||
padding:24rpx;
|
||||
padding: 24rpx;
|
||||
|
||||
.info {
|
||||
background-color: #F4F6F8;
|
||||
@ -280,4 +305,3 @@
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user