/* eslint-disable prefer-destructuring */
import React, { Component } from 'react';
import { UploadOutlined } from '@ant-design/icons';
import { Form } from '@ant-design/compatible';
// import '@ant-design/compatible/assets/index.css';
import { Row, Col, Checkbox, Layout, Spin, Tabs, Avatar, Button, message, Table, Input, Upload } from 'antd-v4';
import * as commonFunc from '@/components/Common/commonFunc';/* 通用单据方法 */ /* 通用单据方法 */
import Toolbar from '@/components/Common/ToolBar/ToolBarNew';
import StaticEditTable from '@/components/Common/CommonTable';/* 可编辑表格 */
import styles from '@/index.less';
import CommonView from '@/components/Common/CommonView';
import CommonBase from '@/components/Common/CommonBase';/* 获取配置及数据 */
import * as commonBusiness from '@/components/Common/commonBusiness';/* 单据业务功能 */
import commonConfig from '@/utils/config';
import * as commonUtils from '@/utils/utils';/* 通用方法 */
import * as commonServices from '@/services/services';/* 服务类 */
import AddIcon from '@/assets/add.svg';
import DisableAddIcon from '@/assets/disableadd.svg';
import CopyIcon from '@/assets/copy.svg';
import CopyAllIcon from '@/assets/copyall.svg';
import DisableCopyIcon from '@/assets/disablecopy.svg';
import DisableCopyAllIcon from '@/assets/disablecopyall.svg';
import DelIcon from '@/assets/delete.svg';
import DisableDelIcon from '@/assets/disabledelete.svg';/* 获取配置及数据 */
import MaterialRemarkIcon from '@/assets/materialremark.svg';
import DisMaRemarklIcon from '@/assets/disablematerialremark.svg';
import ProcessIcon from '@/assets/process.svg';
import DisableProcessIcon from '@/assets/disableprocess.svg';
import MateriallIcon from '@/assets/material.svg';
import DisableMateriallIcon from '@/assets/disablematerial.svg';
import AntdDraggableModal from '@/components/Common/AntdDraggableModal';
import CommonListSelect from '@/components/Common/CommonListSelect';
import CommonListSelectTree from '@/components/Common/CommonListSelectTree';
import StaticEditTree from '@/components/Common/Tree/StaticTree';
import AddChildIcon from '@/assets/addChild.svg';
import DisableAddChildIcon from '@/assets/disableaddChild.svg';
import ContextMenuModal from '@/components/Common/ContextMenuModal';
import CommonDeliverSales from '@/components/Common/CommonBillDeliverEvent';
/* 继承销售模块业务功能 */
const width = '18px';
const height = '18px';
const setAdd = {
title: '增加',
width: { width },
height: { height },
img: ,
disableimg:
,
};
const setAddChild = {
title: '增加',
width: { width },
height: { height },
img:
,
disableimg:
,
};
const setCopy = {
title: '复制',
width: { width },
height: { height },
img:
,
disableimg:
,
};
const setCopyAll = {
title: '复制部件',
width: { width },
height: { height },
img:
,
disableimg:
,
};
const setDelete = {
title: '删除',
width: { width },
height: { height },
img:
,
disableimg:
,
};
const setProcess = {
title: '工序',
width: { width },
height: { height },
img:
,
disableimg:
,
};
const setMaterial = {
title: '材料',
width: { width },
height: { height },
img:
,
disableimg:
,
};
const { Header, Content, Sider } = Layout;
const { TabPane } = Tabs;
// const { confirm } = Modal;
class CommonBillDeliver extends Component {
constructor(props) {
super(props);
this.state = {
};
}
/** 行选择 */
onRowClick = (name, record) => {
if (name === 'control') {
this.props.onTableSelectRowChange(name, [record.sId]);
}
};
onChange = (checkedValues) => {
this.props.onSaveState({
dataPersonArray: checkedValues,
});
};
getMenuStatus = (menu) => {
if (menu.sControlName === 'BtnImport') {
return !this.props.enabled;
}
};
/** 上传后执行函数 */
handleUploadChangeFile = async (info) => {
const { file } = info;
const {
masterData, sModelsId, app, token, sModelsType, slaveConfig, slaveData,
} = this.props;
if (file.response) {
if (file.response.code === 1) {
/* 数据查询成功 */
const errorInfo = file.response.dataset.rows[0].nocanbeInsert;
if (commonUtils.isNotEmptyObject(errorInfo)) {
message.error(errorInfo[0].sReason);
return;
}
/* 把之前存放的数据删除 */
const slaveDelData = [];
if (commonUtils.isNotEmptyArr(slaveData)) {
slaveData.forEach((item) => {
if (commonUtils.isEmptyObject(item.handleType)) {
item.handleType = 'del';
slaveDelData.push(item);
}
});
}
const returnData = file.response.dataset.rows[0].canbeInsert;
let iCount = 0;
let productIdDropDown;
if (productIdDropDown === undefined && commonUtils.isNotEmptyArr(returnData)) { /* 无论导入多少条数据 都只调用1次接口,获取产品下拉数据集 */
const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductName');
if (iIndex > -1) {
const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', slaveConfig.gdsconfigformslave[iIndex], returnData[0]);
productIdDropDown = sqlDropDownData.dropDownData;
}
}
await returnData.forEach(async (tableDataRow) => {
tableDataRow.handleType = 'add';
tableDataRow.sId = commonUtils.createSid();
tableDataRow.sParentId = masterData.sId;
tableDataRow.key = tableDataRow.sId;
/* 若导入模板没有序号,则序号从1自增 */
if (commonUtils.isEmptyObject(tableDataRow.iOrder)) {
iCount += 1;
tableDataRow.iOrder = iCount;
}
for (const child of Object.keys(tableDataRow)) {
const index = child.indexOf('_sRealValue_');
if (index > -1) {
const property = child.substring(0, child.length - 12);
tableDataRow[property] = tableDataRow[child];
}
}
if (productIdDropDown !== undefined) {
const iProductIdIndex = productIdDropDown.findIndex(item => item.sId === tableDataRow.sProductId);
if (iProductIdIndex === -1 && commonUtils.isNotEmptyObject(sModelsType) && sModelsType.includes('sales/salesOrder')) { /* 只有销售模块生成新产品 盘点 ,期间 不生成新的产品 */
tableDataRow.sProductId = tableDataRow.sProductName;
tableDataRow.sProductInfo = JSON.stringify({
sProductId: tableDataRow.sProductName,
sProductName: tableDataRow.sProductName,
sProductStyle: tableDataRow.sProductStyle,
sProductUnit: tableDataRow.sProductUnit,
sProductNo: tableDataRow.sProductNo,
sCustomerProductNo: tableDataRow.sCustomerProductNo,
sProductClassifyId: tableDataRow.sProductClassifyId,
sProductClassifyName: tableDataRow.sProductClassifyName,
});
}
}
if (!tableDataRow.dNProductPrice) {
tableDataRow.dNProductPrice = tableDataRow.dProductForeignPrice;
}
const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('quotation/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
if (sModelsType.includes('purchase/') || sModelsType.includes('quotation/') || sModelsType.includes('manufacture/') || sModelsType.includes('materialsStock/') || sModelsType.includes('outside/')) {
tableDataRow = await this.props.onMaterialsChange(tableDataRow, sModelsId, masterData, {}, 'dAuxiliaryQty', app, token, models);
tableDataRow = commonBusiness.getCalculateAllMoney(app, models, 'dAuxiliaryQty', masterData, tableDataRow);
} else {
tableDataRow = commonBusiness.getCalculateAllMoney(app, models, 'dProductQty', masterData, tableDataRow);
}
});
this.props.onSaveState({ slaveData: returnData, slaveDelData });
} else { /* 失败s */
this.props.getServiceError(file.response);
}
}
};
handleUploadPropsSales = () => {
const { masterData, sModelsType } = this.props;
if (commonUtils.isNotEmptyObject(masterData)) {
const sCustomerId = commonUtils.isEmptyStr(masterData.sCustomerId) ? undefined : masterData.sCustomerId;
let existCustomerId = false;
if (sModelsType.includes('sales/') && commonUtils.isNotEmptyStr(sCustomerId)) {
existCustomerId = true;
} else if (!sModelsType.includes('sales/')) {
existCustomerId = true;
}
return {
disabled: !this.props.enabled || !existCustomerId, /* 是否可用 */
style: { display: commonUtils.convertBooleanToDisplayBlock(true) }, /* 是否显示 */
};
}
};
/** 上传后执行函数 */
handleBeforeUpload = () => {
// const isLt10M = file.size / 1024 / 1024 < 10;
// if (!isLt10M) {
// message.error(commonFunc.showMessage(this.props.app.commonConst, 'picMax'));/* 图片大小需小于10MB! */
// }
};
/** 图片上传后执行函数 */
handleUploadChange = (info, name) => {
const { file } = info;
if (file.response && file.response.code === 1) {
const sPicturePath = file.response.dataset.rows[0].savePathStr;
const uploadInfo = {
sPicturePath,
sFileName: file.name,
};
const { [`${name}Column`]: tableColumn, masterData, [`${name}Data`]: tableData } = this.props;
if (commonUtils.isNotEmptyArr(tableData) && commonUtils.isEmpty(tableData[tableData.length - 1].sPicturePath)) {
tableData[tableData.length - 1].sPicturePath = uploadInfo.sPicturePath;
tableData[tableData.length - 1] = { ...tableData[tableData.length - 1], sPicturePath: uploadInfo.sPicturePath, sFileName: uploadInfo.sFileName };
} else {
const tableDataRow = this.props.onDataRowAdd(name, true);
tableColumn.forEach((slaveChild) => {
const ckey = slaveChild.dataIndex;
if (ckey === 'sProductNo' || ckey === 'sProductName') {
tableDataRow[ckey] = masterData[ckey] !== undefined ? masterData[ckey] : '';
} else if (ckey === 'iOrder') {
tableDataRow[ckey] = '';
} else if (file.response && file.response.code === 1) {
if (uploadInfo[ckey] !== undefined) {
tableDataRow[ckey] = uploadInfo[ckey];
}
}
});
tableData.push(tableDataRow);
}
this.props.onSaveState({ [`${name}Data`]: tableData, enabled: true });
} else if (file.response && file.response.code === -1) {
message.error(file.response.msg);
}
};
handleOk = async (flag, tmpCheck, isWait) => {
const {
sModelsId, masterData, app, checkConditions, sCheckModelId, checkPersonData, currentId, masterConfig, slaveConfig, checkConfig, sCheckRemark,
} = this.props;
const { currentPane } = app;
const bCkxTmpCheck = app.systemData.filter(item => item.sName === 'CkxTmpCheck')[0].sValue;
if (bCkxTmpCheck === '1') {
const returnData = await this.props.onDataAudit(flag, tmpCheck, isWait);
if (returnData.code === 1) {
if (returnData.dataset.rows[0].dataSet.outData[0].sCode === 1) {
this.props.onGetData(masterConfig, slaveConfig, checkConfig);
message.success(returnData.msg);
} else {
message.error(returnData.dataset.rows[0].dataSet.outData[0].sReturn);
}
} else { /* 失败 */
this.props.getServiceError(returnData);
}
} else {
const dataPersonArray = commonUtils.isEmptyObject(this.props.dataPersonArray) ? [] : this.props.dataPersonArray;
if (commonUtils.isEmptyObject(dataPersonArray)) {
checkPersonData.forEach((item) => {
dataPersonArray.push(item.sUserId);
});
}
const dataPersonString = dataPersonArray.join(',');
const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
const value = {
sProName: 'Sp_System_AutoSendCheckMsg',
paramsMap: {
sFormGuid: sModelsId,
sBillKey: currentPane.sProcName,
sTbName: masterConfig.sTbName,
sGuid: masterData.sId,
sBillNo: masterData.sBillNo,
sCheckCondition: checkConditions,
sMemo: sCheckRemark,
sCheckModelGuid: sCheckModelId,
sCheckPerson: dataPersonString,
},
};
const returnData = (await commonServices.postValueService(app.token, value, url)).data;
if (returnData.code === 1) {
const noCheckMsg = commonFunc.showMessage(app.commonConst, 'NoCheckMsg'); /* 您有消息待审核 */
if (returnData.dataset.rows[0].dataSet.outData[0].sCode === 1) {
this.props.handleSendSocketMessage('examine', 'showImg', currentId, dataPersonString, noCheckMsg, null);
const urlCanCheckBill = `${commonConfig.server_host}checkModel/getCanCheckBill?sModelsId=${sModelsId}`;
const valueCanCheckBill = { sCheckModelId, checkPersonData, sBillId: masterData.sId };
const returnCanCheckBill = (await commonServices.postValueService(app.token, valueCanCheckBill, urlCanCheckBill)).data;
if (returnCanCheckBill.code === 1) {
if (returnCanCheckBill.dataset.rows[0].iCount === 1) {
this.props.onDataAudit(1, 1);
this.props.onSaveState({
visible: false,
});
return;
}
} else { /* 失败 */
this.props.getServiceError(returnCanCheckBill);
}
this.props.handleSendSocketMessage('reflush', 'showImg', currentId, dataPersonString, noCheckMsg, null);
message.success(returnData.msg);
} else {
message.error(returnData.dataset.rows[0].dataSet.outData[0].sReturn);
}
} else { /* 失败 */
this.props.getServiceError(returnData);
}
}
this.props.onSaveState({
visible: false,
});
};
handleCancel = () => {
this.props.onSaveState({
visible: false,
});
};
handleTableModal = async () => {
const {
sModelsId, controlData, masterData, slaveData, controlConfig, slaveSelectedRowKeys, enabled, slaveConfig, sModelsType,
} = this.props;
const addState = {};
let treeState = {};
if (this.props.sModelsType.includes('sales/salesOrder')) {
const iSlaveIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]);
const iIndex = controlData.findIndex(item => item.sSlaveId === slaveSelectedRowKeys[0]);
if (iIndex === -1 && iSlaveIndex > -1 && enabled) {
const allTableData = {};
allTableData.master = masterData;
allTableData.slaveData = slaveData;
let dropdownProductClassifyId;
const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductClassifyId');
if (iIndex > -1) {
const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', slaveConfig.gdsconfigformslave[iIndex]);
dropdownProductClassifyId = sqlDropDownData.dropDownData;
}
if (commonUtils.isEmptyArr(dropdownProductClassifyId)) {
const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductClassifyName');
if (iIndex > -1) {
const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', slaveConfig.gdsconfigformslave[iIndex]);
dropdownProductClassifyId = sqlDropDownData.dropDownData;
}
}
if (commonUtils.isNotEmptyArr(dropdownProductClassifyId)) {
const iProductClassifyIdIndex = dropdownProductClassifyId.findIndex(item => item.sId === slaveData[iSlaveIndex].sProductClassifyId);
if (commonUtils.isNotEmptyObject(dropdownProductClassifyId[iProductClassifyIdIndex])) {
const sAllPartsName = dropdownProductClassifyId[iProductClassifyIdIndex].sAllPartsName;
if (commonUtils.isNotEmptyStr(sAllPartsName)) {
const sAssignFieldObj = sAllPartsName.split(',');
for (const child of sAssignFieldObj) {
const tableDataRowAdd = commonFunc.getDefaultData(controlConfig, allTableData);
tableDataRowAdd.handleType = 'add';
tableDataRowAdd.sId = commonUtils.createSid();
tableDataRowAdd.sParentId = masterData && masterData.sId ? masterData.sId : null;
tableDataRowAdd.sSlaveId = slaveSelectedRowKeys[0];
tableDataRowAdd.key = tableDataRowAdd.sId;
tableDataRowAdd.bDefault = false;
tableDataRowAdd.iOrder = 0;
tableDataRowAdd.sPartsName = child;
tableDataRowAdd.dPartsQty = commonUtils.isNull(slaveData[iSlaveIndex].dProductQty, 0) + commonUtils.isNull(slaveData[iSlaveIndex].dGiveQty, 0) + commonUtils.isNull(slaveData[iSlaveIndex].dStockupQty, 0);
tableDataRowAdd.sAllId = tableDataRowAdd.sId;
tableDataRowAdd.sControlParentId = '';
controlData.push(tableDataRowAdd);
}
}
}
}
addState.controlData = controlData;
}
if (controlData !== undefined) {
const iControlIndex = controlData.findIndex(item => item.sSlaveId === slaveSelectedRowKeys[0]);
if (iControlIndex > -1) {
addState.controlSelectedRowKeys = [controlData[iControlIndex].sId];
}
}
if (sModelsType === 'sales/salesOrderPack') {
const sSlaveId = slaveSelectedRowKeys[0];
if (commonUtils.isNotEmptyObject(sSlaveId)) {
treeState = this.props.onGetControlTreeData(controlData, true, sSlaveId);
}
}
}
this.props.onSaveState({
visibleModal: true,
...addState,
...treeState,
});
};
handleTableChooseProcess = () => {
const { processConfig } = this.props;
const iIndex = processConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnChooseProcess');
if (iIndex > -1) {
this.props.onBtnChoose('process', 'BtnChooseProcess', processConfig.gdsconfigformslave[iIndex]);
}
};
handleCancelModal = (modelVisible) => {
this.props.onSaveState({
[modelVisible]: false,
});
};
handleOkModal = async () => {
const {
controlData, materialsData, processData, slaveData, slaveSelectedRowKeys,
} = this.props;
const ctData = controlData.filter(item => item.handleType !== 'del' && item.sSlaveId === slaveSelectedRowKeys[0]);
const mtData = materialsData.filter(item => item.handleType !== 'del' && item.sSlaveId === slaveSelectedRowKeys[0]);
const pData = processData.filter(item => item.handleType !== 'del' && item.sSlaveId === slaveSelectedRowKeys[0] && item.sType !== '3');
const p3Data = processData.filter(item => item.handleType !== 'del' && item.sSlaveId === slaveSelectedRowKeys[0] && item.sType === '3'); /* 成品工序 */
if (commonUtils.isNotEmptyArr(ctData)) {
let mDetail = '';
let pDetail = '';
const slaveIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]);
await ctData.forEach((controlItem, n) => {
if (commonUtils.isNotEmptyObject(controlItem.sPartsName)) {
const qz = n === 0 ? '' : ' ';
if (commonUtils.isNotEmptyObject(controlItem.sPartsName)) {
const yDetail = `${mDetail}${qz}#${controlItem.sPartsName}:`;
const gDetail = `${pDetail}${qz}#${controlItem.sPartsName}:`;
let imDetail = '';
let ipDetail = '';
const materials = mtData.filter(materialsItem => (materialsItem.sControlId === controlItem.sId));
// let materialsIdDropDown;
// const materialsIndex = materialsConfig.gdsconfigformslave.findIndex(item => item.sName === 'sMaterialsName');
// if (materialsIndex > -1) {
// const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'materials', materialsConfig.gdsconfigformslave[materialsIndex]);
// materialsIdDropDown = sqlDropDownData.dropDownData;
// }
materials.forEach((mItem, i) => {
const fh = i === 0 ? '' : ',';
imDetail = `${imDetail}${fh} ${mItem.sMaterialsName}`;
});
// processPropsType
const process = pData.filter(processItem => (processItem.sControlId === controlItem.sId));
// let processIdDropDown;
// const processIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProcessName');
// if (processIndex > -1) {
// const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'process', processConfig.gdsconfigformslave[processIndex]);
// processIdDropDown = sqlDropDownData.dropDownData;
// }
// const processIdDropDown = commonUtils.getStoreDropDownData(sModelsId, 'process', 'sProcessName');
process.forEach((pItem, i) => {
const fh = i === 0 ? '' : ',';
ipDetail = `${ipDetail}${fh} ${pItem.sProcessName}`;
});
if (commonUtils.isNotEmptyObject(imDetail)) {
mDetail = `${yDetail}${imDetail}`;
}
if (commonUtils.isNotEmptyObject(ipDetail)) {
pDetail = `${gDetail}${ipDetail}`;
}
}
}
});
/* 成品工序 */
let ip3Detail = '';
if (commonUtils.isNotEmptyArr(p3Data)) {
p3Data.forEach((pItem, i) => {
const fh = i === 0 ? '' : ',';
ip3Detail = `${ip3Detail}${fh} ${pItem.sProcessName}`;
});
}
if (commonUtils.isNotEmptyObject(ip3Detail)) {
if (commonUtils.isNotEmptyObject(pDetail)) {
pDetail = `${pDetail},${ip3Detail}`;
} else {
pDetail = ip3Detail;
}
}
slaveData[slaveIndex].sMaterialsMemo = mDetail;
slaveData[slaveIndex].sProcessMemo = pDetail;
slaveData[slaveIndex].handleType = commonUtils.isEmpty(slaveData[slaveIndex].handleType) ? 'update' : slaveData[slaveIndex].handleType;
} else if (commonUtils.isNotEmptyArr(controlData) && commonUtils.isEmptyArr(ctData)) {
const sSlaveId = controlData[0].sSlaveId;
const slaveIndex = slaveData.findIndex(item => item.sId === sSlaveId);
slaveData[slaveIndex].sMaterialsMemo = '';
slaveData[slaveIndex].sProcessMemo = '';
slaveData[slaveIndex].handleType = commonUtils.isEmpty(slaveData[slaveIndex].handleType) ? 'update' : slaveData[slaveIndex].handleType;
}
this.props.onSaveState({
visibleModal: false,
controlData,
materialsData,
processData,
slaveData,
});
};
/** 控制选择控制表时,显示部件工序与成品工序 */
handleFilterSlaveData = (name, dataIndex, value, record) => {
return (commonUtils.isNotEmptyStr(record.sSlaveId) && record.sSlaveId.toString().toLowerCase().includes(value.toLowerCase()));
};
/** 控制选择控制表时,显示部件工序与成品工序 */
handleFilterData = (name, dataIndex, value, record) => {
const { slaveSelectedRowKeys } = this.props;
if (name === 'process') {
return (commonUtils.isNotEmptyStr(record.sType) && record.sType === '3' &&
commonUtils.isNotEmptyStr(record.sSlaveId) && record.sSlaveId.toString().toLowerCase().includes(slaveSelectedRowKeys.toString().toLowerCase())) ||
(commonUtils.isNotEmptyStr(record.sControlId) && record.sControlId.toString().toLowerCase().includes(value.toLowerCase()) &&
commonUtils.isNotEmptyStr(record.sSlaveId) && record.sSlaveId.toString().toLowerCase().includes(slaveSelectedRowKeys.toString().toLowerCase()));
} else if (name === 'slaveChild') {
return commonUtils.isNotEmptyStr(record.sDelivergooodSlaveId) && record.sDelivergooodSlaveId.toString().toLowerCase().includes(slaveSelectedRowKeys.toString().toLowerCase());
} else {
return (commonUtils.isNotEmptyStr(record.sType) && record.sType === '2' &&
commonUtils.isNotEmptyStr(record.sSlaveId) && record.sSlaveId.toString().toLowerCase().includes(slaveSelectedRowKeys.toString().toLowerCase())) ||
(commonUtils.isNotEmptyStr(record.sControlId) && record.sControlId.toString().toLowerCase().includes(value.toLowerCase()) &&
commonUtils.isNotEmptyStr(record.sSlaveId) && record.sSlaveId.toString().toLowerCase().includes(slaveSelectedRowKeys.toString().toLowerCase()));
}
// (commonUtils.isNotEmptyStr(record.sControlId) && record.sControlId.toString().toLowerCase().includes(value.toLowerCase()));
};
/* 控制表过滤材料表 工序表数据 */
handleGetFilterData = (name) => {
const { [`${name}Data`]: data, controlSelectedRowKeys, slaveSelectedRowKeys } = this.props;
if (data !== undefined) {
const newArr = data.filter((item) => {
if (name === 'control') {
return (commonUtils.isNotEmptyStr(item.sSlaveId) && item.sSlaveId.toString().toLowerCase().includes(slaveSelectedRowKeys.toString()));
} else {
return (commonUtils.isNotEmptyStr(item.sControlId) && item.sControlId.toString().toLowerCase().includes(controlSelectedRowKeys.toString()) &&
commonUtils.isNotEmptyStr(item.sSlaveId) && item.sSlaveId.toString().toLowerCase().includes(slaveSelectedRowKeys.toString()));
}
});
return newArr.length;
}
};
/* 包装工单过滤行 */ /** 控制选择控制表时,显示部件工序与成品工序 */
handleFilterDataPack = (name, dataIndex, value, record) => {
if (name === 'process') {
return (commonUtils.isNotEmptyStr(record.sType) && record.sType === '3') ||
(commonUtils.isNotEmptyStr(record.sControlId) && record.sControlId.toString().toLowerCase().includes(value.toLowerCase()));
} else {
return (commonUtils.isNotEmptyStr(record.sType) && record.sType === '2') ||
(commonUtils.isNotEmptyStr(record.sControlId) && record.sControlId.toString().toLowerCase().includes(value.toLowerCase()));
}
};
/* 控制表过滤材料表 工序表数据 */
handleGetFilterDataPack = (name) => {
const { [`${name}Data`]: data, controlSelectedRowKeys } = this.props;
if (data !== undefined && commonUtils.isNotEmptyArr(controlSelectedRowKeys)) {
const newArr = data.filter((item) => {
return (commonUtils.isNotEmptyStr(item.sControlId) && item.sControlId.toString().toLowerCase().includes(controlSelectedRowKeys.toString()));
});
return newArr.length;
}
};
/** 添加表格空行 */
handleTableAdd = async (name, flag, bchild) => {
/* 外置处理业务 */
const {
sModelsId, sModelsType, gdsformconst, slaveData, controlData, controlSelectedRowKeys, [`${name}Data`]: tableData, slaveSelectedRowKeys, slaveConfig,
} = this.props;
let tableDataRow = {};
if (name === 'control') {
const {
[`${name}SelectedRowKeys`]: treeSelectedKeys,
} = this.props;
if ((bchild === 'childNode' || bchild === 'sameNode') && (commonUtils.isEmptyArr(treeSelectedKeys) || commonUtils.isEmptyArr(controlSelectedRowKeys))) {
message.warn('请选择部件!'); // 请选择部件
return;
}
tableDataRow = this.props.onDataRowAdd(name, true);
if (commonUtils.isEmptyObject(tableDataRow)) {
return;
}
let dPartsQty = 0;
if (commonUtils.isNotEmptyArr(slaveData)) {
slaveData.forEach((item) => {
dPartsQty += commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0);
});
let productIdDropDown;
const slaveIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductName');
if (slaveIndex > -1) {
const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', slaveConfig.gdsconfigformslave[slaveIndex]);
productIdDropDown = sqlDropDownData.dropDownData;
}
if (productIdDropDown) {
const iProductIdIndex = productIdDropDown.findIndex(item => item.sId === slaveData[0].sProductId);
if (iProductIdIndex > -1) {
tableDataRow.sPartsName = productIdDropDown[iProductIdIndex].sProductName;
}
}
}
const iSlaveIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]);
if (iSlaveIndex > -1) {
if (sModelsType.includes('sales/salesOrder')) {
if (!commonUtils.isEmpty(slaveData[iSlaveIndex].dProductQty)) {
tableDataRow.dPartsQty = commonUtils.isNull(slaveData[iSlaveIndex].dProductQty, 0) + commonUtils.isNull(slaveData[iSlaveIndex].dGiveQty, 0);
}
} else {
tableDataRow.dPartsQty = dPartsQty;
}
tableDataRow.sSlaveId = slaveData[iSlaveIndex].sId;
}
/* 树形部件节点增加同级部件、增加子级部件 */
if (sModelsType === 'sales/salesOrderPack') {
if (bchild === 'sameNode') { /* 添加同级 */
const iIndex = controlData.findIndex(item => item.sId === treeSelectedKeys[0]);
/* 找到同级子元素的sControlParentId */
if (iIndex > -1) {
tableDataRow.sControlParentId = controlData[iIndex].sControlParentId;
/* 找到同级父级sAllId */
const pId = controlData[iIndex].sControlParentId;
const sControlParentId = controlData.findIndex(item => item.sId === pId);
if (sControlParentId > -1) {
const sAllId = controlData[sControlParentId].sAllId;
if (commonUtils.isEmptyObject(sAllId)) {
message.warn('部件数据生成错误![sAllId为空]');
return;
}
tableDataRow.sAllId = `${controlData[sControlParentId].sAllId},${tableDataRow.sId}`;
} else {
tableDataRow.sAllId = tableDataRow.sId;
}
}
}
if (bchild === 'childNode') { /* 添加子级 */
tableDataRow.sControlParentId = treeSelectedKeys[0];
const iIndex = controlData.findIndex(item => item.sId === treeSelectedKeys[0]);
if (iIndex > -1) {
const sAllId = controlData[iIndex].sAllId;
if (commonUtils.isEmptyObject(sAllId)) {
message.warn('子部件数据生成错误![sAllId为空]'); // 获取父节点的sAllId
return;
}
tableDataRow.sAllId = `${controlData[iIndex].sAllId},${tableDataRow.sId}`;
}
}
}
tableData.push(tableDataRow);
let treeState = [];
if (sModelsType === 'sales/salesOrderPack') {
treeState = this.props.onGetControlTreeData(tableData, true, tableDataRow.sSlaveId);
}
this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: [tableDataRow.sId], ...treeState });
} else if (name === 'materials' || name === 'process') {
tableDataRow = this.props.onDataRowAdd(name, true);
if (commonUtils.isEmptyArr(controlSelectedRowKeys)) {
const msg = commonFunc.showMessage(gdsformconst, 'pleaseChooseParts');
message.warn(msg === '' ? '请选择部件' : msg); // 请选择部件
return;
}
const iIndex = controlData.findIndex(item => item.sId === controlSelectedRowKeys[0]);
const iSlaveIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]);
if (iIndex > -1 && iSlaveIndex > -1) {
if (commonUtils.isEmpty(controlData[iIndex].sPartsName) === '') {
message.warn(commonFunc.showMessage(gdsformconst, 'partsNameNotNull')); // 部件名称不能为空
return;
}
tableDataRow.sSlaveId = slaveData[iSlaveIndex].sId;
tableDataRow.sControlId = controlData[iIndex].sId;
tableDataRow.sPartsName = controlData[iIndex].sPartsName;
}
tableData.push(tableDataRow);
this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: [tableDataRow.sId] });
} else {
this.props.onDataRowAdd(name, flag);
}
};
/** 删除表格数据 */
otherTableDel = (name, tableSelectedRowKeys) => {
const tableData = this.props[`${name}Data`];
let tableDelData = this.props[`${name}DelData`];
tableDelData = commonUtils.isEmptyArr(tableDelData) ? [] : tableDelData;
for (const sId of tableSelectedRowKeys) {
/* 看看删除集合和从表中是否都存在该条数据 */
let tableDataIndex = tableData.findIndex(item => item.sControlId === sId);
while (tableDataIndex > -1) {
/* 删除从表中的数据并存入删除集合中 */
const slaveDataFilter = tableData[tableDataIndex];
tableData.splice(tableDataIndex, 1);
slaveDataFilter.handleType = 'del';
tableDelData.push(slaveDataFilter);
tableDataIndex = tableData.findIndex(item => item.sControlId === sId);
}
}
return { [`${name}Data`]: tableData, [`${name}DelData`]: tableDelData, [`${name}SelectedRowKeys`]: [] };
};
otherDeliverTableDel = (name, tableSelectedRowKeys) => {
const tableData = this.props[`${name}Data`];
let tableDelData = this.props[`${name}DelData`];
tableDelData = commonUtils.isEmptyArr(tableDelData) ? [] : tableDelData;
for (const sId of tableSelectedRowKeys) {
/* 看看删除集合和从表中是否都存在该条数据 */
let tableDataIndex = tableData.findIndex(item => item.sDelivergooodSlaveId === sId);
while (tableDataIndex > -1) {
/* 删除从表中的数据并存入删除集合中 */
const slaveDataFilter = tableData[tableDataIndex];
tableData.splice(tableDataIndex, 1);
slaveDataFilter.handleType = 'del';
tableDelData.push(slaveDataFilter);
tableDataIndex = tableData.findIndex(item => item.sDelivergooodSlaveId === sId);
}
}
return { [`${name}Data`]: tableData, [`${name}DelData`]: tableDelData, [`${name}SelectedRowKeys`]: [] };
};
/** 删除表格数据 */
handleTableDel = (name, isWait, tableSelectedRowKeys, isTree) => {
const {
sModelsType, slaveSelectedRowKeys, slaveData,
} = this.props;
if (name === 'control') {
// const tableSelectedRowKeys = this.props[`${name}SelectedRowKeys`]; /* 删除时,选中行取删除参数传过来的 */
const {
controlData, treeSelectedKeys, [`${name}SelectedRowKeys`]: tableSelectedRowKeys,
} = this.props;
if (isTree) {
/* 删除该节点及所有子节点 */
const controlChildData = controlData.filter(item => commonUtils.isNotEmptyObject(item.sAllId) && item.sAllId.indexOf(treeSelectedKeys[0]) > -1 && item.sId !== treeSelectedKeys[0]);
if (commonUtils.isNotEmptyArr(controlData)) {
controlChildData.forEach((itemNew) => {
tableSelectedRowKeys.push(itemNew.sId);
});
}
}
if (commonUtils.isNotEmptyArr(tableSelectedRowKeys)) {
const materialsReturnData = this.otherTableDel('materials', tableSelectedRowKeys);
const processReturnData = this.otherTableDel('process', tableSelectedRowKeys);
const controlReturnData = this.props.onDataRowDel(name, isWait, tableSelectedRowKeys);
let treeState = [];
if (sModelsType === 'sales/salesOrderPack') {
const iSlaveIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]);
if (iSlaveIndex > -1) {
const sSlaveId = slaveData[iSlaveIndex].sId;
treeState = this.props.onGetControlTreeData(controlReturnData.controlData, true, sSlaveId);
}
}
this.props.onSaveState({
...materialsReturnData,
...processReturnData,
...controlReturnData,
...treeState,
});
return true;
} else {
message.warn('请选择要删除的部件!');
return false;
}
} else if (name === 'slave' && sModelsType === 'sales/salesSgoods') {
if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) {
const slaveChildReturnData = this.otherDeliverTableDel('slaveChild', slaveSelectedRowKeys);
const slaveReturnData = this.props.onDataRowDel(name, isWait, slaveSelectedRowKeys);
this.props.onSaveState({
...slaveChildReturnData,
...slaveReturnData,
});
return true;
}
} else {
return this.props.onDataRowDel(name, isWait, tableSelectedRowKeys);
}
};
/** 销售订单删除从表数据时也删除控制材料工序表数据 */
handleSlaveTableDel = (name, isWait, tableSelectedRowKeys) => {
const {
sModelsType, controlData, processData, materialsData,
} = this.props;
if (sModelsType === 'sales/salesOrder' && name === 'slave') {
const controlDataDel = controlData.filter(item => item.sSlaveId === tableSelectedRowKeys[0]);
const controlDataSelectedRowKeys = [];
if (!commonUtils.isEmpty(controlDataDel)) {
for (const item of controlDataDel) {
const materialsDataSelectedRowKey = item.sId;
controlDataSelectedRowKeys.push(materialsDataSelectedRowKey);
}
if (commonUtils.isNotEmptyArr(controlDataSelectedRowKeys)) {
this.props.onDataRowDel('control', isWait, controlDataSelectedRowKeys, true);
}
const materialsDataDel = materialsData.filter(item => item.sSlaveId === tableSelectedRowKeys[0]);
const materialsDataSelectedRowKeys = [];
if (!commonUtils.isEmpty(materialsDataDel)) {
for (const item of materialsDataDel) {
const materialsDataSelectedRowKey = item.sId;
materialsDataSelectedRowKeys.push(materialsDataSelectedRowKey);
}
}
if (commonUtils.isNotEmptyArr(materialsDataSelectedRowKeys)) {
this.props.onDataRowDel('materials', isWait, materialsDataSelectedRowKeys, true);
}
const processDataDel = processData.filter(item => item.sSlaveId === tableSelectedRowKeys[0]);
const processDataSelectedRowKeys = [];
if (!commonUtils.isEmpty(processDataDel)) {
for (const item of processDataDel) {
const processDataSelectedRowKey = item.sId;
processDataSelectedRowKeys.push(processDataSelectedRowKey);
}
}
if (commonUtils.isNotEmptyArr(processDataSelectedRowKeys)) {
this.props.onDataRowDel('process', isWait, processDataSelectedRowKeys, true);
}
}
}
return this.props.onDataRowDel(name, isWait, tableSelectedRowKeys);
};
handleSelect = async (name, selectConfig, selectData) => {
const {
[`${name}Data`]: tableData, [`${name}Config`]: tableConfig, masterData, masterConfig, controlSelectedRowKeys, sModelsId, token, app, tableName, sModelsType,
} = this.props;
const tableSelectedRowKeys = [];
if (name === 'productProcessInfo') {
if (commonUtils.isNotEmptyArr(selectData)) {
let slaveData = [];
let controlData = [];
let materialsData = [];
let processData = [];
let sConfigMasterIdSlave = '';
let sConfigMasterIdControl = '';
let sConfigMasterIdMaterials = '';
let sConfigMasterIdProcess = '';
const selectRowData = selectData[0];
const sConfigIdString = masterConfig.gdsconfigformslave.filter(item => item.sName === 'sConfigId')[0].showDropDown;
if (commonUtils.isNotEmptyStr(sConfigIdString)) {
const sConfigId = JSON.parse(sConfigIdString);
sConfigMasterIdSlave = sConfigId.sConfigMasterIdSlave;
sConfigMasterIdControl = sConfigId.sConfigMasterIdControl;
sConfigMasterIdMaterials = sConfigId.sConfigMasterIdMaterials;
sConfigMasterIdProcess = sConfigId.sConfigMasterIdProcess;
}
if (commonUtils.isEmptyStr(sConfigMasterIdSlave)) {
message.warning(commonFunc.showMessage(app.commonConst, 'slaveParameterErro'));
}
if (commonUtils.isEmptyStr(sConfigMasterIdControl)) {
message.warning(commonFunc.showMessage(app.commonConst, 'controlParameterErro'));
}
if (commonUtils.isEmptyStr(sConfigMasterIdMaterials)) {
message.warning(commonFunc.showMessage(app.commonConst, 'materialsParameterErro'));
}
if (commonUtils.isEmptyStr(sConfigMasterIdProcess)) {
message.warning(commonFunc.showMessage(app.commonConst, 'processParameterErro'));
}
const slaveUrl = `${commonConfig.server_host}business/getBusinessDataByFormcustomId/${sConfigMasterIdSlave}?sModelsId=${sModelsId}`;
const value = { sSqlCondition: { sParentId: selectRowData.sId } };
const slaveReturnData = (await commonServices.postValueService(token, value, slaveUrl)).data;
if (slaveReturnData.code === 1) {
slaveData = slaveReturnData.dataset.rows[0].dataSet;
slaveData.forEach((item) => {
item.handleType = 'add';
item.sId = commonUtils.createSid();
item.sParentId = masterData.sId;
});
} else {
this.props.getServiceError(slaveReturnData);
}
const controlUrl = `${commonConfig.server_host}business/getBusinessDataByFormcustomId/${sConfigMasterIdControl}?sModelsId=${sModelsId}`;
const controlReturnData = (await commonServices.postValueService(token, value, controlUrl)).data;
if (controlReturnData.code === 1) {
controlData = controlReturnData.dataset.rows[0].dataSet;
controlData.forEach((item) => {
item.handleType = 'add';
item.sId = commonUtils.createSid();
item.sParentId = masterData.sId;
});
} else {
this.props.getServiceError(controlReturnData);
}
const materialsUrl = `${commonConfig.server_host}business/getBusinessDataByFormcustomId/${sConfigMasterIdMaterials}?sModelsId=${sModelsId}`;
const materialsReturnData = (await commonServices.postValueService(token, value, materialsUrl)).data;
if (materialsReturnData.code === 1) {
materialsData = materialsReturnData.dataset.rows[0].dataSet;
materialsData.forEach((item) => {
item.handleType = 'add';
item.sId = commonUtils.createSid();
item.sParentId = masterData.sId;
});
} else {
this.props.getServiceError(materialsReturnData);
}
const processUrl = `${commonConfig.server_host}business/getBusinessDataByFormcustomId/${sConfigMasterIdProcess}?sModelsId=${sModelsId}`;
const processReturnData = (await commonServices.postValueService(token, value, processUrl)).data;
if (processReturnData.code === 1) {
processData = processReturnData.dataset.rows[0].dataSet;
processData.forEach((item) => {
item.handleType = 'add';
item.sId = commonUtils.createSid();
item.sParentId = masterData.sId;
});
} else {
this.props.getServiceError(processReturnData);
}
this.props.onSaveState({
processData, materialsData, controlData, slaveData, [`${name}ChooseVisible`]: false, [`${name}SelectedRowKeys`]: tableSelectedRowKeys,
});
}
} else if (tableName === 'slave' && selectConfig.sControlName === 'BtnChooseMaterials') {
this.props.onSelect('slave', selectConfig, selectData);
} else if (sModelsType.includes('cashier/') && selectConfig.sControlName === 'BtnImportFormData') {
const { slaveData } = this.props;
let tableDataNew = [];
if (commonUtils.isNotEmptyArr(slaveData)) {
tableDataNew = slaveData;
tableDataNew.forEach((item, index) => {
const handleType = item.handleType;
if (commonUtils.isEmptyObject(handleType) || handleType === 'update') {
tableDataNew[index] = { ...item, handleType: 'del' };
}
});
}
if (commonUtils.isNotEmptyArr(selectData)) {
selectData.forEach((item) => {
let tableDataRow = {}; // 取默认值
tableDataRow = { ...tableDataRow, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item) }; // 取赋值字段
tableDataRow.handleType = 'add';
tableDataRow.sId = commonUtils.createSid();
tableDataRow.sParentId = masterData.sId;
tableDataNew.push(tableDataRow);
});
this.props.onSaveState({ slaveData: tableDataNew, importFormDataVisible: false });
}
} else {
const { controlData, slaveData, slaveSelectedRowKeys } = this.props;
const iIndex = commonUtils.isNotEmptyArr(controlSelectedRowKeys) ? controlData.findIndex(item => item.sId === controlSelectedRowKeys[0]) : -1;
if (commonUtils.isNotEmptyArr(selectData)) {
selectData.forEach((item) => {
const newCopyTo = {};
newCopyTo.master = masterData;
if (iIndex > -1) {
newCopyTo.control = controlData[iIndex];
}
let tableDataRow = commonFunc.getDefaultData(tableConfig, newCopyTo); // 取默认值
tableDataRow = { ...tableDataRow, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo) }; // 取赋值字段
tableDataRow.handleType = 'add';
tableDataRow.sId = commonUtils.createSid();
tableDataRow.sParentId = masterData.sId;
if (this.props.sModelsType.includes('sales/salesOrder')) {
const iSlaveIndex = commonUtils.isNotEmptyArr(slaveSelectedRowKeys) ? slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]) : -1;
if (iSlaveIndex > -1) {
tableDataRow.sSlaveId = slaveData[iSlaveIndex].sId;
}
}
if (iIndex > -1 && tableDataRow.sType !== '3') {
tableDataRow.sControlId = controlData[iIndex].sId;
tableDataRow.sPartsName = controlData[iIndex].sPartsName;
tableData.push(tableDataRow);
} else if (tableDataRow.sType === '3') {
tableData.push(tableDataRow);
}
tableSelectedRowKeys.push(tableDataRow.sId);
});
}
const tableDataNew = this.sortData(controlData, tableData);
this.props.onSaveState({ [`${name}Data`]: tableDataNew, [`${name}ChooseVisible`]: false, [`${name}SelectedRowKeys`]: tableSelectedRowKeys });
}
};
/** 树节点选中 */
handleTreeSelect = (name, checkedKeys, e) => {
let { controlSelectedRowKeys } = this.props;
controlSelectedRowKeys = checkedKeys; /* 把树形选中节点赋值给表格部件选中节点 */
this.props.onTreeSelect(name, checkedKeys, e);
this.props.onSaveState({
controlSelectedRowKeys,
});
};
sortData = (tableData, processData) => {
processData.sort((g1, g2) => {
const iIndex1 = tableData.findIndex(item => item.sId === g1.sControlId) === -1 ? 999 : tableData.findIndex(item => item.sId === g1.sControlId);
let sPartOrder1 = `0000${iIndex1}`;
sPartOrder1 = sPartOrder1.substring(sPartOrder1.length - 3);
let sOrder1 = `000${g1.iOrder}`;
sOrder1 = sOrder1.substring(sOrder1.length - 3);
const iIndex2 = tableData.findIndex(item => item.sId === g2.sControlId) === -1 ? 999 : tableData.findIndex(item => item.sId === g2.sControlId);
let sPartOrder2 = `0000${iIndex2}`;
sPartOrder2 = sPartOrder2.substring(sPartOrder2.length - 3);
let sOrder2 = `000${g2.iOrder}`;
sOrder2 = sOrder2.substring(sOrder2.length - 3);
return parseInt(sPartOrder1 + g1.sType + sOrder1, 10) - parseInt(sPartOrder2 + g2.sType + sOrder2, 10);
});
return processData;
};
handleGetDataOk = () => {
this.props.onDataImport('zero');
}
handleGetDataCancel = () => {
this.props.onDataImport('all');
}
colseGetDataVisible = () => {
this.props.onSaveState({ isGetDataVisible: false });
}
/* 审核备注文本框改变事件 */
textChange= (e, record) => {
const sCheckRemark = commonUtils.isNotEmptyObject(record) && commonUtils.isNotEmptyObject(e.target.value) ? e.target.value : '';
this.props.onSaveState({ sCheckRemark });/* 审核备注 */
}
// ----------------------------数据修改回带end ---------------------------- //
render() {
const {
pageLoading, masterConfig, visible, checkConditions, checkPersonData, visibleModal, processChooseVisible, materialsChooseVisible, app, sTabId, sModelsType, enabled, slaveSelectedRowKeys,
} = this.props;
const checkCondition = commonFunc.showMessage(app.commonConst, 'checkCondition');/* 审核条件 */
const checkSmemo = commonFunc.showMessage(app.commonConst, 'checkSmemo');/* 备注 */
const columns = [{
title: checkCondition,
dataIndex: 'condition',
key: 'condition',
}, {
title: checkSmemo,
dataIndex: 'sMemo',
key: 'sMemo',
render: (text, record) => {
return (