hurx vor 13 Stunden
Ursprung
Commit
e0dbf95660

+ 11 - 0
src/api/dkhDesign/carouselConfig/index.ts

@@ -61,3 +61,14 @@ export const delCarouselConfig = (id: string | number | Array<string | number>)
     method: 'delete'
   });
 };
+export function changeCarouselConfigStatus(id: string | number, status: number) {
+  const data = {
+    id,
+    status
+  };
+  return request({
+    url: '/mall/carouselConfig/changeStatus',
+    method: 'put',
+    data: data
+  });
+}

+ 12 - 0
src/api/dkhDesign/categoryMain/index.ts

@@ -61,3 +61,15 @@ export const delCategoryMain = (id: string | number | Array<string | number>) =>
     method: 'delete'
   });
 };
+
+export function changeCategoryMainStatus(id: string | number, status: number) {
+  const data = {
+    id,
+    status
+  };
+  return request({
+    url: '/mall/dkhCategoryMain/changeStatus',
+    method: 'put',
+    data: data
+  });
+}

+ 12 - 0
src/api/dkhDesign/headerMenu/index.ts

@@ -61,3 +61,15 @@ export const delHeaderMenu = (id: string | number | Array<string | number>) => {
     method: 'delete'
   });
 };
+
+export function changeHeaderMenuStatus(id: string | number, status: number) {
+  const data = {
+    id,
+    status
+  };
+  return request({
+    url: '/mall/headerMenu/changeStatus',
+    method: 'put',
+    data: data
+  });
+}

+ 12 - 0
src/api/dkhDesign/recommendCategoryConfig/index.ts

@@ -61,3 +61,15 @@ export const delRecommendCategoryConfig = (id: string | number | Array<string |
     method: 'delete'
   });
 };
+
+export function changeRecommendCategoryStatus(id: string | number, status: number) {
+  const data = {
+    id,
+    status
+  };
+  return request({
+    url: '/mall/dkhRecommendCategoryConfig/changeStatus',
+    method: 'put',
+    data: data
+  });
+}

+ 83 - 15
src/views/platform/dkhCustomer/index.vue

@@ -170,7 +170,13 @@
               <el-table-column prop="link" label="跳转地址" show-overflow-tooltip />
               <el-table-column label="状态" width="100" align="center">
                 <template #default="scope">
-                  <el-switch v-model="scope.row.status" :active-value="1" :inactive-value="0" active-color="#13ce66" />
+                  <el-switch
+                    v-model="scope.row.status"
+                    :active-value="1"
+                    :inactive-value="0"
+                    active-color="#13ce66"
+                    @change="changeCarouselConfigStatus(scope.row.id, scope.row.status)"
+                  />
                 </template>
               </el-table-column>
               <el-table-column label="操作" width="150" align="center">
@@ -447,7 +453,13 @@
             </el-table-column>
             <el-table-column label="状态" width="100" align="center">
               <template #default="scope">
-                <el-switch v-model="scope.row.status" :active-value="1" :inactive-value="0" active-color="#13ce66" />
+                <el-switch
+                  v-model="scope.row.status"
+                  :active-value="1"
+                  :inactive-value="0"
+                  active-color="#13ce66"
+                  @change="changeCategoryMainStatus(scope.row.id, scope.row.status)"
+                />
               </template>
             </el-table-column>
             <el-table-column label="操作" width="150" align="center" fixed="right">
@@ -517,7 +529,13 @@
             <el-table-column prop="link" label="跳转地址" min-width="350" show-overflow-tooltip />
             <el-table-column label="状态" width="100" align="center">
               <template #default="{ row }">
-                <el-switch v-model="row.status" :active-value="1" :inactive-value="0" active-color="#13ce66" />
+                <el-switch
+                  v-model="row.status"
+                  :active-value="1"
+                  :inactive-value="0"
+                  active-color="#13ce66"
+                  @change="changeHeaderMenuStatus(row.id, row.status)"
+                />
               </template>
             </el-table-column>
             <el-table-column label="操作" width="150" fixed="right" align="center">
@@ -930,7 +948,13 @@
             </el-table-column>
             <el-table-column label="启用状态" width="100" align="center">
               <template #default="{ row }">
-                <el-switch v-model="row.status" :active-value="1" :inactive-value="0" active-color="#13ce66" />
+                <el-switch
+                  v-model="row.status"
+                  :active-value="1"
+                  :inactive-value="0"
+                  active-color="#13ce66"
+                  @change="changeRecommendCategoryStatus(row.id, row.status)"
+                />
               </template>
             </el-table-column>
             <el-table-column label="操作" width="220" align="center" fixed="right">
@@ -1613,11 +1637,17 @@ import { ref, reactive, computed, watch, onMounted, onUnmounted, nextTick } from
 import { ElMessage, ElMessageBox } from 'element-plus';
 import { globalHeaders } from '@/utils/request';
 import { addMallConfig, updateMallConfig, getCurrentMallConfig } from '@/api/dkhDesign/mallConfig';
-import { listCarouselConfig, delCarouselConfig, addCarouselConfig, updateCarouselConfig } from '@/api/dkhDesign/carouselConfig';
-import { listHeaderMenu, delHeaderMenu, addHeaderMenu, updateHeaderMenu } from '@/api/dkhDesign/headerMenu';
+import {
+  listCarouselConfig,
+  delCarouselConfig,
+  addCarouselConfig,
+  updateCarouselConfig,
+  changeCarouselConfigStatus
+} from '@/api/dkhDesign/carouselConfig';
+import { listHeaderMenu, delHeaderMenu, addHeaderMenu, updateHeaderMenu, changeHeaderMenuStatus } from '@/api/dkhDesign/headerMenu';
 import { listScenarioConfig, addScenarioConfig, updateScenarioConfig } from '@/api/dkhDesign/scenarioConfig';
 import { listAdConfig, addAdConfig, updateAdConfig } from '@/api/dkhDesign/adConfig';
-import { listCategoryMain, delCategoryMain, addCategoryMain, updateCategoryMain } from '@/api/dkhDesign/categoryMain';
+import { listCategoryMain, delCategoryMain, addCategoryMain, updateCategoryMain, changeCategoryMainStatus } from '@/api/dkhDesign/categoryMain';
 import { listBase } from '@/api/pmsProduct/base';
 import { categoryTree } from '@/api/product/base/index';
 import { categoryTreeVO } from '@/api/product/category/types';
@@ -1626,7 +1656,8 @@ import {
   listRecommendCategoryConfig,
   delRecommendCategoryConfig,
   addRecommendCategoryConfig,
-  updateRecommendCategoryConfig
+  updateRecommendCategoryConfig,
+  changeRecommendCategoryStatus
 } from '@/api/dkhDesign/recommendCategoryConfig';
 
 import {
@@ -2855,7 +2886,7 @@ const loadRecommendList = async () => {
       type: item.dataType || 'select',
       categoryPath: item.categoryPath || '',
       categoryLabel: item.categoryLabel || '',
-      selectedProducts: item.selectedProductIds ? JSON.parse(item.selectedProductIds) : [],
+      selectedProducts: item.selectedProductIds ? mapProductsFromBackend(JSON.parse(item.selectedProductIds)) : [],
       sortOrder: item.sortOrder ?? 0,
       status: item.status ?? 1
     }));
