From 1f6c0763a3f49e09bfcd65382b4b758c687bd042 Mon Sep 17 00:00:00 2001 From: 17630416519 Date: Wed, 14 Jan 2026 16:53:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../productManagement/ProWorkorder/index.vue | 158 ++++++++++++++++-- 1 file changed, 145 insertions(+), 13 deletions(-) diff --git a/src/views/productManagement/ProWorkorder/index.vue b/src/views/productManagement/ProWorkorder/index.vue index af609e7..71eefdf 100644 --- a/src/views/productManagement/ProWorkorder/index.vue +++ b/src/views/productManagement/ProWorkorder/index.vue @@ -283,8 +283,8 @@ @@ -802,12 +802,57 @@ function cancel() { reset() } +// 重置表单 +// function reset() { +// // 初始化日期为 ISO 格式(2026-01-13T00:00:00 样式) +// const today = new Date() +// const isoDate = new Date(today.setHours(0, 0, 0, 0)).toISOString().slice(0, 19) +// console.log(isoDate,'isoDate'); +// form.value = { +// id: null, +// productionName: null, +// productionCode: null, +// specification: '', +// customCode: null, +// deliveryNum: 0, +// unit: '只', +// isCarton: 0, +// packageCapacity: 1, +// groupCode: null, +// lineCode: null, +// sort: 1, +// workorderDate: isoDate, // 保持ISO格式 +// year: null, +// week: null, +// date: null, +// priority: '2', +// status: 1, +// beat: 0, +// remark: null, +// createdBy: null, +// createdTime: null, +// updatedBy: null, +// updatedTime: null, +// selectedTimeRange:null +// } +// search01.value = '' +// search02.value = '' +// proxy.resetForm('formRef') +// } // 重置表单 function reset() { - // 初始化日期为 ISO 格式(2026-01-13T00:00:00 样式) + // 正确生成本地时间的 ISO 格式日期(避免时区偏移) const today = new Date() - const isoDate = new Date(today.setHours(0, 0, 0, 0)).toISOString().slice(0, 19) - console.log(isoDate,'isoDate'); + // 方法1:手动拼接 ISO 格式字符串(推荐) + const year = today.getFullYear() + const month = String(today.getMonth() + 1).padStart(2, '0') + const day = String(today.getDate()).padStart(2, '0') + const isoDate = `${year}-${month}-${day}T00:00:00` + + // 方法2:如果需要兼容不同浏览器,也可以用这个方式 + // const isoDate = new Date(today.getTime() - (today.getTimezoneOffset() * 60000)) + // .toISOString().slice(0, 19) + form.value = { id: null, productionName: null, @@ -821,7 +866,7 @@ function reset() { groupCode: null, lineCode: null, sort: 1, - workorderDate: isoDate, // 保持ISO格式 + workorderDate: isoDate, // 现在是正确的当日日期 year: null, week: null, date: null, @@ -832,13 +877,13 @@ function reset() { createdBy: null, createdTime: null, updatedBy: null, - updatedTime: null + updatedTime: null, + selectedTimeRange:null } search01.value = '' search02.value = '' proxy.resetForm('formRef') } - // 插入生产工单 const nextId = ref('') function handleAdd(id = -1) { @@ -854,7 +899,40 @@ function handleAdd(id = -1) { } } -// 修改按钮操作 +// 修改按钮操 +// function handleUpdate(row) { +// reset() +// const id = row.id || ids.value +// getProWorkorder(id).then((res) => { +// const { code, data } = res +// if (code == 200) { +// open.value = true +// title.value = '修改生产工单' +// opertype.value = 2 + +// // 正确处理日期回显(避免时区偏移) +// if (data.workorderDate) { +// // 如果是 ISO 字符串,直接使用;如果是普通日期字符串,拼接为 ISO 格式 +// if (typeof data.workorderDate === 'string') { +// if (data.workorderDate.includes('T')) { +// // 检查是否因时区问题导致日期偏移 +// const dateObj = new Date(data.workorderDate) +// const localDate = new Date(dateObj.getTime() + (dateObj.getTimezoneOffset() * 60000)) +// data.workorderDate = localDate.toISOString().slice(0, 19) +// } else { +// data.workorderDate = `${data.workorderDate}T00:00:00` +// } +// } else if (data.workorderDate instanceof Date) { +// data.workorderDate = `${data.workorderDate.getFullYear()}-${String(data.workorderDate.getMonth() + 1).padStart(2, '0')}-${String(data.workorderDate.getDate()).padStart(2, '0')}T00:00:00` +// } +// } + +// form.value = { +// ...data +// } +// } +// }) +// } function handleUpdate(row) { reset() const id = row.id || ids.value @@ -865,9 +943,21 @@ function handleUpdate(row) { title.value = '修改生产工单' opertype.value = 2 - // 确保回显的日期是 ISO 格式 - if (data.workorderDate && !(data.workorderDate.includes('T'))) { - data.workorderDate = new Date(data.workorderDate).toISOString().slice(0, 19) + // 正确处理日期回显(避免时区偏移) + if (data.workorderDate) { + // 如果是 ISO 字符串,直接使用;如果是普通日期字符串,拼接为 ISO 格式 + if (typeof data.workorderDate === 'string') { + if (data.workorderDate.includes('T')) { + // 检查是否因时区问题导致日期偏移 + const dateObj = new Date(data.workorderDate) + const localDate = new Date(dateObj.getTime() + (dateObj.getTimezoneOffset() * 60000)) + data.workorderDate = localDate.toISOString().slice(0, 19) + } else { + data.workorderDate = `${data.workorderDate}T00:00:00` + } + } else if (data.workorderDate instanceof Date) { + data.workorderDate = `${data.workorderDate.getFullYear()}-${String(data.workorderDate.getMonth() + 1).padStart(2, '0')}-${String(data.workorderDate.getDate()).padStart(2, '0')}T00:00:00` + } } form.value = { @@ -876,7 +966,41 @@ function handleUpdate(row) { } }) } +// function submitForm(toNext = false) { +// proxy.$refs['formRef'].validate((valid) => { +// if (valid) { +// const submitData = { ...form.value } +// if (submitData.workorderDate) { +// if (submitData.workorderDate instanceof Date) { +// submitData.workorderDate = submitData.workorderDate.toISOString().slice(0, 19) +// } +// else if (typeof submitData.workorderDate === 'string' && submitData.workorderDate.includes('-') && !submitData.workorderDate.includes('T')) { +// submitData.workorderDate = new Date(submitData.workorderDate + 'T00:00:00').toISOString().slice(0, 19) +// } +// } +// if (submitData.id != undefined && opertype.value === 2) { +// updateProWorkorder(submitData).then((res) => { +// proxy.$modal.msgSuccess('修改成功') +// if (!toNext) { +// open.value = false +// } +// WorkOrderLog({ workorder: submitData.workorder, log: '修改' }) +// getList() +// }) +// } else { +// submitData.next_id = nextId.value +// Insert_workOrder(submitData).then((res) => { +// proxy.$modal.msgSuccess('新增成功') +// if (!toNext) { +// open.value = false +// } +// getList() +// }) +// } +// } +// }) +// } // 添加&修改 表单提交 - 核心修改:确保提交的是 ISO 格式日期 function submitForm(toNext = false) { proxy.$refs['formRef'].validate((valid) => { @@ -884,6 +1008,15 @@ function submitForm(toNext = false) { // 深拷贝表单数据,避免修改原数据 const submitData = { ...form.value } + if (value1.value && Array.isArray(value1.value)) { + submitData.selectedTimeRange = { + startTime: value1.value[0], + endTime: value1.value[1] + } + } else { + submitData.selectedTimeRange = null + } + // 确保 workorderDate 是 2026-01-13T00:00:00 格式 if (submitData.workorderDate) { // 如果是 Date 对象,转换为 ISO 格式 @@ -918,7 +1051,6 @@ function submitForm(toNext = false) { } }) } - // 删除按钮操作 function handleDelete(row) { const Ids = row.id || ids.value