Просмотр исходного кода

add:添加导入公司,批量编辑冰排、保温箱

zoie 1 день назад
Родитель
Сommit
0773029124

+ 18 - 0
src/api/company.js

@@ -50,3 +50,21 @@ export function delCompany(parameter) {
     data: parameter
   })
 }
+
+// 获取第三方公司树形结构
+export function getThirdTree(parameter) {
+  return request({
+    url: '/api/company/third-tree',
+    method: 'get',
+    params: parameter
+  })
+}
+
+// 导入第三方公司树
+export function importThirdTree(parameter) {
+  return request({
+    url: '/api/company/import-third-tree',
+    method: 'post',
+    data: parameter
+  })
+}

+ 125 - 11
src/views/IceCreamFreezer/IceManagement.vue

@@ -74,6 +74,10 @@ export default {
         type: 'copyIce',
         title: '复制冰排',
         icon: 'el-icon-copy-document',
+      }, {
+        type: 'batchEdit',
+        title: '批量修改',
+        icon: 'el-icon-edit-outline',
       }],
       formList: [{
         type: 'input',
@@ -125,6 +129,7 @@ export default {
       limitNoil: true,
       iceCode: [],
       copyFlag: false,
+        batchEditRows: [],
     }
   },
   mounted() {
@@ -143,6 +148,77 @@ export default {
     this.getList()
   },
   methods: {
+    // 组装冷冻要求
+    formatFreezeClaim(nums = []) {
+      let arr2 = []
+      nums.forEach(item => {
+        if (typeof item === 'number') {
+          arr2.push(item)
+        } else if (typeof item === 'string') {
+          const arr1 = item.split('小时')
+          const num = Number(arr1[0])
+          if (!isNaN(num)) {
+            arr2.push(num)
+          }
+        }
+      })
+      return arr2
+    },
+    // 批量修改可用表单
+    getBatchFormRules() {
+      const source = this.iceColdFlag ? formRulesCold() : formRules()
+      return source.filter(item => item.field !== 'code' && item.field !== 'copyflag').map(rule => {
+        const newRule = {
+          ...rule
+        }
+        if (newRule.rules) {
+          newRule.rules = newRule.rules.map(r => ({
+            ...r,
+            required: false
+          }))
+        }
+        return newRule
+      })
+    },
+    // 重置表单
+    resetRuleFormFields() {
+      this.ruleForm.code = ''
+      this.ruleForm.status = null
+      this.ruleForm.freezeClaim = []
+      this.ruleForm.coolerBoxId = []
+      this.ruleForm.label = ''
+      this.ruleForm.suitableForCold = ''
+      this.ruleForm.forColdTime = null
+      this.ruleForm.iceColdAddress = ''
+      this.ruleForm.sort = null
+      this.ruleForm.copyNumber = null
+    },
+    hasBatchEditChanges() {
+      const commonFields = ['status', 'label', 'suitableForCold', 'forColdTime', 'iceColdAddress', 'sort']
+      const freezeChanged = Array.isArray(this.ruleForm.freezeClaim) && this.ruleForm.freezeClaim.length > 0
+      const otherChanged = commonFields.some(field => this.ruleForm[field] !== '' && this.ruleForm[field] !== null && this.ruleForm[field] !== undefined)
+      return freezeChanged || otherChanged
+    },
+    buildBatchEditParams(row) {
+      const freezeClaim = (Array.isArray(this.ruleForm.freezeClaim) && this.ruleForm.freezeClaim.length > 0) ? this.formatFreezeClaim(this.ruleForm.freezeClaim) : row.freezeClaim
+      const formatNumber = (fieldValue, fallback) => {
+        if (fieldValue === '' || fieldValue === null || fieldValue === undefined) {
+          return fallback
+        }
+        return Number(fieldValue)
+      }
+      return {
+        id: row.id,
+        code: row.code,
+        status: this.ruleForm.status === null || this.ruleForm.status === undefined ? row.status : this.ruleForm.status,
+        freezeClaim: freezeClaim || [],
+        label: this.ruleForm.label !== '' && this.ruleForm.label !== null ? this.ruleForm.label : row.label,
+        suitableForCold: this.ruleForm.suitableForCold !== '' && this.ruleForm.suitableForCold !== null ? this.ruleForm.suitableForCold : row.suitableForCold,
+        forColdTime: formatNumber(this.ruleForm.forColdTime, row.forColdTime),
+        iceColdAddress: this.ruleForm.iceColdAddress !== '' && this.ruleForm.iceColdAddress !== null ? this.ruleForm.iceColdAddress : row.iceColdAddress,
+        sort: formatNumber(this.ruleForm.sort, row.sort),
+      }
+    },
     // 搜索
     searchProtocol(value) {
       this.Pagination.PageIndex = 1
@@ -173,15 +249,6 @@ export default {
     handleAdd() {
       let flag = this.$refs['childRules'].validateForm();
       if (flag) {
-        var turnNum = function (nums) {
-          let arrNum = nums
-          let arr2 = []
-          arrNum.forEach(item => {
-            var arr1 = item.split('小时')
-            arr2.push(Number(arr1[0]))
-          })
-          return arr2;
-        }
         if (this.operationType == 'add') {
           this.confirmLoading = true
           let arr = []
@@ -189,7 +256,7 @@ export default {
           var params = {
             codeList: arr,
             status: this.ruleForm.status,
-            freezeClaim: turnNum(this.ruleForm.freezeClaim),
+            freezeClaim: this.formatFreezeClaim(this.ruleForm.freezeClaim),
             label: this.ruleForm.label,
             suitableForCold: this.ruleForm.suitableForCold,
             forColdTime: Number(this.ruleForm.forColdTime),
@@ -218,7 +285,7 @@ export default {
             id: this.selectingData.id,
             code: this.ruleForm.code,
             status: this.ruleForm.status,
-            freezeClaim: turnNum(this.ruleForm.freezeClaim),
+            freezeClaim: this.formatFreezeClaim(this.ruleForm.freezeClaim),
             label: this.ruleForm.label,
             suitableForCold: this.ruleForm.suitableForCold,
             forColdTime: Number(this.ruleForm.forColdTime),
@@ -277,6 +344,35 @@ export default {
           }).catch(() => {
             this.confirmLoading = false
           })
+        } else if (this.operationType == 'batchEdit') {
+          if (!this.batchEditRows.length) {
+            this.$message.warning('请先选择需要批量修改的冰排')
+            return
+          }
+          if (!this.hasBatchEditChanges()) {
+            this.$message.warning('请至少填写一个需要修改的字段')
+            return
+          }
+          this.confirmLoading = true
+          const requests = this.batchEditRows.map(row => {
+            const params = this.buildBatchEditParams(row)
+            return putIceRaft(params)
+          })
+          Promise.all(requests).then(res => {
+            this.$message({
+              message: '批量修改成功',
+              type: 'success'
+            })
+            this.getList()
+            if (this.$refs.refWaybill) {
+              this.$refs.refWaybill.clearSelected()
+            }
+            this.staffDialogVisible = false
+          }).catch(() => {
+            this.$message.error('批量修改失败')
+          }).finally(() => {
+            this.confirmLoading = false
+          })
         }
       } else {
         this.$message.error('表单信息不完整,请继续填写完整');
@@ -381,6 +477,22 @@ export default {
             type: 'warning'
           });
         }
+      } else if (type == 'batchEdit') {
+        const selectedRows = this.$refs.refWaybill ? this.$refs.refWaybill.waybillIds : []
+        if (!selectedRows || selectedRows.length === 0) {
+          this.$message({
+            message: '请先选择需要批量修改的冰排',
+            type: 'warning'
+          });
+          return
+        }
+        this.batchEditRows = JSON.parse(JSON.stringify(selectedRows))
+        this.copyFlag = false
+        this.iceTracing = false
+        this.staffTitle = '批量修改'
+        this.formRuleList = this.getBatchFormRules()
+        this.resetRuleFormFields()
+        this.staffDialogVisible = true
       } else if (type == 'copyIce') {
         this.operationType = 'add'
         const arrID = this.$refs.refWaybill.waybillIds
@@ -531,6 +643,8 @@ export default {
     // 清空表单
     closeDialog() {
       this.copyFlag = false
+      this.batchEditRows = []
+      this.resetRuleFormFields()
       this.$refs.childRules.resetCheck();
     }
   },

+ 131 - 5
src/views/incubator/IncubatorManagement.vue

@@ -107,6 +107,15 @@ export default {
     // centerControl
   },
   data() {
+    const baseRuleForm = {
+      name: '',
+      sn: '',
+      status: '2',
+      cold_spots: '',
+      cold_temperatures: '',
+      for_cold_cooler_time: '',
+      copyNumber: null,
+    }
     return {
       pickerOptions: {
         shortcuts: [{
@@ -149,6 +158,10 @@ export default {
         type: 'copyIce',
         title: '复制保温箱',
         icon: 'el-icon-copy-document',
+      }, {
+        type: 'batchEdit',
+        title: '批量修改',
+        icon: 'el-icon-edit-outline',
       }
         // {
         //   type: 'screen',
@@ -192,9 +205,10 @@ export default {
       staffDialogVisible: false,
       formRuleList: [],
       ruleForm: {
-        name: '',
-        sn: '',
-        status: '2',
+        ...baseRuleForm
+      },
+      initialRuleForm: {
+        ...baseRuleForm
       },
       confirmLoading: false,
       selectingData: {},
@@ -271,6 +285,8 @@ export default {
       staffName: '',
       limitNo: true,
       copyFlag: false,
+      batchEditRows: [],
+      defaultFormRuleList: [],
     }
   },
   beforeDestroy() {
@@ -298,6 +314,7 @@ export default {
         'cold_temperatures'
       ])
     }
+    this.defaultFormRuleList = JSON.parse(JSON.stringify(this.formRuleList))
 
     function removePointById(arr1, arr2) {
       for (let i = 0; i < arr2.length; i++) {
@@ -375,6 +392,60 @@ export default {
         }
       })
     },
+    cloneDefaultFormRules() {
+      return JSON.parse(JSON.stringify(this.defaultFormRuleList || []))
+    },
+    useDefaultFormRules() {
+      if (this.defaultFormRuleList && this.defaultFormRuleList.length) {
+        this.formRuleList = this.cloneDefaultFormRules()
+      }
+    },
+    resetRuleFormFields() {
+      this.ruleForm = JSON.parse(JSON.stringify(this.initialRuleForm))
+    },
+    fieldValueFilled(value) {
+      return value !== '' && value !== null && value !== undefined
+    },
+    getBatchFormRules() {
+      const editableFields = ['cold_temperatures', 'cold_spots', 'for_cold_cooler_time', 'status']
+      const base = this.cloneDefaultFormRules()
+      return base.filter(item => editableFields.includes(item.field)).map(item => {
+        const newItem = {
+          ...item
+        }
+        if (newItem.rules) {
+          newItem.rules = newItem.rules.map(rule => ({
+            ...rule,
+            required: false
+          }))
+        }
+        return newItem
+      })
+    },
+    hasFieldPermission(field) {
+      return this.defaultFormRuleList && this.defaultFormRuleList.some(item => item.field === field)
+    },
+    hasBatchEditChanges() {
+      const changeableFields = ['status']
+      if (this.hasFieldPermission('cold_temperatures')) {
+        changeableFields.push('cold_temperatures', 'cold_spots', 'for_cold_cooler_time')
+      }
+      return changeableFields.some(field => this.fieldValueFilled(this.ruleForm[field]))
+    },
+    buildBatchEditParams(row) {
+      const params = {
+        id: row.id,
+        name: row.name,
+        sn: row.sn,
+        status: this.fieldValueFilled(this.ruleForm.status) ? this.ruleForm.status : row.status,
+      }
+      if (this.hasFieldPermission('cold_temperatures')) {
+        params.cold_temperatures = this.fieldValueFilled(this.ruleForm.cold_temperatures) ? this.ruleForm.cold_temperatures : row.cold_temperatures
+        params.cold_spots = this.fieldValueFilled(this.ruleForm.cold_spots) ? this.ruleForm.cold_spots : row.cold_spots
+        params.for_cold_cooler_time = this.fieldValueFilled(this.ruleForm.for_cold_cooler_time) ? Number(this.ruleForm.for_cold_cooler_time) : row.for_cold_cooler_time
+      }
+      return params
+    },
     // 选项赋值
     optionMatching(value, field) {
       this.formRuleList.forEach((item, index) => {
@@ -434,6 +505,35 @@ export default {
           }).catch(() => {
             this.confirmLoading = false
           })
+        } else if (this.operationType == 'batchEdit') {
+          if (!this.batchEditRows.length) {
+            this.$message.warning('请先选择需要批量修改的保温箱')
+            return
+          }
+          if (!this.hasBatchEditChanges()) {
+            this.$message.warning('请至少填写一个需要修改的字段')
+            return
+          }
+          this.confirmLoading = true
+          const requests = this.batchEditRows.map(row => {
+            const params = this.buildBatchEditParams(row)
+            return putCoolerBox(params)
+          })
+          Promise.all(requests).then(() => {
+            this.$message({
+              message: '批量修改成功',
+              type: 'success'
+            });
+            this.getList()
+            if (this.$refs.refWaybill) {
+              this.$refs.refWaybill.clearSelected()
+            }
+            this.staffDialogVisible = false
+          }).catch(() => {
+            this.$message.error('批量修改失败')
+          }).finally(() => {
+            this.confirmLoading = false
+          })
         }
       } else {
         this.$message.error('表单信息不完整,请继续填写完整');
@@ -442,6 +542,7 @@ export default {
     buttonData(row, type) {
       this.selectingData = row
       this.operationType = type
+      this.useDefaultFormRules()
       if (type == 'edit') {
         this.staffTitle = '编辑'
         this.staffDialogVisible = true
@@ -483,6 +584,8 @@ export default {
         this.staffTitle = '添加'
         this.staffDialogVisible = true
         this.operationType = type
+        this.useDefaultFormRules()
+        this.resetRuleFormFields()
         if (this.userList.dept.isCoolerReleaseCold) {
           this.obtainIceRaft()
         }
@@ -518,6 +621,8 @@ export default {
           this.copyFlag = true
           this.staffTitle = '添加'
           this.staffDialogVisible = true
+          this.useDefaultFormRules()
+          this.resetRuleFormFields()
           if (this.userList.dept.isCoolerReleaseCold) {
             this.obtainIceRaft()
           }
@@ -527,6 +632,23 @@ export default {
             })
           })
         }
+      } else if (type == 'batchEdit') {
+        const selectedRows = this.$refs.refWaybill ? this.$refs.refWaybill.waybillIds : []
+        if (!selectedRows || selectedRows.length === 0) {
+          this.$message({
+            message: '请先选择需要批量修改的保温箱',
+            type: 'warning'
+          });
+          return
+        }
+        this.operationType = 'batchEdit'
+        this.copyFlag = false
+        this.batchEditRows = JSON.parse(JSON.stringify(selectedRows))
+        this.formRuleList = this.getBatchFormRules()
+        this.resetRuleFormFields()
+        this.ruleForm.status = ''
+        this.staffTitle = '批量修改'
+        this.staffDialogVisible = true
       }
     },
     // 触底事件
@@ -700,8 +822,12 @@ export default {
         item.disabled = false
       })
       this.copyFlag = false
-      this.ruleForm = {}
-      this.$refs.childRules.resetCheck();
+      this.batchEditRows = []
+      this.resetRuleFormFields()
+      this.useDefaultFormRules()
+      if (this.$refs.childRules) {
+        this.$refs.childRules.resetCheck();
+      }
     },
     // 关闭温湿度记录
     temperatureClose() {

+ 160 - 4
src/views/system/CompanyManagement.vue

@@ -21,6 +21,26 @@
         <el-button type="primary" :loading="confirmLoading" @click="handleAdd">确 定</el-button>
       </span>
     </el-dialog>
+    <!-- 导入公司对话框 -->
+    <el-dialog title="导入公司" :visible.sync="importDialogVisible" width="600px" :close-on-click-modal="false"
+      @close="closeImportDialog">
+      <div style="max-height: 500px; overflow-y: auto;">
+        <el-tree
+          ref="companyTree"
+          :data="thirdTreeData"
+          :props="treeProps"
+          show-checkbox
+          node-key="Id"
+          :default-expand-all="true"
+          :check-strictly="false"
+          @check="handleTreeCheck">
+        </el-tree>
+      </div>
+      <span slot="footer" class="dialog-footer">
+        <el-button plain @click="importDialogVisible = false">取 消</el-button>
+        <el-button type="primary" :loading="importLoading" @click="handleImport">确 定</el-button>
+      </span>
+    </el-dialog>
   </div>
 </template>
 
@@ -30,7 +50,9 @@
     getCompanyDetails,
     addCompany,
     putCompany,
-    delCompany
+    delCompany,
+    getThirdTree,
+    importThirdTree
   } from '@/api/company'
   import actionBar from '@/components/actionBar'
   import treeTable from '@/components/treeTable'
@@ -54,6 +76,10 @@
           type: 'add',
           title: '添加公司',
           icon: 'el-icon-plus',
+        }, {
+          type: 'import',
+          title: '导入公司',
+          icon: 'el-icon-upload2',
         }],
         formList: [{
           type: 'input',
@@ -93,6 +119,15 @@
         treeData: employee(),
         treeDataList: [],
         parentId: null,
+        // 导入公司相关
+        importDialogVisible: false,
+        thirdTreeData: [],
+        treeProps: {
+          children: 'Children',
+          label: 'T_name'
+        },
+        selectedCompanyNodes: [],
+        importLoading: false,
       }
     },
     mounted() {
@@ -196,9 +231,130 @@
         }
       },
       openModel(type) {
-        this.staffTitle = '添加'
-        this.staffDialogVisible = true
-        this.operationType = type
+        if (type === 'import') {
+          this.openImportDialog()
+        } else {
+          this.staffTitle = '添加'
+          this.staffDialogVisible = true
+          this.operationType = type
+        }
+      },
+      // 打开导入公司对话框
+      openImportDialog() {
+        this.importDialogVisible = true
+        this.thirdTreeData = []
+        this.selectedCompanyNodes = []
+        this.getThirdTreeData()
+      },
+      // 获取第三方公司树形结构
+      getThirdTreeData() {
+        getThirdTree().then(res => {
+          if (res.code == 200) {
+            this.thirdTreeData = res.data || []
+          }
+        }).catch(() => {
+          this.$message.error('获取公司树形结构失败')
+        })
+      },
+      // 树节点选择变化
+      handleTreeCheck(data, checkedInfo) {
+        // 保存选中的节点ID
+        this.selectedCompanyNodes = checkedInfo.checkedKeys || []
+      },
+      // 处理导入
+      handleImport() {
+        const checkedKeys = this.$refs.companyTree.getCheckedKeys()
+        if (checkedKeys.length === 0) {
+          this.$message.warning('请至少选择一个公司')
+          return
+        }
+        
+        // 构建需要导入的数据结构
+        const importData = this.buildImportData(checkedKeys)
+        
+        if (importData.length === 0) {
+          this.$message.warning('请选择要导入的公司')
+          return
+        }
+        
+        this.importLoading = true
+        importThirdTree(importData).then(res => {
+          if (res.code == 200) {
+            this.$message({
+              message: '导入成功',
+              type: 'success'
+            })
+            this.importDialogVisible = false
+            this.getList()
+          }
+          this.importLoading = false
+        }).catch(() => {
+          this.importLoading = false
+        })
+      },
+      // 构建导入数据结构
+      buildImportData(checkedKeys) {
+        // 从原始数据中查找所有选中的节点
+        const findNodeById = (nodes, id) => {
+          for (const node of nodes) {
+            if (node.Id === id) {
+              return node
+            }
+            if (node.Children && node.Children.length > 0) {
+              const found = findNodeById(node.Children, id)
+              if (found) return found
+            }
+          }
+          return null
+        }
+        
+        // 递归构建树形结构,只包含选中的节点及其选中的子节点
+        const buildTree = (node) => {
+          const result = {
+            Id: node.Id,
+            T_mid: node.T_mid,
+            T_name: node.T_name,
+            T_key: node.T_key || '',
+            T_Address: node.T_Address || node.companyAddress || ''
+          }
+          
+          // 处理子节点
+          if (node.Children && node.Children.length > 0) {
+            const selectedChildren = node.Children
+              .filter(child => checkedKeys.includes(child.Id))
+              .map(child => buildTree(child))
+            
+            if (selectedChildren.length > 0) {
+              result.Children = selectedChildren
+            }
+          }
+          
+          return result
+        }
+        
+        // 找出所有根节点(T_mid为0或父节点未被选中)
+        const rootNodes = []
+        for (const id of checkedKeys) {
+          const node = findNodeById(this.thirdTreeData, id)
+          if (node) {
+            // 检查是否是根节点
+            const isRoot = node.T_mid === 0 || !checkedKeys.includes(node.T_mid)
+            if (isRoot) {
+              rootNodes.push(node)
+            }
+          }
+        }
+        
+        // 构建树形结构
+        return rootNodes.map(node => buildTree(node))
+      },
+      // 关闭导入对话框
+      closeImportDialog() {
+        this.thirdTreeData = []
+        this.selectedCompanyNodes = []
+        if (this.$refs.companyTree) {
+          this.$refs.companyTree.setCheckedKeys([])
+        }
       },
       // 删除公司
       deleteUser(id) {