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.
207 lines
6.1 KiB
207 lines
6.1 KiB
// pages/setting/bank-add/index.js
|
|
import Scene from '../../index/scene'
|
|
import { getBankcardInfo, ocrBankcard } from "../../../api/payment"
|
|
import { postCaptcha } from "../../../api/user"
|
|
import { bindBankCard } from "../../../api/saas"
|
|
const util = require('../../../utils/util')
|
|
const event = require('../../../utils/event')
|
|
const app = getApp()
|
|
|
|
Scene({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
second: '获取验证码',
|
|
userInfo: null,
|
|
form: {
|
|
phone: null, //银行卡预留手机号
|
|
cardName: null, //银行名称
|
|
cardNo: null, //卡号
|
|
openingBank: null,
|
|
cardType: null, //银行卡类型
|
|
idno: null, //身份证号
|
|
name: null, //持卡人姓名
|
|
verificationCode: null, //验证码
|
|
isExist: 0, //查询银行卡是否重复1重复0不重复
|
|
type: 2
|
|
},
|
|
bankName: null,
|
|
cardType: null,
|
|
codeEnable: true
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({ ['form.name']: app.userInfo.realName })
|
|
},
|
|
bindForm: function (e) {
|
|
this.data.form[e.target.id] = e.detail.value
|
|
if (e.target.id == 'cardNo') {
|
|
this.setData({
|
|
['form.cardName']: null,
|
|
bankName: null,
|
|
['form.cardType']: null,
|
|
['form.type']: 2,
|
|
cardType: null
|
|
})
|
|
} else if (e.target.id == 'phone') {
|
|
this.setData({ codeEnable: util.isEmpty(e.detail.value) })
|
|
}
|
|
},
|
|
checkCardNo: function(cardNo){
|
|
cardNo = cardNo.replace(/\s+/g, '')
|
|
getBankcardInfo(cardNo).then(result => {
|
|
this.setData({
|
|
['form.cardName']: result.data.bank,
|
|
['form.type']: 4,
|
|
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 ''
|
|
},
|
|
fetchCaptcha: function(){
|
|
if (util.isEmpty(this.data.form.name)) {
|
|
util.showToast('请输入持卡人姓名')
|
|
return
|
|
}
|
|
if (util.isEmpty(this.data.form.idno)) {
|
|
util.showToast('请输入身份证号码')
|
|
return
|
|
}
|
|
var res = util.checkId(this.data.form.idno)
|
|
if (res.status == 0) {
|
|
util.showToast(res.msg)
|
|
return
|
|
}
|
|
if (util.isEmpty(this.data.form.cardNo)) {
|
|
util.showToast('请输入银行卡卡号')
|
|
return
|
|
}
|
|
if (util.isEmpty(this.data.form.phone)) {
|
|
util.showToast('请输入手机号码')
|
|
return
|
|
}
|
|
if (!(/^1\d{10}$/.test(this.data.form.phone)) || this.data.form.phone.length < 11) {
|
|
util.showToast('请输入11位手机号码')
|
|
return
|
|
}
|
|
this.data.form.cardNo = this.data.form.cardNo.replace(/\s+/g, '')
|
|
wx.showLoading({ title: '正在获取', mask: true })
|
|
postCaptcha({ verifiableAccount: this.data.form.phone, verifiableAccountType: 1, purpose: 4 }).then(result => {
|
|
wx.hideLoading()
|
|
this.setData({ codeEnable: true })
|
|
util.showToast('验证码已经发送')
|
|
this.countDown = this.countDown || this.selectComponent('.count-down')
|
|
this.countDown.reset()
|
|
this.countDown.start()
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
},
|
|
onCountChange: function(e) {
|
|
if(e.detail.minutes != 0){
|
|
return
|
|
}
|
|
this.setData({ second: e.detail.seconds + ' 秒 ' })
|
|
},
|
|
onFinished: function(){
|
|
this.setData({ second: '重新获取验证码', codeEnable: false })
|
|
},
|
|
submitForm: function(){
|
|
if (util.isEmpty(this.data.bankName) && !util.isEmpty(this.data.form.cardNo)) {
|
|
this.checkCardNo(this.data.form.cardNo)
|
|
}
|
|
if (util.isEmpty(this.data.form.name)) {
|
|
util.showToast('请输入持卡人姓名')
|
|
return
|
|
}
|
|
if (util.isEmpty(this.data.form.idno)) {
|
|
util.showToast('请输入身份证号码')
|
|
return
|
|
}
|
|
var res = util.checkId(this.data.form.idno)
|
|
if (res.status == 0) {
|
|
util.showToast(res.msg)
|
|
return
|
|
}
|
|
if (util.isEmpty(this.data.form.cardNo)) {
|
|
util.showToast('请输入银行卡卡号')
|
|
return
|
|
}
|
|
if (util.isEmpty(this.data.bankName) && !util.isEmpty(this.data.form.cardNo)) {
|
|
this.checkCardNo(this.data.form.cardNo)
|
|
return
|
|
}
|
|
if (util.isEmpty(this.data.form.phone) && this.data.form.type == 4) {
|
|
util.showToast('请输入手机号码')
|
|
return
|
|
}
|
|
if (this.data.form.type == 4 && (!(/^1\d{10}$/.test(this.data.form.phone)) || this.data.form.phone.length < 11)) {
|
|
util.showToast('请输入11位手机号码')
|
|
return
|
|
}
|
|
if (util.isEmpty(this.data.form.verificationCode) && this.data.form.type == 4) {
|
|
util.showToast('请输入验证码')
|
|
return
|
|
}
|
|
wx.showLoading({ title: '处理中', mask: true })
|
|
bindBankCard(this.data.form).then(res => {
|
|
wx.hideLoading()
|
|
util.showBackToast('添加成功')
|
|
event.emit('EventMessage', { what: 201, desc: 'AddCard' })
|
|
}).catch(error => {
|
|
wx.hideLoading()
|
|
util.showToast(error)
|
|
})
|
|
},
|
|
scanCard: function(){
|
|
var that = this
|
|
wx.chooseImage({
|
|
count: 1, //默认9
|
|
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
|
|
sourceType: ['album', 'camera'], //从相册选择
|
|
success: (res) => {
|
|
const fileSystemManager = wx.getFileSystemManager()
|
|
fileSystemManager.readFile({
|
|
filePath: res.tempFilePaths[0], // 例如图片临时路径
|
|
encoding: 'base64',
|
|
success(res) {
|
|
that.ocrBankcard(res.data)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
},
|
|
ocrBankcard: function(base64Image){
|
|
wx.showLoading({ title: '处理中', mask: true })
|
|
ocrBankcard({base64Image}).then(res => {
|
|
wx.hideLoading()
|
|
this.setData({ ['form.cardNo']: res.data.card_num })
|
|
this.checkCardNo(res.data.card_num)
|
|
}).catch(error => {
|
|
wx.hideLoading()
|
|
util.showToast(error)
|
|
})
|
|
}
|
|
})
|