hurx 1 hete
szülő
commit
ba84f259e2
1 módosított fájl, 19 hozzáadás és 11 törlés
  1. 19 11
      src/views/enterprisePurchase/index.vue

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

@@ -177,12 +177,10 @@
 
             <el-table :data="carouselList" style="width: 100%" row-key="id" border header-cell-class-name="table-header-custom">
               <el-table-column label="排序" width="70" align="center">
-                <template #default="scope">
+                <template #default="{ $index }">
                   <div class="rank-box">
-                    <el-icon v-if="scope.$index > 0" class="rank-icon" @click="moveRow(scope.$index, -1)"><CaretTop /></el-icon>
-                    <el-icon v-if="scope.$index < carouselList.length - 1" class="rank-icon" @click="moveRow(scope.$index, 1)"
-                      ><CaretBottom
-                    /></el-icon>
+                    <el-icon v-if="$index > 0" class="rank-icon" @click="moveRow($index, -1)"><CaretTop /></el-icon>
+                    <el-icon v-if="$index < carouselList.length - 1" class="rank-icon" @click="moveRow($index, 1)"><CaretBottom /></el-icon>
                   </div>
                 </template>
               </el-table-column>
@@ -409,12 +407,10 @@
 
           <el-table :data="categoryList" border style="width: 100%" header-cell-class-name="table-header-custom">
             <el-table-column label="排序" width="70" align="center">
-              <template #default="scope">
+              <template #default="{ $index }">
                 <div class="rank-box">
-                  <el-icon v-if="scope.$index > 0" class="rank-icon" @click="moveCategory(scope.$index, -1)"><CaretTop /></el-icon>
-                  <el-icon v-if="scope.$index < categoryList.length - 1" class="rank-icon" @click="moveCategory(scope.$index, 1)"
-                    ><CaretBottom
-                  /></el-icon>
+                  <el-icon v-if="$index > 0" class="rank-icon" @click="moveCategory($index, -1)"><CaretTop /></el-icon>
+                  <el-icon v-if="$index < categoryList.length - 1" class="rank-icon" @click="moveCategory($index, 1)"><CaretBottom /></el-icon>
                 </div>
               </template>
             </el-table-column>
@@ -2408,11 +2404,23 @@ const removePanelNote = (index) => {
   categoryForm.panelData.notes.splice(index, 1);
 };
 
-const moveCategory = (index, direction) => {
+const moveCategory = async (index: number, direction: number) => {
   const newIndex = index + direction;
   if (newIndex < 0 || newIndex >= categoryList.value.length) return;
   const item = categoryList.value.splice(index, 1)[0];
   categoryList.value.splice(newIndex, 0, item);
+
+  // 同步排序到后端
+  try {
+    const start = Math.min(index, newIndex);
+    const end = Math.max(index, newIndex);
+    for (let i = start; i <= end; i++) {
+      const row = categoryList.value[i] as any;
+      await updateCategoryMain({ id: row.id, sortOrder: i } as any);
+    }
+  } catch (error) {
+    console.error('排序更新失败:', error);
+  }
 };
 
 onMounted(() => {