/* eslint-disable */ /* eslint-disable prefer-destructuring */ /** * Created by mar105 on 2019-02-15. */ import React, { Component } from 'react'; import { message } from 'antd'; import moment from 'moment'; import * as commonConfig from '../../utils/config'; import * as commonUtils from '../../utils/utils'; import * as commonServices from '../../services/services'; import * as commonFunc from './commonFunc'; import * as commonBusiness from './commonBusiness'; /* 通用单据方法 */ export default (ChildComponent) => { return class extends Component { constructor(props) { super(props); this.state = { pageLoading: true, token: props.routing ? props.formRoute === '/indexOee' ? props.app.token : '' : props.app.token, // /indexOee为oee报产页面 sTabId: this.handleConfigValue('key', props.formRoute), // type无论是indexoee和一般的都使用eles sModelsId: props.routing ? props.sModelsId : (commonUtils.isNotEmptyStr(props.formRoute) && props.formRoute.indexOf('/indexOee') > -1) ? props.sModelsId : this.handleConfigValue('formId'), /* 获取配置数据用的modelId */ formRoute: props.routing ? props.formRoute : (commonUtils.isNotEmptyStr(props.formRoute) && props.formRoute.indexOf('/indexOee') > -1) ? props.formRoute : this.handleConfigValue('route'), /* 组件名: 路由名称 */ formSrcRoute: props.routing ? props.routing.pathname.replace('/', '') : commonUtils.isNotEmptyObject(location.pathname) && location.pathname.toLowerCase() === '/loginoee' ? '/commonAuto' : '', sModelsType: this.handleConfigValue('sModelsType', props.formRoute), /* 组件名: 路由名称 */ bFastOrderView: this.handleConfigValue('bFastOrderView'), /* 是否显示快速下单 */ formData: [], /* 所有配置 */ gdsformconst: [], /* 获取配置常量 */ gdsjurisdiction: [], /* 获取配置权限 */ currentId: (commonUtils.isNotEmptyStr(props.formRoute) && props.formRoute.indexOf('/indexOee') > -1) ? props.checkedId : props.app.currentPane.checkedId, /* 当前数据的Id */ selectedRowKeys: [], /* 已选择的数据行(数据格式:数组) */ clearArray: [], /* table清除数组 */ calculated: false, // 工单是否经过计算 iPageSize: commonConfig.pageSize, /* 默认config配置的pageSize */ }; this.sDateFormat = 'YYYY-MM-DD'; window.addEventListener('beforeunload', this.beforeunload); window.addEventListener('unload', this.unload); } async componentWillMount() { if (commonUtils.isNotEmptyObject(location.pathname) && location.pathname.toLowerCase() !== '/loginoee') { if (this.props.app.webSocket === null || this.props.app.webSocket.readyState !== WebSocket.OPEN) { this.props.dispatch({ type: 'app/createWebSocket', payload: { reStart: true, dispatch: this.props.dispatch } }); } } /* 获取配置 */ this.mounted = true; const { token, sModelsId, formSrcRoute } = this.state; let { iPageSize } = this.state; const config = await commonUtils.getStoreDropDownData(sModelsId, '', ''); if (commonUtils.isEmpty(config)) { const configUrl = `${commonConfig.server_host}business/getModelBysId/${sModelsId}?sModelsId=${sModelsId}&sName=${formSrcRoute}`; const configReturn = (await commonServices.getService(token, configUrl)).data; if (configReturn.code === 1) { const [configData] = configReturn.dataset.rows; const { formData } = configData; if (commonUtils.isNotEmptyArr(formData)) { if (commonUtils.isNotEmptyNumber(formData[0].iPageSize) && formData[0].iPageSize !== 0) { iPageSize = formData[0].iPageSize;/* 后台设定页数 */ } } if (this.mounted) { commonUtils.setStoreDropDownData(sModelsId, '', '', configData); this.setState({ ...configData, iPageSize }); } } else { this.getServiceError(configReturn); } } else { this.setState({ ...config }); } } componentDidMount() { if (this.state.sTabId) { this.props.dispatch({ type: 'app/changeDiffMap', payload: { sTabId: this.state.sTabId, changed: false } }); } if (this.state.formRoute && this.state.formRoute.indexOf('/indexOee') > -1 && this.state.sModelsId && this.state.formRoute) { const sModelData = { sModelsId: this.state.sModelsId, formRoute: this.state.formRoute, }; localStorage.setItem('oeeModelData', JSON.stringify(sModelData)); } /* 关闭浏览器前进行提示 */ } shouldComponentUpdate1(nextProps, nextState) { // // 修改或新增后的保存功能 // if (nextState.enabled && !nextProps.app.diffMap.get(nextState.sTabId) && nextProps.app.diffMap.get(nextState.sTabId) !== undefined) { // this.props.dispatch({ type: 'app/changeDiffMap', payload: { sTabId: nextState.sTabId, changed: true } }); // } // if (!nextState.enabled && nextProps.app.diffMap.get(nextState.sTabId) && nextProps.app.diffMap.get(nextState.sTabId) !== undefined) { // this.props.dispatch({ type: 'app/changeDiffMap', payload: { sTabId: nextState.sTabId, changed: false } }); // } const currentKey = nextProps.app.currentPane.key; /* 当前页签key */ const { formData } = nextState; if (commonUtils.isNotEmptyObject(nextProps.formRoute) && nextProps.formRoute.indexOf('/indexOee') > -1) { return (formData.length > 0); } /* 处理loginOee下拉框切换 重新渲染 */ if (commonUtils.isNotEmptyObject(location.pathname) && location.pathname.toLowerCase() === '/loginoee') { return true; } if (nextProps.app.unReadSid !== this.props.app.unReadSid) { return false; } return (currentKey === nextState.sTabId && formData.length > 0) || (nextState.fastOrderModalVisible !== undefined && nextProps.app.currentPane.notCurrentPane === !nextState.fastOrderModalVisible) || (nextState.visibleStatement !== undefined && nextProps.app.currentPane.notCurrentPane === !nextState.visibleStatement) || (nextState.visibleBatchPriceUpdate !== undefined && nextProps.app.currentPane.notCurrentPane === !nextState.visibleBatchPriceUpdate) || (nextState.modalVisible !== undefined && nextProps.app.currentPane.notCurrentPane === !nextState.modalVisible) || (nextState.visibleModal !== undefined && nextProps.app.currentPane.notCurrentPane === !nextState.visibleModal) || (nextState.materialsChooseVisible !== undefined && nextProps.app.currentPane.notCurrentPane === !nextState.materialsChooseVisible) || (nextState.processChooseVisible !== undefined && nextProps.app.currentPane.notCurrentPane === !nextState.processChooseVisible) || (nextState.visibleFilfile !== undefined && nextProps.app.currentPane.notCurrentPane === !nextState.visibleFilfile) || (nextState.contextMenuModalVisible !== undefined && nextProps.app.currentPane.notCurrentPane === !nextState.contextMenuModalVisible) || (nextState.workScheduleVisible !== undefined && nextProps.app.currentPane.notCurrentPane === !nextState.workScheduleVisible); } componentDidUpdate(nextProps, nextState) { // 修改或新增后的保存功能 if (nextProps.onRemovePane && nextState.enabled && !nextProps.app.diffMap.get(nextState.sTabId) && nextProps.app.diffMap.get(nextState.sTabId) !== undefined) { this.props.dispatch({ type: 'app/changeDiffMap', payload: { sTabId: nextState.sTabId, changed: true } }); } if (nextProps.onRemovePane && !nextState.enabled && nextProps.app.diffMap.get(nextState.sTabId) && nextProps.app.diffMap.get(nextState.sTabId) !== undefined) { this.props.dispatch({ type: 'app/changeDiffMap', payload: { sTabId: nextState.sTabId, changed: false } }); } } componentWillUnmount() { const { currentId, } = this.state; const { userinfo } = this.props.app; window.removeEventListener('beforeunload', this.beforeunload); window.removeEventListener('unload', this.unload); if (commonUtils.isNotEmptyObject(location.pathname) && location.pathname.toLowerCase() !== '/loginoee') { if (this.props.app.webSocket !== null && this.props.app.webSocket.readyState === WebSocket.OPEN) { this.handleSendSocketMessage('release', 'noAction', currentId, userinfo.sId, null, null); } } } /* componentWillUnmount() { this.mounted = false; const { sModelsId } = this.state; const { app, currentId } = this.props; const { webSocket, userinfo, currentPane } = app; const { key } = currentPane; commonUtils.clearFormStoreDropDownData(sModelsId); const { copyTo } = app.currentPane; if (commonUtils.isNotEmptyObject(copyTo)) { const { slaveData } = copyTo; const sIdArray = []; slaveData.forEach((item) => { const redisKey = item.sSlaveId; sIdArray.push(redisKey); }); const sId = sIdArray.toString(); commonFunc.sendWebSocketMessage(webSocket, key, 'copyfinish', 'noAction', userinfo.sId, null, sId, userinfo.sId, null); } if (!commonUtils.isEmpty(currentId)) { commonFunc.sendWebSocketMessage(webSocket, key, 'release', 'noAction', userinfo.sId, null, currentId, userinfo.sId, null); } } */ /** sql条件 */ getSqlCondition = (showConfig, name, record) => { const conditonValues = {}; if (commonUtils.isNotEmptyStr(showConfig.sSqlCondition)) { const conditon = showConfig.sSqlCondition.split(','); conditon.forEach((item) => { if (item.indexOf('.') > -1) { const tableName = item.split('.')[0]; let fieldName = item.split('.')[1]; let fieldNameFilter = item.split('.').length > 2 ? item.split('.')[2] : fieldName; // master.sId 作为参数 master.sId.sId 作为filterDropdown过滤参数 if (showConfig.sDropDownType === 'picArr') { fieldNameFilter = item.split('.').length > 2 ? item.split('.')[2] : fieldName; if (fieldName.indexOf('&Search') > -1) { // 参数为&Search时认为是查找数据集中取数据 const data = this.state[`${tableName}Data`]; if (typeof data === 'object' && data.constructor === Object) { Object.keys(data).forEach((dataItem) => { if (`&Search${data[dataItem]}` === fieldName) { let sTmpName = dataItem; sTmpName = sTmpName.replace('First', 'Third'); if (data[dataItem].substring(0, 1) === 't') { fieldName = `p${sTmpName.substring(1, dataItem.length)}`; } else if (data[dataItem].substring(0, 1) === 'm') { fieldName = data[dataItem].substring(0, 1) + sTmpName.substring(1, sTmpName.length); } else { fieldName = data[dataItem].substring(0, 1) + sTmpName.substring(1, sTmpName.length); } } }); } } else if (fieldName.indexOf('&') > -1) { fieldNameFilter = item.split('.').length > 2 ? item.split('.')[2] : fieldName; conditonValues[fieldNameFilter] = fieldName.replace('&', ''); return; } } if (fieldName !== '') { if (name === tableName && !commonUtils.isEmpty(record)) { const data = record; conditonValues[fieldNameFilter] = data[fieldName]; } else { const data = this.state[`${tableName}Data`]; const selectedRowKeys = this.state[`${tableName}SelectedRowKeys`]; if (typeof data === 'object' && data.constructor === Object) { conditonValues[fieldNameFilter] = data[fieldName]; } else if (commonUtils.isNotEmptyArr(selectedRowKeys)) { let iIndex = data.findIndex(itemData => itemData.sId === selectedRowKeys[0]); iIndex = iIndex > -1 ? iIndex : data.findIndex(itemData => itemData.sSlaveId === selectedRowKeys[0]); if (iIndex > -1) { conditonValues[fieldNameFilter] = data[iIndex][fieldName]; } } else if (commonUtils.isNotEmptyArr(data)) { conditonValues[fieldNameFilter] = data[0][fieldName]; } } } } }); } return conditonValues; }; /** 获取sql下拉数据 */ getSqlDropDownData = async (formId, name, showConfig, record, sKeyUpFilterName, pageNum) => { /* 地址 */ const { formSrcRoute } = this.state; if (commonUtils.isEmpty(showConfig.sFieldToContent)) { if (commonUtils.isEmpty(showConfig.showDropDown)) { return { dropDownData: [], totalPageCount: 0, currentPageNo: 0, conditonValues: {}, }; } const url = `${commonConfig.server_host}business/getSelectLimit/${showConfig.sId}?sModelsId=${this.state.sModelsId}&sName=${formSrcRoute}`; /* 参数 */ const conditonValues = this.getSqlCondition(showConfig, name, record); const body = { sSqlCondition: commonUtils.isEmptyObject(conditonValues) ? '' : conditonValues, /* 查询条件 */ }; if (!commonUtils.isEmpty(pageNum)) { body.sKeyUpFilterName = sKeyUpFilterName; /* 边输入边过滤,暂时没用1 */ body.pageNum = pageNum; // 下拉数据改为无限 body.pageSize = commonConfig.pageSize; // body.pageSize = 9999; } /* 获取数据 */ const json = await commonServices.postValueService(this.props.app.token, body, url); /* code为1代表获取数据成功 */ if (json.data.code === 1) { /* 获取数据集 */ const { rows, totalPageCount, currentPageNo } = json.data.dataset; return { dropDownData: rows, totalPageCount, currentPageNo, conditonValues, }; } else { return { dropDownData: [], totalPageCount: 0, currentPageNo: 0, conditonValues, }; } } else { const returnData = []; if (showConfig.sFieldToContent === '1') { if (name === 'master') { const { [`${name}Data`]: data } = this.state; const sName = `sParamDropDown${showConfig.sName.replace('sParamValue', '')}`; returnData.push(...commonUtils.objectToArr(data[sName])); } else { const { [`${name}Data`]: data, [`${name}SelectedRowKeys`]: selectedRowKeys } = this.state; const sName = `sParamDropDown${showConfig.sName.replace('sParamValue', '')}`; if (commonUtils.isNotEmptyObject(record)) { returnData.push(...commonUtils.objectToArr(record[sName])); } else if (commonUtils.isNotEmptyArr(data) && commonUtils.isNotEmptyArr(selectedRowKeys)) { const iIndex = data.findIndex(item => item.sId === selectedRowKeys.toString()); if (iIndex > -1) { returnData.push(...commonUtils.objectToArr(data[iIndex][sName])); } } } } else { const unionCondition = showConfig.sFieldToContent.split('&&'); unionCondition.forEach((unionItem) => { const conditon = unionItem.split(','); const tableNameContent = conditon[0].split('.')[0]; let data = this.state[`${tableNameContent}Data`]; if (commonUtils.isNotEmptyArr(data)) { if (showConfig.sSqlCondition !== '') { const sSqlCondition = showConfig.sSqlCondition; const sqlConditon = sSqlCondition.split(','); sqlConditon.forEach((item) => { const tableName = item.split('.')[0]; const fieldName = item.split('.')[1]; const fieldNameFilter = item.split('.').length > 2 ? item.split('.')[2] : fieldName; const dataCondition = this.state[`${tableName}Data`]; const selectedRowKeys = this.state[`${tableName}SelectedRowKeys`]; if (typeof dataCondition === 'object' && dataCondition.constructor === Object) { // 对象不用filter // data = data.filter(item => commonUtils.isNull(item[fieldNameFilter], '') === commonUtils.isNull(dataCondition[fieldName], '')); } else if (commonUtils.isNotEmptyArr(selectedRowKeys)) { let iIndex = dataCondition.findIndex(itemData => itemData.sId === selectedRowKeys[0]); iIndex = iIndex > -1 ? iIndex : dataCondition.findIndex(itemData => itemData.sSlaveId === selectedRowKeys[0]); if (iIndex > -1) { data = data.filter(item => commonUtils.isNull(item[fieldNameFilter], '') === commonUtils.isNull(dataCondition[iIndex][fieldName], '')); } } else if (commonUtils.isNotEmptyArr(data)) { data = data.filter(item => commonUtils.isNull(item[fieldNameFilter], '') === commonUtils.isNull(dataCondition[0][fieldName], '')); } }); } if (typeof data === 'object' && data.constructor === Object) { const dataRow = {}; conditon.forEach((item) => { const fieldName = item.split('.')[1]; const fieldNameFilter = item.split('.').length > 2 ? item.split('.')[2] : fieldName; if (fieldName.indexOf('-') >= 0) { fieldName.split('-').forEach((itemField) => { const sFieldValue = commonUtils.isEmpty(data[itemField]) ? '' : data[itemField].toString(); dataRow[fieldNameFilter] = commonUtils.isEmpty(dataRow[fieldNameFilter]) ? sFieldValue : `${dataRow[fieldNameFilter]}-${sFieldValue}`; }); } else { dataRow[fieldNameFilter] = commonUtils.isEmpty(data[fieldName]) ? '' : data[fieldName].toString(); } }); returnData.push(dataRow); } else { data.forEach((itemDataRow) => { const dataRow = {}; conditon.forEach((item) => { const fieldName = item.split('.')[1]; const fieldNameFilter = item.split('.').length > 2 ? item.split('.')[2] : fieldName; if (fieldName.indexOf('-') >= 0) { fieldName.split('-').forEach((itemField) => { const sFieldValue = commonUtils.isEmpty(itemDataRow[itemField]) ? '' : itemDataRow[itemField].toString(); dataRow[fieldNameFilter] = commonUtils.isEmpty(dataRow[fieldNameFilter]) ? sFieldValue : `${dataRow[fieldNameFilter]}-${sFieldValue}`; }); } else { dataRow[fieldNameFilter] = commonUtils.isEmpty(itemDataRow[fieldName]) ? '' : itemDataRow[fieldName].toString(); } }); returnData.push(dataRow); }); } } }); } return { dropDownData: returnData, totalPageCount: 0, currentPageNo: 0 }; } }; /* 获取数字格式化规范 */ getFloatNum = (sName) => { if (sName.toLowerCase().endsWith('price')) { /* 价格 */ return this.props.app.decimals.dNetPrice; } else if (sName.toLowerCase().endsWith('money')) { /* 金额 */ return this.props.app.decimals.dNetMoney; } else { /* 其它 */ return 6; } }; /** 获取sql下拉数据 */ getServiceError = async (returnData) => { if (location.pathname.indexOf('/indexOee/') > -1) { this.props.dispatch({ type: 'app/throwErrorMes', payload: returnData }); } else { this.props.dispatch({ type: 'app/throwError', payload: returnData }); } }; /* 获取数字格式化规范 */ getDateFormat = () => { return this.props.app.dateFormat; }; beforeunload = (e) => { const confirmationMessage = '您确定要离开么?'; if (e) { e.returnValue = confirmationMessage; } return confirmationMessage; } unload = () => { // sessionStorage.clear(); // const { // currentId, sModelsId, // } = this.state; // const url = `${commonConfig.server_host}logout`; // this.handleSendSocketMessage('release', 'noAction', currentId, this.props.app.userinfo.sId, null, null); // this.handleSendSocketMessage('release', 'noAction', sModelsId, this.props.app.userinfo.sId, null, null); // this.props.dispatch({ type: 'app/loginOut', payload: { url, sId: this.props.app.userinfo.sId, loginOutType: 'loginOut' } }); } handleSendSocketMessage = (flag, showType, sId, sendTo, msgInfo, param) => { const { token } = this.props.app; const sendws = this.handleSendWebSocketMsg; const { dispatch } = this.props; if (commonUtils.isNotEmptyObject(token)) { if (this.props.app.webSocket !== null && this.props.app.webSocket.readyState === WebSocket.OPEN) { sendws(flag, showType, msgInfo, sId, sendTo, param); } else { this.props.dispatch({ type: 'app/createWebSocket', payload: { reStart: true, dispatch } }); setTimeout(() => { sendws(flag, showType, msgInfo, sId, sendTo, param); }, 30000); } } }; handleSendWebSocketMsg = (flag, showType, msgInfo, sId, sendTo, param) => { const { app } = this.props; const { webSocket, userinfo, currentPane } = app; const { key } = currentPane; commonFunc.sendWebSocketMessage(webSocket, key, flag, showType, userinfo.sId, msgInfo, sId, sendTo, param); } /** sql下拉新增处理 */ handleSqlDropDownNewRecord = async (showConfig, name) => { const { [`${name}SelectedRowKeys`]: tableSelectedRowKeys, [`${name}Data`]: tableNewData, masterData, formSrcRoute, } = this.state; /* 待用数据声明 */ const sTabId = this.props.app.currentPane.key; /* 当前标签页TabId */ /* 接口地址 */ const sNameUrl = `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${showConfig.sActiveId}?sModelsId=${showConfig.sActiveId}&sName=${formSrcRoute}`; const CallBackRecord = this.handleCallBackRecord;/* 字段名,主从表,字段名 */ /* newRecord时,如果是新增产品,则要带客户过去 */ const addStata = {}; for (const each of this.props.app.panes) { each.notCurrentPane = true; } if (commonUtils.isNotEmptyObject(showConfig) && showConfig.sName === 'sProductName') { if (name !== 'master' && commonUtils.isNotEmptyObject(tableSelectedRowKeys)) { const iIndex = tableNewData.findIndex(item => item.sId === tableSelectedRowKeys.toString()); const newData = tableNewData[iIndex]; addStata.sCustomerId = newData.sCustomerId; addStata.sCustomerNo = newData.sCustomerNo; addStata.sCustomerName = newData.sCustomerName; if (commonUtils.isEmptyObject(addStata.sCustomerId)) { /* 新增产品时,看客户在从表还是主表。如果不在从表,那看是否在主表 */ addStata.sCustomerId = masterData.sCustomerId; addStata.sCustomerNo = masterData.sCustomerNo; addStata.sCustomerName = masterData.sCustomerName; } } } /* 接口参数 */ const payload = { url: sNameUrl, sParentId: sTabId, classifyOption: 'add', newRecordFlag: `NewRecord_${sTabId}`, /* newRecord当前字段 */ newRecordRelation: addStata, /* newRecord 关联字段,如新增产品,带客户信息 */ newRecordMethod: CallBackRecord.bind(this, showConfig.sName, name), /* newRecord当前字段 */ }; /* 调用接口 */ this.props.dispatch({ type: 'content/onRouter', payload }); }; /* 获取配置数据用的sTabId,formId,formRoute */ handleConfigValue = (value, type) => { if (commonUtils.isNotEmptyObject(type) && type.indexOf('/indexOee') > -1) { return this.props[value]; } else { const { secondppopupPane, ppopupPane, currentPane } = this.props.app; return commonUtils.isNotEmptyObject(secondppopupPane) ? secondppopupPane[value] : commonUtils.isNotEmptyObject(ppopupPane) ? ppopupPane[value] : currentPane[value]; } }; /* 获取后台数据(单条) */ handleGetDataOne = async (params) => { const { token, sModelsId } = this.state; const { name, configData, condition, isWait, formSrcRoute, bEditClick, } = params; const lockUrl = `${commonConfig.server_host}business/addSysLocking?sModelsId=${sModelsId}&sName=${formSrcRoute}`; const configDataId = configData.sId; const dataUrl = `${commonConfig.server_host}business/getBusinessDataByFormcustomId/${configDataId}?sModelsId=${sModelsId}&sName=${formSrcRoute}`; const dataReturn = (await commonServices.postValueService(token, condition, dataUrl)).data; if (dataReturn.code === 1) { const [returnData] = dataReturn.dataset.rows[0].dataSet; if (commonUtils.isNotEmptyArr(returnData)) { let addState = {}; const value = { tableName: configData.sTbName, sId: [returnData.sId], }; if(bEditClick === 'update') { /* 只有点击修改时 调用addSysLocking */ const { data } = await commonServices.postValueService(token, value, lockUrl); if (data.code === 1) { /* 失败 */ addState.sUseInfo = ''; } else { /* 失败 */ addState.sUseInfo = data.msg; if (commonUtils.isNotEmptyObject(data.erroMsg)) { message.error(data.erroMsg); } } } addState[`${name}Data`] = returnData; addState.currentId = returnData.sId; if(bEditClick === 'update') { addState[`${name}Data`].enabled = true; } /* 获取主表数据时表字段数据根据条件控制 本表或其他表格字段的显示与隐藏功能 */ if (name === 'master' && commonUtils.isNotEmptyObject(configData)) { const addStateChange = this.handelControlFieldVisible(name, configData, returnData); if (commonUtils.isNotEmptyObject(addStateChange)) { addState = { ...addState, ...addStateChange }; } } if (isWait) { return addState; } else if (this.mounted) { this.setState({ ...addState }); } } } else { this.getServiceError(dataReturn); } }; /* 获取后台数据(数据集) */ handleGetDataSet = async (params) => { const { name, condition, flag, isWait, configData, clearSelectData, } = params; const { token, sModelsId, formRoute, [`${name}SelectedData`]: tableSelectedData, formSrcRoute, formData, [`${name}DelData`]: tableDelData, sModelsType, [`${name}PageSize`]: pageSize, } = this.state; let { menuChildData, [`${name}SelectedRowKeys`]: tableSelectedRowKeys, iPageSize, } = this.state; const masterConditionData = commonUtils.isNotEmptyObject(condition) ? condition.sSqlCondition : {}; /* 根据后台主表配置bPagination判断 是否分页 */ if (commonUtils.isNotEmptyObject(configData) && commonUtils.isNotEmptyObject(condition)) { const { bPagination } = configData; if (!bPagination || bPagination === undefined) { condition.pageSize = 10000; /* 不分页 */ } else { /* 分页 */ // eslint-disable-next-line no-lonely-if if (commonUtils.isNotEmptyArr(formData)) { if (commonUtils.isNotEmptyNumber(formData[0].iPageSize) && formData[0].iPageSize !== 0) { iPageSize = formData[0].iPageSize;/* 后台设定页数 */ } } } } const configDataId = configData.sId; const dataUrl = `${commonConfig.server_host}business/getBusinessDataByFormcustomId/${configDataId}?sModelsId=${sModelsId}&sName=${formSrcRoute}`; const dataReturn = (await commonServices.postValueService(token, condition, dataUrl)).data; if (dataReturn.code === 1) { if( commonUtils.isNotEmptyObject(dataReturn.dataset) && commonUtils.isNotEmptyArr(dataReturn.dataset.rows) ) { let returnData = dataReturn.dataset.rows[0].dataSet; if (this.props && this.props.app && this.props.app.currentPane && this.props.app.currentPane.route && dataReturn.dataset.rows[0].columnConfig) { this.setState({ customConfig: dataReturn.dataset.rows[0].columnConfig }) } // const returnData = dataReturn.dataset.rows[0].dataSet; if (commonUtils.isNotEmptyObject(returnData)) { if (formRoute === '/indexPage/materialRequirementsPlanning') { returnData.forEach((tableDataRow) => { tableDataRow.sSlaveId = tableDataRow.sMaterialsId + tableDataRow.sMaterialsStyle; tableDataRow.dAuxiliaryQtyAll = tableDataRow.dAuxiliaryQty; tableDataRow.dMaterialsQtyAll = tableDataRow.dMaterialsQty; }); } if ((sModelsType && sModelsType.includes('linkTree'))) { returnData.forEach((tableDataRow) => { tableDataRow.dAuxiliaryQtyAll = tableDataRow.dAuxiliaryQty; tableDataRow.dMaterialsQtyAll = tableDataRow.dMaterialsQty; }); } /* 若有sDivRow则数据行上面插入一行 */ const returnFilterData = returnData.filter(item => commonUtils.isNotEmptyObject(item.sDivRow) && item.sDivRow !== ''); if (commonUtils.isNotEmptyArr(returnFilterData)) { returnFilterData.forEach((tableDataRow, index) => { /* 找到白班与晚班区间的汇总条数与工时 */ let startIndex = 0; /* 找到开始下标 */ let endindex = 0; /* 找到结束下标 */ let sliceData = []; startIndex = returnData.findIndex(item => item.sId === returnFilterData[index].sId); if (index + 1 < returnFilterData.length) { endindex = returnData.findIndex(item => item.sId === returnFilterData[index + 1].sId); } if (index === returnFilterData.length - 1) { endindex = returnData.length; } if (startIndex < endindex) { sliceData = returnData.slice(startIndex, endindex); } let num = 0; let dTime = 0; let dPlateQty = 0; /* 付版 */ let dProcessQty = 0; const newRow = {}; newRow.sId = 'sDivRow' + index; newRow.sSlaveId = 'sDivRow' + commonUtils.createSid(); if (commonUtils.isNotEmptyArr(sliceData)) { num = sliceData.length; sliceData.forEach((item) => { if (commonUtils.isNotEmptyNumber(item.dHour1)) { dTime += item.dHour1; dPlateQty += commonUtils.isNotEmptyNumber(item.dPlateQty) ? item.dPlateQty : 0; dProcessQty += commonUtils.isNotEmptyNumber(item.dProcessQty) ? item.dProcessQty : 0; const iSrcIndex = returnData.findIndex(itemReturn => itemReturn.sSlaveId === item.sSlaveId); /* 汇总的每行上都加newRow的sSlaveId作为父级Id */ if (iSrcIndex > -1) { returnData[iSrcIndex] = {...returnData[iSrcIndex], sDivRowParentId: newRow.sSlaveId} } } }); } newRow.sDivRowNew = tableDataRow.sDivRow; newRow.bInsert = true; /* 新插入 */ newRow.sState = null; newRow.sProcessId = tableDataRow.sProcessId; /* 取第一个配置 */ const configArr = configData.gdsconfigformslave.filter(item => item.bVisible && item.sName !== ''); if (commonUtils.isNotEmptyArr(configArr)) { let firstName = ''; if (configArr[0].sName === 'iOrder') { firstName = configArr[1].sName; } else { firstName = configArr[1].sName; } if (commonUtils.isNotEmptyObject(firstName)) { const firstDataIndex = firstName.substring(0, 1); if (firstDataIndex !== 't' && firstDataIndex !== 'p') { newRow[firstName] = tableDataRow.sDivRow; if (num > 0) { newRow[firstName] += 'F' + num + '单'; } if (dProcessQty > 0) { newRow[firstName] += ' - ' + dProcessQty; } if (tableDataRow.sType === "1") { newRow[firstName] += ' - ' + dPlateQty + '付版'; } if (dTime > 0) { // newRow[firstName] += ' - ' + Math.floor(dTime/60) + ":" + (dTime%60) + '小时'; newRow[firstName] += ' - ' + (dTime / 60).toFixed(2) + 'h'; } } } } const iInsertIndex = returnData.findIndex(item => item.sSlaveId === tableDataRow.sSlaveId); if (iInsertIndex > -1) { returnData[iInsertIndex].sDivRow = ''; returnData.splice(iInsertIndex, 0, newRow); /* 在目标位置前面增加一行 */ } }); } if (commonUtils.isEmptyArr(tableSelectedData)) { if (formRoute !== '/indexPage/materialRequirementsPlanning' && formRoute !== '/indexPage/commonClassify') { if (commonUtils.isNotEmptyStr(returnData[0].sSlaveId)) { const keys = []; keys.push(returnData[0].sSlaveId); tableSelectedRowKeys = keys; } else { const keys = []; keys.push(returnData[0].sId); tableSelectedRowKeys = keys; } } if (flag) { tableSelectedRowKeys = []; menuChildData = []; // 打印下拉置空 } } } if (clearSelectData) { tableSelectedRowKeys = []; menuChildData = []; // 打印下拉置空 } /** * 修改日期:2021-03-30 * 修改人:吕杰 * 区域:以下 4 行 * BUG:2185 * 说明:右下角 增加单据个数显示 * 原代码: */ let billNum = ''; if (dataReturn.dataset.billNum) { billNum = `共${dataReturn.dataset.billNum}个单据 `; } const iOeeBillPageSize = iPageSize < 100 ? 100 : iPageSize; const returnPagination = { total: dataReturn.dataset.totalCount, current: dataReturn.dataset.currentPageNo, pageSize: formRoute === '/indexPage/commonSubBill' ? iPageSize : location.pathname.includes('commonOeeBill') ? iOeeBillPageSize : dataReturn.dataset.pageSize, showTotal: (total) => { return ( {`当前显示 ${billNum}共${total}条记录`} ); }, }; // 如果是commonNewBill,不取接口返回的分页数 if (formRoute === '/indexPage/commonNewBill' && pageSize) { returnPagination.pageSize = pageSize; } const sumSet1Default = [{ "dProfit": '辊底重量:0.00', "dTotalProfitMoney": '转入重量:0.00', "dNetMargin": '分切重量:0.00', "dTotalNetProfit": '边料重量:0.00', "dMainBusinessMoney": '转出重量:0.00', "dOperaMoney": '总重量:0.00', "dFreight": '转入数量:0.00', "dOtherbusinessCostMoney": '转出数量:0.00', "dSellingExpenses": '总件数:0', }]; const { sumSet, sumSet1 = sumSet1Default } = dataReturn.dataset.rows[0]; const totalData = sumSet !== undefined ? sumSet : []; const totalData1 = sumSet1 !== undefined ? sumSet1 : []; const filterCondition = commonUtils.isNotEmptyObject(condition) ? condition.bFilter : ''; const orderBy = commonUtils.isNotEmptyObject(condition) ? condition.sFilterOrderBy : ''; /* 去除树搜索filterCondition */ const filterConditionNew = commonUtils.isNotEmptyObject(filterCondition) ? filterCondition.filter(item => item.bFilterType !== 'tree') : ''; let addState = { [`${name}Data`]: returnData, [`${name}Pagination`]: returnPagination, [`${name}FilterCondition`]: filterConditionNew, [`${name}OrderBy`]: orderBy, [`${name}SelectedRowKeys`]: tableSelectedRowKeys, menuChildData, /* 修改日期:2021-03-17 修改人:吕杰 区域:以下一行 需求变更:fix 2135 搜索时添加loading动画 */ pageLoading: false, iPageSize, masterConditionData }; if (commonUtils.isNotEmptyArr(totalData1)) { addState = { ...addState, [`${name}Total1`]: totalData1, [`${name}AllTotal`]: totalData1 }; } if (dataReturn.dataset.currentPageNo === 1) { addState = { ...addState, [`${name}Total`]: totalData, [`${name}AllTotal`]: totalData }; } const slaveSelectedData = []; if ((formRoute === '/indexPage/commonList' || formRoute === '/indexPage/materialRequirementsPlanning') && name === 'slave' && commonUtils.isNotEmptyArr(tableSelectedRowKeys) && !clearSelectData) { tableSelectedRowKeys.forEach((item) => { const iPageIndex = returnData.findIndex(pageItem => pageItem.sSlaveId === item); if (iPageIndex > -1) { slaveSelectedData.push(returnData[iPageIndex]); } else if (commonUtils.isNotEmptyArr(tableSelectedData)) { const iIndex = tableSelectedData.findIndex(pageItem => pageItem.sSlaveId === item); if (iIndex > -1) { slaveSelectedData.push(tableSelectedData[iIndex]); } } }); } else if (formRoute === '/indexPage/materialRequirementsPlanning' && clearSelectData) { /* 处理物料需求计划生成采购申请单,刷新时,数据重复问题 */ addState.slaveInfoSelectedRowKeys = []; addState.slaveInfoSelectedData = []; } addState[`${name}SelectedData`] = slaveSelectedData; /* 如果获取数据集时候 删除数据集有数据 则清空 */ if (commonUtils.isNotEmptyArr(tableDelData)) { addState[`${name}DelData`] = []; } if (isWait) { return addState; } else if (this.mounted) { this.setState(addState); } } else { message.error(name +'表数据获取错误!'); } } else { /* 修改日期:2021-03-17 修改人:吕杰 区域:以下三行 需求变更:fix 2135 搜索时添加loading动画 */ if (!isWait && this.mounted) { this.setState({ pageLoading: false }); } this.getServiceError(dataReturn); } }; /* 获取过滤树数据(数据集) */ handleGetTreeDataSet = async (params, name) => { const { configData, condition, isWait, } = params; const { token, sModelsId, formSrcRoute } = this.state; let treeData = []; const expandedKeys = []; const configDataId = configData.sParentId; const dataUrl = `${commonConfig.server_host}filterTree/getFilterTree/${configDataId}?sModelsId=${sModelsId}&sName=${formSrcRoute}`; const dataReturn = (await commonServices.postValueService(token, condition, dataUrl)).data; if (dataReturn.code === 1) { const returnData = dataReturn.dataset.rows; if (commonUtils.isNotEmptyArr(returnData)) { /* 拼装树结构 */ treeData = returnData; /* 默认展开第一个父节点 */ if (treeData.length > 0) { if (commonUtils.isNotEmptyObject(treeData[0].key)) { expandedKeys.push(treeData[0].key); } } } let addState = { expandedKeys, }; if (name) { addState[`${name}TreeData`] = treeData; } else { addState.treeData = treeData; } addState = { ...addState }; if (isWait) { return addState; } else if (this.mounted) { this.setState(addState); } } else { this.getServiceError(dataReturn); } }; /* 重新获取界面配置 */ handleGetTableConfig = async (name, sModelsId, oldConfig) => { const { token, formSrcRoute, formRoute } = this.state; let tableConfig = {}; const configUrl = `${commonConfig.server_host}business/getModelBysId/${sModelsId}?sModelsId=${sModelsId}&sName=${formSrcRoute}`; const configReturn = (await commonServices.getService(token, configUrl)).data; if (configReturn.code === 1) { const [configData] = configReturn.dataset.rows; const { formData } = configData; if (commonUtils.isNotEmptyArr(formData)) { if (oldConfig) { tableConfig = formData.find(item => item.sId === oldConfig.sId); } else if(formRoute === '/indexPage/commonList') { tableConfig = formData[0]; } else if(formRoute === '/indexPage/commonNewBill') { if (name === 'master') { tableConfig = formData[0]; } else if (name === 'slave') { tableConfig = formData.length > 1 ? formData[1] : {}; } else if (name === 'slave0') { tableConfig = formData.length > 2 ? formData[2] : {}; } else if (name === 'slave1') { tableConfig = formData.length > 3 ? formData[3] : {}; } else if (name === 'slave2') { tableConfig = formData.length > 4 ? formData[4] : {}; } } else { if (name === 'master') { tableConfig = formData[0]; } else if (name === 'slave') { tableConfig = formData.length > 1 ? formData[1] : {}; } else if (name === 'control') { tableConfig = formData.length > 2 ? formData[2] : {}; } else if (name === 'materials') { tableConfig = formData.length > 3 ? formData[3] : {}; } else if (name === 'process') { tableConfig = formData.length > 4 ? formData[4] : {}; } else if (name === 'slave0') { tableConfig = formData.length > 2 ? formData[2] : {}; } else if (name === 'slave1') { tableConfig = formData.length > 3 ? formData[3] : {}; } else if (name === 'slave2') { tableConfig = formData.length > 4 ? formData[4] : {}; } else if (name === 'slave3') { tableConfig = formData.length > 5 ? formData[5] : {}; } else if (name === 'slave4') { tableConfig = formData.length > 6 ? formData[6] : {}; } } } } else { this.getServiceError(configReturn); } return tableConfig; } /* 修改日期:2021-03-18 修改人:吕杰 区域:以下handleSaveState函数 需求变更:添加回调 原代码: handleSaveState = (values) => { if (this.mounted) { this.setState(values); } }; */ /* 数据保存到state */ handleSaveState = (values, callback) => { if (this.mounted) { this.setState(values, typeof callback === 'function' ? callback : undefined); } }; /** 修改主表数据 */ handleMasterChange = (name, sFieldName, changeValue, sId, dropDownData, isWait, masterDataNew) => { const { masterData: masterDataOld } = this.state; const { sModelsId, masterConfig, slaveConfig, slave0Config, slave1Config, slave2Config, slave3Config, slave4Config, slave5Config, } = this.state; const addState = {}; let masterData = masterDataNew === undefined ? masterDataOld === undefined ? {} : masterDataOld : masterDataNew; let { handleType } = masterData; handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType; if (sFieldName.substring(0, 1).toLowerCase() === 'c') { const sAllField = sFieldName.substring(1, sFieldName.length); const allField = sAllField.split('_'); const value = changeValue[sFieldName]; allField.forEach((item, iArr) => { if (value.length > iArr) { changeValue[item] = value[iArr]; } }); } const bClearSelectedRowKeys = location.pathname.includes('commonList') ? false : true; /* 是否清除从表选择行 */ if (!commonUtils.isEmpty(masterConfig.gdsconfigformslave) && commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave) && !commonUtils.isEmpty(sFieldName)) { masterConfig.gdsconfigformslave.filter(item => !commonUtils.isEmpty(item.sSqlCondition) && !commonUtils.isEmpty(item.sChineseDropDown) && (item.sChineseDropDown.includes(`#${sFieldName}`) || item.sChineseDropDown.includes(`*${sFieldName}`)) && (item.sSqlCondition.includes(sFieldName) || item.sSqlCondition.includes(sFieldName.replace('Name', 'Id')))).forEach((item) => { commonUtils.setStoreDropDownData(sModelsId, name, item.sName, []); }); if (commonUtils.isNotEmptyObject(slaveConfig)) { slaveConfig.gdsconfigformslave.filter(item => !commonUtils.isEmpty(item.sSqlCondition) && !commonUtils.isEmpty(item.sChineseDropDown) && (item.sChineseDropDown.includes(`#${sFieldName}`) || item.sChineseDropDown.includes(`*${sFieldName}`)) && (item.sSqlCondition.includes(`master.${sFieldName}`) || item.sSqlCondition.includes(sFieldName.replace('Name', 'Id')))).forEach((item) => { commonUtils.setStoreDropDownData(sModelsId, 'slave', item.sName, []); if (bClearSelectedRowKeys) { addState.slaveSelectedRowKeys = []; } }); } if (commonUtils.isNotEmptyObject(slave0Config)) { slave0Config.gdsconfigformslave.filter(item => !commonUtils.isEmpty(item.sSqlCondition) && !commonUtils.isEmpty(item.sChineseDropDown) && (item.sChineseDropDown.includes(`#${sFieldName}`) || item.sChineseDropDown.includes(`*${sFieldName}`)) && (item.sSqlCondition.includes(`master.${sFieldName}`) || item.sSqlCondition.includes(sFieldName.replace('Name', 'Id')))).forEach((item) => { commonUtils.setStoreDropDownData(sModelsId, 'slave0', item.sName, []); if (bClearSelectedRowKeys) { addState.slave0SelectedRowKeys = []; } }); } if (commonUtils.isNotEmptyObject(slave1Config)) { slave1Config.gdsconfigformslave.filter(item => !commonUtils.isEmpty(item.sSqlCondition) && !commonUtils.isEmpty(item.sChineseDropDown) && (item.sChineseDropDown.includes(`#${sFieldName}`) || item.sChineseDropDown.includes(`*${sFieldName}`)) && (item.sSqlCondition.includes(`master.${sFieldName}`) || item.sSqlCondition.includes(sFieldName.replace('Name', 'Id')))).forEach((item) => { commonUtils.setStoreDropDownData(sModelsId, 'slave1', item.sName, []); if (bClearSelectedRowKeys) { addState.slave1SelectedRowKeys = []; } }); } if (commonUtils.isNotEmptyObject(slave2Config)) { slave2Config.gdsconfigformslave.filter(item => !commonUtils.isEmpty(item.sSqlCondition) && !commonUtils.isEmpty(item.sChineseDropDown) && (item.sChineseDropDown.includes(`#${sFieldName}`) || item.sChineseDropDown.includes(`*${sFieldName}`)) && (item.sSqlCondition.includes(`master.${sFieldName}`) || item.sSqlCondition.includes(sFieldName.replace('Name', 'Id')))).forEach((item) => { commonUtils.setStoreDropDownData(sModelsId, 'slave2', item.sName, []); if (bClearSelectedRowKeys) { addState.slave2SelectedRowKeys = []; } }); } if (commonUtils.isNotEmptyObject(slave3Config)) { slave3Config.gdsconfigformslave.filter(item => !commonUtils.isEmpty(item.sSqlCondition) && !commonUtils.isEmpty(item.sChineseDropDown) && (item.sChineseDropDown.includes(`#${sFieldName}`) || item.sChineseDropDown.includes(`*${sFieldName}`)) && (item.sSqlCondition.includes(`master.${sFieldName}`) || item.sSqlCondition.includes(sFieldName.replace('Name', 'Id')))).forEach((item) => { commonUtils.setStoreDropDownData(sModelsId, 'slave3', item.sName, []); if (bClearSelectedRowKeys) { addState.slave3SelectedRowKeys = []; } }); } if (commonUtils.isNotEmptyObject(slave4Config)) { slave4Config.gdsconfigformslave.filter(item => !commonUtils.isEmpty(item.sSqlCondition) && !commonUtils.isEmpty(item.sChineseDropDown) && (item.sChineseDropDown.includes(`#${sFieldName}`) || item.sChineseDropDown.includes(`*${sFieldName}`)) && (item.sSqlCondition.includes(`master.${sFieldName}`) || item.sSqlCondition.includes(sFieldName.replace('Name', 'Id')))).forEach((item) => { commonUtils.setStoreDropDownData(sModelsId, 'slave4', item.sName, []); if (bClearSelectedRowKeys) { addState.slave4SelectedRowKeys = []; } }); } if (commonUtils.isNotEmptyObject(slave5Config)) { slave5Config.gdsconfigformslave.filter(item => !commonUtils.isEmpty(item.sSqlCondition) && !commonUtils.isEmpty(item.sChineseDropDown) && (item.sChineseDropDown.includes(`#${sFieldName}`) || item.sChineseDropDown.includes(`*${sFieldName}`)) && (item.sSqlCondition.includes(`master.${sFieldName}`) || item.sSqlCondition.includes(sFieldName.replace('Name', 'Id')))).forEach((item) => { commonUtils.setStoreDropDownData(sModelsId, 'slave5', item.sName, []); if (bClearSelectedRowKeys) { addState.slave5SelectedRowKeys = []; } }); } /* 字段输入时 根据规则 控制其他字段的显示与隐藏 */ const iConfigIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === sFieldName); if (iConfigIndex > -1) { const sFiledConfig = masterConfig.gdsconfigformslave[iConfigIndex]; if (commonUtils.isNotEmptyObject(sFiledConfig)) { const tableDataRow = { ...masterData, ...changeValue, handleType }; const sRulesJson = sFiledConfig.sButtonEnabled; if (commonUtils.isNotEmptyObject(sRulesJson) && commonUtils.isJSON(sRulesJson)) { const sRulesObjArr = JSON.parse(sRulesJson); if (commonUtils.isNotEmptyArr(sRulesObjArr)) { console.log('sRulesObjArr:', sRulesObjArr); sRulesObjArr.forEach((sRulesObj) => { const { showColumn, hideColumn, condition, tbName, sConfigName, } = sRulesObj; console.log('tbName:', tbName); /* 主表单表字段根据条件控制 其他字段的显示与隐藏 */ if (commonUtils.isEmptyObject(tbName)) { if (commonUtils.isNotEmptyArr(condition)) { let flag = false; for (const item of condition) { const { bFilterName, bFilterCondition, bFilterValue, } = item; if (bFilterCondition === '>') { if (tableDataRow[bFilterName] > bFilterValue) { flag = true; } } else if (bFilterCondition === '=') { if (tableDataRow[bFilterName] === bFilterValue) { flag = true; } } else if (bFilterCondition === '<') { if (tableDataRow[bFilterName] < bFilterValue) { flag = true; } } } if (flag) { if (commonUtils.isNotEmptyArr(showColumn)) { for (const column of showColumn) { const iShowIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === column); if (iShowIndex > -1) { const sFiledObj = masterConfig.gdsconfigformslave[iShowIndex]; if (commonUtils.isNotEmptyObject(sFiledObj)) { if (commonUtils.isNotEmptyObject(sConfigName) && sConfigName === 'bControl') { masterConfig.gdsconfigformslave[iShowIndex].bControl = true; /* 控制字段bControl的显示与隐藏 */ } else { masterConfig.gdsconfigformslave[iShowIndex].bVisible = true; } } } } } if (commonUtils.isNotEmptyArr(hideColumn)) { for (const column of hideColumn) { const iHideIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === column); if (iHideIndex > -1) { if (commonUtils.isNotEmptyObject(sConfigName) && sConfigName === 'bControl') { masterConfig.gdsconfigformslave[iHideIndex].bControl = true; /* 控制字段bControl的显示与隐藏 */ } else { masterConfig.gdsconfigformslave[iHideIndex].bVisible = false; } } } } addState.masterConfig = masterConfig; } } } else { /* 主表字段根据条件控制 其他表格字段的显示与隐藏 */ const { [`${tbName}Config`]: tableConfig } = this.state; // const { controlConfig: tableConfig } = this.state; if (commonUtils.isNotEmptyObject(tableConfig)) { if (commonUtils.isNotEmptyArr(condition)) { let flag = false; for (const item of condition) { const { bFilterName, bFilterCondition, bFilterValue, } = item; if (bFilterCondition === '>') { if (tableDataRow[bFilterName] > bFilterValue) { flag = true; } } else if (bFilterCondition === '=') { if (tableDataRow[bFilterName] === bFilterValue) { flag = true; } } else if (bFilterCondition === '<') { if (tableDataRow[bFilterName] < bFilterValue) { flag = true; } } } if (flag) { if (commonUtils.isNotEmptyArr(showColumn)) { for (const column of showColumn) { const iShowIndex = tableConfig.gdsconfigformslave.findIndex(item => item.sName === column); if (iShowIndex > -1) { const sFiledObj = tableConfig.gdsconfigformslave[iShowIndex]; if (commonUtils.isNotEmptyObject(sFiledObj)) { tableConfig.gdsconfigformslave[iShowIndex].bVisible = true; } } } } if (commonUtils.isNotEmptyArr(hideColumn)) { for (const column of hideColumn) { const iHideIndex = tableConfig.gdsconfigformslave.findIndex(item => item.sName === column); if (iHideIndex > -1) { const sFiledObj = tableConfig.gdsconfigformslave[iHideIndex]; if (commonUtils.isNotEmptyObject(sFiledObj)) { tableConfig.gdsconfigformslave[iHideIndex].bVisible = false; } } } } if (commonUtils.isNotEmptyObject(tableConfig)) { const tableColumn = commonFunc.getHeaderConfig(tableConfig); // addState.masterConfig = masterConfig; // addState.controlConfig = tableConfig; /* 表格配置塞到addState中 */ // addState.controlColumn = tbColumn; addState[`${tbName}Config`] = tableConfig; addState[`${tbName}Column`] = tableColumn; } } } } } }); } } } } } masterData = { ...masterData, ...changeValue, handleType }; if (isWait) { return { masterData, ...addState }; // , sUseInfo: '' } else if (this.mounted) { this.setState({ masterData, ...addState }); // , sUseInfo: '' return { masterData, ...addState }; } }; /** 表格数据更改 */ // name 不写完整的state名称作用为了要用到total // (name, changeValue, sId, dropDownData) handleTableChange = (name, sFieldName, changeValue, sId, dropDownData, isWait) => { const { [`${name}Data`]: tableData, [`${name}Config`]: tableConfig, sModelsId } = this.state; const iIndex = tableData.findIndex(item => item.sId === sId); let { handleType } = tableData[iIndex]; handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType; if (sFieldName.substring(0, 1).toLowerCase() === 'c') { const sAllField = sFieldName.substring(1, sFieldName.length); const allField = sAllField.split('_'); const value = changeValue[sFieldName]; allField.forEach((item, iArr) => { if (value.length > iArr) { changeValue[item] = value[iArr]; } }); } if (!commonUtils.isEmpty(tableConfig.gdsconfigformslave) && commonUtils.isNotEmptyArr(tableConfig.gdsconfigformslave) && !commonUtils.isEmpty(sFieldName)) { tableConfig.gdsconfigformslave.filter(item => !commonUtils.isEmpty(item.sSqlCondition) && !commonUtils.isEmpty(item.sChineseDropDown) && (item.sChineseDropDown.includes(`#${sFieldName}`) || item.sChineseDropDown.includes(`*${sFieldName}`)) && (item.sSqlCondition.includes(`master.${sFieldName}`) || item.sSqlCondition.includes(sFieldName.replace('Name', 'Id')))).forEach((item) => { commonUtils.setStoreDropDownData(sModelsId, 'slave', item.sName, []); }); // tableConfig.gdsconfigformslave.filter(item => !commonUtils.isEmpty(item.sSqlCondition) && item.sSqlCondition.includes(sFieldName)).forEach((item) => { // commonUtils.setStoreDropDownData(sModelsId, name, item.sName, []); // }); /* 字段输入时 根据规则 控制其他字段的显示与隐藏 */ const iConfigIndex = tableConfig.gdsconfigformslave.findIndex(item => item.sName === sFieldName); if (iConfigIndex > -1) { const sFiledConfig = tableConfig.gdsconfigformslave[iConfigIndex]; if (commonUtils.isNotEmptyObject(sFiledConfig)) { const tableDataRow = { ...tableData[iIndex], ...changeValue, handleType }; const sRulesJson = sFiledConfig.sButtonEnabled; if (commonUtils.isNotEmptyObject(sRulesJson) && commonUtils.isJSON(sRulesJson)) { const sRulesObj = JSON.parse(sRulesJson); if (commonUtils.isNotEmptyObject(sRulesObj)) { const { showColumn, hideColumn, condition } = sRulesObj; if (commonUtils.isNotEmptyArr(condition)) { let flag = false; for (const item of condition) { const { bFilterName, bFilterCondition, bFilterValue, } = item; if (bFilterCondition === '>') { if (tableDataRow[bFilterName] > bFilterValue) { flag = true; } } else if (bFilterCondition === '=') { if (tableDataRow[bFilterName] === bFilterValue) { flag = true; } } else if (bFilterCondition === '<') { if (tableDataRow[bFilterName] < bFilterValue) { flag = true; } } } if (flag) { if (commonUtils.isNotEmptyArr(showColumn)) { for (const column of showColumn) { const iShowIndex = tableConfig.gdsconfigformslave.findIndex(item => item.sName === column); if (iShowIndex > -1) { const sFiledObj = tableConfig.gdsconfigformslave[iShowIndex]; if (commonUtils.isNotEmptyObject(sFiledObj)) { tableConfig.gdsconfigformslave[iShowIndex].bVisible = true; } } } } if (commonUtils.isNotEmptyArr(hideColumn)) { for (const column of hideColumn) { const iHideIndex = tableConfig.gdsconfigformslave.findIndex(item => item.sName === column); if (iHideIndex > -1) { tableConfig.gdsconfigformslave[iHideIndex].bVisible = false; } } } const tableColumn = commonFunc.getHeaderConfig(tableConfig); this.setState({ [`${name}Config`]: tableConfig, [`${name}Column`]: tableColumn }); } } } } } } const tableDataRowNew = { ...tableData[iIndex], ...changeValue, handleType }; const tableDataAfter = commonBusiness.getKeyUpEvent(name, sFieldName, tableConfig, tableDataRowNew, tableDataRowNew, true); if (commonUtils.isNotEmptyObject(tableDataAfter)) { changeValue = { ...tableDataAfter }; } } if (isWait) { return { ...tableData[iIndex], ...changeValue, handleType }; } else { tableData[iIndex] = { ...tableData[iIndex], ...changeValue, handleType }; if (this.mounted) { this.setState({ [`${name}Data`]: tableData, sUseInfo: '' }); } } }; /** 添加表格空行 */ handleTableAdd = (name, isWait) => { /* 外置处理业务 */ const { [`${name}Config`]: tableConfig, masterData, slaveData, slaveSelectedRowKeys, } = this.state; let { [`${name}Data`]: tableData } = this.state; tableData = commonUtils.isEmptyObject(tableData) ? [] : tableData; const allTableData = {}; allTableData.master = masterData; if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) { const iSlaveIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys.toString()); allTableData.slave = slaveData[iSlaveIndex]; } const iOrderArr = []; tableData.forEach((item) => { const iOrder = commonUtils.isNotEmptyNumber(item.iOrder) ? item.iOrder : 0; /* 获取tableData中iOrder最大值 */ iOrderArr.push(iOrder); }); const iOrderMax = Math.max(...iOrderArr); const tableDataRow = commonFunc.getDefaultData(tableConfig, allTableData); tableDataRow.handleType = 'add'; tableDataRow.sId = commonUtils.createSid(); tableDataRow.sParentId = masterData && masterData.sId ? masterData.sId : null; tableDataRow.key = tableDataRow.sId; tableDataRow.bDefault = false; tableDataRow.iOrder = commonUtils.isNotEmptyArr(tableData) ? iOrderMax + 1 : 1; tableDataRow.defaultAdded = tableData.length === 0; if (isWait) { return tableDataRow; } else { // tableData.splice(index, 1, tableDataRow); /* 该处会导致新增时删除首行 */ tableData.push(tableDataRow); if (this.mounted) { this.setState({ [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: [tableDataRow.sId] }); } } }; // name 不写完整的state名称作用为了要用到total /** 删除表格数据 */ handleTableDel = (name, isWait, tableSelectedRowKeys) => { const { app } = this.props; const { [`${name}Data`]: tableData } = this.state; let { [`${name}DelData`]: tableDelData, [`${name}Pagination`]: pagination = {} } = this.state; tableDelData = commonUtils.isEmptyArr(tableDelData) ? [] : tableDelData; if (commonUtils.isNotEmptyArr(tableSelectedRowKeys)) { for (const sId of tableSelectedRowKeys) { /* 看看删除集合和从表中是否都存在该条数据 */ let tableDataIndex = tableData.findIndex(item => item.sId === sId); while (tableDataIndex > -1) { /* 删除从表中的数据并存入删除集合中 */ const slaveDataFilter = tableData[tableDataIndex]; tableData.splice(tableDataIndex, 1); slaveDataFilter.handleType = 'del'; tableDelData.push(slaveDataFilter); tableDataIndex = tableData.findIndex(item => item.sId === sId); } } const addState = {}; if (commonUtils.isNotEmptyObject(pagination)) { addState[`${name}Pagination`] = { ...pagination, total: tableData.length, } } if (isWait) { return { [`${name}Data`]: tableData, [`${name}DelData`]: tableDelData, [`${name}SelectedRowKeys`]: [], ...addState }; } else { if (this.mounted) { this.setState({ [`${name}Data`]: tableData, [`${name}DelData`]: tableDelData, [`${name}SelectedRowKeys`]: [], ...addState, }); } return true; } } else { if (!isWait) { message.warn(commonFunc.showMessage(app.commonConst, 'pleaseChooseDelData')); // 请选择删除数据 } return false; } }; /** 处理选择行发生改变 */ handleTableSelectRowChange = (name, selectedRowKeys, isWait) => { /* 外置处理业务 */ const { formRoute, slaveData, sModelsId, [`${name}Config`]: tableConfig, } = this.state; let { slaveSelectedData } = this.state; const addState = {}; addState[`${name}SelectedRowKeys`] = selectedRowKeys; addState.searchUpDownData = {}; if (name === 'slave' && (formRoute === '/indexPage/commonList' || formRoute === '/indexPage/commonListEdit' || formRoute === '/indexPage/commonListTree' || formRoute.indexOf('/indexOee') > -1)) { const slavePageData = slaveData.filter(item => selectedRowKeys.includes(item.sSlaveId)); slaveSelectedData = commonUtils.isEmpty(slaveSelectedData) ? [] : slaveSelectedData.filter(item => selectedRowKeys.toString().includes(item.sSlaveId)); selectedRowKeys.forEach((item) => { const iIndex = slaveSelectedData.findIndex(selectItem => selectItem.sSlaveId === item); if (iIndex === -1) { const iPageIndex = slavePageData.findIndex(pageItem => pageItem.sSlaveId === item); if (iPageIndex > -1) { slaveSelectedData.push(slavePageData[iPageIndex]); } } }); addState.slaveSelectedData = slaveSelectedData; } if (commonUtils.isNotEmptyObject(tableConfig)) { tableConfig.gdsconfigformslave.forEach((configItem) => { const sFieldName = configItem.sName; if (!commonUtils.isEmpty(tableConfig.gdsconfigformslave) && commonUtils.isNotEmptyArr(tableConfig.gdsconfigformslave) && !commonUtils.isEmpty(sFieldName) && (commonUtils.isEmptyArr(this.state[`${name}SelectedRowKeys`]) || selectedRowKeys.toString() !== this.state[`${name}SelectedRowKeys`].toString())) { tableConfig.gdsconfigformslave.filter(item => !commonUtils.isEmpty(item.sSqlCondition) && !commonUtils.isEmpty(item.sChineseDropDown) && (item.sChineseDropDown.includes(`#${sFieldName}`) || item.sChineseDropDown.includes(`*${sFieldName}`)) && (item.sSqlCondition.includes(`master.${sFieldName}`) || item.sSqlCondition.includes(sFieldName.replace('Name', 'Id')))).forEach((item) => { commonUtils.setStoreDropDownData(sModelsId, 'slave', item.sName, []); }); // tableConfig.gdsconfigformslave.filter(item => !commonUtils.isEmpty(item.sSqlCondition) && item.sSqlCondition.includes(sFieldName)).forEach((item) => { // commonUtils.setStoreDropDownData(sModelsId, name, item.sName, []); // }); } }); } if (this.mounted) { if (isWait) { return addState; } else { this.setState(addState); } } }; handleViewClick = (name, sName, record, index) => { const { [`${name}Config`]: slaveConfig, customConfig, [`${name}Data`]: slaveData, [`${name}Pagination`]: slavePagination, formSrcRoute, masterConfig, } = this.state; let { [`${name}FilterCondition`]: slaveFilterCondition, } = this.state; let picArr = slaveConfig.gdsconfigformslave.filter(item => (item.sName === sName)); if (commonUtils.isNotEmptyArr(customConfig)) { picArr = customConfig.filter(item => item.sName === sName); } if (commonUtils.isNotEmptyObject(sName) && sName.includes('BtnEject')) { picArr = masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sControlName === sName); } if (picArr.length > 0) { const tableDataRow = record; const iIndex = index; // let tableDataRow = {}; // let iIndex = 0; /* 判断slaveData是数组还是对象 */ // if (commonUtils.isNotEmptyObject(slaveData) && slaveData.length > 0) { // iIndex = slaveData.findIndex(item => item.sId === sId); // tableDataRow = iIndex > -1 ? slaveData[iIndex] : {}; // } else if (commonUtils.isNotEmptyObject(slaveData)) { // tableDataRow = slaveData; // } 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=${formSrcRoute}`; const filterCondition = []; const conditionValues = this.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], }); } }); } let copyTo ={}; let bLinkPlanTree = commonUtils.isNotEmptyObject(tableDataRow) && tableDataRow.bLinkPlanTree; if(bLinkPlanTree) { copyTo = { treeKey : tableDataRow.sMachineId + tableDataRow.sWorkCenterId, sWorkCenterName: tableDataRow.sWorkCenterName, } } let payload = { url: sNameUrl, sTabId: commonUtils.createSid(), sParentId: this.state.sTabId, urlDataType: 'newPane', checkedId: tableDataRow[sActiveKey], bFilter: slaveFilterCondition, pageSize: this.state.iPageSize, pages: slavePagination, currentData: [tableDataRow], conditonValues: bLinkPlanTree ? undefined : conditionValues, sListFormmasterId: slaveConfig.sId, newKey: tableDataRow[sActiveKey], currentIndex: iIndex, filterCondition: bLinkPlanTree ? undefined : filterCondition, copyTo: copyTo } this.props.dispatch({ type: 'content/onRouter', payload }); } }; /* 快捷键跳转 */ handleQuickViewClick = (name, sName, record, index, myConfigArr) => { const { [`${name}Config`]: slaveConfig, customConfig, [`${name}FilterCondition`]: slaveFilterCondition, [`${name}Pagination`]: slavePagination, formSrcRoute, masterConfig, } = this.state; let picArr = slaveConfig.gdsconfigformslave.filter(item => (item.sName === sName)); if (commonUtils.isNotEmptyArr(customConfig)) { picArr = customConfig.filter(item => item.sName === sName); } if (commonUtils.isNotEmptyObject(sName) && sName.includes('BtnEject')) { picArr = masterConfig.gdsconfigformslave.filter(item => item.bVisible && item.sControlName === sName); } if (commonUtils.isNotEmptyArr(myConfigArr)) { picArr = myConfigArr; } if (picArr.length > 0) { const tableDataRow = record; const iIndex = index; // let tableDataRow = {}; // let iIndex = 0; /* 判断slaveData是数组还是对象 */ // if (commonUtils.isNotEmptyObject(slaveData) && slaveData.length > 0) { // iIndex = slaveData.findIndex(item => item.sId === sId); // tableDataRow = iIndex > -1 ? slaveData[iIndex] : {}; // } else if (commonUtils.isNotEmptyObject(slaveData)) { // tableDataRow = slaveData; // } 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=${formSrcRoute}`; const filterCondition = []; const conditionValues = this.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], }); } }); } let copyTo = {}; if (commonUtils.isNotEmptyObject(tableDataRow) && tableDataRow.bLinkPlanTree) { copyTo = { treeKey: tableDataRow.sMachineId + tableDataRow.sWorkCenterId, sWorkCenterName: tableDataRow.sWorkCenterName, }; } this.props.dispatch({ type: 'content/onRouter', payload: { url: sNameUrl, sTabId: commonUtils.createSid(), sParentId: this.state.sTabId, urlDataType: 'newPane', checkedId: (commonUtils.isNotEmptyObject(tableDataRow[sActiveKey])) ? tableDataRow[sActiveKey] : myConfigArr[0].sId, sName: myConfigArr[0].sName, bFilter: slaveFilterCondition, pageSize: this.state.iPageSize, pages: slavePagination, currentData: [tableDataRow], conditonValues: conditionValues, sListFormmasterId: slaveConfig.sId, newKey: tableDataRow[sActiveKey], currentIndex: iIndex, filterCondition, copyTo, }, }); } }; handleRowMove = (addState) => { this.setState(addState); }; handleFilterDropDownData = (dropDownData, showConfig, name, record) => { if (!commonUtils.isEmptyArr(dropDownData)) { const conditon = showConfig.sSqlCondition.split(','); let orTableName; let orFieldName; let orFieldNameFilter; let orValue; conditon.forEach((item) => { if (item.indexOf('.') > -1) { const tableName = item.split('.')[0]; const fieldName = item.split('.')[1]; const fieldNameFilter = item.split('.')[2]; if (tableName.indexOf('|') > -1) { orTableName = tableName.replace('|', ''); orFieldName = fieldName; orFieldNameFilter = fieldNameFilter; if (orFieldName.indexOf('&') > -1) { orValue = orFieldName.replace('&', ''); } else if (!commonUtils.isEmpty(orFieldNameFilter)) { if (name === orTableName && !commonUtils.isEmpty(record)) { const data = record; orValue = data[orFieldName]; } else { const data = this.state[`${orTableName}Data`]; const selectedRowKeys = this.state[`${orTableName}SelectedRowKeys`]; if (typeof data === 'object' && data.constructor === Object) { orValue = data[orFieldName]; } else if (commonUtils.isNotEmptyArr(selectedRowKeys)) { const iIndex = data.findIndex(itemData => itemData.sId === selectedRowKeys[0]); if (iIndex > -1) { orValue = data[iIndex][orFieldName]; } } else if (commonUtils.isNotEmptyArr(data)) { orValue = data[0][orFieldName]; } } } orValue = orValue.toString(); } else if (!commonUtils.isEmpty(orFieldName)) { // master.sId 作为参数 control.sId.sControlId 作为filterDropdown过滤参数 if (!commonUtils.isEmpty(fieldNameFilter)) { if (name === tableName && !commonUtils.isEmpty(record)) { const data = record; dropDownData = dropDownData.filter(itemDrop => itemDrop[fieldNameFilter] === data[fieldName] || itemDrop[orFieldNameFilter] === orValue); } else { const data = this.state[`${tableName}Data`]; const selectedRowKeys = this.state[`${tableName}SelectedRowKeys`]; if (typeof data === 'object' && data.constructor === Object) { dropDownData = dropDownData.filter(itemDrop => itemDrop[fieldNameFilter] === data[fieldName] || itemDrop[orFieldNameFilter] === orValue); } else if (commonUtils.isNotEmptyArr(selectedRowKeys)) { const iIndex = data.findIndex(itemData => itemData.sId === selectedRowKeys[0]); if (iIndex > -1) { dropDownData = dropDownData.filter(itemDrop => itemDrop[fieldNameFilter] === data[iIndex][fieldName] || itemDrop[orFieldNameFilter] === orValue); } } else if (commonUtils.isNotEmptyArr(data)) { dropDownData = dropDownData.filter(itemDrop => itemDrop[fieldNameFilter] === data[0][fieldName] || itemDrop[orFieldNameFilter] === orValue); } } } } else if (!commonUtils.isEmpty(fieldNameFilter)) { if (name === tableName && !commonUtils.isEmpty(record)) { const data = record; dropDownData = dropDownData.filter(itemDrop => itemDrop[fieldNameFilter] === data[fieldName]); } else { const data = this.state[`${tableName}Data`]; const selectedRowKeys = this.state[`${tableName}SelectedRowKeys`]; if (typeof data === 'object' && data.constructor === Object) { dropDownData = dropDownData.filter(itemDrop => itemDrop[fieldNameFilter] === data[fieldName]); } else if (commonUtils.isNotEmptyArr(selectedRowKeys)) { const iIndex = data.findIndex(itemData => (commonUtils.isEmpty(itemData.sSlaveId) ? itemData.sId : itemData.sSlaveId) === selectedRowKeys[0]); if (iIndex > -1) { dropDownData = dropDownData.filter(itemDrop => itemDrop[fieldNameFilter] === data[iIndex][fieldName]); } } else if (commonUtils.isNotEmptyArr(data)) { dropDownData = dropDownData.filter(itemDrop => itemDrop[fieldNameFilter] === data[0][fieldName]); } } } } }); } // let dropDownData = dropDownDataOld; // const data = this.state[`${tableName}Data`]; // const selectedRowKeys = this.state[`${tableName}SelectedRowKeys`]; // if (commonUtils.isNotEmptyArr(selectedRowKeys)) { // const SelectedData = data.filter(item => item.sId === selectedRowKeys[0]); // if (SelectedData.length > 0 && commonUtils.isNotEmptyStr(SelectedData[0][fieldName])) { // if (commonUtils.isNotEmptyArr(dropDownData)) { // dropDownData = dropDownData.filter(item => item[fieldName] === SelectedData[0][fieldName]); // } // } // } return dropDownData; }; /* newRecord新纪录保存后,将数据回到到下拉框中 字段名,主从表名,赋值字段 */ handleCallBackRecord = async (sName, name, sId) => { const { [`${name}SelectedRowKeys`]: tableSelectedRowKeys, sModelsId, [`${name}Data`]: tableNewData, slaveData, masterData, sModelsType, token, formRoute, } = this.state; const { app } = this.props; /* 获取下拉的字段showConfig */ const { [`${[name]}Config`]: nameConfig } = this.state; const filedShowConfig = nameConfig.gdsconfigformslave.filter(item => (item.sName === sName)); const AssignField = commonUtils.isNotEmptyArr(filedShowConfig) ? filedShowConfig[0].sAssignField : ''; const sqlDropDownData = await this.getSqlDropDownData(sModelsId, name, filedShowConfig[0]); /* 根据sName得到过滤数据 */ const dropdownData = sqlDropDownData.dropDownData; const filterDataIndex = dropdownData.findIndex(item => (item.sId === sId) || (commonUtils.isNotEmptyObject(item.sNId) && item.sNId === sId)); if (filterDataIndex > -1) { if (name !== 'master' && commonUtils.isNotEmptyObject(tableSelectedRowKeys)) { const newCopyTo = {}; const iIndex = tableNewData.findIndex(item => item.sId === tableSelectedRowKeys.toString()); newCopyTo.master = masterData; newCopyTo.slave = tableNewData[iIndex]; let slaveRow = {}; slaveRow = { ...tableNewData[iIndex], ...commonFunc.getAssignFieldValue(AssignField, dropdownData[filterDataIndex], newCopyTo) }; // 取赋值字段 slaveRow.handleType = commonUtils.isEmpty(slaveRow.handleType) ? 'update' : slaveRow.handleType; if (sName === 'sProductId' || sName === 'sProductName') { slaveRow.sProductInfo = ''; } tableNewData[iIndex] = slaveRow; /* 套装工单、报价单、工艺卡的从表, 点击newRecord后 回带控制表合版数据 */ const addState = {}; if(formRoute && formRoute.includes('PackTableTree') && name === 'slave') { const { controlData } = this.state;; let { packData } = this.state; if(commonUtils.isEmptyArr(packData)){ packData =[]; } if(controlData.length ===1) { const controlRow = controlData[0]; const iIndex = packData.findIndex(item=> item.sControlId === controlRow.sId); if(iIndex > -1){ const packFilterData = packData.filter(item => item.sControlId === controlRow.sId); if (commonUtils.isNotEmptyArr(packFilterData)) { packFilterData.forEach((itemPack, index) => { let packDataRow = itemPack; const sControlId = controlRow.sControlId; packDataRow.sControlId = controlRow.sId; packDataRow.sSlaveId = slaveRow.sId; packDataRow.sProductId = slaveRow.sProductId; /* 产品id */ packDataRow.sCustomerId = slaveRow.sCustomerId; /* 客户id */ packDataRow.sCustomerName = slaveRow.sCustomerName; /* 客户名称 */ packDataRow.sProductName = slaveRow.sProductName; /* 产品名称 */ packDataRow.sProductNo = slaveRow.sProductNo; /* 产品编号 */ packDataRow.dCombineQty = 1; packData[index] = { ...packData[index], ...packDataRow }; if (commonUtils.isNotEmptyObject(packData[index])) { const { sId, sProductNo, dProductQty, dCombineQty, dFactProductQty, sCombinePartsName } = packData[0]; const tableCombineSelectedData = []; const jsonObj = {}; jsonObj.sId = sId; jsonObj.sProductNo = sProductNo; /* 产品编号 */ jsonObj.dCombineQty = commonUtils.isNotEmptyNumber(dCombineQty) ? dCombineQty : 0; /* 排版数 */ jsonObj.dProductQty = commonUtils.isNotEmptyNumber(dProductQty) ? dProductQty : 0; /* 生产数 */ jsonObj.dFactProductQty = commonUtils.isNotEmptyNumber(dFactProductQty) ? dFactProductQty : 0; /* 实际生产数 */ jsonObj.sCombinePartsName = sCombinePartsName; /* 合版部件名称 */ tableCombineSelectedData.push(jsonObj); const sCombinedMemo = commonUtils.isNotEmptyArr(tableCombineSelectedData) ? JSON.stringify(tableCombineSelectedData) : ''; /* JSON对象转换为字符串存放到合版信息中 */ controlRow.sCombinedMemo =commonUtils.isNotEmptyObject(sCombinedMemo)? sCombinedMemo: '合版信息'; controlRow.handleType = commonUtils.isEmpty(controlRow.handleType) ? 'update' : controlRow.handleType; controlData[0]={...controlData,...controlRow}; } }); addState.packData = packData; addState.controlData = controlData; } } } } this.setState({ [`${name}Data`]: tableNewData, ...addState }); } else { /* 主表赋值 */ const changeValue = commonFunc.getAssignFieldValue(AssignField, dropdownData[filterDataIndex]); const masterNewData = { ...masterData, ...changeValue }; // 取赋值字段 const sFieldName = sName; const addState = {}; if (sFieldName === 'sCustomerId' || sFieldName === 'sCustomerNo' || sFieldName === 'sCustomerName' || sFieldName === 'sSupplyId' || sFieldName === 'sSupplyNo' || sFieldName === 'sSupplyName' || sFieldName === 'sWareHouseId' || sFieldName === 'sWareHouseNo' || sFieldName === 'sWareHouseName' || sFieldName === 'tDeliverDate') { const slaveDataNew = []; for (const item of slaveData) { let tableDataRow = ((sFieldName === 'sWareHouseId' || sFieldName === 'sWareHouseNo' || sFieldName === 'sWareHouseName') && (sModelsType.includes('materialsStock/productionmaterialsadjust'))) ? { ...item } : { ...item, [sFieldName]: changeValue[sFieldName] }; if (sFieldName === 'sCustomerId' || sFieldName === 'sCustomerNo' || sFieldName === 'sCustomerName' || sFieldName === 'sSupplyId' || sFieldName === 'sSupplyNo' || sFieldName === 'sSupplyName') { tableDataRow.sTaxId = changeValue.sTaxId; tableDataRow.sTaxNo = changeValue.sTaxNo; tableDataRow.sTaxName = changeValue.sTaxName; tableDataRow.dTaxRate = changeValue.dTaxRate; tableDataRow.handleType = commonUtils.isEmpty(tableDataRow.handleType) ? 'update' : tableDataRow.handleType; const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials'; tableDataRow = commonBusiness.getCalculateAllMoney(app, models, 'sTaxId', masterData, tableDataRow); let dMaterialsMoney = ''; if (sModelsType.includes('outside/')) { /* 工序发外 */ let sComputeId = ''; const sSupplyId = changeValue.sSupplyId; const sProcessId = tableDataRow.sProcessId; /* 根据客户id,工序id获取公式ID */ if (commonUtils.isNotEmptyObject(sSupplyId) && commonUtils.isNotEmptyObject(sProcessId)) { sComputeId = await commonBusiness.getOutSideProcessFormula({ token, sModelsId, sSupplyId, sProcessId, }); if (commonUtils.isNotEmptyObject(sComputeId)) { dMaterialsMoney = await commonBusiness.getFormulaValue({ token, sModelsId, masterData, tableDataRow, sComputeId, }); tableDataRow.dMaterialsMoney = dMaterialsMoney; tableDataRow = commonBusiness.getCalculateMoney(app, masterData, tableDataRow, 'Materials'); } } } } if ((sFieldName === 'sWareHouseId' || sFieldName === 'sWareHouseNo' || sFieldName === 'sWareHouseName') && (!sModelsType.includes('materialsStock/productionmaterialsadjust'))) { tableDataRow.sWareHouseId = changeValue.sWareHouseId; tableDataRow.sWareHouseNo = changeValue.sWareHouseNo; tableDataRow.sWareHouseName = changeValue.sWareHouseName; tableDataRow.sLocationId = changeValue.sLocationId; tableDataRow.sLocationNo = changeValue.sLocationNo; tableDataRow.sLocationName = changeValue.sLocationName; tableDataRow.sWareHouseLocationId = changeValue.sWareHouseLocationId; tableDataRow.sWareHouseLocationNo = changeValue.sWareHouseLocationNo; tableDataRow.sWareHouseLocationName = changeValue.sWareHouseLocationName; tableDataRow.handleType = commonUtils.isEmpty(tableDataRow.handleType) ? 'update' : tableDataRow.handleType; } slaveDataNew.push(tableDataRow); } addState.slaveData = slaveDataNew; // this.props.onSaveState({ slaveData: slaveDataNew }); } this.setState({ [`${name}Data`]: masterNewData, ...addState }); } } } /** 树选择 */ handleTreeSelect = (name, selectedKeys, e) => { const { treeNode } = e.node.props; this.setState({ [`${name}SelectedKeys`]: selectedKeys, [`${name}TreeNode`]: treeNode }); }; /* 通用弹窗 选择数据带回窗体 */ handleSelectCommonPopup = (currentPaneName, selectConfig, selectData, tbName) => { const { [`${tbName}SelectedRowKeys`]: tableSelectedRowKeys, masterData, controlData, controlSelectedRowKeys, sModelsId, } = this.state; // 回弹字段直接设置单价 async function setProductPrice(tableDataRowAdd, item, props) { if (selectConfig.sName === 'sProductId' || selectConfig.sName === 'sProductName' || selectConfig.sName === 'sProductNo') { const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`; const { sCustomerId } = masterData; /* 增加客户id参数 */ const value = { sProName: 'Sp_Cashier_GetProductPrice', paramsMap: { sProductGuid: item.sId, sCustomerId, }, }; const returnData = (await commonServices.postValueService(props.app.token, value, url)).data; if (returnData.code === 1) { tableDataRowAdd.dNProductPrice = returnData.dataset.rows[0].dataSet.outData[0].dPrice; /* 产品单价 */ const dProofingMoney = commonUtils.convertToNum(tableDataRowAdd.dProofingMoney); /* 打样金额 */ const dPlateMoney = commonUtils.convertToNum(tableDataRowAdd.dPlateMoney); /* 制版金额 */ const dKnifeMouldMoney = commonUtils.convertToNum(tableDataRowAdd.dKnifeMouldMoney); /* 刀模金额 */ const dProductQty = commonUtils.convertToNum(tableDataRowAdd.dProductQty); /* 数量 */ const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */ const { dNetPrice } = props.app.decimals; if (dProductQty === 0 || (dProofingMoney === 0 && dPlateMoney === 0 && dKnifeMouldMoney === 0)) { const dProductForeignPrice = returnData.dataset.rows[0].dataSet.outData[0].dPrice; tableDataRowAdd.dProductForeignPrice = dProductForeignPrice; tableDataRowAdd.dProductPrice = commonUtils.convertFixNum(dProductForeignPrice * dCurrencyRate, dNetPrice); } } return tableDataRowAdd; } else { return tableDataRowAdd; } } let { [`${tbName}Data`]: tableData, [`${tbName}Pagination`]: pagination = {} } = this.state; if (commonUtils.isNotEmptyArr(tableData) && commonUtils.isNotEmptyArr(selectData)) { const iIndex = commonUtils.isNotEmptyArr(tableSelectedRowKeys) && commonUtils.isNotEmptyObject(tableSelectedRowKeys[0]) ? tableData.findIndex(item => item.sId === tableSelectedRowKeys[0]) : -1; const iControlIndex = commonUtils.isNotEmptyArr(controlSelectedRowKeys) ? controlData.findIndex(item => item.sId === controlSelectedRowKeys[0]) : -1; /* 控制表 */ selectData.forEach(async (item, index) => { const newCopyTo = {}; newCopyTo.master = masterData; const sName = selectConfig.sKeyUpFilter; /* 将后台配置筛选字段作为 列字段 */ let sValue = ''; if (iIndex > -1) { newCopyTo.slave = tableData[iIndex]; sValue = tableData[iIndex][sName]; } if (iControlIndex > -1) { newCopyTo.control = controlData[iControlIndex]; } /* 第一条数据若字段值为空或者只有一条数据时 则添加到该行 否则新增一行 */ if (selectData.length === 1 || (index === 0 && commonUtils.isEmptyObject(sValue))) { let tableDataRow = {}; // 取默认值 if (tbName === 'master') { tableDataRow = { ...tableData, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo) }; // 取赋值字段 tableData = tableDataRow; tableData.handleType = commonUtils.isEmpty(tableData.handleType) ? 'update' : tableData.handleType; } else { tableDataRow = { ...tableData[iIndex], ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo) }; // 取赋值字段 tableData[iIndex] = tableDataRow; tableData[iIndex].handleType = commonUtils.isEmpty(tableData[iIndex].handleType) ? 'update' : tableData[iIndex].handleType; tableData[iIndex] = await setProductPrice(tableData[iIndex], item, this.props); } } else { let tableDataRowAdd = this.handleTableAdd(tbName, true); tableDataRowAdd = { ...tableDataRowAdd, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo) }; // 取赋值字段 tableDataRowAdd = await setProductPrice(tableDataRowAdd, item, this.props); tableData.push(tableDataRowAdd); } pagination = { ...pagination, total: tableData.length, } this.setState({ [`${tbName}Data`]: tableData, [`${tbName}Pagination`]: pagination }); }); } }; /* 接口数据带入数据 */ handleSelectDialog = (name, selectConfig, selectData, tbName) =>{ const { [`${tbName}SelectedRowKeys`]: tableSelectedRowKeys, masterData, sModelsId, } = this.state; let { [`${tbName}Data`]: tableData } = this.state; if (commonUtils.isNotEmptyArr(tableData) && commonUtils.isNotEmptyArr(selectData)) { const iIndex = commonUtils.isNotEmptyArr(tableSelectedRowKeys) && commonUtils.isNotEmptyObject(tableSelectedRowKeys[0]) ? tableData.findIndex(item => item.sId === tableSelectedRowKeys[0]) : -1; selectData.forEach(async (item, index) => { const newCopyTo = {}; newCopyTo.master = masterData; const sName = selectConfig.sKeyUpFilter; /* 将后台配置筛选字段作为 列字段 */ let sValue = ''; if (iIndex > -1) { newCopyTo.slave = tableData[iIndex]; sValue = tableData[iIndex][sName]; } /* 第一条数据若字段值为空或者只有一条数据时 则添加到该行 否则新增一行 */ if (selectData.length === 1 || (index === 0 && commonUtils.isEmptyObject(sValue))) { let tableDataRow = {}; // 取默认值 if (tbName === 'master') { tableDataRow = { ...tableData, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo) }; // 取赋值字段 tableData = tableDataRow; tableData.handleType = commonUtils.isEmpty(tableData.handleType) ? 'update' : tableData.handleType; } else { tableDataRow = { ...tableData[iIndex], ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo) }; // 取赋值字段 tableData[iIndex] = tableDataRow; tableData[iIndex].handleType = commonUtils.isEmpty(tableData[iIndex].handleType) ? 'update' : tableData[iIndex].handleType; } } this.setState({ [`${tbName}Data`]: tableData }); }); } } /* 自定义复制从窗体 选择数据带回窗体 */ handleCopyFromSelect = (name, selectConfig, selectData) => { const { sModelsType } = this.state; let { masterData, slaveData } = this.state; const addState = {}; if (commonUtils.isNotEmptyArr(selectData)) { const newCopyTo = {}; newCopyTo.master = masterData; selectData.forEach((item) => { if (commonUtils.isNotEmptyObject(sModelsType) && sModelsType.includes('onlyMaster')) { /* 单主表调用复制从数据 */ masterData = { ...masterData, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo) }; // 取赋值字段 masterData.handleType = commonUtils.isEmpty(masterData.handleType) ? 'update' : masterData.handleType; addState.masterData = masterData; } else { /* 从表调用复制从数据 */ if (commonUtils.isEmptyArr(slaveData)) { slaveData = []; } let tableDataRowAdd = this.handleTableAdd('slave', true); tableDataRowAdd = { ...tableDataRowAdd, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo) }; // 取赋值字段 slaveData.push(tableDataRowAdd); addState.slaveData = slaveData; } }); } addState.copyFromChooseVisible = false; this.setState({ ...addState }); }; handelControlFieldVisible = (name, configData, tableData) => { const addState = {}; /* 获取主表数据时表字段数据根据条件控制 本表或其他表格字段的显示与隐藏功能 */ if (name === 'master' && commonUtils.isNotEmptyObject(configData) && commonUtils.isNotEmptyObject(tableData)) { const masterConfig = configData; const iConfigIndex = masterConfig.gdsconfigformslave.findIndex(item => commonUtils.isNotEmptyObject(item.sButtonEnabled)); if (iConfigIndex > -1) { const sFiledConfig = masterConfig.gdsconfigformslave[iConfigIndex]; if (commonUtils.isNotEmptyObject(sFiledConfig)) { const tableDataRow = tableData; const sRulesJson = sFiledConfig.sButtonEnabled; if (commonUtils.isNotEmptyObject(sRulesJson) && commonUtils.isJSON(sRulesJson)) { const sRulesObjArr = JSON.parse(sRulesJson); if (Array.isArray(sRulesObjArr) && commonUtils.isNotEmptyArr(sRulesObjArr)) { console.log('sRulesObjArr:', sRulesObjArr); sRulesObjArr.forEach((sRulesObj) => { const { showColumn, hideColumn, condition, tbName, sConfigName, } = sRulesObj; /* 主表单表字段根据条件控制 其他字段的显示与隐藏 */ if (commonUtils.isEmptyObject(tbName)) { if (commonUtils.isNotEmptyArr(condition)) { let flag = false; for (const item of condition) { const { bFilterName, bFilterCondition, bFilterValue, } = item; if (bFilterCondition === '>') { if (tableDataRow[bFilterName] > bFilterValue) { flag = true; } } else if (bFilterCondition === '=') { if (tableDataRow[bFilterName] === bFilterValue) { flag = true; } } else if (bFilterCondition === '<') { if (tableDataRow[bFilterName] < bFilterValue) { flag = true; } } } if (flag) { if (commonUtils.isNotEmptyArr(showColumn)) { for (const column of showColumn) { const iShowIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === column); if (iShowIndex > -1) { const sFiledObj = masterConfig.gdsconfigformslave[iShowIndex]; if (commonUtils.isNotEmptyObject(sFiledObj)) { if (commonUtils.isNotEmptyObject(sConfigName) && sConfigName === 'bControl') { masterConfig.gdsconfigformslave[iShowIndex].bControl = true; /* 控制字段bControl的显示与隐藏 */ } else { masterConfig.gdsconfigformslave[iShowIndex].bVisible = true; } } } } } if (commonUtils.isNotEmptyArr(hideColumn)) { for (const column of hideColumn) { const iHideIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === column); if (iHideIndex > -1) { if (commonUtils.isNotEmptyObject(sConfigName) && sConfigName === 'bControl') { masterConfig.gdsconfigformslave[iHideIndex].bControl = true; /* 控制字段bControl的显示与隐藏 */ } else { masterConfig.gdsconfigformslave[iHideIndex].bVisible = false; } } } } addState.masterConfig = masterConfig; } } } else { /* 主表字段根据条件控制 其他表格字段的显示与隐藏 */ const { [`${tbName}Config`]: tableConfig } = this.state; // const { controlConfig: tableConfig } = this.state; if (commonUtils.isNotEmptyObject(tableConfig)) { if (commonUtils.isNotEmptyArr(condition)) { let flag = false; for (const item of condition) { const { bFilterName, bFilterCondition, bFilterValue, } = item; if (bFilterCondition === '>') { if (tableDataRow[bFilterName] > bFilterValue) { flag = true; } } else if (bFilterCondition === '=') { if (tableDataRow[bFilterName] === bFilterValue) { flag = true; } } else if (bFilterCondition === '<') { if (tableDataRow[bFilterName] < bFilterValue) { flag = true; } } } if (flag) { if (commonUtils.isNotEmptyArr(showColumn)) { for (const column of showColumn) { const iShowIndex = tableConfig.gdsconfigformslave.findIndex(item => item.sName === column); if (iShowIndex > -1) { const sFiledObj = tableConfig.gdsconfigformslave[iShowIndex]; if (commonUtils.isNotEmptyObject(sFiledObj)) { tableConfig.gdsconfigformslave[iShowIndex].bVisible = true; } } } } if (commonUtils.isNotEmptyArr(hideColumn)) { for (const column of hideColumn) { const iHideIndex = tableConfig.gdsconfigformslave.findIndex(item => item.sName === column); if (iHideIndex > -1) { const sFiledObj = tableConfig.gdsconfigformslave[iHideIndex]; if (commonUtils.isNotEmptyObject(sFiledObj)) { tableConfig.gdsconfigformslave[iHideIndex].bVisible = false; } } } } if (commonUtils.isNotEmptyObject(tableConfig)) { const tableColumn = commonFunc.getHeaderConfig(tableConfig); // addState.masterConfig = masterConfig; // addState.controlConfig = tableConfig; /* 表格配置塞到addState中 */ // addState.controlColumn = tbColumn; addState[`${tbName}Config`] = tableConfig; addState[`${tbName}Column`] = tableColumn; } } } } } }); } } } } } return addState; } /* 下拉多选离开事件 */ handleTableBlur = async (name, sFileName, record, tableConfig) => { const { sModelsId, app } = this.props; const { controlData, slaveConfig,[`${name}Data`]: tableData } = this.state; let { slaveData: slaveDataOld, masterData, slaveDelData, } = this.state; const addState = {}; if(commonUtils.isEmptyArr(slaveDelData)) { slaveDelData = []; } if (sFileName === 'sPartsNameNew') { if(commonUtils.isNotEmptyArr(controlData)) { /* 离开时 把sPartsNameNewId数据挂载到sControlParentId */ let iIndex = controlData.findIndex(item => item.sId === record.sId); if(iIndex === -1) { if(record.sId && record.sId.split('-').length > 1) { iIndex = controlData.findIndex(item => item.sId === record.sId.split('-')[0]); } } if (iIndex > -1) { addState.sControlParentId = controlData[iIndex].sPartsNameNewId; if(commonUtils.isNotEmptyObject(controlData[iIndex].sPartsNameNewId)) { controlData[iIndex] = {...controlData[iIndex], ...addState}; this.props.onSaveState({ controlData: controlData }); } } } } else if (tableConfig.sDropDownType === 'movesql') { /* 通用字段离开调下拉事件 */ let slaveRow = record; const sqlDropDownData = await this.getSqlDropDownData(sModelsId, name, tableConfig, slaveRow); const dDropDownData = sqlDropDownData.dropDownData; const iIndex = tableData.findIndex(item => item.sId === record.sId); if (commonUtils.isNotEmptyArr(dDropDownData) && iIndex > -1) { slaveRow = { ...slaveRow, ...commonFunc.getAssignFieldValue(tableConfig.sAssignField, dDropDownData[0]) }; // 取赋值字段 slaveRow.handleType = commonUtils.isEmpty(slaveRow.handleType) ? 'update' : slaveRow.handleType; tableData[iIndex] = { ...tableData[iIndex] , ...slaveRow }; this.setState({ ...addState }); } } else if(commonUtils.isNotEmptyObject(tableConfig) && commonUtils.isNotEmptyObject(tableConfig.sButtonParam)) { let slaveNewData = []; const allConfig = { slaveConfig }; // console.log('sTmpInfoConfigArr', sTmpInfoConfigArr); const sTmpInfoConfig = tableConfig; const sButtonParam = tableConfig.sButtonParam; const btn = JSON.parse(sButtonParam); const sProName = btn.sproName; if (commonUtils.isNotEmptyObject(sTmpInfoConfig)) { const newCopyTo = {}; newCopyTo.master = masterData; // newCopyTo.slave = commonUtils.isEmpty(slaveData) ? [] : slaveData[0]; // const sRowData = copyTo.slaveData; const sRowData = masterData; const value = { sProName, sProInParam: JSON.stringify({ params: sRowData }) }; const url = `${commonConfig.server_host}procedureCall/doGenericProcedureCall?sModelsId=${sModelsId}`; const dataReturn = (await commonServices.postValueService(app.token, value, url)).data; console.log('dataReturn', dataReturn); if (dataReturn.code === 1) { if (commonUtils.isNotEmptyArr(slaveDataOld)) { slaveDataOld.forEach((item) => { item.handleType = 'del'; slaveDelData.push(item); }); addState.slaveDelData = slaveDelData; } const returnData = dataReturn.dataset.rows[0]; const slaveReturn = returnData.dataSet.proData; if (commonUtils.isNotEmptyArr(slaveReturn)) { slaveReturn.forEach((slaveItem) => { newCopyTo.slave = slaveItem; let slaveRow = commonFunc.getDefaultData(allConfig.slaveConfig, newCopyTo); // 取默认值 // if (salveDetailAssignField) { // slaveRow = {...slaveRow, ...commonFunc.getAssignFieldValue(salveDetailAssignField, copyTo.masterData, newCopyTo)}; // } else if (salveAssignField) { // slaveRow = {...slaveRow, ...commonFunc.getAssignFieldValue(salveAssignField, slaveItem, newCopyTo)}; // 取赋值字段 // } slaveRow = { ...slaveRow, ...slaveItem }; slaveRow.handleType = 'add'; slaveRow.sId = commonUtils.createSid(); slaveRow.sParentId = masterData.sId; slaveNewData.push(slaveRow); }); } addState.slaveData = slaveNewData; this.setState({ ...addState }); } else { this.getServiceError(dataReturn); } } } }; render() { return ( ); } }; };