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.
170 lines
5.5 KiB
170 lines
5.5 KiB
// pages/setting/withdrawal/index.js
|
|
import Dialog from '../../../components/dialog/dialog'
|
|
import { getBalanceInfo, getWithdrawalList, paymentOrder } from '../../../api/payment'
|
|
import { getBankCardList } from "../../../api/saas"
|
|
const util = require('../../../utils/util')
|
|
const math = require('../../../utils/math')
|
|
const event = require('../../../utils/event')
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
accountMoney: 0, //用户余额
|
|
sumMoney: 0, //用户余额
|
|
expendMoney: '',
|
|
banckCardList: [], //用户银行卡列表
|
|
banckList: [],
|
|
orderList: [],
|
|
checkIds: [],
|
|
chooseBankCard: {},
|
|
visible: false,
|
|
columns: []
|
|
},
|
|
onLoad: function () {
|
|
this.getUserInfo()
|
|
this.fetchCardList()
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
onEvent: function(message){
|
|
if (message.what == 201) {
|
|
this.fetchCardList()
|
|
}
|
|
},
|
|
fetchCardList: function(){
|
|
getBankCardList().then(res => {
|
|
this.data.columns = []
|
|
for (let index = 0; index < res.data.length; index++) {
|
|
const element = res.data[index]
|
|
this.data.columns.push(element.bankName + '(' + element.cardNoSuffix + '-' + element.ownerName + ')')
|
|
}
|
|
if (res.data && res.data.length && res.data[0].cardName) {
|
|
const element = res.data[0]
|
|
var defaultCard = { cardId: element.id, cardName: element.bankName + '(' + element.cardNoSuffix + '-' + element.ownerName + ')' }
|
|
this.setData({ banckCardList: res.data, columns: this.data.columns, chooseBankCard: defaultCard })
|
|
} else {
|
|
this.setData({ banckCardList: res.data, columns: this.data.columns })
|
|
}
|
|
})
|
|
},
|
|
/**
|
|
* 获取用户数据
|
|
*/
|
|
getUserInfo: function () {
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
getBalanceInfo().then(result => {
|
|
if(!result.data){
|
|
return
|
|
}
|
|
this.setData({ accountMoney: result.data.accountMoney })
|
|
}).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)
|
|
}
|
|
}
|
|
if(sum <= 0){
|
|
return
|
|
}
|
|
this.setData({ orderList: this.data.orderList, expendMoney: sum})
|
|
},
|
|
chooseCard: function () {
|
|
if (this.data.columns.length > 0) {
|
|
this.setData({ visible: true })
|
|
} else {
|
|
Dialog.confirm({ title: '温馨提示', message: '您还没有绑定银行卡,请先去绑定银行卡' }).then(() => {
|
|
wx.navigateTo({ url: '/pages/settlement/bank-add/index' })
|
|
}).catch(err => {
|
|
})
|
|
}
|
|
},
|
|
onConfirm: function({detail}){
|
|
var nowItem = this.data.banckCardList[detail.index]
|
|
// console.log(nowItem)
|
|
this.data.chooseBankCard.cardName = nowItem.bankName + '(' + nowItem.cardNoSuffix + '-' + nowItem.ownerName + ')'
|
|
this.data.chooseBankCard.cardId = nowItem.id
|
|
this.setData({ visible: false, chooseBankCard: this.data.chooseBankCard })
|
|
},
|
|
onHide: function(){
|
|
this.setData({ visible: false })
|
|
},
|
|
checkAmount: function () {
|
|
if (Number(this.data.expendMoney) <= 0) {
|
|
util.showToast('提现金额必须大于0')
|
|
return
|
|
}
|
|
if (!this.data.chooseBankCard || !this.data.chooseBankCard.cardId) {
|
|
util.showToast('请选择一张银行卡')
|
|
return
|
|
}
|
|
var that = this
|
|
wx.requestSubscribeMessage({
|
|
tmplIds: ['9nSUAoD3kMF0O3BE-YMHQB7US_IKMmjr-DKPMQ4gvsE'],
|
|
complete(res) {
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
paymentOrder({ factoryPermittedBankId: that.data.chooseBankCard.cardId, ids: that.data.checkIds }).then(res => {
|
|
wx.hideLoading()
|
|
if(res.data && res.data.markedWords){
|
|
Dialog.alert({ title: '温馨提示', message: res.data.markedWords }).then(() => {
|
|
wx.navigateBack()
|
|
})
|
|
} else {
|
|
Dialog.alert({ title: '温馨提示', message: '提现申请已经提交,请等待提现结果。' }).then(() => {
|
|
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 || '' })
|
|
},
|
|
onUnload: function(){
|
|
event.remove('EventMessage', this)
|
|
}
|
|
|
|
})
|