// 添加图片按钮点击
tapAddPicBtn() {
if (this.isEdit == 2) {
return
}
let _self = this
// 选择图片
uni.chooseImage({
count: 1,
sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], //从相册选择
success: res => {
uni.showLoading({
title: '图片正在上传',
mask: true
})
console.log(res, 'resdddd')
_self.postPath = res.tempFilePaths[0]
_self.uploadShopRealImage((t, status) => {
const res = JSON.parse(t.responseText);
uni.hideLoading()
if (res.code === 2001) {
console.log(res, '图片上传结果');
this.fw_logo = res.data
}
}).start();
},
error: function(e) {
console.log(e);
}
});
},
// 图片上传方法
uploadShopRealImage(completed) {
//后端接口
var task = plus.uploader.createUpload(this.$api.uploadPicture, {
method: "POST",
priority: 100
},
(t, status) => {
completed(t, status)
}
);
task.addFile(this.postPath, {
key: 'img_ids'
});
//后端参数
task.addData('token', uni.getStorageSync(USERINFO).token + '');
task.addData('userId', uni.getStorageSync(USERINFO).userId + '');
task.addData('type', '1');
task.addData('shop_id', uni.getStorageSync(USERINFO).shop_id + '');
return task;
},
}