// pages/home/authory/index.js import { certificateImage } from "../../api/user" const util = require('../../../utils/util') const app = getApp() Page({ /** * 页面的初始数据 */ data: { monthList: [{ text: '1000吨以下', value: 1 }, { text: '1000-2000吨', value: 2 }, { text: '2000吨以上', value: 3 }], expriseList: [{ text: '1年以下', value: 1 }, { text: '1-5年', value: 2 }, { text: '5-10年', value: 3 }, { text: '10年以上', value: 4 }], form: { identityAuthToken: null }, flag: false, // 是否不可以编辑, false:可编辑;true:不可编辑 disabled: true, imgList: [null] }, onLoad: function (options) { }, bindForm: function (e) { // var form_data = 'form.' + e.target.id this.data.form[e.target.id] = e.detail.value }, showPicker: function (e) { this.pickerView = this.pickerView || this.selectComponent('#picker-view') if(e.currentTarget.id == 'shipmentPerMonth'){ this.pickerView.showPicker(this.data.monthList, null, 1) } else if(e.currentTarget.id == 'experienceTag'){ this.pickerView.showPicker(this.data.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.frontImg)) { util.showToast('请上传身份证正面照片') return } if (util.isEmpty(this.data.form.backImg)) { util.showToast('请上传身份证背面照片') return } wx.showLoading({ title: '处理中', mask: true }) certificateImage(this.data.form).then(result => { wx.hideLoading() var tokenJson = JSON.stringify(result.data) 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} } } }) } }) }, 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 }) } })