@@ -2975,6 +3006,7 @@ const handleRecommendCategoryChange = (val) => {
 
 const submitRecommendForm = async () => {
   const data = JSON.parse(JSON.stringify(recommendForm));
+  const mappedProducts = data.type === 'select' ? mapProductsForSave(data.selectedProducts || []) : [];
   try {
     const apiData: any = {
       customerId: customerId.value,
@@ -2983,7 +3015,7 @@ const submitRecommendForm = async () => {
       dataType: data.type || 'select',
       categoryPath: data.categoryValue?.join(',') || '',
       categoryLabel: data.categoryLabel || '',
-      selectedProductIds: data.type === 'select' ? JSON.stringify(data.selectedProducts || []) : '',
+      selectedProductIds: data.type === 'select' ? JSON.stringify(mappedProducts) : '',
       status: data.status ?? 1
     };
     if (data.id) {
@@ -3040,6 +3072,28 @@ const moveRecommend = async (index: number, direction: number) => {
   }
 };
 
+// 商品数据映射:id→productId,确保productNo存在
+const mapProductsForSave = (products: any[]) => {
+  return products.map((p: any) => ({
+    productId: p.id || p.productId,
+    productNo: p.productNo || '',
+    name: p.name || '',
+    image: p.image || '',
+    price: p.price || '0'
+  }));
+};
+
+// 从后端加载时反向映射:productId→id,兼容旧数据
+const mapProductsFromBackend = (products: any[]) => {
+  return products.map((p: any) => ({
+    id: p.id || p.productId,
+    productNo: p.productNo || '',
+    name: p.name || '',
+    image: p.image || '',
+    price: p.price || '0'
+  }));
+};
+
 // 推荐商品选择增强逻辑
 const selectedProductDialogVisible = ref(false);
 const productSelectionDrawerVisible = ref(false);
@@ -3070,9 +3124,18 @@ const openRecommendProductSelect = (index) => {
 
 const submitSelectedProducts = async () => {
   const item = recommendList.value[currentRecommendIndex.value];
-  if (!item) return;
+  if (!item) {
+    ElMessage.warning('未找到当前推荐分类');
+    return;
+  }
 
   const selectedProducts = item.selectedProducts || [];
+  if (selectedProducts.length === 0) {
+    ElMessage.warning('请先选择商品后再保存');
+    return;
+  }
+
+  const mappedProducts = mapProductsForSave(selectedProducts);
   const data: any = {
     id: item.id,
     customerId: customerId.value,
@@ -3081,12 +3144,14 @@ const submitSelectedProducts = async () => {
     dataType: item.type || 'select',
     categoryLabel: item.categoryLabel || '',
     categoryPath: item.categoryPath || '',
-    selectedProductIds: JSON.stringify(selectedProducts),
+    selectedProductIds: JSON.stringify(mappedProducts),
     status: item.status ?? 1
   };
 
   try {
     await updateRecommendCategoryConfig(data);
+    // 同步更新内存中的数据,确保UI展示与后端一致
+    item.selectedProducts = selectedProducts;
     selectedProductDialogVisible.value = false;
     ElMessage.success('已选商品配置已保存');
   } catch (error) {
@@ -3127,6 +3192,7 @@ const confirmDrawerSelection = async () => {
   const selectedProducts = JSON.parse(JSON.stringify(drawerSelection.value));
   item.selectedProducts = selectedProducts;
 
+  const mappedProducts = mapProductsForSave(selectedProducts);
   try {
     await updateRecommendCategoryConfig({
       id: item.id,
@@ -3136,7 +3202,7 @@ const confirmDrawerSelection = async () => {
       dataType: item.type || 'select',
       categoryLabel: item.categoryLabel || '',
       categoryPath: item.categoryPath || '',
-      selectedProductIds: JSON.stringify(selectedProducts),
+      selectedProductIds: JSON.stringify(mappedProducts),
       status: item.status ?? 1
     });
     ElMessage.success('商品列表同步成功');
@@ -3152,6 +3218,7 @@ const removeSelectedProduct = async (index: number) => {
   if (!item) return;
   item.selectedProducts.splice(index, 1);
 
+  const mappedProducts = mapProductsForSave(item.selectedProducts);
   try {
     await updateRecommendCategoryConfig({
       id: item.id,
@@ -3161,7 +3228,7 @@ const removeSelectedProduct = async (index: number) => {
       dataType: item.type || 'select',
       categoryLabel: item.categoryLabel || '',
       categoryPath: item.categoryPath || '',
-      selectedProductIds: JSON.stringify(item.selectedProducts),
+      selectedProductIds: JSON.stringify(mappedProducts),
       status: item.status ?? 1
     });
     ElMessage.success('移除成功');
@@ -3182,6 +3249,7 @@ const batchRemoveSelectedProducts = () => {
     const selectedIds = selectedRows.map((r: any) => r.id);
     item.selectedProducts = currentList.filter((p: any) => !selectedIds.includes(p.id));
 
+    const mappedProducts = mapProductsForSave(item.selectedProducts);
     try {
       await updateRecommendCategoryConfig({
         id: item.id,
@@ -3191,7 +3259,7 @@ const batchRemoveSelectedProducts = () => {
         dataType: item.type || 'select',
         categoryLabel: item.categoryLabel || '',
         categoryPath: item.categoryPath || '',
-        selectedProductIds: JSON.stringify(item.selectedProducts),
+        selectedProductIds: JSON.stringify(mappedProducts),
         status: item.status ?? 1
       });
       ElMessage.success('批量移除成功');