// plugin/etc/pages/activeDes/activeDes.js import { configPluginData, failPluginData } from "../../../config.js" import Api from "../../../api/index.js" import { requestFnc } from "../../../utils/request.js" import { uploadFile } from "../../../network/upload" import { API } from "../../../network/etcApi" const network = require('../../../network/index'); Page({ /** * 页面的初始数据 */ data: { orderNo: "", isLoading: false, imagePath: '', imagePathUrl: '', isHaveUpload: true }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.configData(options) this.testIsHaveUpload() }, onUnload() { }, // 是否需要上传安装照片 async testIsHaveUpload() { this.setData({ isLoading: true }) var res = await network.etc.isHaveUploadInstallPhoto({ orderNo: this.data.orderNo, }) this.setData({ isLoading: false }) if (res.data) { let data = res.data.upInFlag // 如果需要上传 if (data) { this.setData({ isHaveUpload: true }) } else { wx.redirectTo({ url: `plugin://issuer-plugin/activeDesIn?orderNo=${this.data.orderNo}` }) } } else { wx.showToast({ title: res.message, icon: 'none' }) setTimeout(() => { wx.navigateBack() }, 1500) } }, nextStep() { if (this.data.imagePath) { wx.redirectTo({ url: `plugin://issuer-plugin/activeDesIn?orderNo=${this.data.orderNo}` }) } else { wx.showToast({ title: "请上传安装照片", icon: "none", }) } }, /// -------------- 工具类型 ---------------- /// // 配置默认参数 configData(options) { configPluginData() const orderNo = options?.orderNo if (orderNo) { this.setData({ orderNo }) } }, /// 配置导航栏标题 configNavTitle(title = "设备搜索") { wx.setNavigationBarTitle({ title: title, }) }, chooseImage() { wx.chooseMedia({ count: 1, //默认9 mediaType: ['image'], sizeType: ["compressed"], //可以指定是原图还是压缩图,默认二者都有 success: (res) => { let path = res.tempFiles[0].tempFilePath uploadFile(path).then(res => { console.log(res) wx.showLoading({ title: '上传中...', }) let fileUrl = res.ossFilePath console.log(fileUrl) this.setData({ imagePath: fileUrl, imagePathUrl: `https://qtzl.etcjz.cn/${fileUrl}` }) console.log(`https://qtzl.etcjz.cn/${fileUrl}`) let params = { orderNo: this.data.orderNo, url: fileUrl } API.ETC.uploadInstallPhoto(params) wx.hideLoading(); }) }, fail: function (e) { console.log(e) wx.hideLoading(); }, }) } })