diff --git a/src/components/Common/CommonProductionPlanTreeEvent.js b/src/components/Common/CommonProductionPlanTreeEvent.js index 510e760..9f6b7de 100644 --- a/src/components/Common/CommonProductionPlanTreeEvent.js +++ b/src/components/Common/CommonProductionPlanTreeEvent.js @@ -657,32 +657,58 @@ export default (ChildComponent) => { this.props.onRemovePane(panes, currentPane); }; + handleEndDate = (dateStr, hoursToAdd = 0) => { + const date = moment(dateStr, "YYYY-MM-DD HH:mm:ss"); + if (hoursToAdd) { + date.add(hoursToAdd, 'hours'); + } + return date.format("YYYY-MM-DD HH:mm"); + } + /** 表格数据更改 */ // name 不写完整的state名称作用为了要用到total // (name, changeValue, sId, dropDownData) handleTableChange = async (name, sFieldName, changeValue, sId, dropDownData) => { - const { sModelsId } = this.props; - this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, false); - if (name === 'slave') { - commonUtils.setStoreDropDownData(sModelsId, 'master', 'sTeamId', []); - if (sFieldName === 'iOrder') { - /* 修改汇总表数据后,slaveInfo表iOrder同步更改 */ - const { slaveInfoData, slaveData } = this.props; - const iIndex = slaveData.findIndex(item => item.sId === sId); - if (iIndex > -1) { - const tableDataRow = slaveData[iIndex]; - let childrenData = []; - childrenData = tableDataRow.childrenData; - if (commonUtils.isNotEmptyArr(childrenData)) { - childrenData.forEach((child) => { - const index = slaveInfoData.findIndex(item => item.sId === child.sId); - const addState = {}; - addState.handleType = 'update'; - addState.iOrder = tableDataRow.iOrder; - if (index > -1) { - slaveInfoData[index] = { ...slaveInfoData[index], ...addState } - } - }); - this.props.onSaveState({ slaveData, slaveInfoData }); + const { sModelsId , [`${name}Data`]: tableData, } = this.props; + if(sFieldName === 'dCalcHourTz1') { + let tableDataRow = await this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, true); + + // 计算总小时数 = (dCalcHourTz1 或 dCalcHour1) + dHour(四舍五入到分钟) + const dHourInMinutes = Math.round((tableDataRow.dHour || 0) * 60); // 将小时转换为分钟并四舍五入 + const dHourInHours = dHourInMinutes / 60; // 转换回小时,保留两位小数 + const hoursToAdd = (tableDataRow.dCalcHourTz1 !== undefined ? tableDataRow.dCalcHourTz1 : tableDataRow.dCalcHour1) + dHourInHours; + + const tEndDate = this.handleEndDate(tableDataRow.tStartDate, hoursToAdd); + + console.log('总小时数:', hoursToAdd); + console.log('结束时间:', tEndDate); + tableDataRow.tEndDate = tEndDate; + const iIndex = tableData.findIndex(item => item.sId === sId); + tableData[iIndex] = tableDataRow; + this.props.onSaveState({ slaveData: tableData }); + } else { + this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, false); + if (name === 'slave') { + commonUtils.setStoreDropDownData(sModelsId, 'master', 'sTeamId', []); + if (sFieldName === 'iOrder') { + /* 修改汇总表数据后,slaveInfo表iOrder同步更改 */ + const { slaveInfoData, slaveData } = this.props; + const iIndex = slaveData.findIndex(item => item.sId === sId); + if (iIndex > -1) { + const tableDataRow = slaveData[iIndex]; + let childrenData = []; + childrenData = tableDataRow.childrenData; + if (commonUtils.isNotEmptyArr(childrenData)) { + childrenData.forEach((child) => { + const index = slaveInfoData.findIndex(item => item.sId === child.sId); + const addState = {}; + addState.handleType = 'update'; + addState.iOrder = tableDataRow.iOrder; + if (index > -1) { + slaveInfoData[index] = { ...slaveInfoData[index], ...addState } + } + }); + this.props.onSaveState({ slaveData, slaveInfoData }); + } } } }