// pages/cash/cash.js const app = getApp() var lock = require('../../utils/lock.js') var verify = require('../../utils/verify.js') var net = require('../../utils/net.js') var url = require('../../utils/url.js') Page({ /** * 页面的初始数据 */ data: { wallet: {}, balance: 0, isNeedFinish: true, error: false, sum: 0, input: '', valueName: '', valueCard: '', hiddenDialog: true, }, onLoad: function (options) { this.getWallet() }, getWallet: function () { wx.showLoading({ title: '', }) net.connect({ url: url.host + url.wallet, data: {}, success: res => { wx.hideLoading() var _result = res.data.data this.data.wallet = _result this.data.balance = _result.totalFee - _result.applyFee - _result.finishFee this.data.isNeedFinish = _result.idcard == null this.setData({ balance: this.data.balance }) }, }) }, cash: function (e) { var sum = e.detail.value.amount //验证是否为正整数或保留两位小数 if (!verify.isTwoDecimals(sum)) { wx.showModal({ title: '提示', content: '请填写正确的提现金额,最多保留两位小数', showCancel: false }) return } sum = new Number(sum) //限制最低提现金额10元 if (sum < 10) { wx.showModal({ title: '提示', content: '提现金额不能低于10元', showCancel: false }) return } //限制提现金额不超过当前可提现金额 var balance = this.data.balance if (sum > balance / 100) { this.setData({ error: true }) return } this.data.sum = sum //是否需要完善信息 if (this.data.isNeedFinish) { this.showDialog() return } //提现 this.submitCash(sum) }, submitCash: function (sum) { wx.showLoading({ title: '', }) net.connect({ url: url.host + url.withdraw, data: { fee: parseInt(sum * 100), realName: this.data.wallet.realName, idcard: this.data.wallet.idcard }, method: 'POST', success: res => { wx.hideLoading() wx.showToast({ title: '已提交申请', mask: true }) var balance = this.data.balance balance = Number((balance - sum * 100).toFixed(2)) app.globalData.user.withdrawalbleFee = balance this.data.wallet.applyFee += sum * 100 this.setData({ balance: balance, error: false, input: '' }) }, }) }, finish: function (e) { var name = e.detail.value.name if (!verify.isRealName(name)) { wx.showToast({ title: '请输入真实的姓名', icon: 'none' }) return } var card = e.detail.value.card if (!verify.isIdentityCard(card)) { wx.showToast({ title: '请输入正确的身份证号码', icon: 'none' }) return } this.data.wallet.realName = name this.data.wallet.idcard = card this.data.isNeedFinish = this.data.wallet.idcard == null this.hiddenDialog() this.submitCash(this.data.sum) }, toRecord: function () { if (lock.lockTapDelay()) { return } wx.navigateTo({ url: '../cashRecord/cashRecord?applyFee=' + this.data.wallet.applyFee + '&finishFee=' + this.data.wallet.finishFee, }) }, showDialog: function () { this.setData({ hiddenDialog: false, valueName: '', valueCard: '', }) }, hiddenDialog: function () { this.setData({ hiddenDialog: true }) } })