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.
180 lines
5.4 KiB
180 lines
5.4 KiB
// pages/home/authory/index.js
|
|
const request = require('../../../utils/request'); //导入模块
|
|
const util = require('../../../utils/util');
|
|
const math = require('../../../utils/math.js');
|
|
const app = getApp()
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
form: {
|
|
authType: 0,
|
|
},
|
|
typeList: [{text: '身份证', value: 1}, {text: '身份证', value: 2}],
|
|
flag: false, // 是否不可以编辑, false:可编辑;true:不可编辑
|
|
imgList: [null, null],
|
|
loadingWidth: math.divide(690, 2) - 16,
|
|
pathList: new Array(),
|
|
taskArray: [],
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.pickerView = this.pickerView || this.selectComponent('#picker-view')
|
|
},
|
|
|
|
showPicker: function (e) {
|
|
if (this.data.flag) {
|
|
return
|
|
}
|
|
this.pickerView.showPicker(this.data.typeList, null, 1)
|
|
},
|
|
onPickerChange: function (e) {
|
|
if (!e.detail) {
|
|
return
|
|
}
|
|
if (e.detail.type == 1) {
|
|
this.setData({ ['form.bankName']: e.detail.text, ['form.bankId']: Number(e.detail.value) })
|
|
}
|
|
},
|
|
bindForm: function (e) {
|
|
// var form_data = 'form.' + e.target.id
|
|
this.data.form[e.target.id] = e.detail.value
|
|
},
|
|
submitForm: function(){
|
|
if (util.isEmpty(this.data.form.userName)) {
|
|
util.showToast('请输入真实姓名')
|
|
return
|
|
}
|
|
if (util.isEmpty(this.data.form.idCard)) {
|
|
util.showToast('请输入身份证号码')
|
|
return
|
|
}
|
|
if (util.checkId(this.data.form.idCard).status == 0) {
|
|
util.showToast('身份证号码有误')
|
|
return
|
|
}
|
|
if (util.isEmpty(this.data.pathList[0]) || util.isEmpty(this.data.pathList[0].url)) {
|
|
util.showToast('请上传身份证正面照片')
|
|
return
|
|
}
|
|
this.data.form.cardFront = this.data.pathList[0].url
|
|
if (util.isEmpty(this.data.pathList[1]) || util.isEmpty(this.data.pathList[1].url)) {
|
|
util.showToast('请上传身份证背面照片')
|
|
return
|
|
}
|
|
this.data.form.cardReverse = this.data.pathList[1].url
|
|
// /front/customer/personalAuth 个人会员认证
|
|
wx.showLoading({ title: '处理中', mask: true })
|
|
request.post('/user-centre/front/customer/personalAuth', this.data.form).then(res => {
|
|
wx.hideLoading()
|
|
app.globalData.userInfo.isAuth = 1
|
|
util.showBackToast('上传成功')
|
|
}).catch(error => {
|
|
wx.hideLoading()
|
|
util.showToast(error)
|
|
})
|
|
},
|
|
/*******************************************************图片上传************************************************************/
|
|
uploadImage: function (index, path) {
|
|
var _this = this
|
|
_this.setData({
|
|
['pathList[' + index + ']']: { status: 1, url: '' }
|
|
})
|
|
// /utils/uploadImage 统一上传图片接口
|
|
var task = wx.uploadFile({
|
|
url: app.httpUrl + '/saas-user/utils/uploadImage',
|
|
filePath: path,
|
|
name: 'image',
|
|
header: {
|
|
"Content-Type": "multipart/form-data",
|
|
appversion: app.version
|
|
},
|
|
success: function (result) {
|
|
var resp = JSON.parse(result.data)
|
|
if (resp.code === 0) {
|
|
_this.setData({
|
|
['pathList[' + index + '].status']: 8,
|
|
['pathList[' + index + '].url']: resp.data
|
|
})
|
|
if(_this.data.id > 0){
|
|
var _index = Number(index) + 1
|
|
_this.setData({
|
|
['form.fileUrl' + _index]: resp.msg
|
|
})
|
|
}
|
|
}
|
|
},
|
|
fail: function (res) {
|
|
_this.setData({
|
|
['pathList[' + index + '].status']: -1
|
|
})
|
|
},
|
|
complete: function (res) {
|
|
for (let i = 0; i < _this.data.taskArray.length; i++) {
|
|
if (_this.data.taskArray[i].path === path) {
|
|
_this.data.taskArray.splice(i, 1);
|
|
break
|
|
}
|
|
}
|
|
_this.setData({
|
|
taskArray: _this.data.taskArray
|
|
})
|
|
},
|
|
})
|
|
_this.data.taskArray.push({ path: path, task: task })
|
|
_this.setData({
|
|
taskArray: _this.data.taskArray
|
|
})
|
|
},
|
|
chooseImage(e) {
|
|
if (this.data.flag) {
|
|
return
|
|
}
|
|
var index = e.currentTarget.dataset.index
|
|
wx.chooseImage({
|
|
count: 1, //默认9
|
|
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
|
|
sourceType: ['album', 'camera'], //从相册选择
|
|
success: (res) => {
|
|
this.setData({ ['imgList[' + index + ']']: res.tempFilePaths[0] })
|
|
for (let i = 0; i < res.tempFilePaths.length; i++) {
|
|
this.uploadImage(index, res.tempFilePaths[i])
|
|
}
|
|
}
|
|
});
|
|
},
|
|
viewImage(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(e) {
|
|
var index = e.currentTarget.dataset.index
|
|
// 如果是正在上传的;
|
|
if (this.data.pathList[index] && this.data.pathList[index].status === 1) {
|
|
if (this.data.taskArray[index]) {
|
|
this.data.taskArray[index].abort() // 取消上传任务
|
|
}
|
|
this.data.taskArray.splice(index, 1);
|
|
}
|
|
this.data.imgList[index] = null;
|
|
if (this.data.pathList.length > index){
|
|
this.data.pathList.splice(index, 1);
|
|
}
|
|
this.setData({
|
|
imgList: this.data.imgList,
|
|
pathList: this.data.pathList,
|
|
taskArray: this.data.taskArray
|
|
})
|
|
}
|
|
})
|