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

112 lines
3.4 KiB

// pages/home/authory/index.js
const request = require('../../../utils/request') //导入模块
const util = require('../../../utils/util')
const event = require('../../../utils/event.js')
Page({
/**
* 页面的初始数据
*/
data: {
form: { identityAuthToken: null },
flag: false, // 是否不可以编辑, false:可编辑;true:不可编辑
imgList: [null, null]
},
onLoad: function (options) {
event.on('EventMessage', this, this.onEvent)
this.resetForm()
},
/**
* 生命周期函数--监听页面加载
*/
resetForm: function(){
try {
wx.removeStorageSync('identityAuthToken')
} catch (e) {
// Do something when catch error
}
},
onEvent: function (message) {
if (message.what == 82) {
wx.navigateBack()
}
},
submitForm: function () {
if (util.isEmpty(this.data.form.frontImg)) {
util.showToast('请上传身份证正面照片')
return
}
if (util.isEmpty(this.data.form.backImg)) {
util.showToast('请上传身份证背面照片')
return
}
// /front/customer/personalAuth 个人会员认证
wx.showLoading({ title: '处理中', mask: true })
request.post('/recycle-service/identity-auth/recognize/id-card', this.data.form).then(result => {
wx.hideLoading()
var tokenJson = JSON.stringify({token: result.data.identityAuthToken, idCardNo: result.data.idCardNo, realName: result.data.realName})
wx.setStorageSync('identityAuthToken', tokenJson)
wx.navigateTo({ url: '/pages/home/authory/index' })
}).catch(error => {
wx.hideLoading()
util.showToast(error)
})
},
/*******************************************************图片上传************************************************************/
chooseImage: function(e) {
if (this.data.flag) {
return
}
var index = e.currentTarget.dataset.index
var that = this
wx.chooseImage({
count: 1, //默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], //从相册选择
success: (res) => {
that.setData({ ['imgList[' + index + ']']: res.tempFilePaths[0] })
const fileSystemManager = wx.getFileSystemManager()
var type = that.suffixImage(res.tempFilePaths[0])
fileSystemManager.readFile({
filePath: that.data.imgList[index], // 例如图片临时路径
encoding: 'base64',
success(res) {
let { data } = res // 编码后的数据
if(index == 0){
that.data.form.frontImg = {base64: data, type}
} else {
that.data.form.backImg = {base64: data, type}
}
}
})
}
})
},
suffixImage: function(path){
return path.substring(path.lastIndexOf('.') + 1)
},
viewImage: function(e) {
var urlList = []
for (var i = 0; i < this.data.imgList.length; i++) {
if (!util.isEmpty(this.data.imgList[i])) {
urlList.push(this.data.imgList[i])
}
}
wx.previewImage({
urls: urlList,
current: e.currentTarget.dataset.url
})
},
deleteImg: function(e) {
var index = e.currentTarget.dataset.index
this.data.imgList[index] = null;
this.setData({
imgList: this.data.imgList
})
},
onUnload: function () {
event.remove('EventMessage', this)
}
})