// pages/cash-withdrawal/index.js import { extractCash, extractBank, extractBankFee, getUserInfo } from '../../api/user.js' const app = getApp() const CASH_CHANNELS = { weixin: '微信', bank: '银行卡', alipay: '支付宝' } Page({ /** * 页面的初始数据 */ data: { parameter: { navbar: '1', return: '1', title: '提现', color: true, class: '0' }, navList: [ { name: '银行卡', icon: 'icon-yinhangqia' }, { name: '微信', icon: 'icon-weixin2' }, { name: '支付宝', icon: 'icon-icon34' } ], currentTab: 1, index: 0, array: [], //提现银行 commissionCount: 0.0, //可提现金额 minPrice: 0.0, // 最低提现金额 wxName: '', // 微信实名 bankCardNo: '', // 银行卡号 bankUser: '', // 银行户名 bankName: '', // 银行名称 userInfo: [], isClone: false }, onLoadFun: function () { this.getUserInfo() this.getUserExtractBank() }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) {}, getUserExtractBank: function () { var that = this extractBank().then(res => { var array = res.data.extractBank array.unshift('请选择银行') var idx = 0 for (var i = 0; i < array.length; i++) { if (array[i] == res.data.bankName) { idx = i } } that.setData({ array: array, commissionCount: res.data.commissionCount, minPrice: res.data.minPrice, wxName: res.data.wxpayName, bankCardNo: res.data.bankCardNo, bankName: res.data.bankName, bankUser: res.data.bankUser, index: idx }) }) }, /** * 获取个人用户信息 */ getUserInfo: function () { var that = this getUserInfo().then(res => { that.setData({ userInfo: res.data }) // app.globalData.unread = res.data.notice app.setUnread(res.data.notice) }) }, swichNav: function (e) { if (e.currentTarget.dataset.current > 1) { wx.showToast({ title: '暂未开放', image: '' }) return } this.setData({ currentTab: e.currentTarget.dataset.current }) }, bindPickerChange: function (e) { this.setData({ index: e.detail.value }) }, subCash: function (e) { let value = e.detail.value if (value.money.length == 0) { return app.Tips({ title: '请填写提现金额' }) } if (Number(value.money) > Number(this.data.commissionCount)) { return app.Tips({ title: '提现金额不能大于' + this.data.commissionCount }) } else if (Number(value.money) < Number(this.data.minPrice)) { return app.Tips({ title: '提现金额不能小于' + this.data.minPrice }) } if (this.data.currentTab == 0) { //银行卡 if (value.name.length == 0) return app.Tips({ title: '请填写持卡人姓名' }) if (value.cardnum.length == 0) return app.Tips({ title: '请填写卡号' }) if (this.data.index == 0) return app.Tips({ title: '请选择银行' }) value.extract_type = 'bank' value.bankname = this.data.array[this.data.index] var that = this extractBankFee(value) .then(res => { wx.showModal({ title: '提现确认(含手续费)', content: '银行卡提现:' + value.money + ' 元\n' + '收款人: ' + value.name + '\n' + '手续费: ' + res.data.fee + ' 元\n' + '实际到帐: ' + res.data.valid + ' 元\n' + '说明:手续费为通道费用,非美天旺收取,手续费费率为 ' + res.data.rate * 100 + '%,最少 ' + res.data.min + ' 元,最多 ' + res.data.max + ' 元。', showCancel: true, showConfirm: true, confirmText: '继续提现', success: model => { if (model.confirm) { extractCash(value) .then(rs => { that.getUserInfo() return wx.showModal({ title: '成功', content: rs.msg, showCancel: false, confirmText: '确定', complete: () => { wx.navigateBack({ delta: 1 }) } }) }) .catch(err => { return wx.showModal({ title: '失败', content: err, showCancel: false, confirmText: '确定', complete: () => { wx.navigateBack({ delta: 1 }) } }) }) } } }) }) .catch(err => { return app.Tips({ title: err }) }) } else { if (this.data.currentTab == 1) { //微信 value.extract_type = 'weixin' if (value.name.length == 0) return app.Tips({ title: '请填写微信实名' }) value.weixin = value.name } else if (this.data.currentTab == 2) { //支付宝 value.extract_type = 'alipay' if (value.name.length == 0) return app.Tips({ title: '请填写账号' }) value.alipay_code = value.name } var that = this wx.showModal({ title: '提现确认', content: CASH_CHANNELS[value.extract_type] + '提现: ' + value.money + ' 元\n' + '收款人: 微信登录账号\n' + '手续费: 0 元\n' + '实际到帐: ' + value.money + ' 元\n', confirmText: '继续提现', success: model => { if (model.confirm) { extractCash(value) .then(res => { that.getUserInfo() return wx.showModal({ title: '成功', content: res.msg, showCancel: false, confirmText: '确定', complete: () => { wx.navigateBack({ delta: 1 }) } }) }) .catch(err => { return wx.showModal({ title: '失败', content: err, showCancel: false, confirmText: '确定', complete: () => { wx.navigateBack({ delta: 1 }) } }) }) } } }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () {}, /** * 生命周期函数--监听页面显示 */ onShow: function () { if (app.globalData.isLog && this.data.isClone) { this.getUserInfo() this.getUserExtractBank() } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { this.setData({ isClone: true }) }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () {}, /** * 用户点击右上角分享 */ onShareAppMessage: function () {} })