// plugin/components/enterpriseUpload/enterpriseUpload.js import Api from "../../api/index.js" import { requestFnc } from "../../utils/request.js" import { getStore, setStore } from "../../utils/index.js" Component({ properties: { showOne: { type: Boolean, value: false, }, }, data: { isLoading: false, sides: "1", leftPath: "", rightPath: "", identity: {}, }, attached: function () {}, methods: { //选择图片 chooseImage(e) { console.log(e.currentTarget.dataset.side) this.setData({ sides: e.currentTarget.dataset.side, }) this.compressRef = this.selectComponent("#compress") this.compressRef._changImg() }, ////图片压缩成功 compressRes(file) { this.setData({ isLoading: true, }) let imgStr = file.detail[0].split(";")[1].split(",")[1] if (this.data.sides === "2") { //反面 this.setData({ rightPath: file.detail[0], isLoading: false, }) let obj = { type: "2", imgStr: imgStr, } this.triggerEvent("enterpriseImage", obj) return } if (this.data.sides === "1") { //正面 this.setData({ leftPath: file.detail[0], }) let obj = { type: "1", imgStr: imgStr, } this.triggerEvent("enterpriseImage", obj) let data = { filename: Api.ocrCorp.filename, data: { imageStr: imgStr, vehicleId: getStore("vehicleId"), }, } requestFnc( Api.ocrCorp.url, data, (res) => { let corpInfoObj = JSON.parse(res.encryptedData) corpInfoObj.imageId = res.imageId for (let key in corpInfoObj) { this.data.identity[key] = corpInfoObj[key] } this.setData({ isLoading: false, identity: this.data.identity, }) this.triggerEvent( "enterpriseOcrInfo", this.data.identity ) }, (msg) => { this.setData({ isLoading: false, }) } ) } }, viewImage(e) { console.log(e) wx.previewImage({ urls: [e.currentTarget.dataset.type], }) }, delImg(e) { let data = e.currentTarget.dataset.type wx.showModal({ title: "提示", content: "确定要删除此照片吗?", success: (res) => { if (res.confirm) { if (data == "left") { this.setData({ leftPath: "", }) } else if (data == "right") { this.setData({ rightPath: "", }) } this.triggerEvent("delImg", data) } }, }) }, }, })