hurx 1 week ago
parent
commit
889e7c20bf
1 changed files with 19 additions and 3 deletions
  1. 19 3
      src/views/enterprisePurchase/index.vue

+ 19 - 3
src/views/enterprisePurchase/index.vue

@@ -1081,14 +1081,15 @@
             </el-form-item>
             <el-form-item label="同步分类:">
               <el-select
-                v-model="categoryForm.syncCategory"
+                v-model="categoryForm.syncCategoryId"
                 placeholder="请选择或输入关联的一级分类"
                 style="width: 100%"
                 filterable
                 allow-create
                 default-first-option
+                @change="onSyncCategoryChange"
               >
-                <el-option v-for="opt in syncCategoryOptions" :key="opt" :label="opt" :value="opt" />
+                <el-option v-for="opt in syncCategoryOptions" :key="opt.value" :label="opt.label" :value="opt.value" />
               </el-select>
             </el-form-item>
             <el-form-item label="标签设置:">
@@ -2052,9 +2053,21 @@ const handleDeleteLeftAd = () => {
 // 分类设置模块逻辑
 const categoryThemeColor = ref('#e60012');
 const syncCategoryOptions = computed(() => {
-  return (categoryOptions.value || []).map((item: any) => item.label);
+  return (categoryOptions.value || []).map((item: any) => ({
+    value: item.id,
+    label: item.label
+  }));
 });
 
+const onSyncCategoryChange = (val: string | number) => {
+  if (val) {
+    const node = findNodeById(categoryOptions.value, val);
+    categoryForm.syncCategory = node ? node.label : '';
+  } else {
+    categoryForm.syncCategory = '';
+  }
+};
+
 const categoryList = ref<CategoryMainVO[]>([]);
 
 // 获取分类列表
@@ -2104,6 +2117,7 @@ const categoryForm = reactive({
   id: null,
   name: '',
   icon: '',
+  syncCategoryId: null,
   syncCategory: '',
   tags: [],
   status: 1,
@@ -2121,6 +2135,7 @@ const handleAddCategory = () => {
     id: null,
     name: '',
     icon: '',
+    syncCategoryId: null,
     syncCategory: '',
     tags: [],
     status: 1,
@@ -2141,6 +2156,7 @@ const submitCategoryForm = async () => {
   const data: CategoryMainForm = {
     name: categoryForm.name,
     icon: categoryForm.icon,
+    syncCategoryId: categoryForm.syncCategoryId,
     syncCategory: categoryForm.syncCategory,
     status: categoryForm.status,
     panelMainTitle: categoryForm.panelData.mainTitle,