Browse Source

Merge branch 'master' of https://git.7in6.com/liuhairui/mes-dacheng-admin-backend-ui

m0_70156489 1 day ago
parent
commit
78d287f2e1
1 changed files with 12 additions and 14 deletions
  1. 12 14
      src/view/yunyin/shengchanguanli/MonthlySampleGarments.vue

+ 12 - 14
src/view/yunyin/shengchanguanli/MonthlySampleGarments.vue

@@ -34,11 +34,11 @@
               <el-table ref="multipleTable" style="width: 100%;height: 70vh" tooltip-effect="dark"
                         :row-style="{ height: '25px' }" :header-cell-style="{ padding: '0px' }"
                         :cell-style="{ padding: '0px' }" :header-row-style="{ height: '20px' }"
-                        :data="tableData" border row-key="ID"
+                        :data="tableData" border :row-key="rowKeyOf"
                         size="small"
                         :cell-class-name="gxbgCellClass"
                         highlight-current-row="true"
-                        @row-click="tableRowClick" :show-overflow-tooltip="true"
+                        @row-click="tableRowClick" :show-overflow-tooltip="true" 
                         @selection-change="handleSelectionChange"
                         @cell-click="handleTableCellClick"
                         @row-dblclick="handleRowDblclick">
@@ -278,12 +278,16 @@ const createEmptyRow = () => ({
   备注: ''
 })
 
+// 仅在列表完全为空时放一行可编辑空行,方便首次录入;有数据时不自动加空白行
 const ensureEditableRows = () => {
   if (!tableData.value.length) {
     tableData.value.push(createEmptyRow())
   }
 }
 
+const countSavedRows = () =>
+  tableData.value.filter((item) => item.UniqId).length
+
 const rowKeyOf = (row) => row.UniqId || row.tempId
 const isEditing = (row, prop) =>
   editingCell.rowId === rowKeyOf(row) && editingCell.prop === prop
@@ -301,7 +305,7 @@ const loadListByMonth = async (sys_rq, customer = '') => {
   const res = await getMonthlyGarmentsList(params)
   if (res.code === 0) {
     tableData.value = res.data.result || []
-    total.value = res.data.total || (res.data.result?.length ?? 0)
+    total.value = res.data.total ?? tableData.value.length
   } else {
     tableData.value = []
     total.value = 0
@@ -436,8 +440,10 @@ const deleteRow = async (row, index) => {
       }
     }
     tableData.value.splice(index, 1)
+    total.value = countSavedRows()
+    ensureEditableRows()
     ElMessage.success('删除成功')
-    await refreshData()
+    await refreshTreePreserveSelection()
   } catch (error) {
     ElMessage.error('删除失败')
     console.error('删除失败:', error)
@@ -598,19 +604,11 @@ const handleCellBlur = async (row, prop) => {
       })
       if (res.code === 0) {
         const newId = parseInt(res.data.id)
+        // 就地转成已保存行,不整表重载,避免接口暂时查不到时只剩最新一条 + 自动空白行
         row.UniqId = newId
         delete row.tempId
-
-        // 先刷新列表(保留当前筛选条件),确保新数据立即可见
-        await loadListByMonth(_noderq.value, _nodecode.value)
-        // 安全网:如果刚保存的行不在刷新后的列表中(说明当前筛选看不到它),手动补到顶部
-        const exists = tableData.value.some((item) => item.UniqId === newId)
-        if (!exists) {
-          tableData.value.unshift(row)
-        }
-        // 再刷新树(保留当前选中状态)
+        total.value = countSavedRows()
         await refreshTreePreserveSelection()
-        // 定位回刚新增的行,而不是停在第一行
         await restoreEditedRow(newId)
       } else {
         ElMessage.error('保存失败')