305 lines
5.4 KiB
JavaScript
305 lines
5.4 KiB
JavaScript
// pages/wallet/withdraw.js
|
|
const app = getApp();
|
|
import { bankList, handleWithdrawl } from "../../utils/withdraw"
|
|
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
showModal: false,
|
|
show: false,
|
|
password: '',
|
|
bankId: '',
|
|
bankCard: '',
|
|
bankName: '',
|
|
money: '',
|
|
tenantId: '',
|
|
total: '',
|
|
value: '',
|
|
bankList: [],
|
|
disabled: false
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
this.setData({
|
|
total: options.total,
|
|
tenantId: options.tenantId
|
|
})
|
|
let password = wx.getStorageSync('cooperation').password
|
|
if (!password) {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '暂未设置提现密码,前往设置',
|
|
showCancel: false,
|
|
confirmColor: '#367df9',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
wx.navigateTo({
|
|
url: '/pages/password/password',
|
|
})
|
|
}
|
|
}
|
|
})
|
|
}
|
|
this.getBankList()
|
|
},
|
|
|
|
showModal() {
|
|
let { bankCard, bankId, total, money } = this.data
|
|
let password = wx.getStorageSync('cooperation').password
|
|
if (Number(money) > Number(total)) {
|
|
wx.showToast({
|
|
title: '转出金额不能大于可提现金额',
|
|
icon: 'none'
|
|
})
|
|
} else if (money == 0) {
|
|
wx.showToast({
|
|
title: '提现金额不能为0',
|
|
icon: 'none'
|
|
})
|
|
} else if (!bankCard || !bankId) {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '暂未设置提现银行卡,请联系管理员添加',
|
|
showCancel: false,
|
|
confirmColor: '#367df9',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
|
|
}
|
|
}
|
|
})
|
|
} else if (!password) {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '暂未设置提现密码,前往设置',
|
|
showCancel: false,
|
|
confirmColor: '#367df9',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
wx.navigateTo({
|
|
url: '/pages/password/password',
|
|
})
|
|
}
|
|
}
|
|
})
|
|
}
|
|
else {
|
|
this.setData({
|
|
showModal: true
|
|
})
|
|
}
|
|
},
|
|
|
|
getInput(e) {
|
|
const keys = e.target.id;
|
|
this.setData({
|
|
[keys]: e.detail.value
|
|
})
|
|
let { money, total } = this.data
|
|
if (keys === 'money') {
|
|
if (Number(money) > Number(total)) {
|
|
wx.showToast({
|
|
title: '转出金额不能大于可提现金额',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
if (/^(\d?)+(\.\d{0,2})?$/.test(e.detail.value)) { //正则验证,提现金额小数点后不能大于两位数字
|
|
money = e.detail.value;
|
|
} else {
|
|
money = e.detail.value.substring(0, e.detail.value.length - 1);
|
|
}
|
|
this.setData({
|
|
money: money,
|
|
})
|
|
}
|
|
},
|
|
|
|
onConfirm() {
|
|
let { bankCard, bankId, money, password, tenantId } = this.data
|
|
if (password) {
|
|
this.setData({
|
|
disabled: true
|
|
})
|
|
let data = {
|
|
bankCard, bankId, money, password, tenantId,
|
|
userId: wx.getStorageSync("cooperation").id,
|
|
flag: true,
|
|
workerId: wx.getStorageSync("kybUser").id,
|
|
worker: wx.getStorageSync("kybUser").name + '-' + wx.getStorageSync("kybUser").phone,
|
|
}
|
|
this.setData({
|
|
showModal: false,
|
|
show: false
|
|
})
|
|
wx.showLoading({
|
|
title: '等待中...',
|
|
})
|
|
handleWithdrawl(data).then(res => {
|
|
wx.hideLoading()
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: res.msg,
|
|
showCancel: false,
|
|
confirmColor: '#367df9',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
wx.navigateBack()
|
|
this.setData({
|
|
money: '',
|
|
password: '',
|
|
disabled: false
|
|
})
|
|
}
|
|
}
|
|
})
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: err.msg,
|
|
showCancel: false,
|
|
confirmColor: '#367df9',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
this.setData({
|
|
password: '',
|
|
disabled: false
|
|
})
|
|
}
|
|
}
|
|
})
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title: '请输入提现密码',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
},
|
|
|
|
changeType() {
|
|
this.setData({
|
|
show: !(this.data.show)
|
|
})
|
|
},
|
|
|
|
onCancel() {
|
|
this.setData({
|
|
showModal: false,
|
|
password: '',
|
|
show: false
|
|
})
|
|
},
|
|
|
|
getBankList() {
|
|
bankList().then(res => {
|
|
if (res.data.length > 0) {
|
|
res.data.forEach(item => {
|
|
item.bankStr = `${item.bank}-${item.bankCard}`
|
|
})
|
|
this.setData({
|
|
bankList: res.data,
|
|
bankCard: res.data[0].bankCard,
|
|
bankName: res.data[0].bank,
|
|
bankId: res.data[0].id,
|
|
})
|
|
} else {
|
|
this.setData({
|
|
bankList: [],
|
|
})
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '暂未设置提现银行卡,请联系管理员添加',
|
|
showCancel: false,
|
|
confirmColor: '#367df9',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
}).catch(err => {
|
|
wx.showToast({
|
|
title: err.msg,
|
|
icon: 'none',
|
|
})
|
|
})
|
|
},
|
|
|
|
bindPickerChange(e) {
|
|
const { value } = e.detail;
|
|
let { bankList } = this.data
|
|
this.setData({
|
|
bankCard: bankList[value].bankCard,
|
|
bankName: bankList[value].bank,
|
|
bankId: bankList[value].id,
|
|
})
|
|
},
|
|
|
|
//全部提现
|
|
totalNum() {
|
|
this.setData({
|
|
money: this.data.total
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |