// pages/bank/index/index.js import { $wuxKeyBoard, $wuxDialog } from '../../../components/index' const request = require('../../../utils/request') //导入模块 const util = require('../../../utils/util') const app = getApp() Page({ /** * 页面的初始数据 */ data: { isSetPwd: 0, nowIndex: -1, bankList: [] }, onShow: function () { this.checkPayPassword() this.fetchBankCardList() }, /** * 获取用户银行卡列表 */ fetchBankCardList: function () { wx.showLoading({ title: '加载中', mask: true }) request.get('/saas-user/account/getBankCardList').then(result => { this.setData({ bankList: result.data }) wx.hideLoading() }).catch(err => { wx.hideLoading() util.showToast(err) }) }, /** * 检测是否设置支付密码 */ checkPayPassword() { request.get('/saas-user/account/checkPayPassword').then(res => { this.data.isSetPwd = 1 }).catch(err => { this.data.isSetPwd = -1 }) }, 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 }) request.put('/saas-user/account/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] request.delete('/saas-user/account/bankCard/' + 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) }) } })