From ffecde25db733a6295d24e484684922470c6599a Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期二, 12 五月 2026 13:29:45 +0800
Subject: [PATCH] fix: 编辑产品小类时,提示选择父节点
---
src/views/basicData/product/index.vue | 38 +++++++++++++++++++++++++++-----------
1 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/src/views/basicData/product/index.vue b/src/views/basicData/product/index.vue
index 99ab028..07da49b 100644
--- a/src/views/basicData/product/index.vue
+++ b/src/views/basicData/product/index.vue
@@ -43,12 +43,12 @@
<el-button type="primary"
link
:disabled="isTopLevelNode(data, node)"
- @click="openProDia('edit', data)">
+ @click="openProDia('edit', data, node)">
缂栬緫
</el-button>
<el-button type="primary"
link
- @click="openProDia('add', data)">
+ @click="openProDia('add', data, node)">
娣诲姞浜у搧
</el-button>
<el-button v-if="!node.childNodes.length"
@@ -285,6 +285,8 @@
const search = ref("");
const currentId = ref("");
const currentParentId = ref("");
+ /** 浜у搧寮圭獥锛歛dd 瀛樼埗鑺傜偣 id锛沞dit 瀛樺綋鍓嶈妭鐐� id 涓� parentId锛堜笉渚濊禆鏍戦�変腑椤癸級 */
+ const productDialogTarget = ref(null);
const operationType = ref("");
const treeLoad = ref(false);
const list = ref([]);
@@ -388,17 +390,28 @@
return [null, undefined, "", 0, "0"].includes(data?.parentId);
};
// 鎵撳紑浜у搧寮规
- const openProDia = (type, data) => {
- if (data && type === "edit" && isTopLevelNode(data)) {
+ const openProDia = (type, data, node) => {
+ if (data && type === "edit" && isTopLevelNode(data, node)) {
proxy.$modal.msgWarning("涓�绾ц妭鐐逛笉鑳界紪杈戞垨鍒犻櫎");
return;
}
operationType.value = type;
- productDia.value = true;
- form.value.productName = "";
- if (type === "edit") {
- form.value.productName = data.productName;
+ productDialogTarget.value = null;
+ if (type === "add" && data) {
+ productDialogTarget.value = { parentId: data.id };
+ } else if (type === "edit" && data) {
+ let parentId = data.parentId;
+ if (
+ [null, undefined, ""].includes(parentId) &&
+ node?.parent?.data?.id != null
+ ) {
+ parentId = node.parent.data.id;
+ }
+ productDialogTarget.value = { id: data.id, parentId };
}
+ productDia.value = true;
+ form.value.productName =
+ type === "edit" && data ? data.productName : "";
};
// 鎵撳紑瑙勬牸鍨嬪彿寮规
const openModelDia = (type, data) => {
@@ -417,14 +430,16 @@
proxy.$refs.formRef.validate(valid => {
if (valid) {
if (operationType.value === "add") {
- form.value.parentId = currentId.value;
+ form.value.parentId =
+ productDialogTarget.value?.parentId ?? currentId.value;
form.value.id = "";
} else if (operationType.value === "addOne") {
form.value.id = "";
form.value.parentId = "";
} else {
- form.value.id = currentId.value;
- form.value.parentId = "";
+ form.value.id =
+ productDialogTarget.value?.id ?? currentId.value;
+ form.value.parentId = productDialogTarget.value?.parentId ?? "";
}
addOrEditProduct(form.value).then(res => {
proxy.$modal.msgSuccess("鎻愪氦鎴愬姛");
@@ -437,6 +452,7 @@
// 鍏抽棴浜у搧寮规
const closeProDia = () => {
proxy.$refs.formRef.resetFields();
+ productDialogTarget.value = null;
productDia.value = false;
};
--
Gitblit v1.9.3