From 3b2a5b2218c5eb07e3050fd4c803241a6ab8c837 Mon Sep 17 00:00:00 2001 From: itcast Date: Tue, 25 Nov 2025 19:07:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/AddItemDialog.vue | 69 ++++- src/views/EquipmentRetireApply/detail.vue | 2 +- src/views/business/apply/addApply.vue | 288 ++++++++++++------ src/views/business/apply/applyList.vue | 2 + src/views/business/audit/addAudit.vue | 11 +- src/views/business/outbound/details.vue | 13 +- src/views/business/warehouse/auditDetails.vue | 2 +- src/views/business/warehouse/details.vue | 30 +- .../repairApply/SelectToolDialog.vue | 28 +- .../equipmentRepair/repairApply/addRepair.vue | 2 +- .../repairApply/repairList.vue | 61 +++- .../repairAudit/repairAuditList.vue | 59 +++- 12 files changed, 422 insertions(+), 145 deletions(-) diff --git a/src/views/EquipmentRetireApply/components/AddItemDialog.vue b/src/views/EquipmentRetireApply/components/AddItemDialog.vue index d3b40662..bd103aef 100644 --- a/src/views/EquipmentRetireApply/components/AddItemDialog.vue +++ b/src/views/EquipmentRetireApply/components/AddItemDialog.vue @@ -2,25 +2,46 @@ - - - - - + + + + - - + + + + + + + + - + - + + + + + + + + @@ -51,11 +72,10 @@ - + 查询 重置 - - + @@ -71,8 +91,14 @@ > - - + + + + + @@ -127,7 +153,11 @@ export default { visible: false, queryParams: { name: '', + typeName:'', devType: '', + manageType: '', + typeModelName: '', + devCode: '', equipmentCategory: [], // 新增:装备分类路径(数组) toolCategory: [], // 新增:工具分类路径(数组) equipmentCategoryId: '', // 新增:装备分类ID(用于接口查询) @@ -200,7 +230,12 @@ export default { ...this.queryParams, // 只传递最终的分类ID,简化接口参数 equipmentCategory: this.queryParams.equipmentCategoryId, - toolCategory: this.queryParams.toolCategoryId + toolCategory: this.queryParams.toolCategoryId, + manageType: this.queryParams.manageType, + // 新增:将规格型号和设备编码加入查询参数 + typeModelName: this.queryParams.typeModelName, + devCode: this.queryParams.devCode, + typeName: this.queryParams.typeName, } const res = await getScrapItemListAPI(query) this.itemList = (res.rows || []).map(item => ({ @@ -221,7 +256,9 @@ export default { onHandleReset() { this.queryParams = { name: '', + typeName: '', devType: '', + manageType: '', equipmentCategory: [], toolCategory: [], equipmentCategoryId: '', diff --git a/src/views/EquipmentRetireApply/detail.vue b/src/views/EquipmentRetireApply/detail.vue index 23795a6b..ce8a77c8 100644 --- a/src/views/EquipmentRetireApply/detail.vue +++ b/src/views/EquipmentRetireApply/detail.vue @@ -42,7 +42,7 @@
- 退役申请列表 + 退役申请设备 diff --git a/src/views/business/apply/addApply.vue b/src/views/business/apply/addApply.vue index 8c9a95d0..c8d74eb9 100644 --- a/src/views/business/apply/addApply.vue +++ b/src/views/business/apply/addApply.vue @@ -44,20 +44,22 @@ - + + + @@ -65,7 +67,7 @@ - 自用申请列表 + 自用申请设备 添加 @@ -106,15 +108,18 @@ - + @@ -156,6 +161,23 @@ + + + + + + + + + @@ -260,6 +282,7 @@ export default { name: 'AddEditApply', data() { return { + useTimeRange: [], // 主表单的全局日期范围 routerParams: {}, isLoading: false, showSearch: true, @@ -314,6 +337,7 @@ export default { proCounty: [{ required: true, message: '请选择项目所在区/县', trigger: 'change' }], proLocation: [{ required: true, message: '请输入详细地址', trigger: 'blur' }], useUnit: [{ required: true, message: '请输入需求单位', trigger: 'blur' }], + useTimeRange: [{ required: true, message: '请选择使用到期日期', trigger: 'change' }], }, @@ -329,6 +353,7 @@ export default { typeModelName: '', // 规格型号 devCode: '', // 设备编码 devType: '', // 核心:分类选择(1=装备,2=工具) + manageType: '', categoryPath: '', // 装备分类路径(数组) toolCategoryPath: '', // 工具分类路径(数组) pageNum: 1, // 页码 @@ -340,7 +365,8 @@ export default { devCode: '', categoryEquipment: '', // 装备分类ID(字符串) toolTypeId: '', // 工具分类ID(字符串) - devType: '' // 筛选类型(1=装备,2=工具) + devType: '' ,// 筛选类型(1=装备,2=工具) + manageType:'' }, addTotal: 0, // 添加申请列表总条数 addList: [], // 添加申请列表数据 @@ -371,6 +397,17 @@ export default { this.getEquipmentTree() // 初始化加载装备分类树 this.getToolTree() // 初始化加载工具分类树 }, + + watch: { + // 监听主表单日期范围变化,同步更新表格中所有行的时间段 + 'queryParams.useTimeRange'(newVal) { + if (newVal && newVal.length === 2 && this.tableList.length > 0) { + this.tableList.forEach(item => { + item.useTimeRange = [...newVal]; // 同步主表单的日期范围 + }); + } + } + }, methods: { // 获取使用项目的下拉选 async getUseProjectList() { @@ -422,30 +459,47 @@ export default { // 获取列表数据 async getList(emit = {}) { + // 如果从emit传入id,更新查询参数 if (emit.id) { - this.queryParams.id = emit.id - this.$route.query.id = this.queryParams.id + this.queryParams.id = emit.id; + this.$route.query.id = this.queryParams.id; } - this.isLoading = true + + this.isLoading = true; try { - const params = { ...this.queryParams } - const res = await getApplyDetailsApi(params) - this.tableList = res.data.devDetailsList || [] - if (this.queryParams.id) { - // 编辑或查看时,回填表单数据 - Object.assign(this.queryParams, res.data.devInfo || {}) - // 确保useTime是Date对象,防止Element UI日期选择器显示异常 - if (this.queryParams.useTime) { - this.queryParams.useTime = new Date(this.queryParams.useTime); + const params = { ...this.queryParams }; + const res = await getApplyDetailsApi(params); // 调用接口获取详情 + + // 初始化表格数据(重点处理日期) + this.tableList = (res.data.devDetailsList || []).map(item => ({ + ...item, + // 将后端返回的 useStartTime/useEndTime 转为 Date 对象数组(适配 el-date-picker) + useTimeRange: item.useStartTime && item.useEndTime + ? [new Date(item.useStartTime), new Date(item.useEndTime)] + : [] // 无日期时设为空数组 + })); + + // 如果是编辑/查看模式,初始化主表单数据 + if (this.queryParams.id && res.data.devInfo) { + Object.assign(this.queryParams, res.data.devInfo); + + // 初始化主表单的全局日期范围(如果后端返回了全局日期) + if (res.data.devInfo.useStartTime && res.data.devInfo.useEndTime) { + this.queryParams.useTimeRange = [ + new Date(res.data.devInfo.useStartTime), + new Date(res.data.devInfo.useEndTime) + ]; } } - this.total = res.data.total || 0 + + this.total = res.data.total || 0; } catch (error) { - this.tableList = [] - this.total = 0 - this.$message.error('获取申请详情失败') + this.tableList = []; + this.total = 0; + this.$message.error('获取申请详情失败'); + console.error('getList error:', error); } finally { - this.isLoading = false + this.isLoading = false; } }, @@ -558,7 +612,8 @@ export default { devCode: queryParams.devCode, categoryEquipment, toolTypeId, - devType // 关键:将devType传递给后端筛选 + devType, // 关键:将devType传递给后端筛选 + manageType: queryParams.manageType // 关键:将manageType传递给后端筛选 }; // 调用分页查询方法 @@ -624,7 +679,7 @@ export default { manageType: item.manageType, devCode: item.devCode, storageNum: item.storageNum, - num: item.manageType == 0 ? 1 : item.num, // 编码设备默认1,数量设备取输入值 + num: item.manageType == 0 ? 1 : item.storageNum, // 编码设备默认1,数量设备取输入值 useTime: this.queryParams.useTime ? new Date(this.queryParams.useTime) : null // 默认为主表单的使用日期 }) }) @@ -663,26 +718,30 @@ export default { // 确认添加(将勾选的数据添加到主表格) saveAdd() { if (!this.ids.length) { - this.$message({ - type: 'error', - message: '请勾选要添加的数据' - }) + this.$message.error('请勾选要添加的数据') return } - // 检查是否有数量设备未填写数量 - const invalidItem = this.addTempList.find(item => item.manageType === 1 && (item.num === 0 || !item.num)); + const itemsToAdd = this.addList.filter(item => this.ids.includes(item.id)) + const invalidItem = itemsToAdd.find(item => item.manageType === 1 && (item.num === 0 || !item.num)) if (invalidItem) { - this.$message.error('请为数量管理的设备填写申请数量。'); - return; + this.$message.error('请为数量管理的设备填写申请数量。') + return } - this.addTempList.forEach(item => { - this.tableList.push(item) // 数据包含devType字段 + // 关键修改:新增设备时,初始化 useTimeRange 为 Date 对象数组 + itemsToAdd.forEach(item => { + this.tableList.push({ + ...item, + // 逻辑:主表单有日期则用主表单日期,无则为空数组 + useTimeRange: this.queryParams.useTime + ? [new Date(this.queryParams.useTime), new Date(this.queryParams.useTime)] + : [] + }) }) + // 清除勾选状态 this.ids = [] - this.addTempList = [] if (this.$refs.addTable) { this.$refs.addTable.clearSelection() } @@ -692,67 +751,94 @@ export default { // 提交申请(新增/编辑,devType随数据传递) // 提交 async submit() { - this.$refs.queryForm.validate(async(valid) => { - if (valid) { - this.$confirm('是否确定提交申请?', '提示', { - confirmButtonText: '确定', - cancelButtonText: '取消', - type: 'warning' - }).then(async() => { - this.isLoading = true - try { - //新增 - if (!this.routerParams.id) { - this.queryParams.type = 2 - this.queryParams.leaseType = 0 - const tempTableList = this.tableList.map(item => ({ - ...item, - category: null - })) - const params = { - devInfo: this.queryParams, - devDetailsList: tempTableList - } - const res = await addApplyApi(params) - if (res.code == 200) { - this.$message({ - type: 'success', - message: '添加成功!' - }) - this.$router.go(-1) - // this.$tab.closeOpenPage({ path: '/business/applyList' }) - } - } else if (this.routerParams.id) { - // 修改 - this.queryParams.type = 2 - this.queryParams.leaseType = 0 - const tempTableList = this.tableList.map(item => ({ - ...item, - category: null - })) - const params = { - devInfo: this.queryParams, - devDetailsList: tempTableList - } - const res = await editApplyApi(params) - if (res.code == 200) { - this.$message({ - type: 'success', - message: '修改成功!' - }) - this.$router.go(-1) - // this.$tab.closeOpenPage({ path: '/business/applyList' }) - } + this.$refs.queryForm.validate(async (valid) => { + if (!valid) return; + + this.$confirm('是否确定提交申请?', '提示', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning' + }).then(async () => { + this.isLoading = true; + try { + // --- 修改开始:健壮的日期格式化函数 --- + const safeFormatDate = (dateInput) => { + // 1. 检查输入是否为 null 或 undefined + if (!dateInput) { + console.warn('尝试格式化一个空的日期值'); + return ''; // 或根据业务返回 '1970-01-01' 等默认值 } - } catch (error) { - console.log('🚀 ~ error:', error) - } finally { - this.isLoading = false + // 2. 确保输入是一个 Date 对象 + let date; + if (dateInput instanceof Date) { + date = dateInput; + } else { + // 如果是字符串,尝试将其转换为 Date 对象 + date = new Date(dateInput); + } + + // 3. 检查 Date 对象是否有效 + if (isNaN(date.getTime())) { + console.error('无效的日期值:', dateInput); + return ''; // 或抛出错误 + } + + // 4. 执行格式化 + const year = date.getFullYear(); + const month = (date.getMonth() + 1).toString().padStart(2, '0'); + const day = date.getDate().toString().padStart(2, '0'); + return `${year}-${month}-${day}`; + }; + // --- 修改结束 --- + + // 1. 处理主表单的日期范围 + const devInfo = { ...this.queryParams }; + if (devInfo.useTimeRange && devInfo.useTimeRange.length === 2) { + // 使用健壮的格式化函数 + devInfo.useStartTime = safeFormatDate(devInfo.useTimeRange[0]); + devInfo.useEndTime = safeFormatDate(devInfo.useTimeRange[1]); } - }) - } - }) + delete devInfo.useTimeRange; + + // 2. 处理表格数据的日期 + const tempTableList = this.tableList.map(item => ({ + ...item, + category: null, + // 使用健壮的格式化函数 + useStartTime: safeFormatDate(item.useTimeRange[0]), + useEndTime: safeFormatDate(item.useTimeRange[1]), + useTimeRange: undefined, + useTime: undefined + })); + + const params = { + devInfo, + devDetailsList: tempTableList + }; + + // ... 后续提交逻辑 ... + let res; + if (!this.routerParams.id) { + res = await addApplyApi(params); + } else { + res = await editApplyApi(params); + } + + if (res.code === 200) { + this.$message.success(res.message || '操作成功!'); + this.$router.go(-1); + } else { + this.$message.error(res.message || '操作失败!'); + } + } catch (error) { + this.$message.error('提交申请异常,请稍后重试'); + console.error('submit error:', error); + } finally { + this.isLoading = false; + } + }); + }); }, // 处理分类树数据(适配六级分类) diff --git a/src/views/business/apply/applyList.vue b/src/views/business/apply/applyList.vue index ce2d7eeb..a78a644d 100644 --- a/src/views/business/apply/applyList.vue +++ b/src/views/business/apply/applyList.vue @@ -48,6 +48,8 @@ /> + + 查询 diff --git a/src/views/business/audit/addAudit.vue b/src/views/business/audit/addAudit.vue index ae048e7b..664b2946 100644 --- a/src/views/business/audit/addAudit.vue +++ b/src/views/business/audit/addAudit.vue @@ -75,7 +75,16 @@ - + + + diff --git a/src/views/business/outbound/details.vue b/src/views/business/outbound/details.vue index 2fe18a7d..d97ba289 100644 --- a/src/views/business/outbound/details.vue +++ b/src/views/business/outbound/details.vue @@ -160,7 +160,18 @@ - + + + + + diff --git a/src/views/business/warehouse/auditDetails.vue b/src/views/business/warehouse/auditDetails.vue index fa92b98b..9ca16545 100644 --- a/src/views/business/warehouse/auditDetails.vue +++ b/src/views/business/warehouse/auditDetails.vue @@ -79,7 +79,7 @@ - + - +