From c422239a0580bc31be367c13c5524958d0c49fc4 Mon Sep 17 00:00:00 2001 From: weipengfei <2187978347@qq.com> Date: Fri, 27 Oct 2023 10:59:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=95=86=E5=93=81=E5=A4=9A?= =?UTF-8?q?=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/task_template/dialog_commodity.vue | 100 ++++++++++++++++--- src/views/task_template/edit_admin.vue | 42 +++++--- 2 files changed, 114 insertions(+), 28 deletions(-) diff --git a/src/views/task_template/dialog_commodity.vue b/src/views/task_template/dialog_commodity.vue index 7d1392e..f76bf0c 100644 --- a/src/views/task_template/dialog_commodity.vue +++ b/src/views/task_template/dialog_commodity.vue @@ -26,7 +26,12 @@
- + + @@ -52,22 +63,21 @@ import { usePaging } from "@/hooks/usePaging"; import { useDictData } from "@/hooks/useDictOptions"; import { apiGetProductList } from "@/api/task_template"; -import { defineEmits } from "vue"; +import { defineEmits, computed, watch } from "vue"; + +const tableRef = ref(null); // 当前类型 const props = defineProps({ - type: { - type: Number, - default: 0, - }, - companyTypeList: { - type: Array, - default: () => { - return []; - }, + ids: { + type: String, + default: "", }, }); +let goods_id = props.ids?.split(",") || []; +// console.log(goods_id); + // 查询条件 const queryParams = reactive({ keyword: "", @@ -75,11 +85,36 @@ const queryParams = reactive({ }); // 选中数据 -const emits = defineEmits(["customEvent"]); +const emits = defineEmits(["customEvent", "close"]); // 选中数据子父传递 const handleCurrentChange = (value: any) => { - emits("customEvent", value); + let arr: any = []; + value.forEach((item: any) => { + arr = [...arr, ...item]; + }); + // return console.log(value, arr); + emits("customEvent", arr); +}; + +const changeList = ref([[]]); +let count = 0; +const handleSelectionChange = (value: any[]) => { + // 在翻页时,上一页的数据会被清空, 不得已使用二维数组存取数据 + let index = pager.page ? pager.page - 1 : 0; + if (!changeList.value[index]) changeList.value.push([]); + // 同一页选择多个商品时, 每选择一次, 此方法都会被调用, 所以选择多个时此方法会被调用多次, 在翻页时会出现漏选, 使用此方法避免 + if (index != count && value.length < changeList.value[index].length) { + console.log("加载中"); + } else { + count = index; + changeList.value[index] = JSON.parse(JSON.stringify(value)); + console.log("加载完成"); + } +}; // 多选 + +const commodityClose = () => { + emits("close", null); }; // 分页相关 @@ -90,4 +125,43 @@ const { pager, getLists, resetParams, resetPage } = usePaging({ }); getLists(); + +// 监听数据变化进行勾选 +watch( + () => pager.lists, + (n, o) => { + // 进行勾选 + nextTick(() => { + n.forEach((item: any) => { + item.product_id += ""; + // console.log("过滤前", goods_id); + let f_ids = new Set(); // 删除选中的id + // 对选择过的列表进行回显 + if (goods_id.includes(item.product_id)) { + let index = pager.page ? pager.page - 1 : 0; + if ( + !changeList.value[index]?.find( + (e: any) => e.product_id == item.product_id + ) + ) { + f_ids.add(item.product_id); + changeList.value[index]?.push(item); + } + } + goods_id = goods_id.filter((item: string) => !f_ids.has(item)); // 已选择过的进行删除 + // console.log("长度", goods_id); + // console.log("已选", changeList.value); + // 把changeList列表中的所有值进行勾选 + changeList.value.forEach((c: any) => { + c.forEach((e: any) => { + if (e.product_id == item.product_id) { + tableRef.value.toggleRowSelection(item, true); + } + }); + }); + }); + }); + }, + { deep: true, immediate: true } +); diff --git a/src/views/task_template/edit_admin.vue b/src/views/task_template/edit_admin.vue index bccc547..82cd66e 100644 --- a/src/views/task_template/edit_admin.vue +++ b/src/views/task_template/edit_admin.vue @@ -76,19 +76,20 @@
- - + +
{{ formData.extend.store_name }}
+ 选择商品 -
@@ -294,7 +296,7 @@ const formData = reactive({ extend: { task_role: "", // 任务角色 target: "", //目标数量 - product_id: "", //商品id + goods_id: "", //商品id store_name: "", // 商品名字 }, }); @@ -373,9 +375,19 @@ const openCommodity = () => { }; const customEventCommodity = (e: any) => { - formData.extend.product_id = e.product_id; - formData.extend.store_name = e.store_name; - formRef.value?.clearValidate("extend.product_id"); + let id: string[] | number[] = []; + let name: string[] = []; + e.forEach((item: any) => { + id.push(item.product_id); + name.push(item.store_name); + }); + formData.extend.goods_id = id.join(","); + formData.extend.store_name = name.join(";"); + formRef.value?.clearValidate("extend.goods_id"); + showDialogCommodity.value = false; +}; + +const commodityClose = () => { showDialogCommodity.value = false; }; @@ -452,7 +464,7 @@ const formRules = reactive({ trigger: ["blur"], }, ], - "extend.product_id": [ + "extend.goods_id": [ { required: true, message: "请选择商品",