diff --git a/src/views/business/warehouse/details.vue b/src/views/business/warehouse/details.vue index 46183584..46da00cb 100644 --- a/src/views/business/warehouse/details.vue +++ b/src/views/business/warehouse/details.vue @@ -2,7 +2,7 @@
- + - + @@ -77,7 +77,6 @@ 退库申请列表 - 添加 确定申请 @@ -88,16 +87,18 @@ highlight-current-row border stripe - :max-height="650" + :max-height="570" style="width: 100%" + @selection-change="handleSelectionChange" > + - + - - + + + + - + @@ -392,7 +282,7 @@ export default { this.queryParams.id = this.routerParams.id || '' this.getUseProjectList() if (this.queryParams.status == '0') { - this.queryParams.useUnit = sessionStorage.getItem('deptName') || ''; + this.queryParams.useUnit = sessionStorage.getItem('deptName') || '' } this.provinceList = regionData const obj = Object.assign({}, this.$route, { title }) @@ -418,17 +308,17 @@ export default { if (node.children && node.children.length > 0) { node.children = this.filterTree(node.children) } - node.label = node.deptName; - node.value = node.deptId; + node.label = node.deptName + node.value = node.deptId return node }) .filter(node => node.status !== '1') }, isChange(row) { if (row.isRepair == '1') { - row.realNum = row.manageType == 0 ? 1 : row.num; + row.realNum = row.manageType == 0 ? 1 : row.num } else { - row.realNum = 0; + row.realNum = 0 } }, // 获取使用项目的下拉选 @@ -461,6 +351,38 @@ export default { this.queryParams.proCity = city this.queryParams.proCounty = county } + // 构造查询参数 + const queryParams = { + proCode: value + } + getApplyListApi(queryParams) + .then(response => { + if (response && response.data) { + this.tableList = response.data || [] + // 初始化退库数量(编码设备默认1,数量设备默认1) + this.tableList.forEach(item => { + item.num = item.manageType === 0 ? 1 : 1 + // 补充storageNum字段,使applyNumChange中的判断统一 + item.storageNum = item.useNum + item.useTime = this.queryParams.useTime ? new Date(this.queryParams.useTime) : null + item.isRepair = '0' + item.realNum = 0 + }) + } else { + this.addList = [] + this.addTotal = 0 + this.$message.warning('获取数据格式异常') + } + }) + .catch(error => { + this.addList = [] + this.addTotal = 0 + this.$message.error(`获取设备列表失败:${error.message || '未知错误'}`) + console.error('分页查询失败:', error) + }) + .finally(() => { + this.isLoading = false + }) }, // 选择省份 @@ -527,27 +449,6 @@ export default { // 用户取消,不操作 }) }, - - // 添加申请弹窗 - handleDialog() { - if (!this.queryParams.proCode) { - this.$message({ - type: 'error', - message: '请先选择使用项目' - }) - return - } - this.addQuery.pageNum = 1 - this.resetAddQuery() // 打开时重置查询条件 - this.openAdd = true - // 确保弹窗打开后表格清空选择 - this.$nextTick(() => { - if (this.$refs.addTable) { - this.$refs.addTable.clearSelection() - } - }) - }, - // 处理分类树数据(适配六级分类) processTreeData(data) { return Array.isArray(data) ? data : data ? [data] : [] @@ -617,121 +518,6 @@ export default { return processedItem }) }, - - // 分页查询(支持分类筛选) - getApplyList(pagination = {}) { - // 合并分页参数 - const pageNum = pagination.pageNum || this.addQuery.pageNum - const pageSize = pagination.pageSize || this.addQuery.pageSize - - // 更新分页状态 - this.addQuery.pageNum = pageNum - this.addQuery.pageSize = pageSize - - // 构造查询参数 - const queryParams = { - ...this.filterParams, - pageNum, - pageSize - } - - this.isLoading = true - getApplyListApi(queryParams) - .then(response => { - if (response && response.data) { - this.addList = response.data.rows || [] - this.addTotal = response.data.total || 0 - - // 初始化退库数量(编码设备默认1,数量设备默认1) - this.addList.forEach(item => { - item.num = item.manageType === 0 ? 1 : 1; - // 补充storageNum字段,使applyNumChange中的判断统一 - item.storageNum = item.useNum; - }) - } else { - this.addList = [] - this.addTotal = 0 - this.$message.warning('获取数据格式异常') - } - }) - .catch(error => { - this.addList = [] - this.addTotal = 0 - this.$message.error(`获取设备列表失败:${error.message || '未知错误'}`) - console.error('分页查询失败:', error) - }) - .finally(() => { - this.isLoading = false - }) - }, - - // 查询(支持分类筛选,核心:处理devType和分类ID) - handleAddQuery() { - this.addQuery.pageNum = 1 // 重置为第一页 - const queryParams = { ...this.addQuery } - - // 1. 处理分类类型(devType:1=装备,2=工具) - let devType = queryParams.devType || '' - - // 2. 处理装备分类(仅当选择装备时生效) - let categoryEquipment = '' - if (devType === '1' && queryParams.categoryPath && Array.isArray(queryParams.categoryPath) && queryParams.categoryPath.length > 0) { - categoryEquipment = String(queryParams.categoryPath[queryParams.categoryPath.length - 1]) - } - - // 3. 处理工具分类(仅当选择工具时生效) - let toolTypeId = '' - if (devType === '2' && queryParams.toolCategoryPath && Array.isArray(queryParams.toolCategoryPath) && queryParams.toolCategoryPath.length > 0) { - toolTypeId = String(queryParams.toolCategoryPath[queryParams.toolCategoryPath.length - 1]) - } - - // 保存筛选条件(包含devType) - this.filterParams = { - typeName: queryParams.typeName, - typeModelName: queryParams.typeModelName, - devCode: queryParams.devCode, - categoryEquipment, - toolTypeId, - devType, // 传递分类类型给后端 - proCode: queryParams.proCode // 关联项目编码 - } - - // 执行查询 - this.getApplyList({ - pageNum: this.addQuery.pageNum, - pageSize: this.addQuery.pageSize - }) - }, - - // 重置查询条件 - resetAddQuery() { - this.addQuery = { - proCode: this.queryParams.proCode || '', // 保留当前项目编码 - typeName: '', - typeModelName: '', - devCode: '', - devType: '', // 重置分类选择 - categoryPath: [], // 重置装备分类 - toolCategoryPath: [], // 重置工具分类 - pageNum: 1, - pageSize: 10 - } - - // 同步重置筛选参数 - this.filterParams = { - typeName: '', - typeModelName: '', - devCode: '', - categoryEquipment: '', - toolTypeId: '', - devType: '', - proCode: this.queryParams.proCode || '' - } - - // 重置后查询 - this.getApplyList({ pageNum: 1, pageSize: this.addQuery.pageSize }) - }, - handleBack() { this.$router.go(-1) }, @@ -744,52 +530,16 @@ export default { // 多选框选中数据(保留devType字段) handleSelectionChange(selection) { - this.addTempList = [] - this.ids = selection.map(item => item.id) - selection.forEach(item => { - this.addTempList.push({ - id: item.id, - typeId: item.typeId, - devType: item.devType, // 保留分类类型(1=装备,2=工具) - category: item.category, - typeName: item.typeName, - typeModelName: item.typeModelName, - manageType: item.manageType, - devCode: item.devCode, - useNum: item.useNum, - num: item.manageType == 0 ? 1 : item.num, - useTime: this.queryParams.useTime ? new Date(this.queryParams.useTime) : null, - isRepair: '0', - realNum: 0 - }) - }) - this.single = selection.length != 1 - this.multiple = !selection.length + this.ids = selection }, - - // 表格选择框是否可勾选 - selectable(row) { - // 自用数量为0不可选 - if (!row.useNum || row.useNum <= 0) { - return false - } - // 已添加过的不可选 - return !this.tableList.some(item => item.id === row.id && item.typeId === row.typeId) - }, - - // 检查行是否被选中 - isRowSelected(row) { - return this.ids.includes(row.id) - }, - // 申请数量变化 applyNumChange(row) { - if (row.num > row.storageNum) { // 申请数量大于库存 + if (row.num > row.useNum) { // 申请数量大于库存 this.$message({ type: 'error', message: '退库数量不能大于当前自用数量' }) - row.num = row.storageNum + row.num = row.useNum } else if (row.num < 1) { // 数量不能小于1 this.$message({ type: 'error', @@ -797,48 +547,14 @@ export default { }) row.num = 1 } - - // 如果当前行处于维修状态,同步更新维修数量 - if (row.isRepair === '1') { - row.realNum = row.num; - } - }, - - // 确认添加 - saveAdd() { - if (!this.ids.length) { // 没有选中数据 - this.$message({ - type: 'error', - message: '请勾选数据' - }) - return - } - - // 检查是否有数量设备未填写数量(虽然默认值为1,但做一层保险) - const invalidItem = this.addTempList.find(item => item.manageType === 1 && (!item.num || item.num < 1)); - if (invalidItem) { - this.$message.error('请为数量管理的设备填写有效的退库数量。'); - return; - } - - this.addTempList.forEach(item => { - this.tableList.push(item) - }) - // 清除勾选相关的数据 - this.addTempList = [] - this.ids = [] - if(this.$refs.addTable) { - this.$refs.addTable.clearSelection(); - } - this.openAdd = false }, // 提交 async submit() { this.$refs.queryForm.validate(async(valid) => { if (valid) { - if (this.tableList.length === 0) { - return this.$message.error('请至少添加一项申请设备'); + if (this.ids.length === 0) { + return this.$message.error('请至少选择一项申请设备') } this.$confirm('是否确定提交申请?', '提示', { @@ -851,7 +567,7 @@ export default { // 构造提交参数 this.queryParams.type = 1 this.queryParams.leaseType = 0 - const tempTableList = this.tableList.map(item => ({ + const tempTableList = this.ids.map(item => ({ ...item, category: null // 后端不需要category字段 })) @@ -860,15 +576,14 @@ export default { devDetailsList: tempTableList // 包含devType字段 } - let res; + let res //新增 if (!this.routerParams.id) { res = await addApplyApi(params) - } else if (this.routerParams.isEdit && this.routerParams.id) { + } else if (this.routerParams.id) { // 修改 res = await editApplyApi(params) } - if (res.code == 200) { this.$message({ type: 'success', @@ -876,10 +591,10 @@ export default { }) this.$router.go(-1) } else { - this.$message.error(res.msg || '操作失败'); + this.$message.error(res.msg || '操作失败') } } catch (error) { - this.$message.error('提交申请时发生错误'); + this.$message.error('提交申请时发生错误') console.log('🚀 ~ error:', error) } finally { this.isLoading = false