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

134 lines
3.6 KiB

// pages/bank/index/index.js
import { getBankCardList, deleteBankCard, checkPayPassword, bankCardDefault } from "../../api/saas"
import { $wuxKeyBoard, $wuxDialog } from '../../../components/index'
const util = require('../../../utils/util')
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
isSetPwd: 0,
nowIndex: -1,
bankList: []
},
onShow: function () {
checkPayPassword().then(res => {
this.data.isSetPwd = 1
}).catch(err => {
this.data.isSetPwd = -1
})
this.fetchBankCardList()
},
/**
* 获取用户银行卡列表
*/
fetchBankCardList: function () {
wx.showLoading({ title: '加载中', mask: true })
getBankCardList().then(result => {
this.setData({ bankList: result.data })
wx.hideLoading()
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
},
showActionSheet(e) {
this.data.nowIndex = e.currentTarget.dataset.index
if (this.data.nowIndex < 0) {
if(!app.globalData.userInfo.isAuth){
$wuxDialog().open({
resetOnClose: true,
title: '温馨提示',
content: '您还没有进行个人信息认证,无法绑定银行卡,现在去进行个人信息认证?',
buttons: [{
text: '确定',
type: 'primary',
onTap(e) {
wx.navigateTo({ url: '/pages/home/idcard/index' })
}
}]
})
return
}
wx.navigateTo({url: '/pages/bank/edit/index'})
return
}
var that = this
wx.showActionSheet({
itemList: ['设为默认', '解除绑定'],
success(res){
if (res.tapIndex === 0){
that.setDefault()
}else if (res.tapIndex === 1){
that.unbindCard()
}
}
})
},
setDefault: function (id) {
var item = this.data.bankList[this.data.nowIndex]
wx.showLoading({ title: '处理中', mask: true })
bankCardDefault(item.id).then(res => {
for (let index = 0; index < this.data.bankList.length; index++) {
if(index == this.data.nowIndex){
this.data.bankList[index].isDefault = 1
} else {
this.data.bankList[index].isDefault = 0
}
}
this.setData({
bankList: this.data.bankList
})
wx.hideLoading()
util.showToast('设置成功')
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
},
unbindCard: function () {
var that = this
if (this.data.isSetPwd == 1) {
$wuxKeyBoard().show({
inputText: '输入支付密码',
callback(value) {
that.postUnbindCard(value)
return true
},
})
} 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'
})
}
}]
})
}
},
postUnbindCard: function (pwd) {
wx.showLoading({ title: '处理中', mask: true })
var item = this.data.bankList[this.data.nowIndex]
deleteBankCard(item.id, { password: pwd }).then(res => {
wx.hideLoading()
util.showToast('解除成功')
this.data.bankList.splice(this.data.nowIndex, 1);
this.setData({ bankList: this.data.bankList })
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
}
})