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

// pages/bank/edit/index.js
import { checkBankcard, sendVerifyCode, addBankCard } from "../../../api/saas"
const util = require('../../../utils/util')
import { $wuxCountDown } from '../../../components/index'
Page({
/**
* 页面的初始数据
*/
data: {
form: {
cardMobile: null, //银行卡预留手机号
cardName: null, //银行名称
cardNo: null, //卡号
openingBank: null,
cardType: null, //银行卡类型
idNumber: null, //身份证号
ownerName: null, //持卡人姓名
verificationCode: null, //验证码
isExist: 0, //查询银行卡是否重复1重复0不重复
},
bankName: null,
cardType: null,
second: null,
codeEnable: true,
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
bindForm: function (e) {
// var form_data = 'form.' + e.target.id
this.data.form[e.target.id] = e.detail.value
if (e.target.id == 'cardNo') {
this.setData({
['form.cardName']: null,
bankName: null,
['form.cardType']: null,
cardType: null
})
}
},
inputBlur: function (e) {
if (e.target.id == 'idNumber' && !util.isEmpty(e.detail.value)) {
var result = util.checkId(e.detail.value)
if (result.status == 0) {
util.showToast(result.msg)
}
} else if (e.target.id == 'cardNo' && !util.isEmpty(e.detail.value)) {
if (!util.isEmpty(e.detail.value)) {
checkBankcard(e.detail.value).then(result => {
if (result.data.isExist == 1) {
util.showToast('该银行卡已存在!')
} else {
this.setData({
['form.cardName']: result.data.bank,
bankName: result.data.bankName,
['form.cardType']: result.data.cardType,
cardType: this.getCardType(result.data.cardType)
})
}
}).catch(error => {
util.showToast(error)
})
}
}
},
getCardType: function(type){
if('DC' == type){
return '储蓄卡'
}
if('CC' == type){
return '信用卡'
}
if('SCC' == type){
return '准贷记卡'
}
if('PC' == type){
return '预付费卡'
}
return ''
},
fetchCode: function () {
if (util.isEmpty(this.data.form.ownerName)) {
util.showToast('请输入持卡人姓名')
return
}
if (util.isEmpty(this.data.form.cardNo)) {
util.showToast('请输入银行卡卡号')
return
}
if (util.isEmpty(this.data.form.idNumber)) {
util.showToast('请输入身份证号码')
return
}
if (util.checkId(this.data.form.idNumber).status == 0) {
util.showToast('身份证号码有误')
return
}
if (util.isEmpty(this.data.form.cardName)) {
util.showToast('请检查银行卡卡号是否正确')
return
}
if (util.isEmpty(this.data.form.openingBank)) {
util.showToast('请输入开户行网点')
return
}
if (util.isEmpty(this.data.form.cardMobile)) {
util.showToast('请输入手机号码')
return
}
if (!(/^1\d{10}$/.test(this.data.form.cardMobile)) || this.data.form.cardMobile.length < 11) {
util.showToast('请输入11位手机号码')
return
}
wx.showLoading({ title: '处理中', mask: true })
sendVerifyCode({ phone: this.data.form.cardMobile, codeType: '6', type: 'yzmjc' }).then(result => {
wx.hideLoading()
this.setData({ codeEnable: false })
util.showToast('验证码已经发送')
this.second = new $wuxCountDown({
date: +(new Date) + 60000,
onEnd() {
this.setData({
second: '重新获取验证码',
codeEnable: true
})
},
render(date) {
const sec = this.leadingZeros(date.sec, 2) + ' 秒 '
date.sec !== 0 && this.setData({
second: sec,
})
},
})
}).catch(error => {
wx.hideLoading()
util.showToast(error)
})
},
submitForm: function(){
if (util.isEmpty(this.data.form.ownerName)) {
util.showToast('请输入持卡人姓名')
return
}
if (util.isEmpty(this.data.form.cardNo)) {
util.showToast('请输入银行卡卡号')
return
}
if (util.isEmpty(this.data.form.idNumber)) {
util.showToast('请输入身份证号码')
return
}
if (util.checkId(this.data.form.idNumber).status == 0) {
util.showToast('身份证号码有误')
return
}
if (util.isEmpty(this.data.form.cardName)) {
util.showToast('请检查银行卡卡号是否正确')
return
}
if (util.isEmpty(this.data.form.openingBank)) {
util.showToast('请输入开户行网点')
return
}
if (util.isEmpty(this.data.form.cardMobile)) {
util.showToast('请输入手机号码')
return
}
if (!(/^1\d{10}$/.test(this.data.form.cardMobile)) || this.data.form.cardMobile.length < 11) {
util.showToast('请输入11位手机号码')
return
}
if (util.isEmpty(this.data.form.verificationCode)) {
util.showToast('请输入验证码')
return
}
wx.showLoading({ title: '处理中', mask: true })
addBankCard(this.data.form).then(res => {
wx.hideLoading()
util.showBackToast('添加成功')
}).catch(error => {
wx.hideLoading()
util.showToast(error)
})
}
})