// plugin/etc/pages/activeUploadPhoto/activeUploadPhoto.js import { configPluginData, } from "../../../config.js" import { uploadFile } from "../../../network/upload" const network = require('../../../network/index'); import { API } from "../../../network/etcApi" Page({ /** * 页面的初始数据 */ data: { orderNo: "", obu: "", card: "", imagePath: '', imagePathUrl: '', isHaveUpload: true }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.configData(options) this.testIsHaveUpload() }, // 是否需要上传安装照片 async testIsHaveUpload() { wx.showLoading({ title: '查询中...', }) var res = await network.etc.isHaveUploadInstallPhoto({ orderNo: this.data.orderNo, }) wx.hideLoading() if (res.data) { let data = res.data.upInFlag // 如果需要上传 if (data) { this.setData({ isHaveUpload: true }) } else { this.configJumpToActive(); } } else { wx.showToast({ title: res.message, icon: 'none' }) } }, configJumpToActive() { wx.redirectTo({ url: `plugin://issuer-plugin/activeDeviceStep?orderNo=${this.data.orderNo}&obu=${this.data.obu}&card=${this.data.card}` }) }, nextStep() { if (this.data.imagePath) { this.configUploadInstallPhoto(); // this.configJumpToActive(); } else { wx.showToast({ title: "请上传安装照片", icon: "none", }) } }, // 配置默认参数 configData(options) { configPluginData() const orderNo = options?.orderNo if (orderNo) { this.setData({ orderNo }) } if (options?.obu) { this.setData({ obu: options.obu }) } if (options?.card) { this.setData({ card: options.card }) } }, chooseImage() { const that = this; wx.chooseMedia({ count: 1, //默认9 mediaType: ['image'], sizeType: ["compressed"], //可以指定是原图还是压缩图,默认二者都有 success: (res) => { let path = res.tempFiles[0].tempFilePath wx.showLoading({ title: '上传中...', }) uploadFile(path).then(res => { console.log(res) let fileUrl = res.ossFilePath console.log(fileUrl) that.setData({ imagePath: fileUrl, imagePathUrl: `https://qtzl.etcjz.cn/${fileUrl}` }) console.log(`https://qtzl.etcjz.cn/${fileUrl}`) wx.hideLoading(); }) }, fail: function (e) { wx.hideLoading(); console.log(e) }, }) }, async configUploadInstallPhoto() { let params = { orderNo: this.data.orderNo, url: this.data.imagePath } const res = await API.ETC.uploadInstallPhoto(params) wx.hideLoading(); if (res.code == 0) { this.configJumpToActive(); } else { wx.showToast({ title: res.message || "上传失败,请稍后重试", icon: "none" }) } } })