// pages/control/order/order.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { fileList: [], }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ wash_code:options.wash_code }) this.getdesc() }, toResult(){ var that = this; var fileList=this.data.fileList; var images=[] fileList.map((item, index) => { images[index]=item.url }) if(images=="" || images==[]){ wx.showLoading({ title: "你忘记拍照了", }) setTimeout(function () { wx.hideLoading(); }, 1000); return false; } app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/hand/hand_up", { wash_code:this.data.wash_code, images:images }, "post").then(function (res) { console.log(res); if (res.code != 200) { wx.showLoading({ title: res.message.msg, }) setTimeout(function () { wx.hideLoading(); }, 1000); } else { wx.hideLoading(); var data = res.message.data wx.showLoading({ title: res.message.msg, }) setTimeout(function () { wx.hideLoading(); wx.navigateTo({ url: '../result/result?data='+JSON.stringify(data), }) }, 1000); } }).catch(function (err) { console.log(222); }) }, getdesc(){ var that = this; app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/entry/desc", { wash_code:this.data.wash_code, }, "get").then(function (res) { console.log(res); if (res.code != 200) { wx.showLoading({ title: res.message.msg, }) setTimeout(function () { wx.hideLoading(); wx.navigateBack({ delta: 1 //想要返回的层级 }) }, 1000); } else { wx.hideLoading(); let data = res.message.data that.setData({ data }) } }).catch(function (err) { console.log(222); }) }, afterRead(event) { var that=this; const { file } = event.detail; // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式 wx.uploadFile({ url: app.globalData.baseAppUrl + 'api/common/uploadImg', // 仅为示例,非真实的接口地址 filePath: file.url, header: { "Content-Type": "multipart/form-data", 'accept': 'application/json', }, name: 'file', formData: { user: 'test' }, success(res) { var datas = JSON.parse(res.data) console.log(datas); if(datas.code==200){ // 上传完成需要更新 fileList const { fileList = [] } = that.data; fileList.push({ ...file, url: datas.message.data.path }); that.setData({ fileList }); }else{ wx.showLoading({ title: datas.message.msg, }) setTimeout(function () { wx.hideLoading(); }, 1000); } }, }); }, oncloes(){ wx.navigateBack({ delta: 1 //想要返回的层级 }) } })