Bladeren bron

修复请假外出退费设置表单bug,物资出库增加导出

xiongxing 5 maanden geleden
bovenliggende
commit
f556d4a216

+ 7 - 0
src/api/material/stockInAndOut/index.ts

@@ -133,4 +133,11 @@ export const exportMaterialInbound = (id) => {
   return request.download({
     url: 'material-io/inbound/export?id='+id
   })
+}
+
+// 导出出库单
+export const exportMaterialOutbound = (id) => {
+  return request.download({
+    url: 'material-io/outbound/export?id='+id
+  })
 }

+ 63 - 24
src/views/elderly/fee/out-refund/Form.vue

@@ -142,7 +142,7 @@
                   :data="treeList"
                   :render-after-expand="false"
                   :props="defaultProps"
-                  @change="getItemList(scope.row,true,true)"
+                  @change="getItemList(scope.row, true, shouldAutoFill(scope.row))"
                   filterable
                 />
                 <span v-else>{{
@@ -406,7 +406,8 @@ const handleAdd = () => {
     minimumDays: '',
     isSameDayRefund: '',
     amount: undefined,
-    itemList: []
+    itemList: [],
+    __isNew: true
   })
 }
 const handleDelete = (index: number) => {
@@ -441,8 +442,26 @@ const getTreeData = async () => {
 
 // 项目名称
 // const itemList = ref<{chargeName: string, id: string}>([])
-const getItemList = async (row, flag = true,flag2=false) => {
-  if(flag){
+const shouldAutoFill = (row) => {
+  // 只有新增行才参与自动补齐/自动回填
+  if (!row?.__isNew) return false
+  if (!row?.categoryId) return false
+
+  // 如果该分类存在“缺失的子项”,就允许自动补齐(用于你删除某个子项后再新增补回)
+  const sameCategoryRows = dataForm.value.items.filter(
+    (item) => item !== row && item.categoryId === row.categoryId
+  )
+  const existingItemIdSet = new Set(sameCategoryRows.map((item) => item.itemId).filter(Boolean))
+  if (!Array.isArray(row.itemList) || row.itemList.length === 0) return true
+  const missing = row.itemList.find((it) => it?.id && !existingItemIdSet.has(it.id))
+  return Boolean(missing)
+}
+
+// 项目名称
+// const itemList = ref<{chargeName: string, id: string}>([])
+const getItemList = async (row, flag = true, flag2 = false) => {
+  const prevCategoryId = row.categoryId
+  if (flag) {
     row.itemId = ''
   }
   try {
@@ -453,32 +472,54 @@ const getItemList = async (row, flag = true,flag2=false) => {
     })
     row.itemList = data.list
 
-    // 如果需要自动添加子项
-    if (flag2 && row.itemList && row.itemList.length > 0) {
-      // 清除当前分类下的其他项(除了当前行)
-      const currentCategoryItems = dataForm.value.items.filter(
-        item => item.categoryId === row.categoryId && item !== row
+    // 如果该类型下的所有项目都已经在表格中存在,则禁止再次新增该类型
+    if (row?.__isNew && Array.isArray(row.itemList) && row.itemList.length > 0) {
+      const sameCategoryRows = dataForm.value.items.filter(
+        (item) => item !== row && item.categoryId === row.categoryId
+      )
+      const existingItemIdSet = new Set(sameCategoryRows.map((item) => item.itemId).filter(Boolean))
+      const allExist = row.itemList.every((it) => it?.id && existingItemIdSet.has(it.id))
+      if (allExist) {
+        message.warning('该退费类型下的所有项目已存在,请选择其他类型')
+        row.categoryId = ''
+        row.itemId = ''
+        row.itemList = []
+        return
+      }
+    }
+
+    // 如果需要自动添加子项(仅补齐缺失,不删除/不重置已有行,避免误清空 customAmount)
+    if (flag2 && Array.isArray(row.itemList) && row.itemList.length > 0) {
+      // 新增行在成功触发自动补齐/回填后,避免后续再次触发
+      if (row?.__isNew) {
+        row.__isNew = false
+      }
+      const sameCategoryRows = dataForm.value.items.filter(item => item.categoryId === row.categoryId)
+      const existingItemIdSet = new Set(
+        sameCategoryRows.map(item => item.itemId).filter(Boolean)
       )
 
-      // 删除这些项
-      currentCategoryItems.forEach(item => {
-        const index = dataForm.value.items.indexOf(item)
-        if (index > -1) {
-          dataForm.value.items.splice(index, 1)
+      // 当前行如果还没选子项:优先回填“缺失的子项”
+      if (!row.itemId) {
+        const missing = row.itemList.find((it) => it?.id && !existingItemIdSet.has(it.id))
+        row.itemId = missing?.id || row.itemList[0]?.id || ''
+        if (row.itemId) {
+          existingItemIdSet.add(row.itemId)
         }
-      })
+      }
 
-      // 为当前行设置第一个子项
-      row.itemId = row.itemList[0]?.id || ''
+      // 把该分类下剩余缺失的子项补充为新行(只新增,不动旧行)
+      for (let i = 0; i < row.itemList.length; i++) {
+        const id = row.itemList[i]?.id
+        if (!id || existingItemIdSet.has(id)) continue
+        existingItemIdSet.add(id)
 
-      // 添加剩余的子项作为新行
-      for (let i = 1; i < row.itemList.length; i++) {
         dataForm.value.items.push({
           categoryId: row.categoryId,
-          itemId: row.itemList[i].id,
+          itemId: id,
           type: 3,
-          isCustom: 0, //是否自定义
-          customAmount: '', //自定义金额
+          isCustom: 0, // 是否自定义
+          customAmount: '', // 自定义金额
           maximumDays: '',
           minimumDays: '',
           isSameDayRefund: '',
@@ -487,9 +528,7 @@ const getItemList = async (row, flag = true,flag2=false) => {
         })
       }
     }
-
   } finally {
-
   }
 }
 

+ 11 - 4
src/views/warehouses/materialsOut/index.vue

@@ -39,7 +39,6 @@
     <el-card shadow="never" class="mt-4">
       <div class="mb-4">
         <el-button v-hasPermi="['warehouses:materialsOut:add']" type="primary" plain @click="handleAdd"><Icon icon="ep:plus" class="mr-5px" />新增</el-button>
-        <el-button v-hasPermi="['warehouses:materialsOut:export']" type="success" plain @click="handleExport"><Icon icon="ep:download" class="mr-5px" />导出</el-button>
       </div>
 
       <el-table :data="tableData" v-loading="loading" :header-cell-style="tableHeaderColor">
@@ -58,6 +57,7 @@
           <template #default="{ row }">
             <el-button link type="primary" @click="handleView(row)">查看</el-button>
             <el-button v-hasPermi="['warehouses:materialsOut:edit']" link type="primary" @click="handleEdit(row)">编辑</el-button>
+            <el-button v-hasPermi="['warehouses:materialsOut:export']" link type="success" @click="handleExport(row)">导出</el-button>
             <el-button v-hasPermi="['warehouses:materialsOut:print']" link type="primary" @click="handlePrint(row)">打印</el-button>
             <el-button v-hasPermi="['warehouses:materialsOut:delete']" link type="danger" @click="handleDelete(row)">删除</el-button>
           </template>
@@ -91,10 +91,11 @@
 import { onMounted, reactive, ref } from 'vue'
 import { ElMessage } from 'element-plus'
 import { useUserStore } from '@/store/modules/user'
-import { materialIoPage, materialIoInboundBatchList, getMaterialOutboundDetail, materialIoDelete } from '@/api/material/stockInAndOut'
+import { materialIoPage, materialIoInboundBatchList, getMaterialOutboundDetail, materialIoDelete, exportMaterialOutbound } from '@/api/material/stockInAndOut'
 import { handleTree } from '@/utils/tree'
 import * as DeptApi from '@/api/system/dept'
 import { getStrDictOptions, DICT_TYPE } from '@/utils/dict'
+import download from '@/utils/download'
 
 const MaterialsOutDialog = defineAsyncComponent(() => import('./components/MaterialsOutDialog.vue'))
 const Print = defineAsyncComponent(() => import('./components/Print.vue'))
@@ -308,8 +309,14 @@ const handleEdit = async(row) => {
   dialogVisible.value = true
 }
 
-const handleExport = (row) => {
-  ElMessage.success('已导出当前列表(模拟)')
+const handleExport = async(row) => {
+  try {
+    const res = await exportMaterialOutbound(row.id)
+    download.excel(res, '出库单据明细.xls')
+  } catch (e) {
+    console.error(e)
+    ElMessage.error(e?.message || '导出失败')
+  }
 }
 
 // 删除