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

142 lines
4.6 KiB

// pages/home/authory/index.js
import { ocrLicense, checkLicense } from "../../api/user"
import { updateUserInfo } from '../../api/ztb'
const util = require('../../../utils/util')
const app = getApp()
let monthList = [{ text: '1000吨以下', value: 1 }, { text: '1000-2000吨', value: 2 }, { text: '2000吨以上', value: 3 }]
let expriseList = [{ text: '1年以下', value: 1 }, { text: '1-5年', value: 2 }, { text: '5-10年', value: 3 }, { text: '10年以上', value: 4 }]
Page({
/**
* 页面的初始数据
*/
data: {
form: { },
flag: false, // 是否不可以编辑, false:可编辑;true:不可编辑
disabled: true,
fileList: [],
imgList: [null]
},
onLoad: function (options) {
this.setData({ form: app.globalData.userInfo })
},
bindForm: function (e) {
// var form_data = 'form.' + e.target.id
this.data.form[e.currentTarget.id] = e.detail.value
},
showPicker: function (e) {
this.pickerView = this.pickerView || this.selectComponent('#picker-view')
if(e.currentTarget.id == 'shipmentPerMonth'){
this.pickerView.showPicker(monthList, null, 1)
} else if(e.currentTarget.id == 'experienceTag'){
this.pickerView.showPicker(expriseList, null, 2)
}
},
onPickerChange: function ({detail}) {
if(detail.type == 1){
this.setData({ ['form.shipmentPerMonth']: detail.text })
} else if(detail.type == 2){
this.setData({ ['form.experienceTag']: detail.text })
}
},
submitForm: function () {
if (util.isEmpty(this.data.form.businessLicenseUrl)) {
util.showToast('请上传营业执照')
return
}
if (util.isEmpty(this.data.form.enterpriseName)) {
util.showToast('请输入公司名称')
return
}
if (util.isEmpty(this.data.form.uniformSocialCreditCode)) {
util.showToast('请输社会入统一信用代码')
return
}
if (util.isEmpty(this.data.form.legalPersonName)) {
util.showToast('请输法人姓名')
return
}
wx.showLoading({ title: '处理中', mask: true })
checkLicense(this.data.form).then(result => {
// 修改个人信息
updateUserInfo(this.data.form).then(result => {
wx.hideLoading()
if(!app.globalData.userInfo.isAuth){
wx.redirectTo({ url: '/pages/home/idcard/index' })
}
}).catch(error => {
wx.hideLoading()
util.showToast(error)
})
}).catch(error => {
wx.hideLoading()
util.showToast(error)
})
},
onImageChange: function (e) {
if (e.detail) {
var list = []
e.detail.forEach(element => {
if (!util.isEmpty(element.url)) {
list.push(element.url)
}
})
if(list.length > 0){
this.data.form['businessLicenseUrl'] = list[0]
ocrLicense({businessLicenseUrl: list[0]}).then(result => {
this.setData({
['form.enterpriseName']: result.data.company,
['form.uniformSocialCreditCode']: result.data.regNum,
['form.legalPersonName']: result.data.legalPerson
})
})
}
}
},
/*******************************************************图片上传************************************************************/
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}
}
}
})
}
})
},
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 })
}
})