/* eslint-disable */ /* eslint-disable prefer-destructuring,no-await-in-loop,semi,no-unused-vars */ /** * Created by mar105 on 2019-01-08. */ import React, { Component } from 'react'; import { message } from 'antd-v4'; // Form, Modal, InputNumber // import reactComponentDebounce from 'react-component-debounce'; import * as commonUtils from '../../utils/utils'; /* 通用方法 */ import * as commonBusiness from './commonBusiness'; /* 单据业务功能 */ import * as commonServices from '../../services/services'; /* 服务类 */ import commonConfig from '../../utils/config'; import * as commonFunc from './commonFunc'; import moment from "moment/moment"; /* 通用单据方法 */ export default (ChildComponent) => { return class extends Component { constructor(props) { super(props); this.state = { treeData: [], }; this.filterCondition = []; this.treeChild = {}; this.form = {}; /* 表单对象 */ this.timer = null; this.intervel = 0; this.defaultSelect = false; } componentDidMount() { const fromRedirect = () => { this.defaultSelect = this.props.app.currentPane.copyTo.sWorkOrderProcessId; this.handleGetSearchData(null, [ { bFilterCondition: "like", bFilterName: "sWorkCenterName", bFilterValue: this.props.app.currentPane.copyTo.sWorkCenterName } ], true); } this.intervel = 0; this.timer = setInterval(() => { if (this.props && this.props.app && this.props.app.currentPane && this.props.app.currentPane.copyTo && this.props.app.currentPane.copyTo.sWorkCenterName) { fromRedirect(); clearInterval(this.timer); this.timer = null; } else { if (this.filterCondition.length) { this.handleGetSearchData(null, this.filterCondition); clearInterval(this.timer); this.timer = null; } else { if (this.intervel > 3) { this.handleGetTreeData([]); clearInterval(this.timer); this.timer = null; } else { this.intervel ++; } } } // if (this.filterCondition.length) { // if (this.props && this.props.app && this.props.app.currentPane && this.props.app.currentPane.copyTo && this.props.app.currentPane.copyTo.sWorkCenterName) { // fromRedirect(); // } else { // this.handleGetSearchData(null, this.filterCondition); // } // clearInterval(this.timer); // this.timer = null; // } else { // if (this.intervel > 3) { // if (this.props && this.props.app && this.props.app.currentPane && this.props.app.currentPane.copyTo && this.props.app.currentPane.copyTo.sWorkCenterName) { // fromRedirect(); // } else { // this.handleGetTreeData([]); // } // clearInterval(this.timer); // this.timer = null; // } else { // this.intervel ++; // } // } }, 500) // this.handleGetTreeData([]); // this.handleGetSearchData(); } componentWillUnmount() { clearInterval(this.timer); this.timer = null; } componentWillReceiveProps(nextProps) { const { app, formData, currentId, masterData, searchSolution, sGroupByList, teamSelectedRowKeys, teamData, } = nextProps; const { teamFilterCondition } = this.props; let { isReceive, teamConfig, slaveConfig, slaveInfoConfig, treeLoaded } = nextProps; const { currentPane } = app; const { otherCondition } = currentPane; if (formData.length > 0 && !treeLoaded && searchSolution !== undefined) { isReceive = false; const sId = currentId || nextProps.masterData?.sId || ''; const masterConfig = formData.filter(item => !item.bGrd && item.sTbName === 'eleteam')[0]; treeLoaded = true; // teamConfig = formData.filter(item => item.sTbName === 'Sp_Manufacture_ProductionPlanInfo_WorkCenter')[0]; slaveConfig = formData.filter(item => item.sTbName === 'Sp_Manufacture_ProductionPlanInfo' && item.sGrd !== 'slaveInfo')[0]; slaveInfoConfig = formData.filter(item => item.sTbName === 'Sp_Manufacture_ProductionPlanInfo' && item.sGrd === 'slaveInfo')[0]; // const productionPlanConfig = formData.filter(item => item.sTbName === 'MftProductionPlanSlave')[0]; const workOutsideConfig = commonUtils.isNotEmptyArr(formData.filter(item => item.sTbName.toUpperCase() === 'Sp_Manufacture_ProductionPlanInfo'.toUpperCase() && item.showName === '排程从表(外发)')) ? formData.filter(item => item.sTbName.toUpperCase() === 'Sp_Manufacture_ProductionPlanInfo'.toUpperCase() && item.showName === '排程从表(外发)')[0] : []; const workOutConfirmConfig =commonUtils.isNotEmptyArr(formData.filter(item => item.sTbName.toUpperCase() === 'viw_qlyoutsideproducttest_opsoutsideprocess'.toUpperCase())) ? formData.filter(item => item.sTbName.toUpperCase() === 'viw_qlyoutsideproducttest_opsoutsideprocess'.toUpperCase())[0] : []; // let teamColumn = {}; // if (teamConfig) { // teamColumn = commonFunc.getHeaderConfig(teamConfig) // } const slaveColumn = commonFunc.getHeaderConfig(slaveConfig); const slavePageSize = commonUtils.isNotEmptyNumber(slaveConfig.iPageSize) && slaveConfig.iPageSize !== 0 ? slaveConfig.iPageSize : commonConfig.pageSize; const slaveInfoColumn = slaveInfoConfig ? commonFunc.getHeaderConfig(slaveInfoConfig) : null; // let productionPlanColumn = {}; // if (productionPlanConfig) { // productionPlanColumn = commonFunc.getHeaderConfig(productionPlanConfig); // } let workOutsideColumn = []; if(commonUtils.isNotEmptyObject(workOutsideConfig)) { workOutsideColumn = commonFunc.getHeaderConfig(workOutsideConfig); } let workOutConfirmColumn = []; if(commonUtils.isNotEmptyObject(workOutConfirmConfig)) { workOutConfirmColumn = commonFunc.getHeaderConfig(workOutConfirmConfig); } const workOutsideSize = commonUtils.isNotEmptyObject(workOutsideConfig) && commonUtils.isNotEmptyNumber(workOutsideConfig.iPageSize) && workOutsideConfig.iPageSize !== 0 ? workOutsideConfig.iPageSize : commonConfig.pageSize; const workOutConfirmSize = commonUtils.isNotEmptyObject(workOutConfirmConfig) && commonUtils.isNotEmptyNumber(workOutConfirmConfig.iPageSize) && workOutConfirmConfig.iPageSize !== 0 ? workOutConfirmConfig.iPageSize : commonConfig.pageSize; let currfilterCondition = []; if (commonUtils.isNotEmptyObject(masterData) && !commonUtils.isEmpty(masterData.sSearchSolutionId) && commonUtils.isNotEmptyArr(searchSolution)) { const iIndex = searchSolution.findIndex(item => item.sId === masterData.sSearchSolutionId); if (iIndex > -1 && !commonUtils.isEmpty(searchSolution[iIndex].sCondition)) { currfilterCondition = JSON.parse(searchSolution[iIndex].sCondition); this.filterCondition = currfilterCondition; } } // this.handleGetData('team', teamConfig, currfilterCondition, undefined, '', false, sGroupByList); // this.handleGetData('slave', slaveConfig, [], undefined, '', false, undefined); // this.handleGetData('slaveInfo', slaveInfoConfig, [], undefined, '', false, undefined); this.props.onSaveState({ treeLoaded: treeLoaded, masterConfig, // teamConfig, // teamColumn, slaveConfig, slaveColumn, slaveInfoConfig, slaveInfoColumn, slavePageSize, // productionPlanConfig, // productionPlanColumn, workOutsideConfig, workOutsideColumn, workOutConfirmConfig, workOutConfirmColumn, workOutsideSize, workOutConfirmSize, sId, pageLoading: false, enabled: true, dragPermission: false, dragAndDropSwitch: false, isReceive, masterData: {}, tableBtnEnabled: true, sortEnabled: true, // stateOption: objValue, }); } } shouldComponentUpdate(nextProps) { const { slaveColumn, } = nextProps; return commonUtils.isNotEmptyArr(slaveColumn); } componentDidUpdate(prevProps) { // const { // slaveSelectedRowKeys, moveEnabled, tableBtnEnabled, slaveFilterCondition, // } = prevProps; // let arr = []; // if (slaveFilterCondition) { // // 选中机台即可排序 // arr = slaveFilterCondition.filter(val => val.bFilterName === 'sMachineId') // } // if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys) && !moveEnabled && tableBtnEnabled) { // this.props.onSaveState({ moveEnabled: true }); // // 控制选择机台可选,单独判断; // if (arr.length > 0) { // this.props.onSaveState({ sortEnabled: true }); // } else { // this.props.onSaveState({ sortEnabled: true }); // } // } else if ((commonUtils.isEmptyArr(slaveSelectedRowKeys) && moveEnabled && tableBtnEnabled) || (moveEnabled && !tableBtnEnabled)) { // this.props.onSaveState({ moveEnabled: false }); // // 控制选择机台可选,单独判断; // if (arr.length > 0) { // this.props.onSaveState({ sortEnabled: true }); // } else { // this.props.onSaveState({ sortEnabled: true }); // } // } } onChangeMachine = async () => { const { sModelsId, masterData, slaveInfoSelectedRowKeys } = this.props; const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`; const value = { sProName: 'Sp_Manufacture_ProductionPlanInfo_ChangeMachine', paramsMap: { bSplit: masterData.bSplit, iSplitNum: masterData.iSplitNum, sMachineId: masterData.sMachineId, // sWorkCenterId: masterData.sWorkCenterId, sTeamId: masterData.sTeamId, tStartDate: masterData.tStartDate, sProInParam: JSON.stringify({ params: { key: 'slaveInfo', value: { sId: slaveInfoSelectedRowKeys } } }), }, }; const dataReturn = (await commonServices.postValueService(this.props.app.token, value, url)).data; if (dataReturn.code === 1) { /* 数据查询成功 */ this.handleRefresh(1); this.handleGetTreeData([]); /* 更换机台后更新Tree */ this.props.onSaveState({ isChangeMachine: false, masterData: { ...masterData, sWorkCenterId: '', sMachineId: '', sTeamId: '' } }); } else { /* 失败 */ this.props.getServiceError(dataReturn); } } handleGetTableConfig = async (name, sModelsId) => { /* 混刷 */ if (commonUtils.isNotEmptyObject(sModelsId)) { const newConfig = await this.props.onGetTableConfig(name, sModelsId); if (commonUtils.isNotEmptyObject(newConfig)) { this.props.onSaveState({ [`${[name]}Config`]: newConfig }); } } } /* 快捷键跳转 */ handleViewClick = (name, sName, record, index, myConfig) => { if (sName === 'myTableConfig') { this.handleQuickViewClick(name, sName, record, index, myConfig); }else if(sName === 'sHistroyQty') { const { slaveConfig }= this.props; let sHistoryQtyConfig = {}; if(commonUtils.isNotEmptyObject(slaveConfig)) { const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === 'sHistroyQty'); if(iIndex > -1) { sHistoryQtyConfig = slaveConfig.gdsconfigformslave[iIndex]; } } this.props.onSaveState({ sHistoryQtyConfig: sHistoryQtyConfig, sHistoryQtyRecord: record, sHistoryQtyVisible: true }); } else { this.props.onViewClick(name, sName, record, index, myConfig); } } /* 单独设置界面 */ handleQuickViewClick = async (name, sName, record, index, myConfigArr) => { const { slaveConfig, slaveData, // dispatch, slaveFilterCondition, slavePagination, // slaveOrderBy, // sModelsType, formRoute, // treeFilterCondition, // app, // iPageSize, sModelsId, // slaveSelectedData, // masterData, // employeeConfig, } = this.props; let picArr = slaveConfig.gdsconfigformslave.filter(item => (item.sName === sName)); if (commonUtils.isNotEmptyArr(myConfigArr)) { picArr = myConfigArr; } if (picArr.length > 0) { const getConfig = this.handleGetTableConfig; const tableDataRow = record; const iIndex = index; const [{ sActiveId }] = picArr; let [{ sActiveKey }] = picArr; const sFormId = sActiveId === '1' ? commonUtils.isEmpty(tableDataRow.sFormId) ? tableDataRow.sSrcFormId : tableDataRow.sFormId : sActiveId; if (commonUtils.isNotEmptyObject(sActiveKey) && sActiveKey.includes('.')) { /* 接口按钮跳转 如果有slave.对应字段 则需要取出对应字段 */ const index = sActiveKey.lastIndexOf('.'); sActiveKey = sActiveKey.substring(index + 1, sActiveKey.length); } const sNameUrl = `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sFormId}?sModelsId=${sFormId}&sName=${formRoute}`; const filterCondition = []; const conditionValues = this.props.getSqlCondition(picArr[0], name, tableDataRow); if (!commonUtils.isEmpty(conditionValues)) { Object.keys(conditionValues).forEach((item) => { if ((item === 'tStartDate_pro' || item.substring(0, 1) === 'p')) { if (!commonUtils.isEmpty(conditionValues[item]) && conditionValues[item].length >= 2) { const tStartDate = moment(conditionValues[item][0]).format(this.sDateFormat); const tEndDate = moment(conditionValues[item][1]).add(1, 'days').format(this.sDateFormat); filterCondition.push({ bFilterName: item, bFilterCondition: '=', bFilterValue: `${tStartDate},${tEndDate}`, }); } } else if ((item === 'mStartDate_pro' || item.substring(0, 1) === 'm')) { if (!commonUtils.isEmpty(conditionValues[item])) { const tStartDate = moment(conditionValues[item]).startOf('month').format(this.sDateFormat); const tEndDate = moment(conditionValues[item]).endOf('month').add(1, 'days').format(this.sDateFormat); filterCondition.push({ bFilterName: `t${item.substring(1, item.length)}`, bFilterCondition: '=', bFilterValue: `${tStartDate},${tEndDate}`, }); } } else if (item.substring(0, 1) === 't') { filterCondition.push({ bFilterName: item, bFilterCondition: '=', bFilterValue: moment(conditionValues[item]).format(this.sDateFormat), }); } else { filterCondition.push({ bFilterName: item, bFilterCondition: '=', bFilterValue: conditionValues[item], }); } }); } this.props.dispatch({ type: 'content/onRouter', payload: { url: sNameUrl, refresh: getConfig.bind(this, name, sModelsId), /* 刷新方法 */ sTabId: commonUtils.createSid(), sParentId: this.state.sTabId, urlDataType: 'newPane', checkedId: myConfigArr[0].sId, sName: myConfigArr[0].sName, bFilter: slaveFilterCondition, pageSize: commonConfig.pageSize, pages: slavePagination, currentData: slaveData, conditonValues: conditionValues, newKey: tableDataRow[sActiveKey], currentIndex: iIndex, filterCondition, }, }); } }; /** 获取表数据 */ handleGetData = async (sName, slaveConfig, slaveFilterCondition, page, slaveOrderBy, clearSelectData, sGroupByListNew, nextProps, isWait) => { const { app, workOutsideConfig, slavePageSize, workOutsideSize, workOutConfirmSize, workOutConfirmConfig } = commonUtils.isEmpty(nextProps) ? this.props : nextProps; const sGroupByList = sGroupByListNew !== undefined ? commonUtils.isEmptyArr(sGroupByListNew) ? null : sGroupByListNew : this.props.sGroupByList; const conditonValues = app.currentPane.conditonValues; // const filterCondition = app.currentPane.filterCondition; const filterCondition = ''; const bFilter = []; if (!commonUtils.isEmptyArr(slaveFilterCondition)) { slaveFilterCondition[0].bFilterName = slaveFilterCondition[0].bFilterName.replace('_pro', ''); bFilter.push(...slaveFilterCondition); } if (!commonUtils.isEmptyArr(filterCondition)) { bFilter.push(...filterCondition); } const addState = {}; const pageNum = commonUtils.isEmpty(page) ? 1 : page; addState.pageNum = pageNum; addState.pageSize = commonUtils.isNotEmptyNumber(slavePageSize) && slavePageSize !== 0 ? slavePageSize : commonConfig.pageSize; /* 判断是否是外发 */ let bOutSide = false; const outsideIndex = bFilter.findIndex(item => item.bFilterName === 'iBillOutside_pro' && item.bFilterValue === 1); bOutSide = outsideIndex > -1; if (bOutSide) { addState.pageSize = commonUtils.isNotEmptyNumber(workOutsideSize) && workOutsideSize !== 0 ? workOutsideSize : commonConfig.pageSize; // 发外设定页码; } let bOutConfirm = false; const outconfirmIndex = bFilter.findIndex(item => item.bFilterName === 'iBillConfirm_pro' && item.bFilterValue === 1); bOutConfirm = outconfirmIndex > -1; if (bOutConfirm) { addState.pageSize = commonUtils.isNotEmptyNumber(workOutConfirmSize) && workOutConfirmSize !== 0 ? workOutConfirmSize : commonConfig.pageSize; // 发外设定页码; } let configData = null; if (bOutSide) { configData = workOutsideConfig; } else if(bOutConfirm) { configData = workOutConfirmConfig; } else { configData = slaveConfig } this.props.onSaveState({ pageLoading: true }); bFilter.forEach((item, idx) => { if (item.bFilterName === "iBillOutside_pro" || item.bFilterName === "iBillConfirm_pro") { bFilter.splice(idx, 1); } }) const returnData = await this.props.handleGetDataSet({ name: sName, configData, condition: { ...addState, bFilter, sFilterOrderBy: slaveOrderBy, sSqlCondition: conditonValues, sGroupList: sGroupByList, }, flag: true, clearSelectData, isWait: true, }); let addState1 = {}; if (!isWait) { addState1 = { ...addState1, ...returnData }; } addState1 = { ...addState1, pageLoading: false, Loading: false, loading: false }; if (this.defaultSelect) { let key = this.props.slaveData.filter(item => item.sWorkOrderProcessId === this.defaultSelect); if (key.length > 0) { addState1 = { ...addState1, slaveSelectedRowKeys: [key[0].sId] }; // this.props.onSaveState({ slaveSelectedRowKeys: [key[0].sId] }); this.defaultSelect = false; } } this.props.onSaveState(addState1); if (isWait) { return { ...returnData }; } }; handleGetSearchData = (config, filterCondition, isCopyTo) => { this.treeChild = {} this.filterCondition = filterCondition; this.props.onSaveState({ slaveData: [], }); if (!isCopyTo) { this.handleGetSlaveData(config, filterCondition, true); } this.handleGetTreeData(filterCondition); this.handleResetSearch(); }; refreshTreeData = () => { this.handleGetTreeData(this.filterCondition) }; handleGetSlaveData = (config, filterCondition, isRoot) => { const { slaveConfig, slaveInfoConfig, teamData, teamSelectedRowKeys, } = this.props; const iIndex = filterCondition.findIndex(item => item.bFilterName === 'sTeamId' && item.bFilterCondition === '=' && item.bFilterValue === teamSelectedRowKeys[0]); const filter = []; filterCondition.forEach((itme, i) => { if (iIndex !== i) { filter.push(itme); } }); if (!isRoot) { const addFilter = {}; addFilter.bFilterName = 'sTeamId'; addFilter.bFilterCondition = '='; addFilter.bFilterValue = teamData[0].sId; filter.push(addFilter); } this.handleGetData('slave', slaveConfig, filter, undefined, undefined); // this.handleGetData('slaveInfo', slaveInfoConfig, filter, undefined, undefined); }; /** 主表控件是否全部显示 */ handleToggle = () => { const { expand } = this.props; this.props.onSaveState({ expand: !expand }); }; /** 表单回带 */ handleForm = (form) => { this.form = form; }; /** toolbar保存 */ handleSaveData = async (params, bFresh) => { const { token, sModelsId, } = this.props; const returnData = await commonBusiness.saveData({ token, value: params, sModelsId }); if (commonUtils.isNotEmptyObject(returnData)) { if(!bFresh) { /* 默认刷新 */ this.handleRefresh(1); if (this.props.app.currentPane.refresh !== undefined) { this.props.app.currentPane.refresh(); } } return true; } else { this.props.onSaveState({ pageLoading: false, Loading: false, loading: false }); return false; } }; /** 保存校验 */ handleValidateSave = (bFresh, slaveNewData) => { this.form.validateFields((err) => { /* 验证通过与不通过走不同的流程 */ if (err) { /* 验证失败 */ /* 直接渲染显示错误提示 */ for (const key of Object.keys(err)) { message.error(err[key].errors[0].message); } } else { /* 验证成功 */ const { slaveConfig, slaveDelData, app, productionPlanDelData, tableBtnEnabled, charGanttData, bGantt, } = this.props; let { slaveData = [] } = this.props; if(commonUtils.isNotEmptyArr(slaveNewData) && Array.isArray(slaveNewData)) { slaveData = slaveNewData; } const data = []; if (commonUtils.isEmptyArr(slaveData)) { message.error(commonFunc.showMessage(app.commonConst, 'slaveNotNull')); // 从表不能为空! return; } else { /* 如果是甘特图视图,则进入甘特图视图保存逻辑 */ if (bGantt && commonUtils.isNotEmptyObject(charGanttData)) { const data = []; const addState = {} addState.name = 'slave'; addState.sTable = 'MftProductionPlanSlave'; addState.column = charGanttData.data; data.push(addState); this.handleSaveData({ data, sClientType: '1' }); return; } const productionPlanData = []; const slaveFilter = slaveData.filter(item => item.sDivRowNew); if(commonUtils.isNotEmptyArr(slaveFilter)) { slaveFilter.forEach((item, i) => { const index = slaveData.findIndex(itemS => itemS.sSlaveId === item.sSlaveId); if(index < slaveData.length ){ // slaveData[index].sDivRowNew = ''; if (slaveData[index + 1]) { slaveData[index + 1].sDivRow = item.sDivRowNew; slaveData[index + 1].sDivRowNew = ''; } } }); } let requestDataConfig = [] if (Array.isArray(slaveConfig?.gdsconfigformslave)) { requestDataConfig = slaveConfig.gdsconfigformslave.find(i => i && ['requestDataConfig'].includes(i.sControlName))?.sActiveKey; try { requestDataConfig = JSON.parse(requestDataConfig); if (!Array.isArray(requestDataConfig)) throw ''; } catch (error) { requestDataConfig = []; } } for (const item of slaveData) { const { sSlaveId, handleType, iOrder, tStartDate, sMemo, dAdjustHour, sDivRowNew, sDivRow,bEmploy, sDivRowTmp, sDivRowGroupBy, sAPSCodeDirection, dQty2, dProcessfeesendQty, sMachineId, dCalcHourTz1, dTxHour, tCutDate, dFirstQty, sSrcNo, } = item; if (commonUtils.isEmptyObject(sDivRowNew)) { const sIds = sSlaveId.split('-'); sIds.forEach((newItem) => { const addState = {}; addState.sId = newItem; if (commonUtils.isEmpty(iOrder)) { message.error('序号必填!'); return; } if (commonUtils.isEmpty(tStartDate)) { message.error('时间必填!'); return; } addState.iOrder = iOrder; /* 20210406 zhuzong要求排程保存时候 必传iOrder,tStartDate,sMemo,dAdjustHour 四个参数 */ addState.tStartDate = tStartDate; // if (commonUtils.isNotEmptyObject(sMemo)) { // addState.sMemo = sMemo; // } // if (dAdjustHour !== undefined) { // addState.dAdjustHour = dAdjustHour; // } addState.sMemo = sMemo; addState.sSrcNo = sSrcNo; addState.dAdjustHour = dAdjustHour; addState.dCalcHourTz1 = dCalcHourTz1; addState.handleType = handleType; addState.sDivRowTmp = sDivRowTmp; addState.sDivRowGroupBy = sDivRowGroupBy; addState.sAPSCodeDirection = sAPSCodeDirection; addState.dQty2 = dQty2; addState.dProcessfeesendQty = dProcessfeesendQty; addState.sMachineId = sMachineId; addState.dTxHour = dTxHour; addState.tCutDate = tCutDate; addState.dFirstQty = dFirstQty; requestDataConfig.forEach( i => { addState[i] = item[i]; }); if (sDivRow) { addState.sDivRow = sDivRow; } else { addState.sDivRow = ''; } if (bEmploy) { addState.bEmploy = true; } else { addState.bEmploy = false; } productionPlanData.push(addState); }); } } data.push(commonBusiness.mergeData('productionPlan', 'MftProductionPlanSlave', productionPlanData, productionPlanDelData)); } if (!commonBusiness.validateTable(slaveConfig, slaveData)) { return; } // data.push(commonBusiness.mergeData('slave', 'MftProductionPlanSlave', slaveData, slaveDelData)); this.handleSaveData({ data, sClientType: '1', optName:'保存' }, bFresh); } }); }; /* 数据删除成功跳转到新路由即pane */ handleDelDataSuccess = (props) => { const { app } = props; let { panes, currentPane } = app; /* 删除单据后退出当前路由后,标签panes变化后的集合 */ panes = panes.filter(pane => pane.key !== currentPane.key); /* 跳转到panes集合的最后一个路由,因为panes集合一定含有主页路由所以panes的集合大于等于1 */ currentPane = panes[panes.length - 1]; 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 , [`${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 }); } } } } } }; // 打印 handleBtnPrint = (sActiveId, checked) => { const { app, sModelsId, slaveConfig, slaveSelectedRowKeys, slaveFilterCondition, reportData, } = this.props; const { token } = app; let slaveFilterConditionNew = slaveFilterCondition === undefined ? [] : [...slaveFilterCondition]; let sids = ''; if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) { slaveSelectedRowKeys.forEach((item, i) => { if (i === slaveSelectedRowKeys.length - 1) { sids = `${sids}${item}`; } else { sids = `${sids}${item},`; } }); } if (sids !== '') { slaveFilterConditionNew = []; const sidsNew = commonUtils.isNotEmptyObject(sids) ? sids.replace(/-/g, ',') : ''; const addFilter = {}; addFilter.bFilterName = 'sId'; addFilter.bFilterCondition = 'in'; addFilter.bFilterValue = sidsNew; slaveFilterConditionNew.push(addFilter); } const queryFilter = {}; queryFilter[slaveConfig.sId] = { bFilter: slaveFilterConditionNew }; const queryFilterJson = encodeURIComponent(JSON.stringify(queryFilter)); /* 拿到打印报表名称 */ let printReportName = 'report'; if (commonUtils.isNotEmptyArr(reportData)) { const iIndex = reportData.findIndex(item => item.sId === sActiveId); if (iIndex > -1) { printReportName = reportData[iIndex].sReportName; } } const urlPrint = `${commonConfig.file_host}printReport/printPdf/${sActiveId}/${printReportName}.pdf?${checked ? 'fileType=.xlsx&' : ''}queryFilter=${queryFilterJson}&sModelsId=${sModelsId}&sMaintableId=${slaveConfig.sId}&token=${encodeURIComponent(token)}`; window.open(urlPrint); }; /* 导出Excel */ handleOut = () => { const { slaveConfig, sFilterOrderBy, slaveSelectedRowKeys, slaveFilterCondition, sGroupByList, } = this.props; const newfilterCondition = slaveFilterCondition === undefined ? [] : slaveFilterCondition; let sids = ''; slaveSelectedRowKeys.forEach((item, i) => { if (i === slaveSelectedRowKeys.length - 1) { sids = `${sids}${item}`; } else { sids = `${sids}${item},`; } }); // const addFilter = {}; // addFilter.bFilterName = 'sId'; // addFilter.bFilterCondition = 'in'; // addFilter.bFilterValue = sids; // newfilterCondition.push(addFilter); let url = `${commonConfig.server_host}excel/export/${slaveConfig.sId}?sModelsId=${slaveConfig.sParentId}&token=${this.props.app.token}`; if (commonUtils.isNotEmptyArr(newfilterCondition)) { url = `${url}&bFilter=${encodeURIComponent(JSON.stringify(newfilterCondition))}`; } if (sFilterOrderBy !== undefined && sFilterOrderBy !== '' && Object.keys(sFilterOrderBy).length > 0) { url = `${url}&sFilterOrderBy=${encodeURIComponent(JSON.stringify(sFilterOrderBy))}`; } if (commonUtils.isNotEmptyArr(sGroupByList)) { url = `${url}&sGroupList=${encodeURIComponent(JSON.stringify(sGroupByList))}`; } window.open(url); }; handleConfirmDataChange = (value) => { const { masterData, } = this.props; masterData.dOutsideQty = value; this.props.onSaveState({ masterData }); }; // 按钮操作 handleButtonClick = (name) => { if (name === 'BtnRefresh') { this.handleRefresh(1); } else if (name === 'BtnOut') { this.handleOut(); } else if (name === 'BtnDesignFunction') { this.handleDesignFunction(); } else if (name.includes('BtnJdfUpdate')) { /* JDF更新 */ const downType = name.split('.')[1].toLowerCase(); const { app, sModelsId } = this.props; const { token } = app; const sType = `download${downType}`; const url = `${commonConfig.server_host}xs/updatejmf/7?sModelsId=${sModelsId}&token=${token}`; console.log('BtnJdfUpdate', url); // const url = `${commonConfig.server_host}xs/${sType}?sModelsId=${sModelsId}&token=${token}`; window.open(url); } else if (name.includes('BtnJdfCreate')) { /* JDF创建 */ const downType = name.split('.')[1].toLowerCase(); const { app, sModelsId } = this.props; const { token } = app; const sType = `download${downType}`; const url = `${commonConfig.server_host}xs/sendjmf?sModelsId=${sModelsId}&token=${token}`; console.log('BtnJdfCreate', url); // const url = `${commonConfig.server_host}xs/${sType}?sModelsId=${sModelsId}&token=${token}`; window.open(url); } else if (name.includes('BtnDown')) { const downType = name.split('.')[1].toLowerCase(); const { app, sModelsId } = this.props; const { token } = app; const sType = `download${downType}`; const url = `${commonConfig.server_host}xs/downloadjdf/add/xly.jdf?sModelsId=${sModelsId}&token=${token}`; window.open(url); } }; handleDesignFunction = () => { this.props.onSaveState({ visibleStatement: true }); }; handleUpdated = async (params) => { const { app, sModelsId } = this.props; const { token } = app; const url = `${commonConfig.server_host}productionPlan/getProcessOperation?sModelsId=${sModelsId}`; const { data } = await commonServices.postValueService(token, params, url); if (data.code === 1) { /* 数据查询成功 */ return true; } else { /* 失败 */ this.props.getServiceError(data); return false; } }; handleMasterChange = (name, sFieldName, changeValue, sId, dropDownData, isWait) => { const { sModelsId, slaveData, slaveSelectedRowKeys } = this.props; let { masterData } = this.props; if (sFieldName === 'sMachineId') { commonUtils.setStoreDropDownData(sModelsId, 'master', 'sTeamId', []); }else if(sFieldName === 'iSplitNum') { let returnData = this.props.onChange(name, sFieldName, changeValue, sId, dropDownData, true, masterData); let masterDataNew = {}; if(commonUtils.isNotEmptyObject(returnData)) { masterDataNew = returnData.masterData; } let iIndex = commonUtils.isNotEmptyArr(slaveData) && commonUtils.isNotEmptyArr(slaveSelectedRowKeys) ? slaveData.findIndex(item => slaveSelectedRowKeys.includes(item.sSlaveId)) : -1; let slaveRow = {}; if(iIndex > -1) { slaveRow = slaveData[iIndex]; } let dProcessSyQty = commonUtils.isEmptyObject(slaveRow) ? 0 : commonUtils.convertToNum(slaveRow.dProcessQty - commonUtils.isNull(masterDataNew.iSplitNum, 0)) ; if(dProcessSyQty < 0) { // masterData ={ ...masterDataNew, dProcessSyQty :0}; message.error('超出最大数量' + slaveRow.dProcessQty); return; }else { masterData ={ ...masterDataNew, dProcessSyQty}; } this.props.onSaveState ( { masterData }); } if (isWait) { if (sFieldName !== 'iSplitNum') { return this.props.onChange(name, sFieldName, changeValue, sId, dropDownData, isWait); } } else { // if(sFieldName?.includes('sThird-')) { // return; // } this.props.onChange(name, sFieldName, changeValue, sId, dropDownData, isWait); } }; handleCalculate = () => { const { sModelsId, slaveData } = this.props; const materialsInfo = []; const slaveDataNew = []; slaveData.forEach(async (item) => { const index = materialsInfo.findIndex(obj => obj.sMaterialsId === item.sMaterialsId); item.bMaterialAdequate = 0; if (commonUtils.isNotEmptyStr(item.sMaterialsId) && index === -1) { const url = `${commonConfig.server_host}eleMaterialsStock/getEleMaterialsStoreCurrQty?sModelsId=${sModelsId}`; const body = { sMaterialsId: item.sMaterialsId, /* 查询条件 */ }; const dataReturn = (await commonServices.postValueService(this.props.app.token, body, url)).data; if (dataReturn.code === 1) { if (commonUtils.isNotEmptyArr(dataReturn.dataset.rows[0])) { const materials = dataReturn.dataset.rows[0]; if (commonUtils.isNotEmptyNumber(materials.dAuxiliaryQty) && commonUtils.isNotEmptyNumber(item.dPrintQty) && materials.dAuxiliaryQty > item.dPrintQty) { item.bMaterialAdequate = 1; materialsInfo[index].dAuxiliaryQty = materialsInfo[index].sMaterialsId - item.dPrintQty; } } } } else if (commonUtils.isNotEmptyStr(item.sMaterialsId) && index === -1) { if (commonUtils.isNotEmptyNumber(materialsInfo[index].sMaterialsId) && commonUtils.isNotEmptyNumber(item.dPrintQty) && materialsInfo[index].sMaterialsId > item.dPrintQty) { item.bMaterialAdequate = 1; materialsInfo[index].dAuxiliaryQty = materialsInfo[index].sMaterialsId - item.dPrintQty; } } slaveDataNew.push(item); }); this.props.onSaveState({ slaveData: slaveDataNew }); }; handleTitleChange = async (name, slavePagination, filters, sorter, extra) => { // const tableBtnEnabled = commonUtils.isNotEmptyObject(filters) && commonUtils.isEmptyObject(sorter); const addState = {}; // 搜索时不能使用排序保存,否则数据会出不来。 if (commonUtils.isNotEmptyObject(sorter)) { const slaveData = []; extra.currentDataSource.forEach((item, iIndex) => { const slaveTableRow = { ...item, iOrder: iIndex + 1, handleType: 'update' }; slaveData.push(slaveTableRow); }); if (slaveData.length === this.props.slaveData.length) { addState.slaveData = slaveData; } } this.props.onSaveState({ ...addState, slavePagination, pageLoading: false, }); // this.props.onSaveState({ // tableBtnEnabled: false, pageLoading: true, // }); // const { [`${name}Config`]: tableConfig, [`${name}FilterCondition`]: tableFilterCondition, sGroupByList } = this.props; // const sort = sorter.order === 'ascend' ? 'asc' : 'desc'; // const slaveOrderBy = Object.keys(sorter).length > 0 ? { [sorter.columnKey]: sort } : ''; // 后端未支持空对象, 先用空表示 // const addState = await this.handleGetData(name, tableConfig, tableFilterCondition, undefined, slaveOrderBy, '', sGroupByList, this.props, true); // if (addState === undefined) return; // const { [`${name}Data`]: tempData } = addState; // if (commonUtils.isNotEmptyArr(addState[`${name}Data`])) { // addState[`${name}Data`].forEach((item, iIndex) => { // addState[`${name}Data`][iIndex] = { ...item, iOrder: iIndex + 1, handleType: 'update' }; // }); // } // this.props.onSaveState({ ...addState }); // setTimeout(() => { // /* 刷新commList页面数据 */ // this.props.onSaveState({ pageLoading: false }); // }, 3600); }; /** 处理选择行发生改变s */ handleCallBack = (child) => { if (!child) { return; } this.treeChild = child; const { slaveConfig, slaveInfoConfig, teamFilterCondition, bGantt, masterData, } = this.props; let filter = []; let addFilter = {}; if (child.sType === '1') { addFilter.bFilterName = 'sProcessId'; addFilter.bFilterCondition = '='; addFilter.bFilterValue = child.sMachineId; filter.push(addFilter); addFilter = {}; addFilter.bFilterName = 'sState'; addFilter.bFilterCondition = '='; addFilter.bFilterValue = '0'; filter.push(addFilter); } if (child.sType === '2') { addFilter.bFilterName = 'sMachineId'; addFilter.bFilterCondition = '='; addFilter.bFilterValue = child.sMachineId; filter.push(addFilter); addFilter = {}; addFilter.bFilterName = 'date_format(tStartDate, \'%y-%m-%d\')'; addFilter.bFilterCondition = '='; addFilter.bFilterValue = child.tStartDate; filter.push(addFilter); } if (child.sType === 'workcenter') { addFilter.bFilterName = 'sWorkCenterId'; addFilter.bFilterCondition = '='; addFilter.bFilterValue = child.sId; filter.push(addFilter); } if (child.sType === 'workoutsid') { // addFilter.bFilterName = 'sWorkOutsidId'; // addFilter.bFilterCondition = '='; // addFilter.bFilterValue = child.sId; addFilter.bFilterName = 'sWorkCenterId'; addFilter.bFilterCondition = '='; addFilter.bFilterValue = child.pid; filter.push(addFilter); addFilter = {}; addFilter.bFilterName = 'iBillOutside_pro'; addFilter.bFilterCondition = '='; addFilter.bFilterValue = 1; filter.push(addFilter); } if (child.sType === 'workoutconfirm') { // addFilter.bFilterName = 'sWorkOutsidId'; // addFilter.bFilterCondition = '='; // addFilter.bFilterValue = child.sId; addFilter.bFilterName = 'sWorkCenterId'; addFilter.bFilterCondition = '='; addFilter.bFilterValue = child.pid; filter.push(addFilter); addFilter = {}; addFilter.bFilterName = 'iBillConfirm_pro'; addFilter.bFilterCondition = '='; addFilter.bFilterValue = 1; filter.push(addFilter); } if (child.sType === 'machine') { addFilter.bFilterName = 'sMachineId'; addFilter.bFilterCondition = '='; addFilter.bFilterValue = child.sId; filter.push(addFilter); // addFilter = {}; // addFilter.bFilterName = 'sProcessId'; // addFilter.bFilterCondition = '='; // addFilter.bFilterValue = child.sProcessId; // filter.push(addFilter); } if (child.sType === 'process') { addFilter.bFilterName = 'sProcessId'; addFilter.bFilterCondition = '='; addFilter.bFilterValue = child.sId; filter.push(addFilter); addFilter = {}; addFilter.bFilterName = 'sWorkCenterId'; addFilter.bFilterCondition = '='; addFilter.bFilterValue = child.sWorkCenterId; filter.push(addFilter); } if (commonUtils.isNotEmptyArr(teamFilterCondition)) { filter.push(...teamFilterCondition); } filter = filter.concat(this.filterCondition); this.handleGetData('slave', slaveConfig, filter, undefined, '', false, undefined); /* 甘特图视图下 点击卡片刷新 */ if (bGantt) { this.handleGanttChar('', filter) } // this.handleGetData('slaveInfo', slaveInfoConfig, filter, undefined, '', false, undefined); const rowKeys = []; rowKeys.push(child.sId); /* 清空选择机台信息 */ if(commonUtils.isNotEmptyObject(masterData)) { masterData.sMachineId = ''; masterData.sMachineName = ''; masterData.sWorkCenterId = ''; masterData.sWorkCenterName = ''; } this.props.onSaveState({ teamSelectedRowKeys: rowKeys, masterData }); }; /* 获取甘特图数据 */ handleGanttChar = async (ganttChart, slaveFilterCondition) => { const { token, sModelsId, formRoute, } = this.props; const char = {}; if (commonUtils.isNotEmptyObject(ganttChart)) { char.sProcedureName = ganttChart.sProcedureName; char.paramsMap = ganttChart.paramsMap; } else { char.sProcedureName = 'Sp_Process_CommonGtChar'; char.paramsMap = { }; } let charGanttData = {}; const value = { sProName: char.sProcedureName, paramsMap: char.prodParamsMap, bFilter: slaveFilterCondition, }; this.props.onSaveState({ pageLoading: true }); const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}&sName=${formRoute}`; const { data: returnData } = await commonServices.postValueService(token, value, url); if (returnData.code === 1) { const { dataset } = returnData; if (commonUtils.isNotEmptyObject(dataset)) { const outData = returnData.dataset.rows[0].dataSet.outData[0]; if (outData.sCode === -1) { message.error(outData.sReturn); } else { charGanttData = commonUtils.isEmpty(outData.sReturn) ? [] : JSON.parse(outData.sReturn); this.props.onSaveState({ charGanttData }); } } } else { message.error(returnData.msg); } }; handleGetTreeData = async (filter) => { this.props.onSaveState({ treeLoading: true }); const { sModelsId, app, } = this.props; const { token } = app; const value = { bFilter: filter, }; const url = `${commonConfig.server_host}productionPlan/getProductionPlanTree?sModelsId=${sModelsId}`; const { data: returnData } = await commonServices.postValueService(token, value, url); if (returnData !== undefined && returnData.code === 1) { this.setState({ treeData: returnData.dataset.rows, }); // if (Object.keys(this.treeChild).length === 0) { // this.handleCallBack(returnData.dataset.rows[0]); // } } else { this.props.getServiceError(returnData); } // this.props.onSaveState({ pageLoading: false }); this.props.onSaveState({ treeLoading: false }); } /* 获取稽查模型数据 */ handleCheckModel = async (chart, slaveFilterCondition, other) => { const { app, sModelsId } = this.props; const obj = {}; if (commonUtils.isNotEmptyObject(obj)) { obj.sProcedureName = chart.sProcedureName; obj.paramsMap = chart.paramsMap; } else { obj.sProcedureName = 'Sp_Manufacture_GetAPSstate'; obj.paramsMap = { }; } const value = { sProName: obj.sProcedureName, // sProInParam: obj.paramsMap, bFilter: slaveFilterCondition, }; if (other?.iFlag === 1) { value.iFlag = 1; } const url = `${commonConfig.server_host}procedureCall/doGenericProcedureCall?sModelsId=${sModelsId}`; const returnData = (await commonServices.postValueService(app.token, value, url)).data; if (returnData.code === 1) { message.success(returnData.msg); this.handleButtonClick('BtnRefresh'); this.props.onSaveState({ bCheckModel: true }) } else { this.props.getServiceError({ ...returnData, fn: () => this.handleCheckModel(chart, slaveFilterCondition, { iFlag: 1 }) }); } }; /* 重算时间调用接口 执行存储过程 */ handleChangeTimer1 = async (other) => { const { app, sModelsId, slaveFilterCondition, slaveSelectedRowKeys, slaveData, masterData, } = this.props; let value = {}; this.props.onSaveState({ loadingTimer: true }); if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) { const slaveSelectedData = slaveData.filter(item => slaveSelectedRowKeys.includes(item.sSlaveId) && commonUtils.isEmptyObject(item.sDivRowNew)); const minSelectedData = this.arrayMin(slaveSelectedData); /* iOrder最小的 */ if (commonUtils.isNotEmptyArr(minSelectedData) && commonUtils.isNotEmptyObject(minSelectedData.sMachineId)) { // addFilter.bFilterName = 'sTeamId'; // addFilter.bFilterCondition = '='; // addFilter.bFilterValue = teamData[0].sId; // filter.push(addFilter);; value = { sProName: 'Sp_Manufacture_SetTime', sProInParam: JSON.stringify({ sMachineId: minSelectedData.sMachineId, iOrder: minSelectedData.iOrder, tCStartTime: masterData.tStartDate, sSlaveId: commonUtils.isNotEmptyObject(minSelectedData.sSlaveId) ? minSelectedData.sSlaveId : minSelectedData.sId, }), }; if (other?.iFlag === 1) { value.iFlag = 1; } const url = `${commonConfig.server_host}procedureCall/doGenericProcedureCall?sModelsId=${sModelsId}`; const returnData = (await commonServices.postValueService(app.token, value, url)).data; if (returnData.code === 1) { message.success(returnData.msg); this.handleButtonClick('BtnRefresh'); this.props.onSaveState({ changeTimerVisible: false, loadingTimer:false }) } else { this.props.getServiceError({ ...returnData, fn: () => this.handleChangeTimer({ iFlag: 1 }) }); } } else { message.error('不能重置时间!'); this.props.onSaveState({ loadingTimer:false }) } } else { message.error('请选择一行数据!'); this.props.onSaveState({ loadingTimer:false }) } }; /* 重算时间调用接口 执行存储过程 */ handleChangeTimer = async (other) => { const { app, sModelsId, slaveFilterCondition, slaveSelectedRowKeys, slaveData, masterData, } = this.props; let value = {}; this.props.onSaveState({ pageLoading: true }); if (commonUtils.isNotEmptyObject(this.treeChild) && commonUtils.isNotEmptyObject(this.treeChild.sMachineId)) { const sMachineId = this.treeChild.sMachineId; const slaveSelectedData = slaveData.filter(item => slaveSelectedRowKeys.includes(item.sSlaveId) && commonUtils.isEmptyObject(item.sDivRowNew)); const minSelectedData = this.arrayMin(slaveSelectedData); /* iOrder最小的 */ if (commonUtils.isNotEmptyObject(sMachineId)) { // addFilter.bFilterName = 'sTeamId'; // addFilter.bFilterCondition = '='; // addFilter.bFilterValue = teamData[0].sId; // filter.push(addFilter);; value = { sProName: 'Sp_Manufacture_SetTime', sProInParam: JSON.stringify({ sMachineId: sMachineId, // iOrder: minSelectedData.iOrder, // tCStartTime: masterData.tStartDate, // sSlaveId: commonUtils.isNotEmptyObject(minSelectedData.sSlaveId) ? minSelectedData.sSlaveId : minSelectedData.sId, }), }; if (other?.iFlag === 1) { value.iFlag = 1; } const url = `${commonConfig.server_host}procedureCall/doGenericProcedureCall?sModelsId=${sModelsId}`; const returnData = (await commonServices.postValueService(app.token, value, url)).data; if (returnData.code === 1) { message.success(returnData.msg); this.handleRefresh(1); this.handleGetTreeData([]); // this.handleButtonClick('BtnRefresh'); this.props.onSaveState({ changeTimerVisible: false, loadingTimer:false }) } else { this.props.getServiceError({ ...returnData, fn: () => this.handleChangeTimer({ iFlag: 1 }) }); } } else { message.error('不能重置时间!'); this.props.onSaveState({ pageLoading:false }) } } else { message.error('请选择左侧机台!'); this.props.onSaveState({ pageLoading:false }) } }; /* 锁定调用接口 执行存储过程 */ handleLock= async (other) => { const { app, sModelsId, slaveFilterCondition, slaveSelectedRowKeys, slaveData, masterData, } = this.props; let value = {}; this.props.onSaveState({ pageLoading: true }); if (commonUtils.isNotEmptyObject(this.treeChild) && commonUtils.isNotEmptyObject(this.treeChild.sMachineId)) { const sMachineId = this.treeChild.sMachineId; const slaveSelectedData = slaveData.filter(item => slaveSelectedRowKeys.includes(item.sSlaveId) && commonUtils.isEmptyObject(item.sDivRowNew)); const minSelectedData = this.arrayMin(slaveSelectedData); /* iOrder最小的 */ const sRowData =[]; if(commonUtils.isNotEmptyArr(slaveSelectedData)) { slaveSelectedData.forEach((item, index) => { const tableRow = {}; tableRow.sId =item.sSlaveId; tableRow.iBtnCd =item.iBtnCd; sRowData.push(tableRow); }); } console.log('ssss', sRowData); if (commonUtils.isNotEmptyObject(sMachineId)) { /* 先走保存 */ await this.handleValidateSave(true); value = { sProName: 'Sp_productionPlan_BtnEventLockSd', sProInParam: JSON.stringify({ sMachineId: sMachineId, sRowData, // iOrder: minSelectedData.iOrder, // tCStartTime: masterData.tStartDate, // sSlaveId: commonUtils.isNotEmptyObject(minSelectedData.sSlaveId) ? minSelectedData.sSlaveId : minSelectedData.sId, }), }; const url = `${commonConfig.server_host}procedureCall/doGenericProcedureCall?sModelsId=${sModelsId}`; const returnData = (await commonServices.postValueService(app.token, value, url)).data; if (returnData.code === 1) { message.success(returnData.msg); this.handleButtonClick('BtnRefresh'); this.props.onSaveState({ changeTimerVisible: false, pageLoading:false }) } else { this.props.getServiceError({ ...returnData}); this.props.onSaveState({ pageLoading:false }) } } else { message.error('请选择左侧机台!'); this.props.onSaveState({ pageLoading:false }) } } else { message.error('请选择左侧机台!'); this.props.onSaveState({ pageLoading:false }) } }; /* 自定义排序号 */ orderNum = (tableData) => { const {slaveColumn} = this.props; tableData.forEach((item, index) => { item.iOrder = index + 1; item.handleType = 'update'; }); /* 移动后 重新计算分割间隔条数及用时逻辑 */ const returnFilterData = tableData.filter(item => commonUtils.isNotEmptyObject(item.sDivRowNew) && item.sDivRowNew !==''); if (commonUtils.isNotEmptyArr(returnFilterData)) { returnFilterData.forEach((tableDataRow, index) => { /* 找到白班与晚班区间的汇总条数与工时 */ let startIndex = 0; /* 找到开始下标 */ let endindex = 0; /* 找到结束下标 */ let sliceData =[]; startIndex = tableData.findIndex(item => item.sId === returnFilterData[index].sId); if(index +1 < returnFilterData.length) { endindex = tableData.findIndex(item => item.sId === returnFilterData[index + 1].sId); } if(index === returnFilterData.length -1) { endindex = tableData.length; } if(startIndex < endindex) { sliceData= tableData.slice(startIndex + 1, endindex); } let num = 0; let dTime = 0; let dPlateQty = 0; /* 付版 */ let dProcessQty = 0; let endTime; /* 找到第二个字段 */ const scheduleShow = ['16508090850002295893127095467000'].includes(this.props?.sModelsId); let timeSName = 'dHour1'; if (scheduleShow) timeSName = 'dSumHour'; if(commonUtils.isNotEmptyArr(sliceData)) { num = sliceData.length; sliceData.forEach((item) => { if (commonUtils.isNotEmptyNumber(item[timeSName])) { dTime += item[timeSName]; dPlateQty += item.dPlateQty; dProcessQty += item.dProcessQty; if (item?.tEndDate) { let value = item.tEndDate; if (endTime) { value = moment.max(moment(endTime), moment(item.tEndDate)); } endTime = value; } const iSrcIndex = tableData.findIndex(itemReturn => itemReturn.sSlaveId === item.sSlaveId); /* 汇总的每行上都加newRow的sSlaveId作为父级Id */ if(iSrcIndex > -1) { tableData[iSrcIndex] = {...tableData[iSrcIndex], sDivRowParentId : tableDataRow.sSlaveId, sDivRowTmp : tableDataRow.sDivRowNew} } } }); let sCount = ''; if(num > 0) { sCount += 'F'+ num + '单'; } if(dProcessQty > 0) { sCount += ' - '+ dProcessQty; } if(sliceData[0].sType === "1" && !scheduleShow) { sCount += ' - ' + dPlateQty +'付版'; } if(dTime > 0) { if (scheduleShow) { sCount += ' - ' + Math.floor(dTime / 24) + "d" + (dTime % 24).toFixed(2) + 'h'; } else { sCount += ' - ' + (dTime/60).toFixed(2) + 'h'; }; } if (endTime) { sCount += ' - ' + moment(endTime).format('MM月DD日'); } const sFileName = commonUtils.isNotEmptyArr(slaveColumn) && slaveColumn.length > 2 ? slaveColumn[1].dataIndex : ''; if(sCount && sFileName) { const addState ={}; addState[sFileName] = tableDataRow.sDivRowNew + sCount; tableData[startIndex] = {...tableData[startIndex] , ...addState} } } }); } return tableData; }; getOrderData = (name, type) => { const { [`${name}SelectedRowKeys`]: tableselectedRowKeys, app, slavePagination: slavePaginationOld } = this.props; let { [`${name}Data`]: currentData } = this.props; if (name === 'slave') { const tempData = []; for (const sId of tableselectedRowKeys) { let index = 0; const tableDataIndex = currentData.findIndex(item => item.sId === sId); if (tableDataIndex > -1) { const tableDataRow = JSON.parse(JSON.stringify(currentData[tableDataIndex])); if(commonUtils.isNotEmptyObject(tableDataRow)) { const iSelectedOrder = tableDataRow.iOrder + index + 100; const row = {...tableDataRow, iSelectedOrder : iSelectedOrder } tempData.push(row); } } index +=1; } const tempNew = commonUtils.isNotEmptyArr(tempData) ? JSON.parse(JSON.stringify(tempData)) : []; if (commonUtils.isEmptyArr(tempNew)) { message.warn(commonFunc.showMessage(app.commonConst, 'pleaseChooseMoveData'));/* 请选择要移动数据 */ return; } const len = currentData.length; currentData = this.orderNum(currentData); const newLen = tempNew.length; let num = 0.01;/* 循环增加体 */ let targetiOrder = -1; if (type === 1) { /* 上移 */ const iIndex = currentData.findIndex(item => item.sSlaveId === tempNew[0].sSlaveId);/* 选中第一个节点的下标 */ if (iIndex === 0) { if (newLen === 1) { message.warn(commonFunc.showMessage(app.commonConst, 'NoUp'));/* 无需上移 */ return; } else { targetiOrder = 0; } } else if (iIndex === 1 && currentData[0].sDivRowNew) { message.warn(commonFunc.showMessage(app.commonConst, 'NoUp'));/* 无需上移 */ return; } else { targetiOrder = currentData[iIndex - 1].iOrder - 1; /* 目标排序号 */ } } tempNew.forEach((item) => { const index1 = currentData.findIndex(item1 => item1.sSlaveId === item.sSlaveId); currentData[index1] = { ...item, iOrder: targetiOrder + num, handleType: 'update' }; num += 0.01; }); currentData = this.sortData(currentData); currentData = this.orderNum(currentData); return currentData; } }; sortData = (tempData) => { tempData.sort((g1, g2) => { return g1.iOrder - g2.iOrder; }); return tempData; }; /* 超期计算 */ handleOverExec= async (other) => { const { app, sModelsId, slaveFilterCondition, slaveSelectedRowKeys, slaveData = [], masterData, } = this.props; if(commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) { message.error('请选择数据'); } let value = {}; this.props.onSaveState({ pageLoading: true }); // 创建新的slaveData数组,保持未选中记录顺序不变,只对选中记录重新排序 let newSlaveData = []; let sRowData = []; if (commonUtils.isNotEmptyObject(this.treeChild) && commonUtils.isNotEmptyObject(this.treeChild.sMachineId)) { const sMachineId = this.treeChild.sMachineId; const slaveSelectedData = slaveData.filter(item => slaveSelectedRowKeys.includes(item.sSlaveId) && commonUtils.isEmptyObject(item.sDivRowNew)); const minSelectedData = this.arrayMin(slaveSelectedData); /* iOrder最小的 */ if(commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) { newSlaveData = this.getOrderData('slave', 1); slaveSelectedRowKeys.forEach(slaveId => { const item = slaveData.find(item => item.sSlaveId === slaveId && commonUtils.isEmptyObject(item.sDivRowNew)); if (item) { const tableRow = { sId: item.sSlaveId, iOrder: item.iOrder, sSrcNo: item.sSrcNo }; sRowData.push(tableRow); } }); } /* 先走保存 */ await this.handleValidateSave(true, newSlaveData); value = { sProName: 'Sp_productionPlan_BtnEventCnl', sProInParam: JSON.stringify({ sMachineId: sMachineId, sRowData, }), }; console.log('sRowData', sRowData); console.log('value', value); const url = `${commonConfig.server_host}procedureCall/doGenericProcedureCall?sModelsId=${sModelsId}`; const returnData = (await commonServices.postValueService(app.token, value, url)).data; if (returnData.code === 1) { message.success(returnData.msg); // this.handleButtonClick('BtnRefresh'); this.handleRefresh(1); this.handleGetTreeData([]); this.props.onSaveState({ pageLoading: false }) } else { this.props.getServiceError({ ...returnData}); this.props.onSaveState({ pageLoading:false }) } } else { message.error('请选择左侧机台!'); this.props.onSaveState({ pageLoading:false }) } }; // 查找数组中最小值 arrayMin = (arrs) => { let min = arrs[0]; for (let i = 1, ilen = arrs.length; i < ilen; i += 1) { if (arrs[i].iOrder < min.iOrder) { min = arrs[i]; } } return min; } /* handleRefresh = async () => { const { clearArray, slaveConfig, slaveInfoConfig, teamFilterCondition, slaveFilterCondition, } = this.props; this.props.onSaveState({ clearArray: [], searchText: '', teamSelectedData: [], slaveSelectedRowKeys: [], slaveSelectedData: [], slaveInfoSelectedRowKeys: [], slaveInfoSelectedData: [], tableBtnEnabled: true, }); // teamSelectedRowKeys: [], this.handleGetData('slave', slaveConfig, slaveFilterCondition, undefined, '', false, undefined); this.handleGetData('slaveInfo', slaveInfoConfig, slaveFilterCondition, undefined, '', false, undefined); if (!commonUtils.isEmpty(clearArray)) { for (const item of clearArray) { const { confirm, clearFilters } = item; confirm(); clearFilters(); } } this.props.onSaveState({ loading: false, }); } */ // handleRefresh = () => { // this.handleCallBack(this.treeChild); // } handleRefresh = (flag) => { this.handleResetSearch(flag); this.handleCallBack(this.treeChild); } handleResetSearch = (flag) => { const { clearArray, masterData, } = this.props; let { expKeys } = this.props; if (flag !== 1) { /* flag 不等于1 代表是清空操作 */ this.treeChild = {} } /* 清空选择机台信息 */ if(commonUtils.isNotEmptyObject(masterData)) { masterData.sMachineId = ''; masterData.sMachineName = ''; masterData.sWorkCenterId = ''; masterData.sWorkCenterName = ''; } this.props.onSaveState({ clearArray: [], searchText: '', teamSelectedData: [], slaveSelectedRowKeys: [], slaveSelectedData: [], slaveInfoData: [], /* 刷新后清除slaveInfoData */ slaveInfoSelectedRowKeys: [], slaveInfoSelectedData: [], tableBtnEnabled: true, machineEnabled: false, sortedInfo: {}, masterData, }); if (!commonUtils.isEmpty(clearArray)) { for (const item of clearArray) { const { confirm, clearFilters } = item; confirm(); clearFilters(); } } /* 刷新后关闭所有expKeys */ expKeys = []; /* 刷新后清除slaveInfoData */ this.props.onSaveState({ loading: false, expKeys, }); } handleResetTableSearch = () => { // this.props.onSaveState({ clearArray: [] }); this.handleRefresh(1); } // 进行存储过程按钮存储过程参数解析拼接 根据存储过程按钮参数配置进行解析,配置是json格式 {"sproName":"cal_sss","inMap":"master.sSlaveId,slave.sId"} handleBtnEent = (btnConfig, btnName, sValue) => { const { masterData } = this.props; const sButtonParam = btnConfig.sButtonParam; const btn = JSON.parse(sButtonParam); const sProName = btn.sproName; const inParams = []; const inMap = btn.inMap; const inlist = inMap.split(','); const masterArr = []; const slaveArr = []; const slaveInfoArr = []; const controlArr = []; const materialsArr = []; const processArr = []; if (inlist.length > 0) { inlist.forEach((item) => { const itemArr = item.split('.'); if (itemArr.length > 0) { const sname = itemArr[0]; const stype = itemArr[1]; if (commonUtils.isNotEmptyStr(sname) && sname === 'master') { masterArr.push(stype); } if (commonUtils.isNotEmptyStr(sname) && sname === 'slave') { slaveArr.push(stype); } if (commonUtils.isNotEmptyStr(sname) && sname === 'slaveInfo') { slaveInfoArr.push(stype); } if (commonUtils.isNotEmptyStr(sname) && sname === 'control') { controlArr.push(stype); } if (commonUtils.isNotEmptyStr(sname) && sname === 'materials') { materialsArr.push(stype); } if (commonUtils.isNotEmptyStr(sname) && sname === 'process') { processArr.push(stype); } } }); if (commonUtils.isNotEmptyArr(masterArr) && commonUtils.isNotEmptyObject(masterData)) { const addState = {}; addState.key = 'master'; const val = []; const currVal = {}; masterArr.forEach((filed) => { currVal[`${filed}`] = masterData[`${filed}`]; }); val.push(currVal); addState.value = val; inParams.push({ ...addState }); } if (commonUtils.isNotEmptyArr(slaveArr)) { const addState = this.handleProParams('slave', slaveArr); if (commonUtils.isNotEmptyObject(addState)) { inParams.push({ ...addState }); } } if (commonUtils.isNotEmptyArr(slaveInfoArr)) { const addState = this.handleProParams('slaveInfo', slaveInfoArr); if (commonUtils.isNotEmptyObject(addState)) { inParams.push({ ...addState }); } } if (commonUtils.isNotEmptyArr(controlArr)) { const addState = this.handleProParams('control', controlArr); if (commonUtils.isNotEmptyObject(addState)) { inParams.push({ ...addState }); } } if (commonUtils.isNotEmptyArr(materialsArr)) { const addState = this.handleProParams('materials', materialsArr); if (commonUtils.isNotEmptyObject(addState)) { inParams.push({ ...addState }); } } if (commonUtils.isNotEmptyArr(processArr)) { const addState = this.handleProParams('process', processArr); if (commonUtils.isNotEmptyObject(addState)) { inParams.push({ ...addState }); } } } this.handleProcedureCall(btnConfig, sProName, JSON.stringify({ params: inParams, changeValue: sValue })); }; // 根据配置解析拼接具体参数 handleProParams = (sKey, arr) => { const { [`${sKey}Data`]: tableData, [`${sKey}SelectedRowKeys`]: selectedRowKeys } = this.props; const keyData = tableData.filter(item => selectedRowKeys.includes(item.sId) || selectedRowKeys.includes(item.sSlaveId)); if (commonUtils.isNotEmptyArr(keyData)) { const addState = {}; addState.key = sKey; const val = []; keyData.forEach((currData) => { const currVal = {}; arr.forEach((filed) => { currVal[`${filed}`] = currData[`${filed}`]; }); val.push(currVal); }); addState.value = val; return addState; } else { return undefined; } }; // 存储过程按钮调用存储过程 handleProcedureCall = async (btnConfig, proName, proInParam, other) => { const { app, sModelsId, sCurrMemoProps } = this.props; const value = { sProName: proName, sProInParam: proInParam }; if (other?.iFlag === 1) { value.iFlag = 1; } const url = `${commonConfig.server_host}procedureCall/doGenericProcedureCall?sModelsId=${sModelsId}`; const returnData = (await commonServices.postValueService(app.token, value, url)).data; /** * 修改日期:2021-03-26 * 修改人:吕杰 * 区域:以下 2 行 * BUG: * 说明:执行完接口调用后关闭弹窗 * 原代码: */ sCurrMemoProps.bVisibleMemo = false; this.props.onSaveState({ loading: false, sCurrMemoProps }); if (returnData.code === 1) { message.success(returnData.msg); this.handleButtonClick('BtnRefresh'); } else { this.props.getServiceError({ ...returnData, fn: () => this.handleProcedureCall(btnConfig, proName, proInParam, { iFlag: 1 }) }); } } /* 点击展开图标时,调用接口获取嵌套字表数据 */ handleOnExpand = async (expanded, record) => { const { sModelsId, expKeys } = this.props; let { slaveInfoData } = this.props; const { sSlaveId } = record; /* 添加移除展开的sId */ let newExp = commonUtils.isNotEmptyArr(expKeys) ? expKeys : []; if (expanded) { if (commonUtils.isNotEmptyObject(sSlaveId)) { newExp.push(record.sSlaveId); } } else { newExp = newExp.filter(item => item !== record.sSlaveId); } this.props.onSaveState({ expKeys: newExp }); let childrenData = []; if (commonUtils.isNotEmptyArr(slaveInfoData) && commonUtils.isNotEmptyObject(sSlaveId)) { childrenData = slaveInfoData.filter(item => sSlaveId.split('-').includes(item.sId)); } if (expanded && commonUtils.isEmptyArr(childrenData)) { if (commonUtils.isNotEmptyObject(sSlaveId)) { const planLoadingSate = {}; planLoadingSate.sId = sSlaveId; planLoadingSate.planLoading = true; this.props.onSaveState({ planLoadingSate }); const { token } = this.props; const url = `${commonConfig.server_host}workOrderPlan/getProductionPlanInfo?sModelsId=${sModelsId}`; const value = { sSlaveId }; const dataReturn = (await commonServices.postValueService(token, value, url)).data; if (dataReturn.code === 1) { const returnData = dataReturn.dataset.rows; if (commonUtils.isNotEmptyArr(returnData)) { childrenData = returnData; if (commonUtils.isEmptyArr(slaveInfoData)) { slaveInfoData = []; } childrenData.forEach((child) => { // const iIndex = slaveInfoData.findIndex(item => item.sId === child.sId);; // if (iIndex === -1) { // slaveInfoData.push(child); // } slaveInfoData.push(child); }); } planLoadingSate.planLoading = false; this.props.onSaveState({ planLoadingSate, slaveInfoData, }); } else { this.props.getServiceError(dataReturn); planLoadingSate.planLoading = false; this.props.onSaveState({ planLoadingSate }); } } } } handlePartNameClick =(sName, showConfig, record) => { if (commonUtils.isNotEmptyObject(sName) && commonUtils.isNotEmptyObject(showConfig) && commonUtils.isNotEmptyObject(record)) { this.props.onSaveState({ workScheduleConfig: showConfig, workScheduleRecord: record, workScheduleVisible: true, }); } } handleCloseModel = (modelVisible) => { this.props.onSaveState({ [modelVisible]: false }); }; render() { const { masterData } = this.props; const imgSrc = commonBusiness.handleAddIcon(masterData); return ( ); } }; };