question_uniapp/pages/wallet/putforward.vue
2025-06-06 03:08:19 +08:00

249 lines
8.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="page">
<nav-bar title="Put forward" bgColor="#fff">
<image slot="right" style="width: 40rpx; height: 40rpx; margin-right: 20px;" src="/static/images/r2.png" mode="cover" @click="onTokenJump('/pages/wallet/fundrecords?id=3')"></image>
</nav-bar>
<view style="width: 92%; margin: 10px auto; padding: 15px 10px;">
<uni-forms :modelValue="putmodel" label-position="top" :rules="rules" ref="form">
<uni-forms-item name="address">
<view style="padding-bottom: 10px;">
<view style="float: left; font-size: 16px; color: #333; font-weight: 400;">Address</view>
<view style="float: right; font-size: 14px; color: #333; font-weight: 400;" @click="onPageJump('/pages/wallet/switchnetwork')">
<image style="width: 18px; height: 18px; float: left;" v-if="network=='TRC-20'" src="/static/images/s1.png" mode="cover"></image>
<span style="margin-left: 10px; float: left;" v-if="network=='TRC-20'">Tron(TRC20)</span>
<image style="width: 18px; height: 18px; float: left;" v-if="network=='BEP-20'" src="/static/images/s2.png" mode="cover"></image>
<span style="margin-left: 10px; float: left;" v-if="network=='BEP-20'">BSC-BNB(BEP20)</span>
<uni-icons size="20" type="down" style=" margin-left: 10px;"></uni-icons>
</view>
<view style="clear: both;"></view>
</view>
<view>
<uni-easyinput type="text" v-model="putmodel.address" placeholder="Enter address">
<template #right>
<picker :range="formattedItems" mode="selector" @change="onPickerChange">
<image src="/static/images/r4.png" style="float: left; width: 40rpx; height: 40rpx; margin-right: 20rpx;"></image>
</picker>
</template>
</uni-easyinput>
</view>
</uni-forms-item>
<uni-forms-item label="Withdrawal amount" labelWidth="400rpx" name="amount">
<view>
<uni-easyinput type="number" v-model="putmodel.amount" :placeholder="'At least ' + withdrawlminimum + ' U'">
<template #right>
<view style="float: left; font-size: 12px;">USDT</view>
<view style="margin:20rpx; float: right;">
<span class="s" @click="max">Max</span></view>
</template>
</uni-easyinput>
</view>
<view style="font-size: 14px; color: #999; font-weight: 500; line-height: 50upx;">Available balance
<span style="color: #1D61E7;">{{user.money }} USDT</span></view>
</uni-forms-item>
<uni-forms-item label="PIN code" name="pincode">
<uni-easyinput type="password" :passwordIcon="true" v-model="putmodel.pincode" placeholder="Enter PIN code" />
</uni-forms-item>
</uni-forms>
</view>
<view style="bottom: 0px; position: absolute; width:100vw; height: 180px;">
<view class="cell_list">
<view class="cell_left txt">Network costs</view>
<view class="cell_right ">{{costs}} USDT</view>
</view>
<view class="cell_list">
<view class="cell_left txt">Expected arrival</view>
<view class="cell_right" style="font-size: 18px; font-weight: 600;">{{totalAmount}} USDT</view>
</view>
<view class="cell_list">
<button type="primary" round style="width: 100%;" @click="submit">Submit</button>
</view>
</view>
</view>
</template>
<script>
import { getUserInfo } from '@/config/utils';
import {
mapState,
mapMutations
} from 'vuex';
export default {
data() {
return {
network:'TRC-20',
costs: 0.00,
totalAmount: 0.00,
withdrawlminimum: 1,
putmodel: {
address: '',
addressId: '',
amount: '',
pincode: '',
},
init:{},
user:{},
addressList: [],
rules: {
address: {
rules:[{required: true,errorMessage: this.$t('putforward.text1')}],
},
amount:{
rules:[
{required: true,errorMessage: this.$t('putforward.text2')},
// {validateFunction:function(rule, value, data, callback){
// if (parseFloat(value) < parseFloat(_this.init.withdrawl_minimum[_this.network])) {
// callback(Error(_this.$t('putforward.text3', {par: _this.init.withdrawl_minimum[_this.network]})))
// }
// return;
// }}
],
},
pincode:{
rules:[ {required: true,errorMessage: this.$t('putforward.text5')},
{minLength: 6, maxLength: 6, errorMessage: this.$t('putforward.text6'), }
],
}
},
};
},
computed: {
...mapState(['userInfo']),
formattedItems() {
return this.addressList.map(item => `${item.title} (${item.network})`);
}
},
watch: {
'putmodel.amount'(newVal, oldVal) {
this.totalAmount = parseFloat(newVal == '' ? 0 : newVal) + parseFloat(this.costs);
}
},
//第一次加载
async onLoad(e) {
this.$http.get('/api/common/init?lang='+this.$i18n.locale).then(res => {
this.init = res.data;
if(e.network != typeof(undefined) && e.network != undefined){
if(e.network != this.neetwork){
this.network=e.network;
}
};
this.costs = this.init.withdrawl_fee[this.network];
this.withdrawlminimum = this.init.withdrawl_minimum[this.network];
this.totalAmount = parseFloat(this.putmodel.amount == '' ? 0 : this.putmodel.amount) + parseFloat(this.costs);
let data = {
lang: this.$i18n.locale,
network: this.network,
page: 1,
limit: 100
};
this.$http.post('/api/address/list', data).then(res => {
if(res.code == 0){
this.addressList = res.data.data;
}
});
});
this.user = await getUserInfo(this.$i18n.locale);
this.user.money = parseFloat(this.user.money).toFixed(4);
},
//页面显示
onShow() {},
//方法
methods: {
...mapMutations(['setUserInfo']),
max(){
let money = (parseFloat(this.user.money) - parseFloat(this.costs));
this.putmodel.amount = money < 0 ? 0 : money;
},
onPickerChange(e) {
let address = this.addressList[e.detail.value];
this.putmodel.address = address.address;
this.putmodel.addressId = address.id;
},
onPageJump(url) {
uni.navigateTo({
url: url.indexOf('switchnetwork') > 0 ? url + "?network="+this.network+"&page=putforward" : url+"?page=putforward"
});
},
onTokenJump(url) {
this.judgeLogin(() => {
uni.navigateTo({
url: url
});
});
},
submit(form){
if (parseFloat(this.putmodel.amount) < parseFloat(this.withdrawlminimum)) {
uni.showToast({
icon: 'error',
title:this.$t('putforward.text3', {par: this.withdrawlminimum})
});
return;
}
if (parseFloat(this.putmodel.amount)+parseFloat(this.costs) > parseFloat(this.user.money)){
uni.showToast({
icon: 'error',
title:this.$t('putforward.text4')
});
return;
}
this.$refs.form.validate().then(res=>{
var data = {
amount: this.totalAmount,
address_id: this.putmodel.addressId,
trade_password: this.putmodel.pincode,
lang: this.$i18n.locale
};
this.$http.post('/api/withdrawl/create', data).then(res => {
if(res.code == 0){
uni.showToast({
title: res.msg
});
this.putmodel= {
address: '',
addressId: '',
amount: '',
pincode: '',
}
setTimeout(() => {
uni.navigateTo({
url: '/pages/wallet/ExtractResults?id='+res.data.id
});
}, 1000);
}
});
}).catch(err =>{})
}
},
//页面隐藏
onHide() {},
//页面卸载
onUnload() {},
//页面下来刷新
onPullDownRefresh() {},
//页面上拉触底
onReachBottom() {},
//用户点击分享
onShareAppMessage(e) {
return this.wxShare();
}
};
</script>
<style lang="scss" scoped>
@import '@/style/mixin.scss';
body{background-color: #fff;}
.page{min-height: 96vh;position: relative;}
.rechargeTitle{
font-weight: 400;font-size: 16px;color: #999999;line-height: 23px; text-align: center; margin-top: 30px;
}
.rechargeNet{
font-weight: 600;font-size: 20px;color: #333;line-height: 23px; text-align: center; margin-top: 20px;
}
.txt{
font-size: 14px; color:#999; font-weight: 500;
}
.cell_right{
font-size: 14px; color:#333; font-weight: 500;
}
.s{
border-radius: 10px; border: 1px solid #1D61E7; padding: 2px 8px; color: #1D61E7; font-size: 28rpx; font-weight: 600;
}
</style>