Browse Source

修复盲注表

wengan01 1 month ago
parent
commit
54df143059
1 changed files with 52 additions and 12 deletions
  1. 52 12
      src/views/system/physical/blindLevels/index.vue

+ 52 - 12
src/views/system/physical/blindLevels/index.vue

@@ -97,7 +97,7 @@
           </el-table-column>
           <el-table-column label="是否休息" align="center" width="120">
             <template #default="scope">
-              <el-select v-model="scope.row.isBreak" size="small" style="width: 100px">
+              <el-select v-model="scope.row.isBreak" size="small" style="width: 100px" @change="handleIsBreakChange(scope.row)">
                 <el-option label="否" :value="0" />
                 <el-option label="是" :value="1" />
               </el-select>
@@ -255,6 +255,8 @@ const uploadFile = ref<File | null>(null);
 const rowErrors = ref<Map<string | number, string[]>>(new Map());
 // 全量数据(前端分页,保证跨页显示级别连续)
 const allData = ref<BlindLevelsVO[]>([]);
+// 过滤后数据(用于搜索过滤+分页)
+const filteredData = ref<BlindLevelsVO[]>([]);
 
 const props = defineProps({
   blindStructureId: {
@@ -344,32 +346,47 @@ const { queryParams, form, rules } = toRefs(data);
 const getList = async () => {
   loading.value = true;
   try {
+    const { levelNumber: levelNumberFilter, ...restParams } = queryParams.value;
     const res = await listBlindLevels({
-      ...queryParams.value,
+      ...restParams,
       pageNum: 1,
       pageSize: 999999
     });
-    allData.value = (res.rows || [])
+    const rawData = (res.rows || [])
       .map((item: any) => ({
         ...item,
         isBreak: item.isBreak === true || item.isBreak === 1 ? 1 : 0
       }))
       .sort((a, b) => (a.displayOrder || 0) - (b.displayOrder || 0));
-    total.value = allData.value.length;
+
+    rawData.forEach((row, idx) => {
+      const nonBreakBefore = rawData.slice(0, idx).filter((r: any) => r.isBreak !== 1).length;
+      (row as any)._displayLevel = nonBreakBefore + 1;
+    });
+
+    allData.value = rawData;
+
+    if (levelNumberFilter !== undefined && levelNumberFilter !== '' && levelNumberFilter !== null) {
+      const filterLevel = Number(levelNumberFilter);
+      filteredData.value = rawData.filter((row: any) => row._displayLevel === filterLevel);
+    } else {
+      filteredData.value = [...rawData];
+    }
+
+    total.value = filteredData.value.length;
     applyPagination();
   } finally {
     loading.value = false;
   }
 };
 
-/** 根据当前页码和每页条数,从全量数据中截取当前页 */
+/** 根据当前页码和每页条数,从过滤后的数据中截取当前页 */
 const applyPagination = () => {
   const pageNum = queryParams.value.pageNum || 1;
   const pageSize = queryParams.value.pageSize || 10;
   const start = (pageNum - 1) * pageSize;
-  blindLevelsList.value = allData.value.slice(start, start + pageSize);
-  // 同步总条数(本地插入/删除后保持分页信息正确)
-  total.value = allData.value.length;
+  blindLevelsList.value = filteredData.value.slice(start, start + pageSize);
+  total.value = filteredData.value.length;
 };
 
 /** 独立排序方法:按展示顺序字段排序(用于插入和保存后重新排序) */
@@ -379,13 +396,28 @@ const sortListByDisplayOrder = () => {
 
 /** 计算显示级别:基于全量数据计算,跨页级别连续 */
 const getDisplayLevel = (row: BlindLevelsVO): string | number => {
-  const idx = allData.value.findIndex((r) => r.id === row.id);
-  if (idx === -1) return row.levelNumber;
-  const nonBreakBefore = allData.value.slice(0, idx).filter((r) => r.isBreak !== 1).length;
   if (row.isBreak === 1) {
+    const idx = allData.value.findIndex((r) => r.id === row.id);
+    if (idx === -1) return '休息';
+    const nonBreakBefore = allData.value.slice(0, idx).filter((r: any) => r.isBreak !== 1).length;
     return `休息(第${nonBreakBefore}级后)`;
   }
-  return nonBreakBefore + 1;
+  return (row as any)._displayLevel ?? row.levelNumber;
+};
+
+/** 重新计算全量数据的显示级别并应用过滤 */
+const recomputeAndFilter = () => {
+  allData.value.forEach((row: any, idx: number) => {
+    const nonBreakBefore = allData.value.slice(0, idx).filter((r: any) => r.isBreak !== 1).length;
+    row._displayLevel = nonBreakBefore + 1;
+  });
+  const levelNumberFilter = queryParams.value.levelNumber;
+  if (levelNumberFilter !== undefined && levelNumberFilter !== '' && levelNumberFilter !== null) {
+    const filterLevel = Number(levelNumberFilter);
+    filteredData.value = allData.value.filter((row: any) => row._displayLevel === filterLevel);
+  } else {
+    filteredData.value = [...allData.value];
+  }
 };
 
 /** 取消按钮 */
@@ -460,6 +492,7 @@ const handleDelete = async (row?: BlindLevelsVO) => {
     const idx = allData.value.findIndex((r) => r.id === row.id);
     if (idx !== -1) {
       allData.value.splice(idx, 1);
+      recomputeAndFilter();
       applyPagination();
     }
     proxy?.$modal.msgSuccess('删除成功');
@@ -576,6 +609,12 @@ const stepValue = (row: BlindLevelsVO, field: 'smallBlind' | 'bigBlind' | 'ante'
   (row as any)[field] = Math.max(0, val + delta);
 };
 
+/** 是否休息变更时重新计算显示级别 */
+const handleIsBreakChange = (row: BlindLevelsVO) => {
+  recomputeAndFilter();
+  applyPagination();
+};
+
 /** 表格行样式(有错误的行标红) */
 const tableRowClassName = ({ row }: { row: BlindLevelsVO }) => {
   if (rowErrors.value.has(row.id)) {
@@ -654,6 +693,7 @@ const handleInsertAfter = (row: BlindLevelsVO) => {
 
     // 重新排序并按当前页展示
     allData.value.sort((a, b) => (a.displayOrder || 0) - (b.displayOrder || 0));
+    recomputeAndFilter();
     applyPagination();
     proxy?.$modal.msgSuccess('已插入新行(点击保存后生效)');
   } finally {