纸通宝小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

153 lines
4.3 KiB

// pages/withdrawal/checkout/index.js
import { checkPayPassword, getBalanceInfo, getBankCardList, postWithdraw } from "../../api/saas"
import { $wuxKeyBoard, $wuxDialog } from '../../../components/index'
const util = require('../../../utils/util')
// const md5 = require('../../../utils/md5')
const math = require('../../../utils/math')
Page({
/**
* 页面的初始数据
*/
data: {
accountMoney: 0, //用户余额
expendMoney: '',
xsaccountMoney: null, //显示余额
banckCardList: [], //用户银行卡列表
banckList: [],
isSetPwd: 0,
chooseBankCard: null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.pickerView = this.pickerView || this.selectComponent('#picker-view')
this.getUserInfo()
},
onShow: function () {
getBankCardList().then(res => {
var list = []
for (let index = 0; index < res.data.length; index++) {
const element = res.data[index]
list.push({
text: element.bankName + '(' + element.cardNoSuffix + ')',
value: element.id
})
}
this.setData({ banckCardList: res.data, banckList: list })
if (this.data.banckCardList[0] && this.data.banckCardList[0].cardName) {
const element = this.data.banckCardList[0]
var defaultCard = { cardId: element.id, cardName: element.bankName + '(' + element.cardNoSuffix + ')' }
this.setData({ chooseBankCard: defaultCard })
}
})
checkPayPassword().then(res => {
this.data.isSetPwd = 1
}).catch(err => {
this.data.isSetPwd = -1
})
},
/**
* 获取用户数据
*/
getUserInfo: function () {
getBalanceInfo().then(res => {
this.setData({
accountMoney: res.data.accountMoney,
xsaccountMoney: math.minus(res.data.accountMoney, res.data.frozenMoney)
})
})
},
bindAndSet(e) {
this.setData({ expendMoney: e.detail.value })
},
allExpend: function () {
this.setData({ expendMoney: this.data.xsaccountMoney })
},
chooseCard: function () {
if (this.data.chooseBankCard) {
this.pickerView.showPicker(this.data.banckList, this.data.chooseBankCard.cardId)
} else {
$wuxDialog().open({
resetOnClose: true,
title: '温馨提示',
content: '您还没有绑定银行卡,请先去绑定银行卡',
buttons: [{
text: '确定',
type: 'primary',
onTap(e) {
wx.navigateTo({
url: '/pages/bank/edit/index'
})
}
}]
})
}
},
onPickerChange: function (e) {
if(!e.detail){
return
}
this.setData({
['chooseBankCard.cardName']: e.detail.text,
['chooseBankCard.cardId']: e.detail.value
})
},
checkoutMoney: function () {
if (Number(this.data.expendMoney) <= 0) {
util.showToast('提现金额必须大于0')
return
}
if (this.data.xsaccountMoney != null) {
if (Number(this.data.xsaccountMoney) < Number(this.data.expendMoney)) {
util.showToast('账户余额不够')
return
}
}
if (!this.data.chooseBankCard || !this.data.chooseBankCard.cardId) {
util.showToast('请选择一张银行卡')
return
}
var that = this
if (this.data.isSetPwd == 1) {
$wuxKeyBoard().show({
inputText: '输入支付密码',
callback(value) {
that.withdrawalMoney(value)
return true
},
onForget(type) {
wx.navigateTo({ url: '/pages/bank/password/index' })
}
})
} else if (this.data.isSetPwd == -1) {
$wuxDialog().open({
resetOnClose: true,
title: '温馨提示',
content: '您还没有设置支付密码,请先设置支付密码',
buttons: [{
text: '取消'
}, {
text: '确定',
type: 'primary',
onTap(e) {
wx.navigateTo({
url: '/pages/bank/password/index'
})
}
}]
})
}
},
withdrawalMoney: function (pwd) {
wx.showLoading({ title: '加载中', mask: true })
postWithdraw({ bankId: this.data.chooseBankCard.cardId, money: this.data.expendMoney, password: pwd }).then(res => {
wx.hideLoading()
util.showBackToast('提现成功')
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
}
})