纸通宝小程序
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.
 

188 lines
5.7 KiB

// pages/withdrawal/checkout/index.js
import { getBalanceInfo, getWithdrawalList, getBankCardList } from '../../api/payment'
import { $wuxDialog } from '../../../components/index'
const util = require('../../../utils/util')
const math = require('../../../utils/math')
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
safeBottom: app.globalData.safeBottom,
accountMoney: 0, //用户余额
sumMoney: 0, //用户余额
expendMoney: '',
xsaccountMoney: 0, //显示余额
banckCardList: [], //用户银行卡列表
banckList: [],
orderList: [],
checkIds: [],
chooseBankCard: null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.pickerView = this.pickerView || this.selectComponent('#picker-view')
this.setData({ safeBottom: app.globalData.safeBottom })
},
onShow: function () {
this.getUserInfo()
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 })
}
})
},
/**
* 获取用户数据
*/
getUserInfo: function () {
// /account/balance 用户余额
wx.showLoading({ title: '加载中', mask: true })
getBalanceInfo().then(result => {
this.setData({
accountMoney: result.data.accountMoney,
xsaccountMoney: math.minus(result.data.accountMoney, result.data.frozenMoney)
})
}).catch(err => {
console.log(err)
})
getWithdrawalList().then(result => {
wx.hideLoading()
this.data.sumMoney = 0
for (let index = 0; index < result.data.length; index++) {
const element = result.data[index]
if(element.status == 0){
this.data.sumMoney = math.plus(this.data.sumMoney, element.money)
}
}
this.setData({ orderList: result.data, sumMoney: this.data.sumMoney })
}).catch(err => {
wx.hideLoading()
})
},
allExpend: function () {
var sum = 0
this.data.checkIds = []
for (let index = 0; index < this.data.orderList.length; index++) {
const element = this.data.orderList[index]
if(element.status == 0){
element.check = true
this.data.checkIds.push(element.id)
sum = math.plus(sum, element.money)
}
}
this.setData({ orderList: this.data.orderList, expendMoney: sum || '' })
},
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/create/index'
})
}
}]
})
}
},
onCardChange: function(e){
if(!e.detail){
return
}
this.setData({
['chooseBankCard.cardName']: this.data.banckCardList[e.detail.current].bankName,
['chooseBankCard.cardId']: this.data.banckCardList[e.detail.current].id
})
},
onPickerChange: function (e) {
if(!e.detail){
return
}
this.setData({ ['chooseBankCard.cardName']: e.detail.text, ['chooseBankCard.cardId']: e.detail.value })
},
checkoutAmount: function () {
if (Number(this.data.expendMoney) <= 0) {
util.showToast('提现金额必须大于0')
return
}
if (!this.data.chooseBankCard || !this.data.chooseBankCard.cardId) {
util.showToast('请选择一张银行卡')
return
}
wx.showLoading({ title: '加载中', mask: true })
paymentOrder({ bankId: this.data.chooseBankCard.cardId, ids: this.data.checkIds }).then(res => {
wx.hideLoading()
if(res.data.markedWords){
$wuxDialog().open({
maskClosable: false,
title: '温馨提示',
content: res.data.markedWords,
buttons: [{
text: '确定',
type: 'primary',
onTap(e) {
wx.navigateBack()
}
}]
})
} else {
$wuxDialog().open({
maskClosable: false,
title: '温馨提示',
content: '提现申请已经提交,请等待提现结果。',
buttons: [{
text: '确定',
type: 'primary',
onTap(e) {
wx.navigateBack()
}
}]
})
}
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
},
checkList: function(e){
var item = this.data.orderList[e.currentTarget.dataset.index]
if(item.status != 0){
return
}
var checked = !item.check
var sum = 0
this.data.checkIds = []
for (let index = 0; index < this.data.orderList.length; index++) {
const element = this.data.orderList[index]
if(index == e.currentTarget.dataset.index){
element.check = !element.check
}
if(element.check){
sum = math.plus(sum, element.money)
this.data.checkIds.push(element.id)
}
}
this.setData({ ['orderList[' + e.currentTarget.dataset.index + '].check']: checked, expendMoney: sum || '' })
}
})