Files
lichebao/pages/order/editVoucherImg/index.js
T
2022-12-20 17:33:07 +08:00

103 lines
2.6 KiB
JavaScript

import _ from '../../../commons/js/commons'
const app = getApp()
Page({
data: {
destory_img:{},
},
onLoad: function (options) {
for (let key in options) {
this.setData({
[key]: options[key]
})
}
this.getAppCusorderdata()
},
onShow: function () {
},
//获取订单图片
getAppCusorderdata(){
let params = {};
params['id'] = this.data.id;
_.apiQuery.getAppCusorderdata(params).then(res=>{
this.setData({
imgInfo:res.data,
})
if(res.data.img_status == 1){
this.setData({
destory_img:res.data.imgs.destory_img.length==0?{}:res.data.imgs.destory_img,
})
}
wx.stopPullDownRefresh()
})
},
//选择图片
chooseImg(e) {
let that = this
//上传交强险
if(e.currentTarget.dataset.type=='destory_img'){
wx.chooseImage({
count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success(res) {
wx.showLoading({
title: '上传中',
})
wx.uploadFile({
url:_.config.api.upImg,
filePath:res.tempFilePaths[0],
name: 'img',
formData: {
'app': 'liche'
},
success: (resp) => {
resp.data = JSON.parse(resp.data);
if (resp.data.code == 200) {
let params = {};
params['id'] = that.data.id;
params['destory_img'] = resp.data.data.url;
_.apiQuery.putAppCusorderdata(params).then(res2 => {
wx.hideLoading();
that.getAppCusorderdata()
}).catch(res2=>{
wx.hideLoading();
});
}else{
wx.hideLoading();
wx.showToast({
title: '上传失败',
icon: 'none',
duration: 2000
})
}
},
})
},
fail: res => {
wx.showToast({
title: '文件选择失败',
icon: 'none',
duration: 2000
})
}
})
}
},
//查看图片
previewImage: function (e) {
if(e.currentTarget.dataset.type=='destory_img'){
wx.previewImage({
current:this.data.imgInfo.imgs.destory_img.img,
urls:[this.data.imgInfo.imgs.destory_img.img],
})
}
},
})