Commit 752ac4b8 by LJM

图片操作

parent bda86a26
Showing with 38 additions and 15 deletions
...@@ -341,6 +341,7 @@ ...@@ -341,6 +341,7 @@
data() { data() {
return { return {
noexebshowFalg: true, //控制是否会触发生命周期 noexebshowFalg: true, //控制是否会触发生命周期
img_upload_url: uni.getStorageSync('img_upload_url') || 'http://image.liexindev.net', //oss系统
company_id: uni.getStorageSync('company_id') || 1, company_id: uni.getStorageSync('company_id') || 1,
input_flag: false, input_flag: false,
flag: false, flag: false,
...@@ -887,7 +888,7 @@ ...@@ -887,7 +888,7 @@
const imagePaths = chooseImageRes.tempFilePaths; const imagePaths = chooseImageRes.tempFilePaths;
// 判断选择的图片数量是否超过最大限制数量 // 判断选择的图片数量是否超过最大限制数量
let maxNum = Number(imagePaths.length) + Number(this.list[index].recheck_img_list.length); //当前上传的+已经上传的 let maxNum = Number(imagePaths.length) + Number(this.list[index].sign_pic_ids.length); //当前上传的+已经上传的
if (maxNum > this.maxNum) { if (maxNum > this.maxNum) {
uni.hideLoading(); uni.hideLoading();
uni.showToast({ uni.showToast({
...@@ -922,27 +923,25 @@ ...@@ -922,27 +923,25 @@
uni.hideLoading(); uni.hideLoading();
let data = JSON.parse(uploadFileRes.data); let data = JSON.parse(uploadFileRes.data);
if (data.code === 0) { if (data.code === 0) {
// 根据参数index更新list里的数组recheck_img_list // 根据参数index更新list里的数组sign_pic_ids
let itemToUpdate = this.list[index]; let itemToUpdate = this.list[index];
itemToUpdate.recheck_img_list.push({ itemToUpdate.sign_pic_ids.push({
pic_id: data.data.oss_image_id, img_id: data.data.oss_image_id,
small_image_url: data.data.small_image_url, small_image_url: data.data.small_image_url,
big_image_url: data.data.big_image_url big_image_url: data.data.big_image_url,
url: data.data.oss_image_url,
id_del: 1
}); });
// 更新整个list数组 // 更新整个list数组
this.list = [...this.list]; this.list = [...this.list];
// 获取特定索引位置的recheck_img_list // 只传新上传图片的 img_id
let pickImgList = this.list[index].recheck_img_list; let img_id = data.data.oss_image_id;
// 使用flatMap获取所有的pic_id并拼接成字符串
let pic_ids = pickImgList.flatMap(item => item.pic_id).join(',');
//签约图片更新 //签约图片更新
this.signUserPic(this.list[index].stock_out_id, pic_ids, 1); this.signUserPic(this.list[index].stock_out_id, img_id, 1);
} else { } else {
uni.showToast({ uni.showToast({
...@@ -974,7 +973,7 @@ ...@@ -974,7 +973,7 @@
* @param {string} img_id - 图片ID,多个以逗号分隔 * @param {string} img_id - 图片ID,多个以逗号分隔
* @param {number} type - 操作类型:1-新增 2-删除 * @param {number} type - 操作类型:1-新增 2-删除
*/ */
signUserPic(stock_out_id, img_id, type) { signUserPic(stock_out_id, img_id, type, callback) {
// 使用对象展开运算符一次性更新参数 // 使用对象展开运算符一次性更新参数
this.signUserPicParams = { this.signUserPicParams = {
...this.signUserPicParams, ...this.signUserPicParams,
...@@ -989,8 +988,7 @@ ...@@ -989,8 +988,7 @@
title: '操作成功', title: '操作成功',
icon: 'success' icon: 'success'
}); });
typeof callback == 'function' && callback();
setTimeout(() => this.getData(), 2000);
} else { } else {
uni.showToast({ uni.showToast({
title: res.msg, title: res.msg,
...@@ -998,6 +996,31 @@ ...@@ -998,6 +996,31 @@
}); });
} }
}); });
},
/**
* 删除图片
* @param {Object} index 主索引index
* @param {Object} i 图片索引
*/
deletePic(index, i) {
uni.showModal({
title: '确认删除',
content: '确定要删除这张图片吗?',
success: (res) => {
if (res.confirm) {
//签约图片删除
this.signUserPic(this.list[index].stock_out_id, this.list[index].sign_pic_ids[i].img_id, 2, () => {
this.list[index].sign_pic_ids.splice(i, 1);
this.list = [...this.list];
this.$forceUpdate();
});
} else if (res.cancel) {
// 用户点击取消
console.log('用户点击取消');
}
}
});
} }
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment