/* eslint-disable */
/* eslint-disable prefer-destructuring,no-await-in-loop,radix,,no-loop-func */
/**
* Created by pm on 2021-08-17 用于送货单个性化.
*/
import React, { Component } from 'react';
import { Modal, Progress } from 'antd-v4';
import { message } from '@/utils/common/message';
import moment from 'moment';
import * as commonUtils from '../../utils/utils'; /* 通用方法 */
import * as commonBusiness from './commonBusiness'; /* 单据业务功能 */
import * as commonServices from '../../services/services'; /* 服务类 */
import commonConfig from '../../utils/config';
import * as commonFunc from './commonFunc';
import { cloneDeep } from 'lodash';
import styles from '@/components/Common/ToolBar/index.less';
const { confirm } = Modal;
export default (ChildComponent) => {
return class extends Component {
constructor(props) {
super(props);
this.state = {
changleCustomerId: '',
dPackQtyChange: 0,
};
this.form = {}; /* 表单对象 */
const { sModelsId, sModelsType } = props;
if (sModelsType.includes('cashier/')) {
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerId', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerNo', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerName', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyId', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyNo', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyName', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyId', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyNo', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyName', []);
}
commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sSrcNo', []);
}
async componentWillReceiveProps(nextProps) {
const {
formData, currentId, sModelsType, formRoute,
} = nextProps;
const {
slaveConfig: slaveConfigOld,
masterConfig: masterConfigOld,
app,
employeeConfig: employeeConfigOld,
} = nextProps;
if (commonUtils.isEmptyObject(slaveConfigOld) && formData.length > 0 && (sModelsType !== 'cashier/financialTransfer' && sModelsType !== 'cashier/financialAdjustment' && sModelsType !== 'quality/accident' && sModelsType !== 'purchase/purchaseEnquiry' && sModelsType !== 'complaint/complaint' && sModelsType !== 'print/printLabel' && sModelsType !== 'commonBill/onlyMaster' && formRoute.indexOf('indexOee') === -1)) {
const sId = currentId || nextProps.masterData?.sId || '';
/* 数据Id */
const masterConfig = formData.filter(item => !item.bGrd)[0];
const BtnDesignFunctionConfig = commonUtils.isNotEmptyObject(masterConfig) ? masterConfig.gdsconfigformslave.filter(item => item.sControlName === 'BtnBsOperation.BtnDesignFunction') : {};
const reportDesign = commonFunc.showMessage(app.commonConst, 'reportDesign');/* 报表设计 */
if (commonUtils.isEmptyObject(BtnDesignFunctionConfig)) {
masterConfig.gdsconfigformslave.push({
bCanInput: false,
bEntireLine: false,
bFilter: false,
bFind: false,
bFirstEmpty: false,
bIsOther: false,
bMultipleChoice: false,
bNewRecord: false,
bNotEmpty: false,
bNotRepeat: false,
bReadonly: false,
bSum: false,
bTree: false,
bVisible: true,
iColValue: 1,
iFitWidth: 120,
/* iIncrement: 26154, */
iOrder: 1,
iTag: 0,
iVisCount: 0,
iconName: 'menu-unfold',
sActiveKey: '',
sAssignField: '',
sBig5: '',
sBig5DropDown: '',
sBrandsId: '1111111111',
sChinese: '报表设计',
sChineseDropDown: '',
sColor: '',
sColorTerms: '',
sControlName: 'BtnBsOperation.BtnDesignFunction',
sDateFormat: '',
sDefault: '',
sDropDownType: '',
sEnglish: '',
sEnglishDropDown: '',
sFilterSql: '',
/* sId: '19211681019715580740769130', */
sKeyUpFilter: '',
sMaxValue: '',
sMinValue: '',
sName: '',
sNotRepeatColumn: '',
/* sParentId: '19211681019715428730724240', */
sRelation: '',
sSelectRelation: '',
sSqlCondition: '',
sSubsidiaryId: '1111111111',
showDropDown: '',
showName: reportDesign,
});
}
/* bGrd代表是否是表格 */
let slaveConfig = formData.filter(item => item.bGrd && item.sTbName !== 'sysbillcheckresult')[0];
let slaveColumn = commonFunc.getHeaderConfig(slaveConfig);
const slavePageSize = commonUtils.isNotEmptyObject(slaveConfig) && commonUtils.isNotEmptyNumber(slaveConfig.iPageSize) && slaveConfig.iPageSize !== 0 ?
slaveConfig.iPageSize : commonConfig.pageSize;
const checkConfig = commonUtils.isNotEmptyArr(formData.filter(item => item.bGrd && item.bGrdVisible && item.sTbName === 'sysbillcheckresult')) ? formData.filter(item => item.bGrd && item.sTbName === 'sysbillcheckresult')[0] : {};
let checkColumn = {};
if (commonUtils.isNotEmptyObject(checkConfig)) {
checkColumn = commonFunc.getHeaderConfig(checkConfig);
}
let addState = {};
addState.slavePageSize = slavePageSize;
if (formRoute === '/indexPage/commonBill' && sModelsType === 'cost/cosexpenseshare') {
const { sModelsId } = this.props;
const { sId, sParentId } = slaveConfig;
let sAssignStandardConfig = {};
const filterData = slaveConfig.gdsconfigformslave.filter(item => item.sName === 'sAssignStandard');
if (commonUtils.isNotEmptyArr(filterData)) {
sAssignStandardConfig = filterData[0];
}
const url = `${commonConfig.server_host}costCenter/getCostCenterConfig?sModelsId=${sModelsId}`;
const body = {
sId,
sParentId,
sAssignStandardConfig,
};
const dataReturn = (await commonServices.postValueService(app.token, body, url)).data;
if (dataReturn.code === 1) {
/* 获取数据集 */
const { rows } = dataReturn.dataset;/* 获取费用分摊单据配置 */
if (commonUtils.isNotEmptyArr(rows) && rows.length > 0) {
slaveConfig = rows[0];
slaveColumn = commonFunc.getHeaderConfig(slaveConfig);
}
} else { /* 失败s */
this.props.getServiceError(dataReturn);
return [];
}
}
if (formRoute === '/indexPage/commonBill' || formRoute === '/indexPage/commonSubBill') {
if (sId === '') {
const config = {};
let addState1 = {};
let infoList = []; // bShowSlaveChild 处理
if (sModelsType.includes('sales/salesOrder')) {
const controlConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesordercontrol'.toUpperCase())[0];
const controlColumn = commonFunc.getHeaderConfig(controlConfig);
const materialsConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesordermaterials'.toUpperCase())[0];
const materialsColumn = commonFunc.getHeaderConfig(materialsConfig);
const processConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesorderprocess'.toUpperCase())[0];
const processColumn = commonFunc.getHeaderConfig(processConfig);
const colorConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesorderparam'.toUpperCase())[0];
let colorColumn;
if (commonUtils.isNotEmptyObject(colorConfig)) {
colorColumn = commonFunc.getHeaderConfig(colorConfig);
}
const packConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesordercontrolcombine'.toUpperCase())[0];
let packColumn;
if (commonUtils.isNotEmptyObject(packConfig)) {
packColumn = commonFunc.getHeaderConfig(packConfig);
}
config.controlConfig = controlConfig;
config.materialsConfig = materialsConfig;
config.processConfig = processConfig;
config.colorConfig = colorConfig;
config.packConfig = packConfig;
addState1 = {
controlConfig,
controlColumn,
materialsConfig,
materialsColumn,
processConfig,
processColumn,
colorConfig,
colorColumn,
packConfig,
packColumn,
};
} else if (sModelsType === 'purchase/purchaseOrder') {
const orderDetailConfig = commonUtils.isNotEmptyArr(formData.filter(item => item.sTbName.toUpperCase() === 'purpurchaseorderDetail'.toUpperCase())) ?
formData.filter(item => item.sTbName.toUpperCase() === 'purpurchaseorderDetail'.toUpperCase())[0] : {};
if(commonUtils.isNotEmptyObject(orderDetailConfig)) {
const orderDetailColumn = commonFunc.getHeaderConfig(orderDetailConfig);
config.orderDetailConfig = orderDetailConfig;
this.handleGetOneMemoData('orderDetail', orderDetailConfig);
addState1 = {
orderDetailConfig,
orderDetailColumn,
};
}
}
if (formRoute === '/indexPage/commonSubBill') { /* 附属子表获取数据 */
let bShowSlaveChild = false;
const bShowSlaveChildIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'bShowSlaveChild');
if (bShowSlaveChildIndex !== -1) {
bShowSlaveChild = masterConfig.gdsconfigformslave[bShowSlaveChildIndex].bVisible;
}
if (bShowSlaveChild) {
const filterSlaveData = formData.filter((item, index) => {
return index >= 2
&& item.sTbName !== 'sysbillcheckresult'
&& item.bGrd
&& item.bGrdVisible
&& item.sGrd
&& item.sGrd.indexOf('_') === -1
});
const filterSlaveChildData = formData.filter((item, index) => {
return index >= 2
&& item.bGrd
&& item.bGrdVisible
&& item.sGrd
&& item.sGrd.indexOf('_') !== -1
});
const addState2 = {};
const memoDataList = [];
const slaveInfoList = [];
const slaveChildInfoList = [];
[slaveConfig, ...filterSlaveData].forEach((config, index) => {
const slaveName = `slave${index === 0 ? '' : index - 1}`;
if (index !== 0) {
addState2[`${slaveName}Config`] = config;
addState2[`${slaveName}Column`] = commonFunc.getHeaderConfig(config);
memoDataList.push({
name: slaveName,
config,
});
slaveInfoList.push(slaveName);
}
filterSlaveChildData.filter(childConfig =>
config.sChildTableName
&& config.sChildTableName.split(',').includes(childConfig.sGrd)
).forEach((childConfig, childIndex) => {
const slaveChildName = `${slaveName}Child${childIndex}`;
addState2[`${slaveChildName}Config`] = childConfig;
addState2[`${slaveChildName}Column`] = commonFunc.getHeaderConfig(childConfig);
const slaveChildPageSize = commonUtils.isNotEmptyObject(childConfig) && commonUtils.isNotEmptyNumber(childConfig.iPageSize)
&& childConfig.iPageSize !== 0 ? childConfig.iPageSize : commonConfig.pageSize;
addState2[`${slaveChildName}PageSize`] = slaveChildPageSize;
memoDataList.push({
name: slaveChildName,
config: childConfig,
});
slaveChildInfoList.push(slaveChildName);
});
});
addState2.slaveInfoList = slaveInfoList;
addState2.slaveChildInfoList = slaveChildInfoList;
infoList = slaveChildInfoList;
addState1 = { ...addState1, ...addState2 };
} else {
const filterData = formData.filter(item => item.bGrd && item.sTbName !== 'sysbillcheckresult' && item.bGrdVisible);
if (commonUtils.isNotEmptyArr(filterData) && filterData.length > 1 && filterData.length === 2) {
const slaveChildConfig = filterData[1];
const slaveChildColumn = commonFunc.getHeaderConfig(slaveChildConfig);
this.handleGetOneMemoData('slaveChild', slaveChildConfig);
const slaveChildPageSize = commonUtils.isNotEmptyObject(slaveChildConfig) && commonUtils.isNotEmptyNumber(slaveChildConfig.iPageSize) && slaveChildConfig.iPageSize !== 0 ?
slaveChildConfig.iPageSize : commonConfig.pageSize;
addState1 = {
slaveChildConfig,
slaveChildColumn,
slaveChildPageSize,
};
} else if (commonUtils.isNotEmptyArr(filterData) && filterData.length > 2) {
const slaveChildConfig = commonUtils.isNotEmptyArr(formData.filter(item => item.bGrd && item.sTbName !== 'sysbillcheckresult' && item.bGrdVisible && commonUtils.isNotEmptyObject(item.sChildTableName))) ?
formData.filter(item => item.bGrd && item.sTbName !== 'sysbillcheckresult' && item.bGrdVisible && commonUtils.isNotEmptyObject(item.sChildTableName))[0] : {};
const slaveChildColumn = commonUtils.isNotEmptyObject(slaveChildConfig) ? commonFunc.getHeaderConfig(slaveChildConfig):[];
this.handleGetOneMemoData('slaveChild', slaveChildConfig);
const slaveChildPageSize = commonUtils.isNotEmptyObject(slaveChildConfig) && commonUtils.isNotEmptyNumber(slaveChildConfig.iPageSize) && slaveChildConfig.iPageSize !== 0 ?
slaveChildConfig.iPageSize : commonConfig.pageSize;
addState1 = {
slaveChildConfig,
slaveChildColumn,
slaveChildPageSize,
};
// eslint-disable-next-line no-unused-vars
const addState2 = {};
const memoDataList = [];
const slaveInfoList = [];
let slaveIndex = 0;
formData.forEach((item, index) => {
if (index >= 2 && commonUtils.isNotEmptyObject(item) && item.bGrd && item.sTbName !== 'sysbillcheckresult' && item.bGrdVisible && commonUtils.isEmptyObject(item.sChildTableName)) {
addState1[`slave${slaveIndex}Config`] = item;
config[`slave${slaveIndex}Config`] = item;
addState1[`slave${slaveIndex}Column`] = commonFunc.getHeaderConfig(item);
memoDataList.push({
name: `slave${slaveIndex}`,
config: item,
});
slaveInfoList.push(`slave${slaveIndex}`);
// eslint-disable-next-line no-plusplus
slaveIndex++;
}
});
addState1.slaveInfoList = slaveInfoList;
}
}
}
config.masterConfig = masterConfig;
config.slaveConfig = slaveConfig;
if (Array.isArray(infoList)) {
infoList.forEach(i => {
config[`${i}Config`] = addState1[`${i}Config`];
})
}
addState = await this.handleAdd(config, nextProps.app.currentPane.copyTo, true, infoList);
addState = { ...addState, ...addState1 };
// if (sModelsType.includes('sales/salesOrder') || sModelsType === 'purchase/purchaseOrder') {
// this.props.onSaveState(addState1);
// }
} else {
this.handleGetData(masterConfig, slaveConfig, checkConfig);
if (sModelsType.includes('sales/salesOrder')) {
const controlConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesordercontrol'.toUpperCase())[0];
const controlColumn = commonFunc.getHeaderConfig(controlConfig);
const materialsConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesordermaterials'.toUpperCase())[0];
const materialsColumn = commonFunc.getHeaderConfig(materialsConfig);
const processConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesorderprocess'.toUpperCase())[0];
const processColumn = commonFunc.getHeaderConfig(processConfig);
const colorConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesorderparam'.toUpperCase())[0];
let colorColumn;
if (commonUtils.isNotEmptyObject(colorConfig)) {
colorColumn = commonFunc.getHeaderConfig(colorConfig);
}
const packConfig = formData.filter(item => item.sTbName.toUpperCase() === 'salsalesordercontrolcombine'.toUpperCase())[0];
let packColumn;
if (commonUtils.isNotEmptyObject(packConfig)) {
packColumn = commonFunc.getHeaderConfig(packConfig);
}
this.handleGetMemoData(controlConfig, materialsConfig, processConfig, colorConfig, packConfig);
this.props.onSaveState({
controlConfig,
controlColumn,
materialsConfig,
materialsColumn,
processConfig,
processColumn,
colorConfig,
colorColumn,
packConfig,
packColumn,
});
} else if (sModelsType === 'manufacture/workOrder3') {
const controlConfig = formData.filter(item => item.sTbName.toUpperCase() === 'mftproductcontrol'.toUpperCase())[0];
const controlColumn = commonFunc.getHeaderConfig(controlConfig);
const materialsConfig = formData.filter(item => item.sTbName.toUpperCase() === 'mftproductmaterials'.toUpperCase())[0];
const materialsColumn = commonFunc.getHeaderConfig(materialsConfig);
const processConfig = formData.filter(item => item.sTbName.toUpperCase() === 'mftproductprocess'.toUpperCase())[0];
const processColumn = commonFunc.getHeaderConfig(processConfig);
this.handleGetMemoData(controlConfig, materialsConfig, processConfig);
this.props.onSaveState({
controlConfig,
controlColumn,
materialsConfig,
materialsColumn,
processConfig,
processColumn,
});
} else if (formRoute === '/indexPage/commonSubBill') { /* 通用子从表获取数据 */
let bShowSlaveChild = false;
const bShowSlaveChildIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'bShowSlaveChild');
if (bShowSlaveChildIndex !== -1) {
bShowSlaveChild = masterConfig.gdsconfigformslave[bShowSlaveChildIndex].bVisible;
}
if (bShowSlaveChild) {
const filterSlaveData = formData.filter((item, index) => {
return index >= 2
&& item.sTbName !== 'sysbillcheckresult'
&& item.bGrd
&& item.bGrdVisible
&& item.sGrd
&& item.sGrd.indexOf('_') === -1
});
const filterSlaveChildData = formData.filter((item, index) => {
return index >= 2
&& item.bGrd
&& item.bGrdVisible
&& item.sGrd
&& item.sGrd.indexOf('_') !== -1
});
const addState2 = {};
const memoDataList = [];
const slaveInfoList = [];
const slaveChildInfoList = [];
[slaveConfig, ...filterSlaveData].forEach((config, index) => {
const slaveName = `slave${index === 0 ? '' : index - 1}`;
if (index !== 0) {
addState2[`${slaveName}Config`] = config;
addState2[`${slaveName}Column`] = commonFunc.getHeaderConfig(config);
memoDataList.push({
name: slaveName,
config,
});
slaveInfoList.push(slaveName);
}
filterSlaveChildData.filter(childConfig =>
config.sChildTableName
&& config.sChildTableName.split(',').includes(childConfig.sGrd)
).forEach((childConfig, childIndex) => {
const slaveChildName = `${slaveName}Child${childIndex}`;
addState2[`${slaveChildName}Config`] = childConfig;
addState2[`${slaveChildName}Column`] = commonFunc.getHeaderConfig(childConfig);
memoDataList.push({
name: slaveChildName,
config: childConfig,
});
slaveChildInfoList.push(slaveChildName);
});
});
this.handleGetMemoData1(memoDataList);
addState2.memoDataList = memoDataList;
addState2.slaveInfoList = slaveInfoList;
addState2.slaveChildInfoList = slaveChildInfoList;
this.props.onSaveState({
...addState2,
});
} else {
const filterData = formData.filter(item => item.bGrd && item.sTbName !== 'sysbillcheckresult' && item.bGrdVisible);
if (commonUtils.isNotEmptyArr(filterData) && filterData.length > 1 && filterData.length === 2) {
const slaveChildConfig = filterData[1];
const slaveChildPageSize = commonUtils.isNotEmptyObject(slaveChildConfig) && commonUtils.isNotEmptyNumber(slaveChildConfig.iPageSize) && slaveChildConfig.iPageSize !== 0 ?
slaveChildConfig.iPageSize : commonConfig.pageSize;
const slaveChildColumn = commonFunc.getHeaderConfig(slaveChildConfig);
this.handleGetOneMemoData('slaveChild', slaveChildConfig);
this.props.onSaveState({
slaveChildConfig,
slaveChildColumn,
slaveChildPageSize,
});
} else if (commonUtils.isNotEmptyArr(filterData) && filterData.length > 2) {
const slaveChildConfig = commonUtils.isNotEmptyArr(formData.filter(item => item.bGrd && item.sTbName !== 'sysbillcheckresult' && item.bGrdVisible && commonUtils.isNotEmptyObject(item.sChildTableName))) ?
formData.filter(item => item.bGrd && item.sTbName !== 'sysbillcheckresult' && item.bGrdVisible && commonUtils.isNotEmptyObject(item.sChildTableName))[0] : {};
const slaveChildPageSize = commonUtils.isNotEmptyObject(slaveChildConfig) && commonUtils.isNotEmptyNumber(slaveChildConfig.iPageSize) && slaveChildConfig.iPageSize !== 0 ?
slaveChildConfig.iPageSize : commonConfig.pageSize;
const slaveChildColumn = commonFunc.getHeaderConfig(slaveChildConfig);
this.handleGetOneMemoData('slaveChild', slaveChildConfig);
const addState2 = {};
const memoDataList = [];
const slaveInfoList = [];
let slaveIndex = 0;
formData.forEach((item, index) => {
if (index >= 2 && commonUtils.isNotEmptyObject(item) && item.bGrd && item.sTbName !== 'sysbillcheckresult' && item.bGrdVisible && commonUtils.isEmptyObject(item.sChildTableName)) {
addState2[`slave${slaveIndex}Config`] = item;
addState2[`slave${slaveIndex}Column`] = commonFunc.getHeaderConfig(item);
memoDataList.push({
name: `slave${slaveIndex}`,
config: item,
});
slaveInfoList.push(`slave${slaveIndex}`);
// eslint-disable-next-line no-plusplus
slaveIndex++;
}
});
this.handleGetMemoData1(memoDataList);
addState2.memoDataList = memoDataList;
addState2.slaveInfoList = slaveInfoList;
this.props.onSaveState({
slaveChildConfig,
slaveChildColumn,
slaveChildPageSize,
...addState2,
});
}
}
} else if (sModelsType === 'purchase/purchaseOrder') {
const orderDetailConfig = formData.filter(item => item.sTbName.toUpperCase() === 'purpurchaseorderDetail'.toUpperCase())[0];
const orderDetailColumn = commonFunc.getHeaderConfig(orderDetailConfig);
this.handleGetOneMemoData('orderDetail', orderDetailConfig);
this.props.onSaveState({
orderDetailConfig,
orderDetailColumn,
});
}
}
}
this.props.onSaveState({
masterConfig, slaveConfig, slaveColumn, checkConfig, checkColumn, sId, pageLoading: false, ...addState,
});
} else if (commonUtils.isEmptyObject(masterConfigOld) && formData.length === 1 && (sModelsType === 'cashier/financialTransfer' || sModelsType === 'purchase/purchaseEnquiry' || sModelsType === 'cashier/financialAdjustment' || sModelsType === 'print/printLabel' || sModelsType === 'complaint/complaint' || sModelsType === 'commonBill/onlyMaster') && formRoute.indexOf('indexOee') === -1) {
const config = {};
const sId = currentId || nextProps.masterData?.sId || '';
/* 数据Id */
const masterConfig = formData.filter(item => !item.bGrd)[0];
let addState = {};
if (formRoute === '/indexPage/commonBill') {
if (sId === '') {
const config = {};
config.masterConfig = masterConfig;
addState = await this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
} else {
this.handleGetData(masterConfig, undefined, undefined);
}
}
addState.onlyMaster = true;
if (formRoute === '/indexPage/printlabel') {
config.masterConfig = masterConfig;
addState = await this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
}
this.props.onSaveState({
masterConfig, sId, pageLoading: false, ...addState,
});
} else if (commonUtils.isEmptyObject(slaveConfigOld) && commonUtils.isEmptyObject(masterConfigOld) && formData.length === 2 && (sModelsType === 'quality/accident') && formRoute.indexOf('indexOee') === -1) {
const sId = currentId || nextProps.masterData?.sId || '';
/* 数据Id */
const masterConfig = formData.filter(item => !item.bGrd)[0];
const slaveConfig = formData.filter(item => item.bGrd && item.sTbName === 'mftqualityaccidentSlave')[0];
const slaveColumn = commonFunc.getHeaderConfig(slaveConfig);
let addState = {};
if (formRoute === '/indexPage/commonBill') {
if (sId === '') {
const config = {};
config.masterConfig = masterConfig;
config.slaveConfig = slaveConfig;
addState = await this.handleAdd(config, nextProps.app.currentPane.copyTo, true);
} else {
this.handleGetData(masterConfig, slaveConfig, undefined);
}
}
addState.onlyMaster = true;
addState.onlyMasterAndSlave = true;
this.props.onSaveState({
masterConfig, sId, slaveConfig, slaveColumn, pageLoading: false, ...addState,
});
} else if (formRoute.indexOf('indexOee') > -1 && commonUtils.isEmptyObject(employeeConfigOld) && commonUtils.isEmptyObject(slaveConfigOld) && formData.length > 0) {
if (formRoute === '/indexOee/labelPrint' && commonUtils.isEmpty(slaveConfigOld)) { /* 入库标签打印 */
const sId = currentId || nextProps.masterData?.sId || '';
/* 数据Id */
const masterConfig = formData[0];
const slaveConfig = formData[0];
const slaveColumn = commonFunc.getHeaderConfig(slaveConfig);
// this.props.handleGetDataOne({ name: 'master', configData: masterConfig, condition: { sSqlCondition: { sParentId: sId } } });
this.handleGetOneMemoData('slave', slaveConfig);
this.props.onSaveState({
masterConfig, sId, slaveConfig, slaveColumn, pageLoading: false,
});
}
}
}
componentDidMount() {
this.props.onSaveState({
onEventDataChange: this.handleTableChange
})
}
shouldComponentUpdate(nextProps) {
const { slaveColumn, masterConfig } = nextProps;
return commonUtils.isNotEmptyArr(slaveColumn) || commonUtils.isNotEmptyObject(masterConfig);
}
/*
修改日期:2021-03-18
修改人:吕杰
区域:以下onKeyDown函数
需求变更:为解决bug 2031添加
*/
/** 键盘事件监听 */
onKeyDown = (e, record, sName, name) => {
const { [`${name}Data`]: tableData, [`${name}Column`]: tableColumn, [`${name}Config`]: tableConfig } = this.props;
let keyCode = e.keyCode;
let firstName;
let bEnter = false;
if (keyCode === 13) {
// 判断当前单元格是否是最后,不是则跳到下一格,是则跳到下一行第一格
bEnter = true;
const uniqueTableId = `table_${this.props.sModelsId}_${tableConfig.sId}`;
const currentTable = document.getElementById(uniqueTableId);
const currentTr = currentTable.querySelector(`tr[data-row-key="${record.sId}"]`);
const allInput = currentTr.querySelectorAll(`input[id*="${record.sId}"]`);
const iIndex = Array.from(allInput).findIndex(item => item.getAttribute('id') === `${sName}${record.sId}`);
if (iIndex < allInput.length - 1) {
keyCode = 39;
} else {
const oFirstInput = allInput[0];
firstName = oFirstInput.getAttribute('id').replace(record.sId, '');
keyCode = 40;
}
}
// 以下if条件为 为解决bug2031问题入口 需求:收款单里输入的收款金额,上下键操作把加减金额改为选择上下行(通过上下方向键切换行数)
if ([38, 40].includes(keyCode)) { // 上键、下键
e.preventDefault();
if (tableData.length > 1) { // 当从表行数大于一行时才有上下移动的意义
const index = tableData.findIndex(item => item.sId === record.sId); // 获取当前编辑行的下标
if (index > -1) {
if (keyCode === 38 && index > 0) { // 方向键上键 且 当前编辑行下标大于0时,为0时无法向上
const lastSid = tableData[index - 1].sId; // 获取上一个id
this.props.onSaveState({ [`${name}SelectedRowKeys`]: [lastSid] }, () => commonUtils.focus(`${sName}${lastSid}`));
}
if (keyCode === 40 && index < tableData.length - 1) { // 方向键下键 且 当前编辑行下标小于最大值时,为最大值时无法向下
const nextSid = tableData[index + 1].sId; // 获取下一个id
this.props.onSaveState({ [`${name}SelectedRowKeys`]: [nextSid] }, () => commonUtils.focus(`${firstName || sName}${nextSid}`));
}
}
}
}
const move = (keyCode, cursortPosition, columnIndex, currentElement) => {
const inputType = currentElement.getAttribute('type');
const value = currentElement.value;
if (keyCode === 37 && columnIndex > 0 && cursortPosition < 1) { // 左移 则 列下标必须大于0, 且光标在最左侧
const lastId = `${tableColumn[columnIndex - 1].dataIndex}${record.sId}`;
if (!commonUtils.focus(lastId, e)) move(keyCode, cursortPosition, columnIndex - 1, currentElement); // 递归
}
if (keyCode === 39 && columnIndex < tableColumn.length - 1) { // 右移 则 列下标必须小于列数量-1
if (!record[sName] || cursortPosition >= value.length || inputType === 'search' || bEnter) { // 当前列为空 或 光标位置不小于当前值的长度
const nextId = `${tableColumn[columnIndex + 1].dataIndex}${record.sId}`;
if (!commonUtils.focus(nextId, e)) move(keyCode, cursortPosition, columnIndex + 1, currentElement); // 递归
}
}
};
if ([37, 39].includes(keyCode)) { // 左键、右键
const currentElement = document.getElementById(`${sName}${record.sId}`); // 当前编辑框对象
if (currentElement) {
const cursortPosition = commonUtils.getCursortPosition(currentElement); // 光标位置
const columnIndex = tableColumn.findIndex(item => item.dataIndex === sName); // 当前列下标
move(keyCode, cursortPosition, columnIndex, currentElement);
}
}
}
/* 单击右键全部更新,弹出窗选择后,更新此列所有数据 (只更新非只读字段) */
onContextMenu = (e, record, showConfig, tbName) => {
const contextMenuConfig = [];
const showConfigNew = JSON.parse(JSON.stringify(showConfig)); /* 深拷贝配置 */
contextMenuConfig.push(showConfigNew);
this.props.onSaveState({
contextMenuModalVisible: true, /* 右击全部更新弹窗 */
contextMenuConfig, /* 右击字段配置 数组形式 */
contextMenuRecord: record, /* 右击数据 */
contextMenuName: showConfig.showName, /* 右击字段 */
contextMenuTbName: tbName, /* 右击字段 */
});
}
/** 获取应收账款 */
getCustomerReceipt = async (masterData) => {
const { sModelsId } = this.props;
if (!commonUtils.isEmpty(masterData.sCustomerId)) {
const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
const value = { sProName: 'Sp_Receivables_AR', paramsMap: { sStatistics: masterData.sCustomerId } };
const dataReturn = (await commonServices.postValueService(this.props.app.token, value, url)).data;
if (dataReturn.code === 1) {
/* 数据查询成功 */
const [returnData] = dataReturn.dataset.rows[0].dataSet.outData;
const masterDataNew = {
...masterData,
dNoReceiptMoney: returnData.dNoReceiptMoney,
dDueReceiptMoney: returnData.dNoReceiptMoney,
};
this.props.onSaveState({ masterData: masterDataNew });
} else { /* 失败 */
this.props.getServiceError(dataReturn);
}
}
};
/** 获取上查下查数据 */
getSearchUpDownData = async (showConfig) => {
const { sModelsId } = this.props;
const url = `${commonConfig.server_host}searchupdown/getSearchUpDown/${showConfig.sId}?sModelsId=${sModelsId}`;
const conditonValues = this.props.getSqlCondition(showConfig);
if (commonUtils.isNotEmptyObject(conditonValues)) {
const iIndex = Object.keys(conditonValues).findIndex(item => commonUtils.isEmpty(conditonValues[item]));
if (iIndex === -1) {
/* 调用后台接口 */
const body = {
sSqlCondition: commonUtils.isEmptyObject(conditonValues) ? '' : conditonValues, /* 查询条件 */
};
const dataReturn = (await commonServices.postValueService(this.props.app.token, body, url)).data;
if (dataReturn.code === 1) {
/* 数据查询成功 */
return dataReturn.dataset.rows;
} else { /* 失败 */
this.props.getServiceError(dataReturn);
return [];
}
}
}
};
handlePackDataAdd= (item, index, sControlId) => {
const tableDataRow = {};
tableDataRow.sId = commonUtils.createSid();
tableDataRow.handleType = 'add';
tableDataRow.sSlaveId = item.sId;
tableDataRow.sParentId = item.sParentId;
tableDataRow.sControlId = sControlId;
tableDataRow.iOrder = item.iOrder;
tableDataRow.sProductId = item.sProductId; /* 产品id */
tableDataRow.sCustomerId = item.sCustomerId; /* 客户id */
tableDataRow.sCustomerName = item.sCustomerName; /* 客户名称 */
tableDataRow.sProductName = item.sProductName; /* 产品名称 */
tableDataRow.sProductNo = item.sProductNo; /* 产品编号 */
tableDataRow.dProductQty = commonUtils.isNull(item.dProductQty, 0) + commonUtils.isNull(item.dGiveQty, 0) + commonUtils.isNull(item.dStockupQty, 0); /* 生产数量 */ /* 生产数量 */
tableDataRow.sProductUnit = item.sProductUnit; /* 单位 */
tableDataRow.sProductStyle = item.sProductStyle; /* 产品规格 */
return tableDataRow;
}
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;
};
/** 获取主表、从表、审核表数据 */
handleGetData = async (masterConfig, slaveConfig, checkConfig, bEditClick) => {
const { currentId, sModelsId } = this.props; /* 当前页签数据 */
const sId = currentId || this.props.masterData?.sId || '';
await this.props.handleGetDataOne({
name: 'master', configData: masterConfig, condition: { sId, pageSize: '', pageNum: '' }, bEditClick,
});
// commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sProductId', []);
// commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sProductNo', []);
// commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sProductName', []);
if (!commonUtils.isEmptyObject(slaveConfig)) {
const getData = await this.props.handleGetDataSet({
name: 'slave', configData: slaveConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
});
if (commonUtils.isNotEmptyObject(getData) && commonUtils.isNotEmptyArr(getData.slaveData)) {
getData.slaveData.forEach((item, iIndex) => {
if (commonUtils.isNotEmptyObject(item.sReportParam)) {
item = { ...item, ...commonUtils.convertStrToObj(item.sReportParam) };
getData.slaveData[iIndex] = item;
}
});
if(sModelsId === '12710101117043772382700' || sModelsId === '12710101117356129272400') { /* 默认查询 不勾选从表 */
getData.slaveSelectedRowKeys = [];
}
this.props.onSaveState({ ...getData });
}
if (commonUtils.isNotEmptyObject(getData) && commonUtils.isNotEmptyStr(getData.slaveData) && sModelsId !=='12710101117043772382700'
&& sModelsId !=='12710101117356129272400') {
const selectRowKey = getData.slaveData[0].sId;
const selectRowKeyArr = [];
selectRowKeyArr.push(selectRowKey);
this.handleTableSelectRowChange('slave', selectRowKeyArr);
}
}
if (!commonUtils.isEmptyObject(checkConfig)) {
this.props.handleGetDataSet({
name: 'check', configData: checkConfig, condition: { sSqlCondition: { sParentId: sId } },
});
}
};
/* 获取表数据 */
handleGetMemoData = async (controlConfig, materialsConfig, processConfig, colorConfig, packConfig) => {
const { currentId, sModelsType } = this.props; /* 当前页签数据 */
const sId = currentId || this.props.masterData?.sId || ''; /* 数据Id */
const addStateControl = await this.props.handleGetDataSet({
name: 'control', configData: controlConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
});
const { controlData, controlSelectedRowKeys } = addStateControl; /* 同步树选中节点与部件选中节点 */
let treeState = [];
if (sModelsType === 'sales/salesOrderPack') {
treeState = this.handleGetControlTreeData(controlData, true);
}
this.props.handleGetDataSet({
name: 'materials', configData: materialsConfig, condition: { sSqlCondition: { sParentId: sId } },
});
const addStateProcess = await this.props.handleGetDataSet({
name: 'process', configData: processConfig, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
});
if (addStateProcess) {
if (Array.isArray(addStateProcess.processData)) {
// eslint-disable-next-line array-callback-return
addStateProcess.processData.map((itemProcess) => {
if (commonUtils.isNotEmptyObject(sModelsType.includes('quotation/') ? itemProcess.sProcessParam : sModelsType.includes('manufacture/') ? itemProcess.sWorkOrderParam : itemProcess.sProcessParam)) {
itemProcess.sProcessParamStr = '';
// eslint-disable-next-line no-plusplus
for (let i = 1; i < 7; i++) {
const iIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === `sParamValue${i.toString()}`);
if (iIndex > -1 && !commonUtils.isEmpty(itemProcess[`sParam${i.toString()}`])) {
itemProcess.sProcessParamStr += `${itemProcess[`sParam${i.toString()}`]}:${itemProcess[`sParamValue${i.toString()}`]},`;
}
}
if (itemProcess.sProcessParamStr === '') {
itemProcess.sProcessParamStr = '工艺参数';
}
}
});
addStateProcess.processData = this.sortData(addStateControl.controlData, addStateProcess.processData);
}
}
if (commonUtils.isNotEmptyObject(colorConfig)) {
this.props.handleGetDataSet({
name: 'color', configData: colorConfig, condition: { sSqlCondition: { sParentId: sId } },
});
}
if (commonUtils.isNotEmptyObject(packConfig)) {
this.props.handleGetDataSet({
name: 'pack', configData: packConfig, condition: { sSqlCondition: { sParentId: sId } },
});
}
this.props.onSaveState({
pageLoading: false, ...addStateControl, ...addStateProcess, ...treeState, treeSelectedKeys: controlSelectedRowKeys,
});
};
/* 获取单张表数据 */
handleGetOneMemoData = (memoName, memoConfig) => {
const { currentId } = this.props; /* 当前页签数据 */
const sId = currentId || this.props.masterData?.sId || ''; /* 数据Id */
if (commonUtils.isNotEmptyObject(sId)) { /* 解决detail数据没有问题 */
this.props.handleGetDataSet({
name: memoName, configData: memoConfig, condition: { sSqlCondition: { sParentId: sId } },
});
}
};
handleGetMemoData1 = async (memoDataList, isWait) => {
const { currentId, sModelsType, sModelsId } = this.props; /* 当前页签数据 */
const sId = currentId || this.props.masterData?.sId || ''; /* 数据Id */
let addState = {};
// eslint-disable-next-line no-plusplus
for (let i = 0; i < memoDataList.length; i++) {
const item = memoDataList[i];
const result = await this.props.handleGetDataSet({
name: item.name, configData: item.config, condition: { sSqlCondition: { sParentId: sId } }, isWait: true,
});
addState = { ...addState, ...result };
}
if(sModelsId === '12710101117043772382700') { /* 默认查询 不勾选从表 */
addState.slave0SelectedRowKeys = [];
}
if (isWait) {
return addState;
} else {
this.props.onSaveState({
pageLoading: false, ...addState,
});
}
};
/** 获取部件树 */
handleGetControlTreeData= (controlDataOld, isWait, sSlaveId) => {
/* 生成部件树结构 */
let treeData = [];
const expandedKeys = [];
let { treeSelectedKeys } = this.props;
let controlData = [];
if (commonUtils.isNotEmptyObject(sSlaveId)) {
controlData = controlDataOld.filter(item => item.sSlaveId === sSlaveId);
} else {
controlData = controlDataOld;
}
if (commonUtils.isNotEmptyArr(controlData)) {
const rootData = commonUtils.isNotEmptyArr(controlData) ? controlData.filter(item => commonUtils.isEmpty(item.sControlParentId)) : []; /* 找到所有一级树结构 */
rootData.forEach((item) => {
const treeDataRow = {};
const { sId, sPartsName } = item;
treeDataRow.key = sId;
treeDataRow.showName = sPartsName;
treeDataRow.sAllId = item.sAllId;
const children = this.handleGetControlTreeChildData(sId, controlData);
let sChildren = '1'; /* 树形结构最后一个节点设置为1 */
if (commonUtils.isNotEmptyArr(children)) {
sChildren = '0'; /* 树形结构其他节点设置为0 */
}
treeDataRow.sChildren = sChildren;
/* 添加sChildren,sAllId 值 */
const iIndex = controlData.findIndex(item => item.sId === sId);
if (iIndex > -1) {
// controlData[iIndex].sAllId = sAllId;
controlData[iIndex].sChildren = sChildren;
}
treeDataRow.children = commonUtils.isNotEmptyArr(children) ? children : [];
treeData.push(treeDataRow);
});
if (commonUtils.isEmptyArr(treeSelectedKeys)) {
expandedKeys.push(treeData[treeData.length - 1].key);
}
} else {
treeSelectedKeys = [];
treeData = [];
}
if (isWait) {
return { treeData };
} else {
this.props.onSaveState({
treeData,
// expandedKeys,
});
}
};
/** 获取子节点数据 */
handleGetControlTreeChildData= (sParentId, controlData) => {
if (commonUtils.isNotEmptyObject(sParentId) && commonUtils.isNotEmptyArr(controlData)) {
const childTree = commonUtils.isNotEmptyArr(controlData) ? controlData.filter(item => item.sControlParentId === sParentId) : [];
const children = [];
if (commonUtils.isNotEmptyArr(childTree)) {
childTree.forEach((child) => {
const { sId, sPartsName } = child;
const treeDataRow = {};
treeDataRow.key = sId;
treeDataRow.showName = sPartsName;
treeDataRow.parentKey = sParentId;
treeDataRow.sAllId = child.sAllId;
const data = this.handleGetControlTreeChildData(sId, controlData);
let sChildren = '1'; /* 最后一个节点设置为1 */
if (commonUtils.isNotEmptyArr(data)) {
sChildren = '0';
}
treeDataRow.sChildren = sChildren;
/* 添加sChildren,sAllId 值 */
const iIndex = controlData.findIndex(item => item.sId === sId);
if (iIndex > -1) {
// controlData[iIndex].sAllId = sAllId;
controlData[iIndex].sChildren = sChildren;
}
treeDataRow.children = commonUtils.isNotEmptyArr(data) ? data : [];
children.push(treeDataRow);
});
}
return children;
}
};
/** 根据key查找树节点并改变属性 */
handleSearchNodes= (key, data, showNameNew) => {
if (commonUtils.isNotEmptyObject(showNameNew)) {
data.forEach((item) => {
if (item.key === key) {
item.showName = showNameNew;
} else if (commonUtils.isNotEmptyArr(item.children)) {
this.handleSearchNodes(key, item.children, showNameNew);
}
});
}
};
/** 点击新增按钮 */
handleAdd = async (config, copyTo, isWait, slaveChildInfoList) => {
/* 外置处理业务 */
const {
sModelsId, sModelsType, app, token,
} = this.props;
if (sModelsType.includes('cashier/')) {
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerId', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerNo', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerName', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyId', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyNo', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyName', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyId', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyNo', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyName', []);
}
let masterConfig = commonUtils.isEmptyObject(config) ? {} : config.masterConfig;
if (!isWait) {
masterConfig = this.props.masterConfig;
}
let configNew = {};
if (commonUtils.isEmptyObject(config)) {
const { slaveConfig } = this.props;
configNew.slaveConfig = slaveConfig;
} else {
configNew = config;
}
let masterData = commonFunc.getDefaultData(masterConfig);
masterData.handleType = 'add';
masterData.sId = commonUtils.createSid();
masterData.sFormId = sModelsId;
masterData.maxBillNo = 'sBillNo';
/* 取newRecord过来的数据 */
const addNewRecordStata = commonUtils.isNotEmptyObject(app.currentPane) && app.currentPane.newRecordRelation ? app.currentPane.newRecordRelation : {};
if(commonUtils.isNotEmptyObject(addNewRecordStata)) {
masterData = {...masterData, ...addNewRecordStata};
}
let slaveData = [];
const controlData = [];
const materialsData = [];
const processData = [];
const orderDetailData = [];
const dailyData = [];
const packData = [];
const colorData = [];
const slaveChildData = []; /* 子从表数据 */
const slave0Data = []; /* 从表0数据 */
const infoList = {}; /* slaveChildInfoList */
// const slaveTotal = [];
// const tableDataTotal = {};
if (commonUtils.isNotEmptyObject(copyTo)) {
const copyToMasterConfig = copyTo.config.filter(item => item.sControlName === copyTo.name);
const masterAssignField = commonUtils.isNotEmptyArr(copyToMasterConfig) ? copyToMasterConfig[0].sAssignField : '';
const newCopyTo = {};
newCopyTo.master = copyTo.masterData;
newCopyTo.slave = commonUtils.isEmpty(copyTo.slaveData) ? [] : copyTo.slaveData[0];
masterData = { ...masterData, ...commonFunc.getAssignFieldValue(masterAssignField, copyTo.masterData, newCopyTo) };
if (commonBusiness.getGeyPayDate(masterData) !== undefined) {
masterData.tGetPayDate = commonBusiness.getGeyPayDate(masterData);
}
let sWareHouseNameDropDown;
const iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sWareHouseName');
if (false) {
const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
let dataUrl;
let condition;
if (models === 'Product') {
dataUrl = `${commonConfig.server_host}eleProductStock/getProductWareHouse?sModelsId=${sModelsId}`;
condition = { sProductId: copyTo.slaveData[0].sProductId };
} else {
dataUrl = `${commonConfig.server_host}eleMaterialsStock/getMaterialsWareHouse?sModelsId=${sModelsId}`;
condition = { sMaterialsId: copyTo.slaveData[0].sMaterialsId, sMaterialsStyle: copyTo.slaveData[0].sMaterialsStyle };
}
const dataReturn = (await commonServices.postValueService(token, condition, dataUrl)).data;
if (dataReturn.code === 1) {
const sWareHouseId = dataReturn.dataset.rows.length > 0 ? dataReturn.dataset.rows[0].sWareHouseId : '';
const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', masterConfig.gdsconfigformslave[iIndex]);
sWareHouseNameDropDown = sqlDropDownData.dropDownData;
if (commonUtils.isNotEmptyArr(sWareHouseNameDropDown) && !sModelsType.includes('materialsStock/productionmaterialsadjust')) {
const { sAssignField } = masterConfig.gdsconfigformslave[iIndex];
const iWareHouseNameIndex = sWareHouseNameDropDown.findIndex(item => item.sId === sWareHouseId);
if (iWareHouseNameIndex > -1) {
masterData = { ...masterData, ...commonFunc.getAssignFieldValue(sAssignField, sWareHouseNameDropDown[iWareHouseNameIndex]) };
}
}
}
}
const copyToSlaveConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.slave`.toLowerCase());
const slaveAssignField = commonUtils.isNotEmptyArr(copyToSlaveConfig) ? copyToSlaveConfig[0].sAssignField : '';
if (slaveAssignField !== '') {
let iCount = 0;
let flagCopyTo = false;
if (commonUtils.isEmptyArr(copyTo.controlData)) {
flagCopyTo = true;
}
for (const slaveItem of copyTo.slaveData) {
const newCopyTo = {};
newCopyTo.master = copyTo.masterData;
newCopyTo.slave = slaveItem;
const newSid = commonUtils.createSid();
let slaveRow = commonFunc.getDefaultData(config.slaveConfig, newCopyTo, { newSid }); // 取默认值
slaveRow = { ...slaveRow, ...commonFunc.getAssignFieldValue(slaveAssignField, slaveItem, newCopyTo) }; // 取赋值字段
if ((!commonUtils.isEmpty(slaveRow.dProductQty) && slaveRow.dProductQty !== slaveRow.dSrcQty) ||
(!commonUtils.isEmpty(slaveRow.dAuxiliaryQty) && slaveRow.dAuxiliaryQty !== slaveRow.dSrcAuxiliaryQty)) {
const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
const sFieldName = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'dProductQty' : 'dAuxiliaryQty';
commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, slaveRow);
}
if (commonUtils.isNotEmptyObject(slaveRow.sReportParam)) {
slaveRow = { ...slaveRow, ...commonUtils.convertStrToObj(slaveRow.sReportParam) };
}
slaveRow.handleType = 'add';
slaveRow.sId = newSid;
slaveRow.sParentId = masterData.sId;
slaveRow.sSqlConditionOldId = slaveRow.sSqlConditionId;
slaveRow.sSqlConditionId = slaveRow.sId;
if (commonUtils.isEmptyObject(slaveRow.sWareHouseId)) {
slaveRow.sWareHouseId = masterData.sWareHouseId;
slaveRow.sWareHouseNo = masterData.sWareHouseNo;
slaveRow.sWareHouseName = masterData.sWareHouseName;
slaveRow.sLocationId = masterData.sLocationId;
slaveRow.sLocationNo = masterData.sLocationNo;
slaveRow.sLocationName = masterData.sLocationName;
slaveRow.sWareHouseLocationId = masterData.sWareHouseLocationId;
slaveRow.sWareHouseLocationNo = masterData.sWareHouseLocationNo;
slaveRow.sWareHouseLocationName = masterData.sWareHouseLocationName;
}
slaveRow.sOriginalId = slaveItem.sSlaveId;/* 翻单前的sId */
/* 若复制到没有序号,则序号从1自增 */
if (commonUtils.isEmptyNumber(slaveRow.iOrder)) {
iCount += 1;
slaveRow.iOrder = iCount;
}
slaveRow = this.handleGetCostomValue(slaveRow, copyTo, masterData);
slaveData.push(slaveRow);
if (sModelsType.includes('sales/salesOrder') && flagCopyTo && commonUtils.isNotEmptyArr(copyTo.slaveData)) {
const { token } = this.props;
const sSlaveId = commonUtils.isNotEmptyStr(slaveItem.sSlaveId) ? slaveItem.sSlaveId : slaveItem.sId;
const sParentId = commonUtils.isNotEmptyStr(slaveItem.sParentId) ? slaveItem.sParentId : slaveItem.sId;
let condition = {};
if (sModelsType === 'sales/salesOrderPack') {
condition = { sParentId };
} else {
condition = { sSlaveId };
}
/* 通用报价单:101251240115016244276286330 */
const dataUrl = slaveItem.sFormId === '19211681019715780306452560' || slaveItem.sFormId === '101251240115016076506222050'
|| slaveItem.sFormId === '101251240115016036175782700' || slaveItem.sFormId === '101251240115016002356125200' || slaveItem.sFormId === '101251240115016244276286330' ?
`${commonConfig.server_host}salesorder/getQuotationPartsInfo?sModelsId=${sModelsId}` :
`${commonConfig.server_host}salesorder/getPartsInfo?sModelsId=${sModelsId}`;
const dataReturn = (await commonServices.postValueService(token, condition, dataUrl)).data;
if (dataReturn.code === 1) {
const returnData = dataReturn.dataset.rows[0];
slaveItem.sId = sSlaveId;
copyTo.controlData = returnData.controlData;
copyTo.materialsData = returnData.materialsData;
copyTo.processData = returnData.processData;
copyTo.packData = returnData.packData;
copyTo.colorData = returnData.colorData;
} else {
this.props.getServiceError(dataReturn);
}
}
const copyToControlConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.control`.toLowerCase());
const controlAssignField = commonUtils.isNotEmptyArr(copyToControlConfig) ? copyToControlConfig[0].sAssignField : '';
if (controlAssignField !== '') {
if (commonUtils.isNotEmptyObject(copyTo.controlData)) {
const treeCopyNodes = new Map();
let controlFilterData = [];
const srcFormRoute = copyTo.srcFormRoute;
if (srcFormRoute === '/indexPage/quotationPack' || slaveItem.sFormId === '101251240115016076506222050') {
controlFilterData = copyTo.controlData;
} else {
controlFilterData = copyTo.controlData.filter(controlItem => controlItem.sSlaveId === slaveItem.sId);
}
await controlFilterData.forEach(async (controlItem) => {
const newCopyTo = {};
newCopyTo.master = copyTo.masterData;
newCopyTo.control = controlItem;
const newSid = commonUtils.createSid();
let controlRow = commonFunc.getDefaultData(config.controlConfig, newCopyTo, { newSid }); // 取默认值
controlRow = { ...controlRow, ...commonFunc.getAssignFieldValue(controlAssignField, controlItem, newCopyTo) }; // 取赋值字段
if ((!commonUtils.isEmpty(controlRow.dProductQty) && controlRow.dProductQty !== controlRow.dSrcQty) ||
(!commonUtils.isEmpty(controlRow.dAuxiliaryQty) && controlRow.dAuxiliaryQty !== controlRow.dSrcAuxiliaryQty)) {
const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
const sFieldName = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'dProductQty' : 'dAuxiliaryQty';
commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, controlRow);
}
controlRow.handleType = 'add';
controlRow.sId = newSid;
controlRow.sOriginalId = controlItem.sId; /* 复制前的部件表sId */
controlRow.sParentId = masterData.sId;
controlRow.sSlaveId = slaveRow.sId;
if (sModelsType === 'sales/salesOrderPack') {
/* 如果有树形结构 则sAllId,sControlParentId赋值 */
const sAllOldId = controlItem.sAllId;
let arr = [];
if (commonUtils.isNotEmptyObject(sAllOldId)) {
arr = sAllOldId.split(',');
}
const newId = controlRow.sId;
let sOldParentId = '';
let sNewParentAllId = '';
if (arr.length < 2) { /* 根节点复制 */
controlRow.sAllId = newId;
sOldParentId = newId;
sNewParentAllId = newId;
} else {
sOldParentId = arr[arr.length - 2];
if (treeCopyNodes.has(sOldParentId)) {
sNewParentAllId = treeCopyNodes.get(sOldParentId);
} else {
const obj = arr[arr.length - 1];
sNewParentAllId = sAllOldId.replace((`,${obj}`), '');
}
const sNewArr = sNewParentAllId.split(',');
controlRow.sControlParentId = sNewArr[sNewArr.length - 1];
sNewParentAllId = `${sNewParentAllId},${newId}`;
controlRow.sAllId = sNewParentAllId;
}
treeCopyNodes.set(controlItem.sId, sNewParentAllId);
}
controlData.push(controlRow);
const copyToMaterialsConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.materials`.toLowerCase());
const materialsAssignField = commonUtils.isNotEmptyArr(copyToMaterialsConfig) ? copyToMaterialsConfig[0].sAssignField : '';
if (materialsAssignField !== '') {
if (commonUtils.isNotEmptyObject(copyTo.materialsData)) {
let materialsFilterData = [];
const srcFormRoute = copyTo.srcFormRoute;
if (srcFormRoute === '/indexPage/quotationPack' || slaveItem.sFormId === '101251240115016076506222050') {
materialsFilterData = copyTo.materialsData.filter(materialsItem => materialsItem.sControlId === controlItem.sId);
} else {
materialsFilterData = copyTo.materialsData.filter(materialsItem => materialsItem.sSlaveId === slaveItem.sId && materialsItem.sControlId === controlItem.sId);
}
await materialsFilterData.forEach(async (materialsItem) => {
const newCopyTo = {};
newCopyTo.master = copyTo.masterData;
newCopyTo.materials = materialsItem;
const newSid = commonUtils.createSid();
let materialsRow = commonFunc.getDefaultData(config.materialsConfig, newCopyTo, { newSid }); // 取默认值
materialsRow = { ...materialsRow, ...commonFunc.getAssignFieldValue(materialsAssignField, materialsItem, newCopyTo) }; // 取赋值字段
if ((!commonUtils.isEmpty(materialsRow.dProductQty) && materialsRow.dProductQty !== materialsRow.dSrcQty) ||
(!commonUtils.isEmpty(materialsRow.dAuxiliaryQty) && materialsRow.dAuxiliaryQty !== materialsRow.dSrcAuxiliaryQty)) {
const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
const sFieldName = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'dProductQty' : 'dAuxiliaryQty';
commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, materialsRow);
}
materialsRow.handleType = 'add';
materialsRow.sId = newSid;
materialsRow.sParentId = masterData.sId;
materialsRow.sControlId = controlRow.sId;
materialsRow.sPartsName = controlRow.sPartsName;
materialsRow.sSlaveId = slaveRow.sId;
// 材料对应工序的ID要变化
if (commonUtils.isNotEmptyArr(copyTo.processData)) {
const iProcessIndex = processData.findIndex(item => item.sControlId === controlRow.sId && item.sSrcProcessTbId === materialsItem.sProcessTbId);
if (iProcessIndex > -1) {
materialsRow.sProcessTbId = processData[iProcessIndex].sId;
}
}
if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAuxiliaryQty') > -1) {
const urlMaterialsStock = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
const valueMaterialsStock = {
sProName: 'Sp_Inventory_MaterialsInventoryV56',
paramsMap: {
sMaterialsGuid: materialsRow.sMaterialsId,
sMaterialsStyle: materialsRow.sMaterialsStyle,
sWarehouseGuid: materialsRow.sWarehouseId,
sLocationalGuid: materialsRow.sLocationId,
sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
sDefine_no: materialsRow.sDefineNo,
sDefine_no2: materialsRow.sDefineNo2,
iGetQty: 1,
iHasZero: 1,
},
};
const returnDataMaterialsStock = (await commonServices.postValueService(app.token, valueMaterialsStock, urlMaterialsStock)).data;
if (returnDataMaterialsStock.code === 1) {
materialsRow.dMaterialsStockAuxiliaryQty = returnDataMaterialsStock.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
}
}
if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAvailableQty') > -1) {
const urlMaterialsAvailableQty = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
const valueMaterialsAvailableQty = {
sProName: 'Sp_Inventory_MaterialsInventoryV56',
paramsMap: {
sMaterialsGuid: materialsRow.sMaterialsId,
sMaterialsStyle: materialsRow.sMaterialsStyle,
sWarehouseGuid: materialsRow.sWarehouseId,
sLocationalGuid: materialsRow.sLocationId,
sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
sDefine_no: materialsRow.sDefineNo,
sDefine_no2: materialsRow.sDefineNo2,
iGetQty: 2,
iHasZero: 1,
},
};
const returnDataMaterialsAvailableQty = (await commonServices.postValueService(app.token, valueMaterialsAvailableQty, urlMaterialsAvailableQty)).data;
if (returnDataMaterialsAvailableQty.code === 1) {
materialsRow.dMaterialsStockAvailableQty = returnDataMaterialsAvailableQty.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
}
}
materialsData.push(materialsRow);
});
}
}
const copyToProcessConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.process`.toLowerCase());
const processAssignField = commonUtils.isNotEmptyArr(copyToProcessConfig) ? copyToProcessConfig[0].sAssignField : '';
if (processAssignField !== '') {
if (commonUtils.isNotEmptyObject(copyTo.processData)) {
let processFilterData = [];
const srcFormRoute = copyTo.srcFormRoute;
if (srcFormRoute === '/indexPage/quotationPack' || slaveItem.sFormId === '101251240115016076506222050') {
processFilterData = copyTo.processData.filter(processItem => processItem.sControlId === controlItem.sId);
} else {
processFilterData = copyTo.processData.filter(processItem => processItem.sSlaveId === slaveItem.sId && processItem.sControlId === controlItem.sId);
}
processFilterData.forEach((processItem) => {
const newCopyTo = {};
newCopyTo.master = copyTo.masterData;
newCopyTo.process = processItem;
const newSid = commonUtils.createSid();
let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo, { newSid }); // 取默认值
processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
if ((!commonUtils.isEmpty(processRow.dProductQty) && processRow.dProductQty !== processRow.dSrcQty) ||
(!commonUtils.isEmpty(processRow.dAuxiliaryQty) && processRow.dAuxiliaryQty !== processRow.dSrcAuxiliaryQty)) {
const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'process';
const sFieldName = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'dProductQty' : 'dAuxiliaryQty';
commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, processRow);
}
processRow.handleType = 'add';
processRow.sId = newSid;
processRow.sParentId = masterData.sId;
processRow.sControlId = controlRow.sId;
processRow.sPartsName = controlRow.sPartsName;
processRow.sSlaveId = slaveRow.sId;
processData.push(processRow);
});
}
}
/* 合版表复制到 */
if (sModelsType === 'sales/salesOrderPack') {
const copyToPackConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.pack`.toLowerCase());
const packAssignField = commonUtils.isNotEmptyArr(copyToPackConfig) ? copyToPackConfig[0].sAssignField : '';
if (commonUtils.isNotEmptyObject(packAssignField)) {
/* 复制到时增加合版表 */
if (commonUtils.isNotEmptyArr(copyTo.packData)) {
await copyTo.packData.filter(item => item.sSlaveId === slaveItem.sId && item.sControlId === controlItem.sId).forEach(async (packItem) => {
newCopyTo.pack = packItem;
let packRow = commonFunc.getDefaultData(config.packConfig, newCopyTo); // 取默认值
packRow = { ...packRow, ...commonFunc.getAssignFieldValue(packAssignField, packItem, newCopyTo) }; // 取赋值字段
/* sSlaveId赋值 */
const packRowAdd = this.handlePackDataAdd(slaveRow, 0, controlRow.sId);
packRow = { ...packRow, ...packRowAdd };
/* 将控制表中的合版备注sId为新的sId */
let JsonData = [];
const jsonStr = controlRow.sCombinedMemo;
if (commonUtils.isNotEmptyObject(jsonStr) && commonUtils.isJSON(jsonStr)) {
JsonData = JSON.parse(jsonStr);
if (commonUtils.isNotEmptyArr(JsonData)) {
let sCombinedMemoNew = '';
JsonData.forEach((item, index) => {
if (item.sId === packItem.sId) {
JsonData[index].sId = packRow.sId;
}
});
sCombinedMemoNew = JSON.stringify(JsonData);
controlRow.sCombinedMemo = sCombinedMemoNew;
const icontrolIndex = controlData.findIndex(item => item.sId === controlRow.sId);
if (icontrolIndex) {
controlData[icontrolIndex] = { ...controlData[icontrolIndex], sCombinedMemo: sCombinedMemoNew };
}
}
}
packData.push(packRow);
});
}
}
}
});
}
const copyToMaterialsConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.materials`.toLowerCase());
const materialsAssignField = commonUtils.isNotEmptyArr(copyToMaterialsConfig) ? copyToMaterialsConfig[0].sAssignField : '';
if (materialsAssignField !== '') {
if (commonUtils.isNotEmptyObject(copyTo.materialsData)) {
let materialsFilterData = [];
const srcFormRoute = copyTo.srcFormRoute;
if (srcFormRoute === '/indexPage/quotationPack' || slaveItem.sFormId === '101251240115016076506222050') {
materialsFilterData = copyTo.materialsData.filter(item => item.sType === '2');
} else {
materialsFilterData = copyTo.materialsData.filter(item => item.sSlaveId === slaveItem.sId && item.sType === '2');
}
await materialsFilterData.forEach(async (materialsItem) => {
const newCopyTo = {};
newCopyTo.master = copyTo.masterData;
newCopyTo.materials = materialsItem;
const newSid = commonUtils.createSid();
let materialsRow = commonFunc.getDefaultData(config.materialsConfig, newCopyTo, { newSid }); // 取默认值
materialsRow = { ...materialsRow, ...commonFunc.getAssignFieldValue(materialsAssignField, materialsItem, newCopyTo) }; // 取赋值字段
if ((!commonUtils.isEmpty(materialsRow.dProductQty) && materialsRow.dProductQty !== materialsRow.dSrcQty) ||
(!commonUtils.isEmpty(materialsRow.dAuxiliaryQty) && materialsRow.dAuxiliaryQty !== materialsRow.dSrcAuxiliaryQty)) {
const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
const sFieldName = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'dProductQty' : 'dAuxiliaryQty';
commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, materialsRow);
}
materialsRow.handleType = 'add';
materialsRow.sId = newSid;
materialsRow.sParentId = masterData.sId;
materialsRow.sSlaveId = slaveRow.sId;
if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAuxiliaryQty') > -1) {
const urlMaterialsStock = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
const valueMaterialsStock = {
sProName: 'Sp_Inventory_MaterialsInventoryV56',
paramsMap: {
sMaterialsGuid: materialsRow.sMaterialsId,
sMaterialsStyle: materialsRow.sMaterialsStyle,
sWarehouseGuid: materialsRow.sWarehouseId,
sLocationalGuid: materialsRow.sLocationId,
sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
sDefine_no: materialsRow.sDefineNo,
sDefine_no2: materialsRow.sDefineNo2,
iGetQty: 1,
iHasZero: 1,
},
};
const returnDataMaterialsStock = (await commonServices.postValueService(app.token, valueMaterialsStock, urlMaterialsStock)).data;
if (returnDataMaterialsStock.code === 1) {
materialsRow.dMaterialsStockAuxiliaryQty = returnDataMaterialsStock.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
}
}
if (Object.keys(materialsRow).length > 0 && Object.keys(materialsRow).findIndex(item => item === 'dMaterialsStockAvailableQty') > -1) {
const urlMaterialsAvailableQty = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
const valueMaterialsAvailableQty = {
sProName: 'Sp_Inventory_MaterialsInventoryV56',
paramsMap: {
sMaterialsGuid: materialsRow.sMaterialsId,
sMaterialsStyle: materialsRow.sMaterialsStyle,
sWarehouseGuid: materialsRow.sWarehouseId,
sLocationalGuid: materialsRow.sLocationId,
sWarehouseLocationGuid: materialsRow.sWarehouseLocationId,
sDefine_no: materialsRow.sDefineNo,
sDefine_no2: materialsRow.sDefineNo2,
iGetQty: 2,
iHasZero: 1,
},
};
const returnDataMaterialsAvailableQty = (await commonServices.postValueService(app.token, valueMaterialsAvailableQty, urlMaterialsAvailableQty)).data;
if (returnDataMaterialsAvailableQty.code === 1) {
materialsRow.dMaterialsStockAvailableQty = returnDataMaterialsAvailableQty.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
}
}
materialsData.push(materialsRow);
});
}
}
const copyToProcessConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.process`.toLowerCase());
const processAssignField = commonUtils.isNotEmptyArr(copyToProcessConfig) ? copyToProcessConfig[0].sAssignField : '';
if (processAssignField !== '') {
if (commonUtils.isNotEmptyObject(copyTo.processData)) {
let processFilterData = [];
const srcFormRoute = copyTo.srcFormRoute;
if (srcFormRoute === '/indexPage/quotationPack' || slaveItem.sFormId === '101251240115016076506222050') {
processFilterData = copyTo.processData.filter(item => item.sType === '3');
} else {
processFilterData = copyTo.processData.filter(item => item.sSlaveId === slaveItem.sId && item.sType === '3');
}
processFilterData.forEach((processItem) => {
const newCopyTo = {};
newCopyTo.master = copyTo.masterData;
newCopyTo.process = processItem;
const newSid = commonUtils.createSid();
let processRow = commonFunc.getDefaultData(config.processConfig, newCopyTo, { newSid }); // 取默认值
processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
if ((!commonUtils.isEmpty(processRow.dProductQty) && processRow.dProductQty !== processRow.dSrcQty) ||
(!commonUtils.isEmpty(processRow.dAuxiliaryQty) && processRow.dAuxiliaryQty !== processRow.dSrcAuxiliaryQty)) {
const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'process';
const sFieldName = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'dProductQty' : 'dAuxiliaryQty';
commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, processRow);
}
processRow.handleType = 'add';
processRow.sId = newSid;
processRow.sParentId = masterData.sId;
processRow.sSlaveId = slaveRow.sId;
/* 通用报价单的合版部件名称换成新生成的控制表sId */
if (commonUtils.isNotEmptyObject(processRow.sCombinePartsName)) {
/* 新的sCombinePartsName赋值 */
let sCombinePartsNameStr = ''; /* 新生成合版部件名称 */
const sCombinePartsNameOldArr = processRow.sCombinePartsName.split(',');
if (commonUtils.isNotEmptyArr(sCombinePartsNameOldArr)) {
const controlFilterData = controlData.filter(item => sCombinePartsNameOldArr.includes(item.sOriginalId));
if (commonUtils.isNotEmptyArr(controlFilterData)) {
controlFilterData.forEach((item) => {
sCombinePartsNameStr += `${item.sId},`;
});
}
sCombinePartsNameStr = commonUtils.isNotEmptyObject(sCombinePartsNameStr) ? sCombinePartsNameStr.substr(0, sCombinePartsNameStr.length - 1) : '';
processRow.sCombinePartsName = sCombinePartsNameStr;
}
}
processData.push(processRow);
});
}
}
/* 颜色表 */
const copyToColorConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.param`.toLowerCase());
const colorAssignField = commonUtils.isNotEmptyArr(copyToColorConfig) ? copyToColorConfig[0].sAssignField : '';
if (colorAssignField !== '') {
if (commonUtils.isNotEmptyArr(copyTo.colorData)) {
if (commonUtils.isNotEmptyObject(config.colorConfig)) {
copyTo.colorData.forEach((colorItem) => {
newCopyTo.color = colorItem;
const newSid = commonUtils.createSid();
let colorRow = commonFunc.getDefaultData(config.colorConfig, newCopyTo, { newSid }); // 取默认值
colorRow = { ...colorRow, ...commonFunc.getAssignFieldValue(colorAssignField, colorItem, newCopyTo) }; // 取赋值字段
colorRow.handleType = 'add';
colorRow.sId = newSid;
colorRow.sParentId = masterData.sId;
colorData.push(colorRow);
});
}
}
}
}
}
}
if (!commonUtils.isEmpty(masterData.sTestStandardId)) {
const dataUrl = `${commonConfig.server_host}eleteamemployee/getObtainInspectionStandards?sModelsId=${sModelsId}&sParentId=${masterData.sTestStandardId}`;
const dataReturn = (await commonServices.getService(this.props.app.token, dataUrl)).data;
const slaveDelData = [];
if (dataReturn.code === 1) {
const returnSlaveData = dataReturn.dataset.rows;
slaveData.forEach((item) => {
item.handleType = 'del';
slaveDelData.push(item);
});
slaveData = [];
const newCopyTo = {};
newCopyTo.master = masterData;
const iConfigIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'sTestStandardName');
returnSlaveData.forEach((item, iIndex) => {
const newSid = commonUtils.createSid();
let tableDataRow = commonFunc.getDefaultData(config.slaveConfig, {}, { newSid });
tableDataRow.handleType = 'add';
tableDataRow.sId = newSid;
tableDataRow.sParentId = masterData && masterData.sId ? masterData.sId : null;
tableDataRow.key = tableDataRow.sId;
tableDataRow.iOrder = iIndex;
if (iConfigIndex > -1) {
tableDataRow = { ...tableDataRow, ...commonFunc.getAssignFieldValue(masterConfig.gdsconfigformslave[iConfigIndex].sAssignField, item, newCopyTo) }; // 取赋值字段
}
slaveData.push(tableDataRow);
});
}
}
const slave0AssignField = commonUtils.isNotEmptyArr(copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.slave0`.toLowerCase())) ?
copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.slave0`.toLowerCase())[0].sAssignField : '';
if (slave0AssignField && !commonUtils.isEmpty(copyTo) && copyTo.slave0Data) {
if (commonUtils.isNotEmptyArr(copyTo.slave0Data)) {
copyTo.slave0Data.forEach((slave0Item) => {
const newCopyTo = {};
newCopyTo.master = copyTo.masterData;
newCopyTo.slave0 = slave0Item;
const newSid = commonUtils.createSid();
let slave0Row = commonFunc.getDefaultData(config.slave0Config, newCopyTo, { newSid }); // 取默认值
if(slave0AssignField) {
slave0Row = { ...slave0Row, ...commonFunc.getAssignFieldValue(slave0AssignField, slave0Item, newCopyTo) }; // 取赋值字段
}
const iIndex = slaveData.findIndex(slaveItem => slaveItem.sMaterialsId + slaveItem.sMaterialsStyle === slave0Item.sMaterialsGS);
if (iIndex !== -1) {
slaveData[iIndex].sWorkOrderNo = commonUtils.isEmptyObject(slaveData[iIndex].sWorkOrderNo) ? slave0Row.sWorkOrderNo : `${slaveData[iIndex].sWorkOrderNo},${slave0Row.sWorkOrderNo}`;
}
slave0Row.handleType = 'add';
slave0Row.sId = newSid;
slave0Row.sParentId = masterData.sId;
slave0Data.push(slave0Row);
});
}
}
console.log('w233', slaveChildInfoList);
if (Array.isArray(slaveChildInfoList)) {
slaveChildInfoList.forEach(i => {
infoList[`${i}Data`] = [];
const assignField = commonUtils.isNotEmptyArr(copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.${i}`.toLowerCase())) ?
copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.${i}`.toLowerCase())[0].sAssignField : '';
if (assignField && !commonUtils.isEmpty(copyTo) && copyTo[`${i}Data`]) {
if (commonUtils.isNotEmptyArr(copyTo[`${i}Data`])) {
copyTo[`${i}Data`].forEach((item) => {
const newCopyTo = {};
newCopyTo.master = copyTo.masterData;
newCopyTo[i] = item;
const newSid = commonUtils.createSid();
let row = commonFunc.getDefaultData(config[`${i}Config`], newCopyTo, { newSid }); // 取默认值
if(assignField) {
row = { ...row, ...commonFunc.getAssignFieldValue(assignField, item, newCopyTo) }; // 取赋值字段
}
row.handleType = 'add';
row.sId = newSid;
row.sParentId = masterData.sId;
console.log('row前', row);
const iIndex = commonUtils.isNotEmptyArr(slaveData) ? slaveData.findIndex(item => item.sSqlConditionOldId === row.sSqlConditionId) : -1;
if(iIndex > -1) {
row.sSqlConditionId = slaveData[iIndex].sId;
console.log('sSqlConditionId', row.sSqlConditionId, slaveData[iIndex].sId)
}
console.log('row后', row);
infoList[`${i}Data`].push(row);
});
}
}
})
}
}
if (sModelsType === 'purchase/purchaseOrder' && !commonUtils.isEmpty(copyTo) && commonUtils.isNotEmptyArr(copyTo.copyOtherData)) {
const copyToDetailConfig = copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.detail`.toLowerCase());
const detailAssignField = commonUtils.isNotEmptyArr(copyToDetailConfig) ? copyToDetailConfig[0].sAssignField : '';
if (detailAssignField !== '') {
const copyDetail = copyTo.copyOtherData.filter(item => item.name === 'detail')[0];
const detail = copyDetail.data;
detail.forEach((detailItem) => {
const newCopyTo = {};
newCopyTo.master = copyTo.masterData;
newCopyTo.detail = detailItem;
const newSid = commonUtils.createSid();
let tempDetail = commonFunc.getDefaultData(config.orderDetailConfig, newCopyTo, { newSid }); // 取默认值
tempDetail = { ...tempDetail, ...commonFunc.getAssignFieldValue(detailAssignField, detailItem, newCopyTo) }; // 取赋值字段
const iIndex = slaveData.findIndex(slaveItem => slaveItem.sMaterialsId + slaveItem.sMaterialsStyle === detailItem.sMaterialsGS);
if (iIndex !== -1) {
slaveData[iIndex].sWorkOrderNo = commonUtils.isEmptyObject(slaveData[iIndex].sWorkOrderNo) ? detailItem.sWorkOrderNo : `${slaveData[iIndex].sWorkOrderNo},${detailItem.sWorkOrderNo}`;
}
tempDetail.handleType = 'add';
tempDetail.sId = newSid;
tempDetail.sParentId = masterData.sId;
tempDetail = this.handleGetCostomValue(tempDetail, copyTo, masterData);
orderDetailData.push(tempDetail);
slaveChildData.push(tempDetail);
});
}
} else if ( commonUtils.isNotEmptyObject(copyTo)) { /* detail 生成slaveChild */
const copyToDetailConfig = commonUtils.isNotEmptyArr(copyTo.config) ? copyTo.config.filter(item => item.sControlName.toLowerCase() === `${copyTo.name}.detail`.toLowerCase() ||
item.sControlName.toLowerCase() === `${copyTo.name}.slaveChild`.toLowerCase()) : [];
const detailAssignField = commonUtils.isNotEmptyArr(copyToDetailConfig) ? copyToDetailConfig[0].sAssignField : '';
if (detailAssignField !== '') {
let detail = [];
if (commonUtils.isNotEmptyArr(copyTo.copyOtherData)) {
const copyDetail = copyTo.copyOtherData.filter(item => item.name === 'detail')[0];
if (commonUtils.isEmptyArr(copyDetail)) {
detail = copyTo.copyOtherData;
} else {
detail = copyDetail.data;
}
} else if (commonUtils.isNotEmptyArr(copyTo.slaveChildData)) {
detail = copyTo.slaveChildData;
}
if (commonUtils.isNotEmptyArr(detail)) {
detail.forEach((detailItem) => {
const newCopyTo = {};
newCopyTo.master = copyTo.masterData;
newCopyTo.detail = detailItem;
const newSid = commonUtils.createSid();
let tempDetail = commonFunc.getDefaultData(config.orderDetailConfig, newCopyTo, { newSid }); // 取默认值
tempDetail = { ...tempDetail, ...commonFunc.getAssignFieldValue(detailAssignField, detailItem, newCopyTo) }; // 取赋值字段
tempDetail.handleType = 'add';
tempDetail.sId = newSid;
tempDetail.sParentId = masterData.sId;
const iIndex = commonUtils.isNotEmptyArr(slaveData) ? slaveData.findIndex(item => item.sSqlConditionOldId === tempDetail.sSqlConditionId) : -1;
if(iIndex > -1) {
tempDetail.sSqlConditionId = slaveData[iIndex].sId;
console.log('sSqlConditionId', tempDetail.sSqlConditionId)
}
// tempDetail.sSqlConditionId = commonUtils.isNotEmptyArr(slaveData) ? slaveData[0].sSqlConditionId : '';
tempDetail = this.handleGetCostomValue(tempDetail, copyTo, masterData);
orderDetailData.push(tempDetail);
slaveChildData.push(tempDetail);
});
}
}
}
/* 剔除订单到收款单,费用分摊单据新增空行 */
if (slaveData.length === 0 && commonUtils.isNotEmptyObject(configNew.slaveConfig) && this.props.sModelsType !== 'cashier/receipt' && this.props.sModelsType !== 'cashier/payment' && this.props.sModelsType !== 'cost/cosexpenseshare'
&& sModelsType !== 'sales/salesInvoice' && sModelsType !== 'purchase/purchaseInvoice' && sModelsType !== 'purchase/outsideInvoice') {
const allTableData = {};
allTableData.master = masterData;
allTableData.slave = slaveData;
const newSid = commonUtils.createSid();
const tableDataRowAdd = commonFunc.getDefaultData(configNew.slaveConfig, allTableData, { newSid });
const bEmptyAddLine = configNew.slaveConfig.gdsconfigformslave.find(item => item.sControlName === 'bEmptyAddLine');
if (!(commonUtils.isNotEmptyObject(bEmptyAddLine) && bEmptyAddLine.bVisible)) {
tableDataRowAdd.handleType = 'add';
tableDataRowAdd.sId = newSid;
tableDataRowAdd.sParentId = masterData && masterData.sId ? masterData.sId : null;
tableDataRowAdd.key = tableDataRowAdd.sId;
tableDataRowAdd.bDefault = false;
tableDataRowAdd.iOrder = 1;
tableDataRowAdd.sSqlConditionId = tableDataRowAdd.sId;
slaveData.push(tableDataRowAdd);
}
}
if (sModelsType === 'sales/salesSgoods') { /* 送货单中如果只有一个仓库,默认带这个仓库 */
// const sWareHouseNameDropDown = commonUtils.getStoreDropDownData(sModelsId, 'master', 'sWareHouseName');
let sWareHouseNameDropDown;
const masterIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sWareHouseName');
if (masterIndex > -1) {
const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'master', masterConfig.gdsconfigformslave[masterIndex]);
sWareHouseNameDropDown = sqlDropDownData.dropDownData;
}
if (commonUtils.isNotEmptyArr(sWareHouseNameDropDown) && sWareHouseNameDropDown.length === 1) {
const addStata = {};
addStata.sWareHouseId = sWareHouseNameDropDown[0].sId;
addStata.sWareHouseNo = sWareHouseNameDropDown[0].sNo;
addStata.sWareHouseName = sWareHouseNameDropDown[0].sName;
addStata.sLocationId = sWareHouseNameDropDown[0].sLocationId;
addStata.sLocationNo = sWareHouseNameDropDown[0].sLocationNo;
addStata.sLocationName = sWareHouseNameDropDown[0].sLocationName;
addStata.sWareHouseLocationId = sWareHouseNameDropDown[0].sWareHouseLocationId;
addStata.sWareHouseLocationNo = sWareHouseNameDropDown[0].sWareHouseLocationNo;
addStata.sWareHouseLocationName = sWareHouseNameDropDown[0].sWareHouseLocationName;
const iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sWareHouseName');
if (iIndex > -1) {
masterData = { ...masterData, ...addStata }; /* 主表赋默认仓库 */
if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) { /* 从表赋默认仓库 */
slaveData.forEach((item, index) => {
slaveData[index] = { ...item, ...addStata };
});
}
}
}
}
const treeState = this.handleGetControlTreeData(controlData, true); /* 加载树形结构数据 */
const state = {
masterData,
slaveData,
slaveTotal: [],
slaveSelectedRowKeys: commonUtils.isNotEmptyArr(slaveData) ? [slaveData[slaveData.length - 1].sId] : [],
checkData: [],
checkSelectedRowKeys: [],
searchUpDownData: {},
enabled: true,
controlData,
materialsData,
processData,
dailyData,
packData,
colorData,
orderDetailData,
slaveChildData,
...infoList,
slave0Data,
...treeState,
processSelectedRowKeys: [],
controlSelectedRowKeys: [],
materialsSelectedRowKeys: [],
calculated: false,
};
state.sUseInfo = '';
if (isWait) {
return state;
} else {
this.props.onSaveState(state);
return true;
}
};
// 自定义取值
handleGetCostomValue = (slaveRow, copyTo, masterData) => {
const { app, sModelsType } = this.props;
if (sModelsType === 'purchase/purchaseInstore') {
const iIndex = app.systemData.findIndex(item => item.sName === 'CbxMaterialsDefine');
if (iIndex > -1) {
const sCbxMaterialsDefine = app.systemData[iIndex].sValue;
if (sCbxMaterialsDefine === 'datenum') {
slaveRow.sDefineNo = moment(new Date()).format('YYYYMMDD');
} else if (sCbxMaterialsDefine === 'datetimenum') {
slaveRow.sDefineNo = moment(new Date()).format('YYYYMMDDHHmm');
} else if (sCbxMaterialsDefine === 'yearnum') {
slaveRow.sDefineNo = moment(new Date()).format('YYYY');
} else if (sCbxMaterialsDefine === 'yearmonthnum') {
slaveRow.sDefineNo = moment(new Date()).format('YYYYMM');
} else if (sCbxMaterialsDefine === 'worknum') {
slaveRow.sDefineNo = slaveRow.sWorkOrderNo;
} else if (sCbxMaterialsDefine === 'manuualno') {
slaveRow.sDefineNo = slaveRow.sManualNo;
} else if (sCbxMaterialsDefine === 'createnownum') { /* 批号根据生产日期+当前日期 */
slaveRow.sDefineNo = moment(slaveRow.tProductionDate).format('YYYYMMDDHHmm') + moment(new Date()).format('YYYYMMDDHHmm');
}
}
} else if (sModelsType === 'productStock/productInStore' || sModelsType === 'outside/outsideinstoreAll') { /* 成品入库、整单发外入库 */
const iIndex = app.systemData.findIndex(item => item.sName === 'CbxProductDefine');
if (iIndex > -1) {
const sCbxProductDefine = app.systemData[iIndex].sValue;
if (sCbxProductDefine === 'datenum') {
slaveRow.sDefineNo = moment(new Date()).format('YYYYMMDD');
} else if (sCbxProductDefine === 'datetimenum') {
slaveRow.sDefineNo = moment(new Date()).format('YYYYMMDDHHmm');
} else if (sCbxProductDefine === 'yearnum') {
slaveRow.sDefineNo = moment(new Date()).format('YYYY');
} else if (sCbxProductDefine === 'yearmonthnum') {
slaveRow.sDefineNo = moment(new Date()).format('YYYYMM');
} else if (sCbxProductDefine === 'worknum') {
slaveRow.sDefineNo = slaveRow.sWorkOrderNo;
} else if (sCbxProductDefine === 'manuualno') {
slaveRow.sDefineNo = slaveRow.sManualNo;
} else if (sCbxProductDefine === 'worktimenum') { /* 批号根据工单号码+日期时间批号 */
slaveRow.sDefineNo = slaveRow.sWorkOrderNo + moment(new Date()).format('YYYYMMDDHH');
} else if (sCbxProductDefine === 'yearToDate') { /* 2259 批号根据工单制单日期年月日,年取两位 */
slaveRow.sDefineNo = moment(copyTo.masterData.tCreateDate || new Date()).format('YYMMDD');
}
}
} else if (sModelsType === 'sales/salesCheck') {
slaveRow.dSrcNoCheckMoney = slaveRow.dProductForeignMoney;
} else if (sModelsType === 'purchase/purchasecheck') {
slaveRow.dSrcNoCheckMoney = slaveRow.dMaterialsMoney;
} else if (sModelsType === 'purchase/purchaseOrder' && false) { // bug 2171 修正 吕杰 2021-03-26
const dProcurementCycle = commonUtils.isNull(slaveRow.dProcurementCycle, 0);
const tCreateDate = masterData && commonUtils.isNotEmptyObject(masterData.tCreateDate) ? masterData.tCreateDate : new Date();
const tDeliverDate = moment(tCreateDate).add(dProcurementCycle, 'days').format(commonUtils.dateFormatA);
slaveRow.tDeliverDate = tDeliverDate;
slaveRow.dProcurementCycle = dProcurementCycle;
}
return slaveRow;
}
/** 点击修改按钮操作 */
handleEdit = async () => {
const {
masterConfig, slaveConfig, checkConfig, currentId, app, masterData, dispatch, billnosetting, slaveChildConfig, slave0Config,
} = this.props;
const { userinfo, systemData } = app;
const { sMakePerson } = masterData; /* 本单据制单人 */
const { sUserName, sType } = userinfo;/* 登录用户 */
// 判断是否全局都有配置
const iIndex = systemData.findIndex(item => item.sName === 'CkxModifyBillNoMakePerson');
let sValue = 0;
if (iIndex > -1) {
sValue = systemData[iIndex].sValue; // 全局配置的值; 1为开启:所有人都可以编辑,0是关闭;
}
const bModify = billnosetting.bModify; /* 勾选了可修改及代表普通用户非制单人可以修改单据 */
if (!+sValue && !bModify && sType !== 'sysadmin' && sUserName !== sMakePerson) {
message.error(commonFunc.showMessage(app.commonConst, 'NoUpdateByNoMakePerson'));
this.props.onSaveState({
loading: false,
});
return;
}
let timValue = 0;
if (this.props.app.webSocket === null || this.props.app.webSocket.readyState !== WebSocket.OPEN) {
this.props.dispatch({ type: 'app/createWebSocket', payload: { reStart: true, dispatch } });
timValue = 3000;
}
const reset = (ws, config1) => {
clearTimeout(config1.timerServer);
clearTimeout(config1.serverTimer);
start(ws, config1);
};
const start = (ws, config1) => {
config1.timerServer = setTimeout(() => {
const message = { sendFrom: this.props.app.userinfo.sId, connectTest: 'test' }; // param 存放其它参数 keyName 需要放入Redis的数据key,keyValue 需要放入Redis的数据key 的值
ws.send(JSON.stringify(message));
}, config1.timeoutServer);
};
setTimeout(() => {
this.props.app.webSocket.onmessage = async (msg) => {
reset(this.props.app.webSocket, commonConfig);
const rtmsg = JSON.parse(msg.data);
if (rtmsg.action === 'showMsg') {
message.warning(rtmsg.msg);
this.props.onSaveState({ loading: false });
} else if (rtmsg.action === 'loginOut') {
if (location.pathname.indexOf('/indexOee') > -1) {
dispatch({ type: 'app/throwErrorOee', payload: { code: -2, msg: rtmsg.msg } });
} else if (location.pathname.indexOf('/indexMobile') > -1) {
dispatch({ type: 'app/throwErrorMobile', payload: { code: -2, msg: rtmsg.msg } });
} else {
dispatch({ type: 'app/throwError', payload: { code: -2, msg: rtmsg.msg } });
}
} else if (rtmsg.action === 'update') {
await this.handleGetData(masterConfig, slaveConfig, checkConfig, 'update');
if(commonUtils.isNotEmptyObject(slaveChildConfig)) {
await this.handleGetOneMemoData('slaveChild', slaveChildConfig);
}
if(commonUtils.isNotEmptyObject(slave0Config)) {
await this.handleGetOneMemoData('slave0', slave0Config);
}
this.props.onSaveState({ enabled: true, calculated: false, loading: false });
} else if (this.props.app.webSocket.homeAction) {
this.props.app.webSocket.homeAction(msg);
}
};
this.props.handleSendSocketMessage('update', 'showMsg', currentId, userinfo.sId, null, null);
}, timValue);
};
/** 表单回带 */
handleForm = (form) => {
this.form = form;
};
/** toolbar审核(消审) */
handleAudit = async (flag) => {
/* 待用数据声明 */
let bResult = true;
const { masterData, gdsformconst } = this.props;
if (!commonUtils.isEmpty(masterData)) {
/* 作废订单不能审核 */
if (masterData.bInvalid) {
message.warning(commonFunc.showMessage(app.commonConst, 'sToVoid'));
this.props.onSaveState({
loading: false,
});
return '';
}
/** 数据审核 */
bResult = await this.dataAudit(flag);
} else {
this.props.onSaveState({
loading: false,
});
}
return bResult;
};
/** 数据审核 */
dataAudit = async (flag, tmpCheck, isWait) => {
message.destroy();
/* 待用数据声明 */
const {
sModelsId, masterData, app, masterConfig, slaveConfig, checkConfig, token, sModelsType, controlConfig, materialsConfig, processConfig, colorConfig, packConfig, slaveData,
orderDetailConfig, slaveChildConfig, formRoute, slave0Config,
} = this.props;
const FriendlyReminder = commonFunc.showLocalMessage(this.props, 'FriendlyReminder', '温馨提示');
const sSlaveIdArray = [];
if (commonUtils.isNotEmptyArr(slaveData)) {
slaveData.forEach((item) => {
sSlaveIdArray.push(commonUtils.isNotEmptyObject(item.sId) ? item.sId : item.sSlaveId);
});
}
const slaveId = sSlaveIdArray.toString();
/* 数据参数 */
const value = {
sClientType: '1',
paramsMap: {
iFlag: flag,
iTmpCheck: commonUtils.isEmptyNumber(tmpCheck) ? 0 : tmpCheck,
sFormGuid: sModelsId,
sGuid: masterData.sId,
sSlaveId: slaveId,
sBillNo: commonUtils.isNotEmptyObject(masterData.sBillNo) ? masterData.sBillNo : '',
},
};
let clearFlag = false;
if (sModelsType.includes('sales/salesOrder') || sModelsType.includes('manufacture/workOrder')) {
if (commonUtils.isNotEmptyArr(slaveData)) {
for (const item of slaveData) {
if (commonUtils.isNotEmptyStr(item.sProductInfo)) {
clearFlag = true;
break;
}
}
} else {
this.props.onSaveState({
loading: false,
});
return;
}
}
/* 数据审核 */
const url = `${commonConfig.server_host}business/doExamine?sModelsId=${sModelsId}`;
const returnData = (await commonServices.postValueService(app.token, value, url)).data;
if (isWait) {
return returnData;
} else {
/* 接收返回值 */
const check = commonFunc.showMessage(app.commonConst, 'BtnExamine');/* 审核 */
const BtnCancelExamine = commonFunc.showMessage(app.commonConst, 'BtnCancelExamine');/* 销审 */
if (returnData.code === 1) { /* 成功 */
this.props.onSaveState({
loading: false,
});
if (flag === 1) {
/* 审核 */
if (clearFlag && (sModelsType.includes('sales/salesOrder') || sModelsType.includes('manufacture/workOrder'))) {
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sProductId', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sProductNo', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sProductName', []);
}
let outData;
if (commonUtils.isNotEmptyObject(returnData.dataset)) {
outData = returnData.dataset.rows[0].dataSet.outData;
}
if (commonUtils.isNotEmptyStr(outData[0].sReturn)) {
const sReturnArray = outData[0].sReturn.split('|');
if (outData[0].sReturn.split('-').length < 2) {
// 正常业务提示,非审核模板
// if (this.props.app.currentPane.refresh !== undefined) {
// this.props.app.currentPane.refresh();
// }
message.error(check + outData[0].sReturn);
return;
}
const checkConditions = [];
let checkPersonData = {};
sReturnArray.forEach((item) => {
const checkCondition = item.split('-')[2];
const iIndex = checkConditions.findIndex(itemCondition => itemCondition.condition === checkCondition);
if (iIndex <= -1) {
checkConditions.push({
key: commonUtils.createSid(),
condition: checkCondition,
});
}
});
const sCheckModelId = sReturnArray[0].split('-')[1];
if (commonUtils.isNotEmptyStr(sCheckModelId)) {
const urlCheck = `${commonConfig.server_host}checkModel/getUserListByModelId/${sCheckModelId}?sModelsId=${sModelsId}`;
const dataReturn = (await commonServices.getService(token, urlCheck)).data;
if (dataReturn.code === 1) {
checkPersonData = dataReturn.dataset.rows;
checkPersonData.forEach((item) => {
item.key = commonUtils.createSid();
});
this.props.onSaveState({
checkConditions, checkPersonData, sCheckModelId, visible: true,
});
return true;
} else { /* 失败 */
this.props.getServiceError({ msg: check + dataReturn });
}
}
} else {
message.success(check + returnData.msg);
}
} else {
/* 消审 */
const { outData } = returnData.dataset.rows[0].dataSet;
if (commonUtils.isNotEmptyStr(outData[0].sReturn)) {
message.error(outData[0].sReturn);
} else {
// if (this.props.app.currentPane.refresh !== undefined) {
// this.props.app.currentPane.refresh();
// }
message.success(BtnCancelExamine + returnData.msg);
}
}
await this.handleGetData(masterConfig, slaveConfig, checkConfig);
if ((sModelsType.includes('sales/salesOrder') || sModelsType === 'manufacture/workOrder3') && !commonUtils.isEmpty(controlConfig)) {
await this.handleGetMemoData(controlConfig, materialsConfig, processConfig, colorConfig, packConfig);
} else if (commonUtils.isNotEmptyObject(formRoute) && formRoute.includes('commonSubBill') && !commonUtils.isEmpty(slaveChildConfig)) {
await this.handleGetOneMemoData('slaveChild', slaveChildConfig);
} else if (sModelsType === 'purchase/purchaseOrder') {
await this.handleGetOneMemoData('orderDetail', orderDetailConfig);
}
if(commonUtils.isNotEmptyObject(slaveChildConfig)) {
this.handleGetOneMemoData('slaveChild', slaveChildConfig);
}
if (this.props.app.currentPane.refresh !== undefined) {
this.props.app.currentPane.refresh();
}
}else if(returnData.code === -8){
Modal.info({
title: FriendlyReminder,
content: (
{this.handleGetMsg(returnData.msg)}
),
onOk() {},
});
this.props.onSaveState({
loading: false,
});
return false;
} else { /* 失败 */
this.props.getServiceError(returnData);
this.props.onSaveState({
loading: false,
});
return false;
}
return true;
}
};
/** toolbar保存 */
handleSaveData = async (params) => {
const {
token, sModelsId, currentId, masterData, masterConfig, slaveConfig, checkConfig, billnosetting, app, sModelsType,
controlConfig, materialsConfig, processConfig, colorConfig, packConfig, orderDetailConfig, dispatch, slaveChildConfig, formRoute,
slaveInfoList, slaveChildInfoList,
} = this.props;
const { userinfo } = app;
const { copyTo } = app.currentPane;
const onSendSocketMessage = this.props.handleSendSocketMessage;
const BtnSave = commonFunc.showMessage(app.commonConst, 'BtnSave');/* 保存 */
params.optName = BtnSave;
const returnData = await commonBusiness.saveData({ token, value: params, sModelsId, is2True: true });
if (commonUtils.isNotEmptyObject(returnData)) {
if (commonUtils.isNotEmptyObject(copyTo)) {
const { slaveData, srcFormRoute } = copyTo;
const sIdArray = [];
if (commonUtils.isNotEmptyObject(srcFormRoute) && srcFormRoute.includes('materialRequirementsPlanning')) { /* 物料需求计划用sWorkOrderMaterialId作为唯一键 */
const { copyOtherData } = copyTo;
if (commonUtils.isNotEmptyArr(copyOtherData) && copyOtherData[0].name === 'detail' && commonUtils.isNotEmptyArr(copyOtherData[0].data)) {
const slaveDetailData = copyOtherData[0].data;
slaveDetailData.forEach((item) => {
const redisKey = item.sWorkOrderMaterialId;
sIdArray.push(redisKey);
});
} else { /* 变更单、采购申请单 */
slaveData.forEach((item) => {
const redisKey = item.sWorkOrderMaterialId;
sIdArray.push(redisKey);
});
}
const sId = sIdArray.toString();
onSendSocketMessage('copyfinish', 'noAction', sId, userinfo.sId, null, null);
} else if (commonUtils.isNotEmptyObject(slaveData)) {
slaveData.forEach((item) => {
const redisKey = item.sSlaveId;
sIdArray.push(redisKey);
});
const sId = sIdArray.toString();
onSendSocketMessage('copyfinish', 'noAction', sId, userinfo.sId, null, null);
}
}
onSendSocketMessage('release', 'noAction', currentId, userinfo.sId, null, null);
this.props.onSaveState({
enabled: false, currentId: masterData.sId,
});
// 保存后更新panes,currentPane的checkedId,防止浏览器刷新时重新又变成新增。
const iPaneIndex = app.panes.findIndex(item => item.key === app.currentPane.key);
app.panes[iPaneIndex].checkedId = masterData.sId;
app.currentPane.checkedId = masterData.sId;
dispatch({ type: 'app/savePanesAndCurrentPane', payload: { panes: app.panes, currentPane: app.currentPane } });
if (billnosetting.bAutoCheck) {
await this.handleAudit(1);
} else {
await this.handleGetData(masterConfig, slaveConfig, checkConfig);
if(commonUtils.isNotEmptyArr(slaveInfoList)) {
slaveInfoList.forEach( async(name, index) => {
const tbName = name.replace('Config', '');
const {[`${tbName}Config`]: tableConfig } = this.props;
if (tableConfig && tableConfig.sTbName && tableConfig.sSqlStr !== "noQuery") {
await this.handleGetOneMemoData(tbName, tableConfig);
}
});
}
if(commonUtils.isNotEmptyArr(slaveChildInfoList)) {
slaveChildInfoList.forEach( async(name, index) => {
const tbName = name.replace('Config', '');
const {[`${tbName}Config`]: tableConfig } = this.props;
if (tableConfig && tableConfig.sTbName && tableConfig.sSqlStr !== "noQuery") {
await this.handleGetOneMemoData(tbName, tableConfig);
}
});
}
if ((sModelsType.includes('sales/salesOrder') || sModelsType.includes('manufacture/workOrder')) && !commonUtils.isEmpty(controlConfig)) {
await this.handleGetMemoData(controlConfig, materialsConfig, processConfig, colorConfig, packConfig);
} else if (commonUtils.isNotEmptyObject(formRoute) && formRoute.includes('commonSubBill') && !commonUtils.isEmpty(slaveChildConfig)) {
await this.handleGetOneMemoData('slaveChild', slaveChildConfig);
} else if (sModelsType === 'purchase/purchaseOrder') {
await this.handleGetOneMemoData('orderDetail', orderDetailConfig);
}
if (this.props.app.currentPane.refresh !== undefined) {
this.props.app.currentPane.refresh();
}
}
this.props.onSaveState({
loading: false,
});
return true;
} else {
this.props.onSaveState({
loading: false,
});
return false;
}
};
/** toolbar校验保存 */
handleValidateSave = () => {
this.form.validateFields(async (err) => {
/* 验证通过与不通过走不同的流程 */
if (err) { /* 验证失败 */
/* 直接渲染显示错误提示 */
for (const key of Object.keys(err)) {
message.error(err[key].errors[0].message);
}
this.props.onSaveState({
loading: false,
});
} else { /* 验证成功 */
const {
masterConfig, slaveConfig, slaveData, slaveDelData, slaveChildData, app, sModelsType, controlConfig, controlData, controlDelData, materialsConfig, materialsData, materialsDelData, processConfig, processData, processDelData, colorConfig, colorData, colorDelData, packConfig, packData, packDelData, orderDetailConfig, orderDetailData, orderDetailDelData,
slaveChildConfig, slaveChildDelData, formRoute, slave0Config, slave0Data, slave0DelData, slaveChildInfoList, slaveInfoList,
} = this.props;
// const { slaveData, slaveChildData, error, bGroupDataByDefineNo } = await this.handleGroupDataByDefineNo();
// if (error) {
// this.props.onSaveState({
// loading: false,
// });
// return;
// }
let { masterData } = this.props;
if (sModelsType !== 'commonBill/onlyMaster' && !sModelsType.includes('sales/salesInvoice') && !sModelsType.includes('purchase/purchaseInvoice') && !sModelsType.includes('purchase/outsideInvoice') && sModelsType !== 'cashier/financialTransfer' && sModelsType !== 'cashier/financialAdjustment'
&& !sModelsType.includes('cashier/receipt') && !sModelsType.includes('cashier/payment') && !sModelsType.includes('purchase/purchaseEnquiry')) {
if (slaveConfig && slaveConfig.bNotCanEmpty && commonUtils.isEmptyArr(slaveData)) {
message.error(`${slaveConfig.showName || ''}${commonFunc.showMessage(app.commonConst, 'slaveNotNull')}`); // 从表不能为空!
// if (bGroupDataByDefineNo) {
// commonUtils.isEmptyArr(slaveData) && message.error('按批次汇总失败,请检查批次号等数据!');
// } else {
//
// }
this.props.onSaveState({
loading: false,
});
return;
}
if (slaveChildConfig && slaveChildConfig.bNotCanEmpty && commonUtils.isEmptyArr(slaveChildData)) {
message.error(`${slaveChildConfig.showName || ''}${commonFunc.showMessage(app.commonConst, 'slaveNotNull')}`); // 从表不能为空!
this.props.onSaveState({
loading: false,
});
return;
}
}
// && sModelsType === 'materialsStock/productionmaterialsadjust'
if (commonUtils.isNotEmptyArr(slaveData)) {
let flag = true;
for (const item of slaveData) {
if (sModelsType === 'materialsStock/productionmaterialsadjust') {
if (commonUtils.isNotEmptyStr(item.sWareHouseId)) {
if (masterData.sWareHouseId === item.sWareHouseId && masterData.sWarehouseLocationId === item.sWarehouseLocationId && masterData.sLocationId === item.sLocationId) {
message.error(commonFunc.showMessage(app.commonConst, 'NotSameMateMaterialWarehouse'));/* 材料调拨原仓库与调入仓库不能一致 */
flag = false;
break;
}
}
}
// {"paper":"纸张","finished":"成品","half_finished":"半成品","accessories":"辅料","corrugated":"瓦楞"}
if (commonUtils.isNotEmptyObject(item.sMaterialsType) && item.sMaterialsType === 'paper' && commonUtils.isEmptyObject(item.sMaterialsStyle)) {
if (sModelsType.includes('sales/')) {
message.error(item.sProductName + commonFunc.showMessage(app.commonConst, 'NoStyle'));/* 请填写"${item.sProductName}"的规格 */
} else {
message.error(item.sMaterialsName + commonFunc.showMessage(app.commonConst, 'NoStyle'));/* 请填写"${item.sMaterialsName}"的规格 */
}
flag = false;
break;
}
/* 子从表勾选了表格内容不能为空,并且是非查看表格,如果从表对应的子从表数据为空 则进行提示 */
if(slaveChildConfig?.sTbName !=='noTable' && commonUtils.isNotEmptyObject(slaveChildConfig) && slaveChildConfig.bNotCanEmpty) {
const filterData = slaveChildData.filter(itemChild => itemChild.sSqlConditionId === item.sSqlConditionId);
if(commonUtils.isEmptyArr(filterData) ) {
message.error('第' + item.iRowNum + '行从表对应的'+ `${slaveChildConfig.sChinese || ''}${commonFunc.showMessage(app.commonConst, 'slaveNotNull')}`);
flag = false;
break;
}
}
}
if (!flag) {
this.props.onSaveState({
loading: false,
});
return;
}
}
if (!commonBusiness.validateTable(slaveConfig, slaveData, this.props)) {
this.props.onSaveState({
loading: false,
});
return;
}
if (commonUtils.isNotEmptyArr(slaveData) && sModelsType === 'materialsStock/productionmaterials') {
let flag = true;
const iIndex = app.systemData.findIndex(item => item.sName === 'CkxMaterialsStockLimit');
if (iIndex > -1) {
const bCkxMaterialsStockLimit = app.systemData[iIndex].sValue;
if (bCkxMaterialsStockLimit === '1') {
flag = await this.handleEleMaterialsStoreCurrQty(slaveData);
}
}
if (!flag) {
this.props.onSaveState({
loading: false,
});
return;
}
}
if (sModelsType === 'purchase/purchaseEnquiry') {
delete masterData.maxBillNo;
}
if (commonUtils.isNotEmptyObject(formRoute) && formRoute.includes('commonSubBill') && !commonUtils.isEmpty(slaveChildConfig)) {
const slaveChildDataFilter = slaveChildData?.filter(item => {
return slaveData.map(item => item.sSqlConditionId).includes(item.sSqlConditionId);
});
if (!commonBusiness.validateTable(slaveChildConfig, slaveChildDataFilter, this.props, '2')) {
this.props.onSaveState({
loading: false,
});
return;
}
}
if (sModelsType === 'cashier/receipt' || sModelsType === 'cashier/payment') {
let flag = true;
if (masterData.sSettlementId === 'bank') {
if (commonUtils.isEmptyStr(masterData.sBankId) || commonUtils.isEmptyStr(masterData.sBankAccount)) {
message.error(commonFunc.showMessage(app.commonConst, 'requiredsBankAccount'));/* 收/付款条件为银行时,银行、银行账号为必填项 */
flag = false;
}
}
if (masterData.sSettlementId === 'bill') {
if (commonUtils.isEmptyStr(masterData.sBankId) || commonUtils.isEmptyStr(masterData.sInvoiceNo)) {
message.error(commonFunc.showMessage(app.commonConst, 'requiredsInvoiceNo'));/* 收/付款条件为票据时,银行、票据号码为必填项 */
flag = false;
}
}
let dslaveTotalMoney = 0;
let flagCheckSave = true;
if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) {
for (const item of slaveData) {
if (item.handleType !== 'del') {
if (commonUtils.isNotEmptyNumber(item.dTotalMoney)) {
dslaveTotalMoney += item.dTotalMoney;
}
const dBalanceMoney = commonUtils.isNull(item.dBalanceMoney, 0);
const dTotalMoney = commonUtils.isNull(item.dTotalMoney, 0);
const dRoundingMoney = commonUtils.isNull(item.dRoundingMoney, 0);
const dCount = dRoundingMoney + dTotalMoney;
let bWarning = false;
if (dBalanceMoney > 0 || dBalanceMoney === 0) {
if (dCount > dBalanceMoney) {
bWarning = true;
}
} else if (dCount < dBalanceMoney) {
bWarning = true;
}
if (bWarning) {
if (sModelsType.includes('cashier/receipt')) {
message.error(commonFunc.showMessage(app.commonConst, 'NoOverBalanceMoneyReceipt'));/* 总金额不能超过未收/付款宽金额 */
} else if (sModelsType.includes('cashier/payment')) {
message.error(commonFunc.showMessage(app.commonConst, 'NoOverBalanceMoneyPay'));/* 总金额不能超过未收/付款宽金额 */
}
this.props.onSaveState({
loading: false,
});
return;
}
}
const flatDel = commonUtils.isNull(item.dTotalMoney, 0) !== 0 || commonUtils.isNull(item.dRoundingMoney, 0) !== 0;
if (!flatDel) {
item.handleType = undefined; /* 付款单和收款单,去掉收款和付款金额为0的记录 */
} else {
flagCheckSave = false;
}
}
}
if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0 && flagCheckSave) {
message.warning('表格内容不能为空![dTotalMoney或dRoundingMoney必须大于0]');
this.props.onSaveState({
loading: false,
});
return;
}
const dPmoney = this.props.getFloatNum('dProductMoney');
dslaveTotalMoney = commonUtils.convertFixNum(dslaveTotalMoney, dPmoney);/* 取系统设定小数位 */
if (commonUtils.isNotEmptyArr(slaveData) && commonUtils.isNotEmptyNumber(masterData.dTotalMoney) && commonUtils.isNotEmptyNumber(masterData.dAdvanceMoney) && commonUtils.convertFixNum(masterData.dTotalMoney - masterData.dAdvanceMoney, dPmoney) !== dslaveTotalMoney) {
message.error(commonFunc.showMessage(app.commonConst, 'NotSameTotalMoney'));/* 主从表总金额不一致 */
flag = false;
}
/* 收付款保存前,看到从表没数据,预收勾上时,自动调用一下分摊 */
if (commonUtils.isEmptyArr(slaveData)) {
masterData = this.handleShare();
}
if (!flag) {
this.props.onSaveState({
loading: false,
});
return;
}
}
/* 销售发票、采购发票、发外发票 ,去掉总金额+舍入为0的数据 */
if (sModelsType === 'sales/salesInvoice' || sModelsType === 'purchase/purchaseInvoice' || sModelsType === 'purchase/outsideInvoice') {
let flagCheckSave = true;
if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) {
for (const item of slaveData) {
const flatDel = commonUtils.isNull(item.dTotalMoney, 0) !== 0 || commonUtils.isNull(item.dRoundingMoney, 0) !== 0;
if (!flatDel) {
item.handleType = undefined; /* 付款单和收款单,去掉收款和付款金额为0的记录 */
} else {
flagCheckSave = false;
}
}
}
/* 收付款保存前,看到从表没数据,预收勾上时,自动调用一下分摊 */
if (commonUtils.isEmptyArr(slaveData)) {
masterData = this.handleShare();
}
if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0 && flagCheckSave) {
message.warning('表格内容不能为空![dTotalMoney或dRoundingMoney必须大于0]');
this.props.onSaveState({
loading: false,
});
return;
}
}
const data = [];
data.push(commonBusiness.mergeData('master', masterConfig.sTbName, [masterData]));
if (sModelsType !== 'commonBill/onlyMaster' && sModelsType !== 'cashier/financialTransfer' && sModelsType !== 'cashier/financialAdjustment' && !sModelsType.includes('purchase/purchaseEnquiry')) {
data.push(commonBusiness.mergeData('slave', slaveConfig.sTbName, slaveData, slaveDelData));
}
if (sModelsType.includes('sales/salesOrder') && !commonUtils.isEmpty(controlConfig)) {
if (commonUtils.isNotEmptyArr(materialsData)) {
const flag = true;
// for (const item of materialsData) { /* 销售订单中的物料规格不是必填项,只有工单里才要判断必填 */
// if (commonUtils.isNotEmptyObject(item.sMaterialsType) && item.sMaterialsType === 'paper' && commonUtils.isEmptyObject(item.sMaterialsStyle)) {
// message.error(item.sMaterialsName + commonFunc.showMessage(app.commonConst, 'NoStyle'));/* 请填写规格 */
// flag = false;
// break;
// }
// }
if (!flag) {
this.props.onSaveState({
loading: false,
});
return;
}
}
data.push(commonBusiness.mergeData('control', controlConfig.sTbName, controlData, controlDelData));
data.push(commonBusiness.mergeData('materials', materialsConfig.sTbName, materialsData, materialsDelData));
data.push(commonBusiness.mergeData('process', processConfig.sTbName, processData, processDelData));
if (commonUtils.isNotEmptyObject(colorConfig)) {
data.push(commonBusiness.mergeData('color', colorConfig.sTbName, colorData, colorDelData));
}
if (commonUtils.isNotEmptyObject(packConfig)) {
data.push(commonBusiness.mergeData('pack', packConfig.sTbName, packData, packDelData));
}
}
if (sModelsType === 'purchase/purchaseOrder' && !commonUtils.isEmpty(orderDetailConfig)) {
data.push(commonBusiness.mergeData('detail', orderDetailConfig.sTbName, orderDetailData, orderDetailDelData));
} else if (commonUtils.isNotEmptyObject(formRoute) && formRoute.includes('commonSubBill') && !commonUtils.isEmpty(slaveChildConfig)) {
data.push(commonBusiness.mergeData('slaveChild', slaveChildConfig.sTbName, slaveChildData, slaveChildDelData));
}
if (!commonUtils.isEmpty(slave0Config)) {
data.push(commonBusiness.mergeData('slave0', slave0Config.sTbName, slave0Data, slave0DelData));
}
if(commonUtils.isNotEmptyArr(slaveInfoList)){
slaveInfoList.forEach(name => {
const tbName = name.replace('Config', '');
const {[`${tbName}Config`]: tableConfig, [`${tbName}Data`]: tableData, [`${tbName}DelData`]: tableDelData } = this.props;
if (tableConfig && tableConfig.sTbName && tableConfig.sSqlStr !== "noQuery" && tbName !== 'slave0') {
const tableDataNew = tbName === "master" ? [tableData] : tableData;
data.push(commonBusiness.mergeData(tbName, tableConfig.sTbName, tableDataNew, tableDelData));
}
});
}
if(commonUtils.isNotEmptyArr(slaveChildInfoList)){
slaveChildInfoList.forEach(name => {
const tbName = name.replace('Config', '');
const {[`${tbName}Config`]: tableConfig, [`${tbName}Data`]: tableData, [`${tbName}DelData`]: tableDelData } = this.props;
if (tableConfig && tableConfig.sTbName && tableConfig.sSqlStr !== "noQuery") {
const tableDataNew = tbName === "master" ? [tableData] : tableData;
data.push(commonBusiness.mergeData(tbName, tableConfig.sTbName, tableDataNew, tableDelData));
}
});
}
this.handleSaveData({ data, sClientType: '1', sSysLogSrcId: masterData.sId });
}
});
};
// // 保存前根据批次号重新汇总数据
// handleGroupDataByDefineNo = async () => {
// const { formRoute, slaveConfig = {}, slaveData, slaveChildData } = this.props;
// if (
// formRoute === '/indexPage/commonSubBill' &&
// commonUtils.isNotEmptyArr(slaveData) &&
// commonUtils.isNotEmptyArr(slaveChildData)
// ) {
// const { gdsconfigformslave = [] } = slaveConfig;
// const bGroupDataByDefineNo = gdsconfigformslave.some(item => item.bVisible && item.sControlName === 'bGroupDataByDefineNo');
// if (bGroupDataByDefineNo) {
//
// const bSSqlConditionIdEmpty = slaveData.some(item => !item.sSqlConditionId);
// if (bSSqlConditionIdEmpty) {
// message.error('从表未配置sSqlConditionId字段,汇总失败!');
// return { error: true };
// }
//
// // 从表的sSqlConditionId数组
// const sSqlConditionIdArr = slaveData.map(item => item.sSqlConditionId);
// // 过滤子从表数据(有sSqlConditionId、sSqlConditionId在sSqlConditionIdArr内、有批次号)
// const slaveChildDataFilter = slaveChildData.filter(
// item =>
// item.sSqlConditionId &&
// sSqlConditionIdArr.includes(item.sSqlConditionId) &&
// (item.sDefineNo || item.sDefineNo2)
// );
// // 按sSqlConditionId分组子从表数据
// const sSqlConditionIdGroup = slaveChildDataFilter.reduce((result, child) => {
// const { sSqlConditionId } = child;
// let iIndex = result.findIndex(arr => arr && arr.some(item => item.sSqlConditionId === sSqlConditionId));
// if (iIndex === -1) {
// result.push([]);
// iIndex = result.length - 1;
// }
// result[iIndex].push(child);
// return result;
// }, []);
//
// const slaveChildDataGroup = [];
// sSqlConditionIdGroup.forEach(group => {
// // 按批次号分组子从表数据
// const defineNoGroup = group.reduce((result, child) => {
// const { sDefineNo, sDefineNo2 } = child;
// let iIndex = result.findIndex(arr => arr && arr.some(item => {
// const _sDefineNo = commonUtils.isEmptyStr(item.sDefineNo) ? '' : item.sDefineNo;
// const _sDefineNo2 = commonUtils.isEmptyStr(item.sDefineNo2) ? '' : item.sDefineNo2;
// const sDefineNoNew = commonUtils.isEmptyStr(sDefineNo) ? '' : sDefineNo;
// const sDefineNo2New = commonUtils.isEmptyStr(sDefineNo2) ? '' : sDefineNo2;
// return _sDefineNo === sDefineNoNew && _sDefineNo2 === sDefineNo2New;
// }));
// if (iIndex === -1) {
// result.push([]);
// iIndex = result.length - 1;
// }
// result[iIndex].push(child);
// return result;
// }, []);
// slaveChildDataGroup.push(defineNoGroup);
// });
// const slaveDataNew = [];
// for (let index0 = 0; index0 < slaveChildDataGroup.length; index0++) {
// const group = slaveChildDataGroup[index0];
//
// // 获取关联的从表数据
// const sSqlConditionId = group[0][0].sSqlConditionId;
// const iSlaveIndex = slaveData.findIndex(item => item.sSqlConditionId === sSqlConditionId);
// const { sId } = slaveData[iSlaveIndex];
//
// for (let index = 0; index < group.length; index++) {
// const defineNoGroup = group[index];
// let dAuxiliaryQty = 0;
// let dEscrowQty = 0;
// let dGiveAuxiliaryQty = 0;
// let dProductQty = 0;
// defineNoGroup.forEach(item => {
// const { itype, iType } = item;
// const type = itype !== undefined ? itype : iType !== undefined ? iType : 1;
// if (type === 1) {
// dAuxiliaryQty += commonUtils.isNull(item.dAuxiliaryQty, 0);
// } else if (type === 2) {
// dEscrowQty += commonUtils.isNull(item.dAuxiliaryQty, 0);
// } else if (type === 3) {
// dGiveAuxiliaryQty += commonUtils.isNull(item.dAuxiliaryQty, 0);
// } else if (type === 10) {
// dAuxiliaryQty += commonUtils.isNull(item.dProductQty, 0);
// } else if (type === 11) {
// dProductQty += commonUtils.isNull(item.dAuxiliaryQty, 0);
// }
// })
//
// const iIndex = slaveData.findIndex(item => item.sId === sId);
// let slaveRowData = {};
// slaveRowData = await this.handleTableChange('slave', 'dEscrowQty', { dEscrowQty }, sId, [], true);
// slaveData[iIndex] = slaveRowData;
// window.tmpSlaveData = slaveData;
// slaveRowData = await this.handleTableChange('slave', 'dGiveAuxiliaryQty', { dGiveAuxiliaryQty }, sId, [], true);
// slaveData[iIndex] = slaveRowData;
// window.tmpSlaveData = slaveData;
// slaveRowData = await this.handleTableChange('slave', 'dAuxiliaryQty', { dAuxiliaryQty }, sId, [], true);
// slaveData[iIndex] = slaveRowData;
// if (defineNoGroup.some(item => item.itype === 11 || item.iType === 11)) {
// window.tmpSlaveData = slaveData;
// slaveRowData = await this.handleTableChange('slave', 'dProductQty', { dProductQty }, sId, [], true);
// slaveData[iIndex] = slaveRowData;
// }
// window.tmpSlaveData = null;
//
// if (slaveDataNew.some(item => item.sId === sId)) {
// slaveRowData = { ...slaveRowData, sId: commonUtils.createSid(), handleType: 'add' };
// } else {
// const handleType = slaveRowData.handleType || 'add';
// const addState = handleType === 'add' ? { sId: commonUtils.createSid() } : {};
// slaveRowData = { ...slaveRowData, handleType, ...addState };
// }
// slaveRowData.sDefineNo = defineNoGroup[0].sDefineNo;
// slaveRowData.sDefineNo2 = defineNoGroup[0].sDefineNo2;
// slaveDataNew.push(slaveRowData);
// }
// }
// return {
// slaveData: slaveDataNew,
// slaveChildData: slaveChildData,
// bGroupDataByDefineNo
// }
// }
// }
// return { slaveData, slaveChildData };
// }
// 子从表数据修改后根据批次号重新汇总数据
handleGroupDataByDefineNoAfterChange = async () => {
// const { slaveData = [], slaveChildData = [], error, bGroupDataByDefineNo } = await this.handleGroupDataByDefineNo();
// if (error || !bGroupDataByDefineNo) return;
// if (slaveChildData.length && !slaveData.length) return;
//
// const { slaveSelectedRowKeys = [] } = this.props;
// const addState = {};
// if (commonUtils.isEmptyArr(slaveSelectedRowKeys) || !slaveData.some(item => item.sId === slaveSelectedRowKeys[0])) {
// addState.slaveSelectedRowKeys = [slaveData[0].sId];
// }
//
// this.props.onSaveState({
// slaveData, slaveChildData, ...addState
// })
}
/* 切换作废状态 */
handleOkChangeInvaild = async (props) => {
const {
sModelsId, masterData, masterConfig, handleType,
} = props;
const value = {
sClientType: '1',
sId: [masterData.sId],
sTableName: masterConfig.sTbName,
handleType,
};
const url = `${commonConfig.server_host}checkModel/updatebInvalid?sModelsId=${sModelsId}`;
const { data } = await commonServices.postValueService(props.app.token, value, url);
if (data.code === 1) {
message.success(data.msg);
masterData.bInvalid = handleType === 'toVoid'; /* 作废状态 */
props.onSaveState({ masterData });
/* 审核(消审)后刷新跳转路由数据(commonList)的数据 */
if (props.app.currentPane.refresh !== undefined) {
props.app.currentPane.refresh();
}
} else {
props.getServiceError(data);
}
};
/* 作废、取消作废的公用函数 */
handleInvalid = (obj) => {
const props = { ...this.props, ...this.state, ...obj };
const onOkInvaild = this.handleOkChangeInvaild;
confirm({
title: obj.title,
onOk() {
onOkInvaild(props);
},
onCancel() {
},
});
};
/* 单据页上查下查跳转页面 */
handleSearchUpDown = async (sId, sActiveId) => {
/* 待用数据声明 */
const { dispatch, sTabId } = this.props;
dispatch({
type: 'content/onRouter',
payload: {
url: `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sActiveId}?sModelsId=${sActiveId}`, /* 接口地址 */
sParentId: sTabId, /* 父页面编号 */
checkedId: sId,
},
});
};
/* 上查下查三级菜单 在上一条下一条时必须清除searchUpDownData */
handleSearchUpDownThird = async (upDownKey) => {
/* 待用数据声明 */
const { masterConfig, searchUpDownData: searchUpDownDataOld } = this.props;
/** 获取sqlCondition参数:{sSqlCondition,sId} */
const searchUpDownData = commonUtils.isEmptyObject(searchUpDownDataOld) ? {} : { ...searchUpDownDataOld };
if (commonUtils.isNotEmptyObject(masterConfig)) {
const searchUpDownConfig = masterConfig.gdsconfigformslave.filter(item => item.sControlName.includes(`${upDownKey}`));
for (const item of searchUpDownConfig) {
if (commonUtils.isEmptyArr(searchUpDownData[item.sControlName])) {
searchUpDownData[item.sControlName] = await this.getSearchUpDownData(item);
}
}
this.props.onSaveState({ searchUpDownData });
}
};
/* 单据页复制到 */
handleCopyTo = async (name, sActiveId) => {
/* 待用数据声明 */
const {
masterConfig,
masterData,
slaveData,
controlData,
materialsData,
processData,
packData,
slaveChildData,
slave0Data,
app,
token,
sModelsId,
formRoute,
} = this.props;
// 从表有sCopyToCondition则不能复制,并提示
if (commonUtils.isNotEmptyArr(slaveData) && name.includes('.')) {
const sCopyToConditionIndex = slaveData.findIndex(item => item.sCopyToCondition);
if (sCopyToConditionIndex !== -1) {
message.warning(slaveData[sCopyToConditionIndex].sCopyToCondition);
this.props.onSaveState({
loading: false,
});
return;
}
}
const copyTo = {};
const copyToConfig = masterConfig.gdsconfigformslave.filter(item => item.sControlName.includes(name));
copyTo.name = name;
copyTo.config = copyToConfig;
copyTo.masterData = masterData;
copyTo.slaveData = slaveData;
copyTo.controlData = controlData;
copyTo.materialsData = materialsData;
copyTo.processData = processData;
copyTo.packData = packData;
copyTo.slaveChildData = slaveChildData;
copyTo.slave0Data = slave0Data;
const tbSuffix = '';
let sId = '';
if (!commonUtils.isEmpty(slaveData)) {
sId = slaveData[0].sId;
}
if (commonUtils.isNotEmptyObject(name) && name.toLowerCase().includes('btncopyto.tmpinfobysql')) { /* 根据配置下拉sql获取数据源 */
const dataUrl = `${commonConfig.server_host}salesorder/getTmpInfoBySql/?sModelsId=${sModelsId}`;
const sConfigformId = commonUtils.isEmpty(copyToConfig) ? '' : copyToConfig[0].sParentId;
const sControlName = commonUtils.isNotEmptyObject(name) ? name : 'BtnCopyTo.TmpInfoBySql';
const sRowData = masterData;
const values = { sConfigformId, sControlName, sRowData };
const dataReturn = (await commonServices.postValueService(token, values, dataUrl)).data;
if (dataReturn.code === 1) {
const returnData = dataReturn.dataset.rows[0];
if (commonUtils.isNotEmptyObject(returnData)) {
for (const key of Object.keys(returnData)) {
const sName = `${key}Data`;
const masterName = name.replace('BtnCopyTo.','').trim();
if(key === masterName) {
copyTo.masterData = returnData[key][0];
}else {
copyTo[sName] = returnData[key];
}
}
if (commonUtils.isNotEmptyArr(copyTo.masterData) && Array.isArray(copyTo.masterData)) {
copyTo.masterData = copyTo.masterData[0];
}
}
} else {
this.props.getServiceError(dataReturn);
}
}
const dataUrl = `${commonConfig.server_host}bill/billCopyToCheck/?sModelsId=${sModelsId}&sActiveId=${sActiveId}&tbSuffix=${tbSuffix}&sName=${formRoute}`;
const values = { sSlaveId: sId };
const dataReturn = (await commonServices.postValueService(token, values, dataUrl)).data;
if (dataReturn.code === 1) {
this.props.onSaveState({
loading: false,
});
// eslint-disable-next-line no-underscore-dangle
const _this = this; // 解决confirm中this指向问题;
if (dataReturn.dataset.rows.length > 0) {
confirm({
title: commonFunc.showMessage(app.commonConst, 'beUsedToNew'), /* 单据已存在,是否填写新单据 */
onOk() {
_this.handleDispatch(copyTo, sActiveId);
},
onCancel() {
},
});
} else {
this.handleDispatch(copyTo, sActiveId);
}
}
};
handleDispatch = (copyTo, sActiveId) => {
const { dispatch } = this.props;
console.log('copyTo', copyTo);
dispatch({
type: 'content/onRouter',
payload: {
url: `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sActiveId}?sModelsId=${sActiveId}`, /* 接口地址 */
copyTo,
},
});
}
/* 复制从产品工艺卡列表 */
handleCopyFrom = async (obj) => {
/* 待用数据声明 */
const {
slaveData,
} = this.props;
this.copyName = obj.name;
const { token } = this.props;
const url = `${commonConfig.server_host}/gdsmodule/getGdsmoduleById/${obj.copyFromSActiveId}?sModelsId=${obj.copyFromSActiveId}`;
const dataReturn = (await commonServices.getService(token, url)).data;
if (dataReturn.code === 1) {
const returnData = dataReturn.dataset.rows[0];
if (obj.copyFromKey.includes('customizeFormInfo')) { /* 复制从自定义窗体 */
this.props.onSaveState({ copyFromChooseVisible: true, copyFromChooseData: returnData, copyFromKey: obj.copyFromKey });
} else {
this.props.onSaveState({ productProcessInfoChooseVisible: true, productProcessInfoChooseData: returnData, productProcessInfoCopyFromKey: obj.copyFromKey });
}
} else {
this.props.getServiceError(dataReturn);
}
};
/* 上一条、下一条、首条、末条 */
handleSearchData = async (handleType) => {
const {
sModelsId, app, currentIndexFlag, currentPageNo, slaveChildConfig, memoDataList, masterData,
masterConfig, slaveConfig, checkConfig, sSrcModelsId,
} = this.props;
let { sBillIdsArray = []} = this.props;
let { currentId } = this.props;
const { currentPane, token } = app;
const tipLast = commonFunc.showLocalMessage(this.props, 'tipLast', '当前已经是最后一条');
const tipFirst = commonFunc.showLocalMessage(this.props, 'tipFirst', '当前已经是第一条');
const {
pages, sFilterOrderBy, bFilter, sListFormmasterId, currentIndex,
} = currentPane;
let currentPosition = currentIndexFlag ? currentPageNo : commonUtils.isEmptyObject(pages) ? 1 : (((pages.current - 1) * commonConfig.pageSize) + Number.parseInt(currentIndex, 10)) + 1;
if (currentIndex === undefined) {
currentPosition = 1;
}
// if (handleType === 'first') {
// currentPosition = 1;
// } else if (handleType === 'end') {
// currentPosition = pages.total;
// }
if (!commonUtils.isNum(currentPosition)) { // 如果是列表直接点增加,就跳到第一条去
currentPosition = 1;
}
let bExist = false;
/* 如果sBillIdsArray已存在 则不请求 */
if(commonUtils.isNotEmptyArr(sBillIdsArray) && sBillIdsArray.length > 0) {
const index = sBillIdsArray.indexOf(currentId);
if(index > -1) {
if ("next".includes(handleType)) {
currentPosition = index + 1;
if(currentPosition > sBillIdsArray.length - 1 ){
message.warn(tipLast);
return ;
}
} else if ("up".includes(handleType)) {
if(index === 0){
message.warn(tipFirst);
return ;
}
currentPosition = index - 1;
} else if ("first".includes(handleType)) {
currentPosition = 0;
} else if ("end".includes(handleType)) {
currentPosition = sBillIdsArray.length - 1;
}
currentId = sBillIdsArray[currentPosition];
currentPosition = currentPosition + 1;
bExist = true;
} else {
bExist = false;
}
}
/* 如果是第一次请求 */
if(!bExist) {
const bFromList = commonUtils.isEmptyObject(pages) ? true: false;
if(bFromList) {
if(handleType ==='next' || handleType ==='end') {
message.warn(tipLast);
return ;
}else {
message.warn(tipFirst);
return ;
}
}
const value = {
sClientType: '1', sFilterOrderBy, bFilter, sListFormmasterId, currentPosition, handleType, iCountSum: pages.total,
sUpId: masterData?.sId, sParentModelId :sSrcModelsId,
};
const url = `${commonConfig.server_host}business/getBusinessDataByIndex?sModelsId=${sModelsId}`;
/* 接收返回值 */
const { data } = await commonServices.postValueService(token, value, url);
/* 接收返回值 */
/* 成功的话刷新页面(同步主表和从表数据),不成功就弹出错误提示 */
if (data.code === 1) {
/* 数据查询成功 */
const returnData = data.dataset.rows[0];
/* 拿到接口返回的sBillids */
console.log('returnData', returnData);
const sBillIds = returnData.sBillIds;
if(commonUtils.isNotEmptyArr(sBillIds)) {
sBillIdsArray = sBillIds;
}
currentId = returnData.sId;
currentPosition = returnData.currentPosition;
} else { /* 失败 */
this.props.getServiceError(data);
return false;
}
}
this.props.onSaveState({
currentIndexFlag: true,
currentPageNo: currentPosition,
currentId,
searchUpDownData: {},
slaveSelectedRowKeys: [],
sBillIdsArray,
},
() => {
this.handleGetData(masterConfig, slaveConfig, checkConfig);
if(commonUtils.isNotEmptyObject(slaveChildConfig)) {
this.handleGetOneMemoData('slaveChild', slaveChildConfig);
}
if (commonUtils.isNotEmptyObject(memoDataList)) {
this.handleGetMemoData1(memoDataList);
}
});
return true;
};
/* 取消操作 */
handleCancel = (obj) => {
/* 待用数据声明 */
const that = this;
const {
currentId, masterConfig, slaveConfig, checkConfig, app, slaveChildConfig,
} = this.props;
const { userinfo } = app;
const onSendSocketMessage = this.props.handleSendSocketMessage;
const onGetDataOk = this.handleGetData;
const onSaveStateOk = this.props.onSaveState;
const { copyTo } = app.currentPane;
confirm({
title: obj.title,
onOk() {
// 解决新建页签sid为空的bug
if (!currentId) {
const { panes, currentPane } = that.props.app;
const currentPaneIndex = panes.findIndex(item => item.key === currentPane.key);
const newPanes = [];
if (currentPaneIndex > 0) {
panes.forEach((item, index) => {
if (index !== currentPaneIndex) {
newPanes.push(item);
}
});
that.props.dispatch({ type: 'app/removePane', payload: { changePanes: newPanes, currentPane: panes[currentPaneIndex - 1] } });/* 关闭当前页签 */
}
/* 复制到新增页签取消时 关闭页签 并清除操作记录 */
if (commonUtils.isNotEmptyObject(copyTo)) {
const { slaveData, srcFormRoute, copyOtherData } = copyTo;
if (commonUtils.isNotEmptyObject(srcFormRoute) && srcFormRoute.includes('materialRequirementsPlanning')) { /* 物料需求计划用sWorkOrderMaterialId作为唯一键 */
const sIdArray = [];
if (commonUtils.isNotEmptyArr(copyOtherData) && copyOtherData[0].name === 'detail' && commonUtils.isNotEmptyArr(copyOtherData[0].data)) {
const slaveDetailData = copyOtherData[0].data;
slaveDetailData.forEach((item) => {
const redisKey = item.sWorkOrderMaterialId;
sIdArray.push(redisKey);
});
} else { /* 变更单、采购申请单 */
slaveData.forEach((item) => {
const redisKey = item.sWorkOrderMaterialId;
sIdArray.push(redisKey);
});
}
const sId = sIdArray.toString();
onSendSocketMessage('copyfinish', 'noAction', sId, userinfo.sId, null, null);
} else if (commonUtils.isNotEmptyArr(slaveData)) {
const sIdArray = [];
slaveData.forEach((item) => {
const redisKey = item.sSlaveId;
sIdArray.push(redisKey);
});
const sId = sIdArray.toString();
onSendSocketMessage('copyfinish', 'noAction', sId, userinfo.sId, null, null);
}
}
return;
}
//
const bChanged = commonBusiness.handleGetChanged(that.props) ;
if(bChanged) {
that.handleGetOneMemoData('slaveChild', slaveChildConfig);
onGetDataOk(masterConfig, slaveConfig, checkConfig);
}
onSaveStateOk({ enabled: false });
if (commonUtils.isNotEmptyObject(copyTo)) {
const { slaveData } = copyTo;
const sIdArray = [];
slaveData.forEach((item) => {
const redisKey = item.sSlaveId;
sIdArray.push(redisKey);
});
const sId = sIdArray.toString();
onSendSocketMessage('copyfinish', 'noAction', sId, userinfo.sId, null, null);
}
onSendSocketMessage('release', 'noAction', currentId, userinfo.sId, null, null);
},
onCancel() {
},
});
};
/* 删除 */
handleDel = (obj) => {
const props = { ...this.props, ...this.state };
const onOkDel = this.handleOkDel;
confirm({
title: obj.title,
onOk() {
onOkDel(props);
},
onCancel() {
},
});
};
/* 确定要删除 */
handleOkDel = async (props) => {
/* 数据参数 */
const {
token, sModelsId, sModelsType, masterConfig, masterData, slaveConfig, checkConfig, orderDetailConfig, slaveChildConfig, slave0Config, app, formRoute,
} = props;
const { userinfo, systemData } = app;
const { sMakePerson } = masterData; /* 本单据制单人 */
const { sUserName, sType } = userinfo;/* 登录用户 */
const iIndex = systemData.findIndex(item => item.sName === 'CkxModifyBillNoMakePerson');
if (iIndex > -1) {
const sValue = systemData[iIndex].sValue;
if (sValue === '0') { /* 系统未启用非制单人修改单据,普通用户非制单人不可以修改制单人的单据 */
if (sType !== 'sysadmin' && sUserName !== sMakePerson) {
message.error(commonFunc.showMessage(app.commonConst, 'NoDelByNoMakePerson'));
return;
}
}
}
const value = {
sClientType: '1',
data: {
sMasterTable: masterConfig.sTbName,
sId: [masterData.sId],
},
};
const sSlaveTable = [];
if (commonUtils.isNotEmptyObject(slaveConfig)) {
sSlaveTable.push({
tableName: slaveConfig.sTbName,
relationName: 'sParentId',
});
}
if (commonUtils.isNotEmptyObject(checkConfig)) {
sSlaveTable.push({
tableName: checkConfig.sTbName,
relationName: 'sParentId',
});
}
if (commonUtils.isNotEmptyObject(slave0Config)) {
sSlaveTable.push({
tableName: slave0Config.sTbName,
relationName: 'sParentId',
});
}
if (sModelsType === 'purchase/purchaseOrder' && !formRoute.includes('commonSubBill')) {
if (commonUtils.isNotEmptyObject(orderDetailConfig)) {
sSlaveTable.push({
tableName: orderDetailConfig.sTbName,
relationName: 'sParentId',
});
}
}
if (commonUtils.isNotEmptyObject(formRoute) && formRoute.includes('commonSubBill') && !commonUtils.isEmpty(slaveChildConfig)) {
sSlaveTable.push({
tableName: slaveChildConfig.sTbName,
relationName: 'sParentId',
});
}
value.sSlaveTable = sSlaveTable;
const { sBillNo, sId } = masterData || {};
const url = `${commonConfig.server_host}business/delMasSlaBusinessData?sModelsId=${sModelsId}&sBillNo=${sBillNo}&sSysLogSrcId=${sId}`;
/* 接收返回值 */
const { data } = await commonServices.postValueService(token, value, url);
if (data.code === 1) {
/* 数据删除成功 */
if (this.props.app.currentPane.refresh !== undefined) {
this.props.app.currentPane.refresh();
}
this.handleDelDataSuccess(props);
} else { /* 失败 */
this.props.getServiceError(data);
}
};
/* 数据删除成功跳转到新路由即pane */
handleDelDataSuccess = (props) => {
const { app } = props;
let { panes, currentPane } = app;
/* 删除单据后退出当前路由后,标签panes变化后的集合 */
panes = panes.filter(pane => pane.key !== currentPane.key);
/* 跳转到panes集合的最后一个路由,因为panes集合一定含有主页路由所以panes的集合大于等于1 */
currentPane = panes[panes.length - 1];
this.props.onRemovePane(panes, currentPane);
};
handleDataReplace = (sId, tableDataRow, type) => {
const { slaveChildData, slaveSelectedRowKeys, slaveData } = this.props;
delete tableDataRow?.sWorkOrderUsed;
delete tableDataRow?.bInuse;
delete tableDataRow?.rowTag;
if (!Array.isArray(slaveChildData)) return {
tableDataRow: { ...tableDataRow || {}, sSqlConditionId: sId, sSlaveId: sId },
slaveChildData: [],
};
if (type === 'copy') {
const sSqlConditionId = slaveData.find(i => i && slaveSelectedRowKeys.includes(i.sId))?.sSqlConditionId;
const addSlaveChildValue = cloneDeep(slaveChildData?.filter(i => i && i.sSqlConditionId === sSqlConditionId));
const iOrderArr = [];
slaveChildData.forEach((item) => {
const iOrder = commonUtils.isNotEmptyNumber(item.iOrder) ? item.iOrder : 0; /* 获取tableData中iOrder最大值 */
iOrderArr.push(iOrder);
});
const iOrderMax = Math.max(...iOrderArr);
addSlaveChildValue.forEach((i, index) => { if (i) {
const uuid = commonUtils.createSid();
i.handleType = 'add';
i.key = uuid;
i.iOrder = commonUtils.isNotEmptyArr(slaveChildData) ? iOrderMax + 1 + index : 0;
i.sSqlConditionId = sId;
i.sId = uuid;
i.sSlaveId = uuid;
delete i.rowTag;
delete i?.bInuse;
delete i.sWorkOrderUsed;
}});
return {
tableDataRow: { ...tableDataRow || {}, sSqlConditionId: sId, sSlaveId: sId },
slaveChildData: [...slaveChildData, ...addSlaveChildValue || []],
}
}
return {
tableDataRow: { ...tableDataRow || {}, sSqlConditionId: sId, sSlaveId: sId },
slaveChildData: [...slaveChildData],
};
}
/** 添加表格空行 */
handleTableAdd = (name, isWait) => {
/* 从CommonBase获取默认参数 */
const {
masterData, masterConfig, sModelsType, app, [`${name}Pagination`]: tablePagination, slaveData, slaveSelectedRowKeys,
} = this.props;
let { [`${name}Data`]: tableData } = this.props;
tableData = commonUtils.isEmptyObject(tableData) ? [] : tableData;
let tableDataRow = this.props.onDataRowAdd(name, true);
/* 添加行的业务处理拿出去 */
if (sModelsType.includes('sales/')) {
if (commonUtils.isEmptyStr(masterData.sCustomerId)) {
const iIndex = masterConfig.gdsconfigformslave.findIndex(item => ((item.sName === 'sCustomerId' || item.sName === 'sCustomerNo' || item.sName === 'sCustomerName') && item.bVisible));
if (iIndex > -1) {
const { showName } = masterConfig.gdsconfigformslave[iIndex];
message.warn(showName + commonFunc.showMessage(app.commonConst, 'isNotNull')); // 不能为空
return;
}
}
}
if (commonUtils.isEmptyObject(tableDataRow.sWareHouseId)) {
tableDataRow.sWareHouseId = masterData.sWareHouseId;
tableDataRow.sWareHouseNo = masterData.sWareHouseNo;
tableDataRow.sWareHouseName = masterData.sWareHouseName;
tableDataRow.sLocationId = masterData.sLocationId;
tableDataRow.sLocationNo = masterData.sLocationNo;
tableDataRow.sLocationName = masterData.sLocationName;
tableDataRow.sWareHouseLocationId = masterData.sWareHouseLocationId;
tableDataRow.sWareHouseLocationNo = masterData.sWareHouseLocationNo;
tableDataRow.sWareHouseLocationName = masterData.sWareHouseLocationName;
}
let addState = {};
if (name === 'slave') {
if (['12710101117007068710620'].includes(this.props.sModelsId)) {
const value = this.handleDataReplace(tableDataRow.sId, tableDataRow);
addState.slaveChildData = value.slaveChildData;
tableDataRow = { ...value.tableDataRow || {} };
}
tableDataRow.sSqlConditionId = tableDataRow.sId;
}
if (name === 'slaveChild') {
/* 找到从表的sSqlConditionId */
if(commonUtils.isEmptyArr(slaveSelectedRowKeys)) {
message.error('请选择父级!');
return ;
}
let iIndex = slaveData.findIndex(item => slaveSelectedRowKeys.includes(item.sId));
if (iIndex > -1) {
tableDataRow.sSqlConditionId = slaveData[iIndex].sSqlConditionId;
}
}
if (isWait) {
return tableDataRow;
} else if (commonUtils.isNotEmptyObject(tableDataRow)) {
tableData.push(tableDataRow);
this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}Pagination`]: { ...tablePagination, total: tableData.length, current: 9999 }, [`${name}SelectedRowKeys`]: [tableDataRow.sId], ...addState });
}
};
/** 复制 */
handleTableCopy = (name, isWait, isTree) => {
const {
[`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: tableSelectedRowKeys, [`${name}Pagination`]: tablePagination, sModelsType,
} = this.props;
if (commonUtils.isEmptyArr(tableSelectedRowKeys)) {
message.warn(commonFunc.showMessage(this.props.app.commonConst, 'pleaseChooseCopyData'));/* 请选择复制数据 */
} else {
if (sModelsType === 'sales/salesOrderPack' && isTree) { /* 树形 */
const {
[`${name}SelectedRowKeys`]: treeSelectedKeys,
} = this.props;
const controlChildData = tableData.filter(item => item.sAllId.indexOf(treeSelectedKeys[0]) > -1 && item.sId !== treeSelectedKeys[0]);
if (commonUtils.isNotEmptyArr(tableData)) {
controlChildData.forEach((itemNew) => {
tableSelectedRowKeys.push(itemNew.sId);
});
}
}
const treeCopyNodes = new Map();
for (const sId of tableSelectedRowKeys) {
const tableDataIndex = tableData.findIndex(item => item.sId === sId);
if (tableDataIndex > -1) {
const tableDataRow = JSON.parse(JSON.stringify(tableData[tableDataIndex]));
tableDataRow.sId = commonUtils.createSid();
tableDataRow.handleType = 'add';
tableDataRow.key = tableDataRow.sId;
tableDataRow.sSrcSlaveId = '';
tableDataRow.sSrcId = '';
tableDataRow.dSrcQty = null;
tableDataRow.rowTag = null;
tableDataRow.sOrderdetailUsed = '';
tableDataRow.sProductionUsed = '';
tableDataRow.sWorkOrderUsed = '';
tableDataRow.dWorkOrderQty = 0;
const iOrderArr = [];
tableData.forEach((item) => {
const iOrder = commonUtils.isNotEmptyNumber(item.iOrder) ? item.iOrder : 0; /* 获取tableData中iOrder最大值 */
iOrderArr.push(iOrder);
});
const iOrderMax = Math.max(...iOrderArr);
tableDataRow.iOrder = commonUtils.isNotEmptyArr(tableData) ? iOrderMax + 1 : 0;
if (commonUtils.isNotEmptyObject(tableDataRow.sMaterialsMemo)) {
tableDataRow.sMaterialsMemo = '';
}
if (commonUtils.isNotEmptyObject(tableDataRow.sProcessMemo)) {
tableDataRow.sProcessMemo = '';
}
if (sModelsType === 'sales/salesOrderPack' && isTree) { /* 树形 */
const sAllOldId = tableData[tableDataIndex].sAllId;
const arr = sAllOldId.split(',');
const newId = commonUtils.createSid();
tableDataRow.sId = newId;
let sOldParentId = '';
let sNewParentAllId = '';
if (arr.length < 2) { /* 根节点复制 */
tableDataRow.sAllId = newId;
sOldParentId = newId;
sNewParentAllId = newId;
} else {
sOldParentId = arr[arr.length - 2];
if (treeCopyNodes.has(sOldParentId)) {
sNewParentAllId = treeCopyNodes.get(sOldParentId);
} else {
const obj = arr[arr.length - 1];
sNewParentAllId = sAllOldId.replace((`,${obj}`), '');
}
const sNewArr = sNewParentAllId.split(',');
tableDataRow.sControlParentId = sNewArr[sNewArr.length - 1];
sNewParentAllId = `${sNewParentAllId},${newId}`;
tableDataRow.sAllId = sNewParentAllId;
}
treeCopyNodes.set(sId, sNewParentAllId);
}
if (isWait) {
return tableDataRow;
} else if (commonUtils.isNotEmptyObject(tableDataRow)) {
tableData.push(tableDataRow);
let treeState = [];
if (sModelsType === 'sales/salesOrderPack') {
treeState = this.handleGetControlTreeData(tableData, true);
}
this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}Pagination`]: { ...tablePagination, total: tableData.length, current: 9999 }, ...treeState }, () => {
const params = {
sFieldName: 'dAuxiliaryQty',
tableDataRow,
}
// 汇总到从表方法
this.handleWriteBack(params);
// this.handleGroupDataByDefineNoAfterChange();
});
}
}
}
}
};
/** 复制全部 */
handleTableCopyAll = (name, isWait, isTree) => {
const {
slaveData, controlData, slaveSelectedRowKeys, materialsData, [`${name}Pagination`]: tablePagination, sModelsType,
} = this.props;
let { processData } = this.props;
if (name === 'slave') {
if (commonUtils.isEmptyArr(slaveSelectedRowKeys)) {
message.warn(commonFunc.showMessage(this.props.app.commonConst, 'pleaseChooseCopyData'));/* 请选择复制数据 */
} else {
for (const sId of slaveSelectedRowKeys) {
const slaveDataIndex = slaveData.findIndex(item => item.sId === sId);
let addState = {};
if (slaveDataIndex > -1) {
let slaveDataRow = JSON.parse(JSON.stringify(slaveData[slaveDataIndex]));
slaveDataRow.sId = commonUtils.createSid();
slaveDataRow.handleType = 'add';
slaveDataRow.key = slaveDataRow.sId;
const iOrderArr = [];
slaveData.forEach((item) => {
const iOrder = commonUtils.isNotEmptyNumber(item.iOrder) ? item.iOrder : 0; /* 获取tableData中iOrder最大值 */
iOrderArr.push(iOrder);
});
const iOrderMax = Math.max(...iOrderArr);
slaveDataRow.iOrder = commonUtils.isNotEmptyArr(slaveData) ? iOrderMax + 1 : 0;
if (['12710101117007068710620'].includes(this.props.sModelsId)) {
const value = this.handleDataReplace(slaveDataRow.sId, slaveDataRow, 'copy');
addState.slaveChildData = value.slaveChildData;
slaveDataRow = { ...value.tableDataRow || {} };
}
slaveData.push(slaveDataRow);
if (sModelsType !== 'sales/salesOrderPack') {
if (commonUtils.isNotEmptyArr(controlData)) {
controlData.filter(itemControl => itemControl.sSlaveId === sId).forEach((itemControl) => {
const tableDataRow = JSON.parse(JSON.stringify(itemControl));
tableDataRow.sId = commonUtils.createSid();
tableDataRow.handleType = 'add';
tableDataRow.key = tableDataRow.sId;
tableDataRow.sSlaveId = slaveDataRow.sId;
controlData.push(tableDataRow);
/* 部件表复制其材料表、工序表 */
materialsData.filter(item => item.sControlId === itemControl.sId && item.sType !== '2').forEach((item) => {
const materialsRow = JSON.parse(JSON.stringify(item));
materialsRow.sId = commonUtils.createSid();
materialsRow.handleType = 'add';
materialsRow.sControlId = tableDataRow.sId;
materialsRow.sPartsName = tableDataRow.sPartsName;
materialsRow.sSlaveId = tableDataRow.sSlaveId;
materialsData.push(materialsRow);
});
processData.filter(item => item.sControlId === itemControl.sId && item.sType !== '3').forEach((item) => {
const processRow = JSON.parse(JSON.stringify(item));
processRow.sId = commonUtils.createSid();
processRow.handleType = 'add';
processRow.sControlId = tableDataRow.sId;
processRow.sPartsName = tableDataRow.sPartsName;
processRow.sSlaveId = tableDataRow.sSlaveId;
processData.push(processRow);
});
processData = this.sortData(controlData, processData);
});
}
if (commonUtils.isNotEmptyArr(materialsData)) { /* 订单从表复制全部 复制成品材料 */
materialsData.filter(item => item.sSlaveId === sId && item.sType === '2').forEach((materialsItem) => {
const materialsRow = JSON.parse(JSON.stringify(materialsItem));
materialsRow.handleType = 'add';
materialsRow.sId = commonUtils.createSid();
materialsRow.sSlaveId = slaveDataRow.sId;
materialsData.push(materialsRow);
});
}
if (commonUtils.isNotEmptyArr(processData)) { /* 订单从表复制全部 复制成品工序 */
processData.filter(item => item.sSlaveId === sId && item.sType === '3').forEach((processItem) => {
const processRow = JSON.parse(JSON.stringify(processItem));
processRow.handleType = 'add';
processRow.sId = commonUtils.createSid();
processRow.sSlaveId = slaveDataRow.sId;
processData.push(processRow);
});
}
}
}
this.props.onSaveState({
slaveData,
[`${name}Pagination`]: { ...tablePagination, total: slaveData.length, current: 9999 },
controlData,
materialsData,
processData,
...addState,
});
}
}
} else if (name === 'control') {
const {
[`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: tableSelectedRowKeys,
} = this.props;
if (commonUtils.isEmptyArr(tableSelectedRowKeys)) {
message.warn(commonFunc.showMessage(this.props.app.commonConst, 'pleaseChooseCopyData'));/* 请选择复制数据 */
} else {
/* 获取复制节点下的所有子节点 */
if (sModelsType === 'sales/salesOrderPack' && isTree) { /* 树形 */
const {
[`${name}SelectedRowKeys`]: treeSelectedKeys,
} = this.props;
const controlChildData = tableData.filter(item => item.sAllId.indexOf(treeSelectedKeys[0]) > -1 && item.sId !== treeSelectedKeys[0]);
if (commonUtils.isNotEmptyArr(tableData)) {
controlChildData.forEach((itemNew) => {
tableSelectedRowKeys.push(itemNew.sId);
});
}
}
const treeCopyNodes = new Map();
for (const sId of tableSelectedRowKeys) {
const tableDataIndex = tableData.findIndex(item => item.sId === sId);
if (tableDataIndex > -1) {
const tableDataRow = JSON.parse(JSON.stringify(tableData[tableDataIndex]));
tableDataRow.sId = commonUtils.createSid();
tableDataRow.handleType = 'add';
tableDataRow.key = tableDataRow.sId;
const iOrderArr = [];
tableData.forEach((item) => {
const iOrder = commonUtils.isNotEmptyNumber(item.iOrder) ? item.iOrder : 0; /* 获取tableData中iOrder最大值 */
iOrderArr.push(iOrder);
});
const iOrderMax = Math.max(...iOrderArr);
tableDataRow.iOrder = commonUtils.isNotEmptyArr(tableData) ? iOrderMax + 1 : 0;
if (sModelsType === 'sales/salesOrderPack' && isTree) { /* 树形 */
const sAllOldId = tableData[tableDataIndex].sAllId;
const arr = sAllOldId.split(',');
const newId = commonUtils.createSid();
tableDataRow.sId = newId;
let sOldParentId = '';
let sNewParentAllId = '';
if (arr.length < 2) { /* 根节点复制 */
tableDataRow.sAllId = newId;
sOldParentId = newId;
sNewParentAllId = newId;
} else {
sOldParentId = arr[arr.length - 2];
if (treeCopyNodes.has(sOldParentId)) {
sNewParentAllId = treeCopyNodes.get(sOldParentId);
} else {
const obj = arr[arr.length - 1];
sNewParentAllId = sAllOldId.replace((`,${obj}`), '');
}
const sNewArr = sNewParentAllId.split(',');
tableDataRow.sControlParentId = sNewArr[sNewArr.length - 1];
sNewParentAllId = `${sNewParentAllId},${newId}`;
tableDataRow.sAllId = sNewParentAllId;
}
treeCopyNodes.set(sId, sNewParentAllId);
}
if (isWait) {
return tableDataRow;
} else if (commonUtils.isNotEmptyObject(tableDataRow)) {
tableData.push(tableDataRow);
let treeState = [];
if (sModelsType === 'sales/salesOrderPack') {
treeState = this.handleGetControlTreeData(tableData, true);
}
/* 部件表复制其材料表、工序表 */
materialsData.filter(item => item.sControlId === sId && item.sType !== '2').forEach((item) => {
const materialsRow = JSON.parse(JSON.stringify(item));
materialsRow.sId = commonUtils.createSid();
materialsRow.handleType = 'add';
materialsRow.sControlId = tableDataRow.sId;
materialsRow.sPartsName = tableDataRow.sPartsName;
materialsData.push(materialsRow);
});
processData.filter(item => item.sControlId === sId && item.sType !== '3').forEach((item) => {
const processRow = JSON.parse(JSON.stringify(item));
processRow.sId = commonUtils.createSid();
processRow.handleType = 'add';
processRow.sControlId = tableDataRow.sId;
processRow.sPartsName = tableDataRow.sPartsName;
processData.push(processRow);
});
processData = this.sortData(tableData, processData);
this.props.onSaveState({
[`${name}Data`]: tableData,
[`${name}Pagination`]: { ...tablePagination, total: tableData.length, current: 9999 },
materialsData,
processData,
...treeState,
});
}
}
}
}
}
else if (name === 'slaveChild') {
const {
[`${name}Data`]: tableData, [`${name}SelectedRowKeys`]: tableSelectedRowKeys,
} = this.props;
if (commonUtils.isEmptyArr(tableSelectedRowKeys)) {
message.warn(commonFunc.showMessage(this.props.app.commonConst, 'pleaseChooseCopyData'));/* 请选择复制数据 */
} else {
for (const sId of tableSelectedRowKeys) {
const tableDataIndex = tableData.findIndex(item => item.sId === sId);
if (tableDataIndex > -1) {
const tableDataRow = JSON.parse(JSON.stringify(tableData[tableDataIndex]));
tableDataRow.sId = commonUtils.createSid();
tableDataRow.handleType = 'add';
tableDataRow.key = tableDataRow.sId;
const iOrderArr = [];
tableData.forEach((item) => {
const iOrder = commonUtils.isNotEmptyNumber(item.iOrder) ? item.iOrder : 0; /* 获取tableData中iOrder最大值 */
iOrderArr.push(iOrder);
});
const iOrderMax = Math.max(...iOrderArr);
tableDataRow.iOrder = commonUtils.isNotEmptyArr(tableData) ? iOrderMax + 1 : 0;
tableData.push(tableDataRow);
}
this.props.onSaveState({ tableData, [`${name}Pagination`]: { ...tablePagination, total: tableData.length, current: 9999 }}, () => {
const params = {
sFieldName: 'dAuxiliaryQty',
tableDataRow: commonUtils.isEmptyArr(tableData) ? {} : tableData[0],
}
// 汇总到从表方法
this.handleWriteBack(params);
// this.handleGroupDataByDefineNoAfterChange();
});
}
}
}
};
// 删除行
handleDataRowDel = (name, isWait, tableSelectedRowKeys) => {
return this.props.onDataRowDel(name, isWait, tableSelectedRowKeys, () => {
if (name === 'slaveChild') {
const params = {
sFieldName: 'dAuxiliaryQty',
tableDataRow: commonUtils.isEmptyArr(this.props.slaveChildData) ? [] : this.props.slaveChildData[0],
}
// 汇总到从表方法
this.handleWriteBack(params);
// this.handleGroupDataByDefineNoAfterChange();
}
});
}
singlePQtyChange = (tableDataRow) => {
const bZfZf = tableDataRow.iPrintMode === 2; // 正反版
const bSample = tableDataRow.dSumPQty >= 4; // 样本
tableDataRow.iPrintModePo = tableDataRow.iPrintMode <= 2 ? 2 : tableDataRow.iPrintMode === 3 ? 0 : -1;
if (bSample) {
if (tableDataRow.dSinglePQty > 0) {
tableDataRow.dPlateQty = Math.ceil(tableDataRow.dSumPQty / tableDataRow.dSinglePQty);
}
if (bZfZf && (tableDataRow.iPrintModePo === 2)) { // 双面样本,正反
if (tableDataRow.dPlateQty < 2) { // 不管建议放正自翻版了,点方式什么是什么
tableDataRow.dPlateQty = 2;
tableDataRow.iStick = Math.ceil(commonUtils.isNull(tableDataRow.dPlateQty, 0) / 2);
tableDataRow.dSumPlateQty = tableDataRow.iStick * (
commonUtils.isNull(tableDataRow.iPositiveColor, 0) +
commonUtils.isNull(tableDataRow.iPositiveSpecialColor, 0) +
commonUtils.isNull(tableDataRow.iOppositeColor, 0) +
commonUtils.isNull(tableDataRow.iOppositeSpecialColor, 0));
} else {
if (tableDataRow.iPrintModePo !== 2) { // 单面样本
tableDataRow.dPlateQty = (commonUtils.isNull(tableDataRow.dSumPQty, 0) * 0.5) / tableDataRow.dSinglePQty;
tableDataRow.iStick = Math.ceil(tableDataRow.dPlateQty);
tableDataRow.dSumPlateQty = tableDataRow.iStick * (commonUtils.isNull(tableDataRow.iPositiveColor, 0) +
commonUtils.isNull(tableDataRow.iPositiveSpecialColor, 0));
} else {
tableDataRow.dPlateQty = commonUtils.isNull(tableDataRow.dSumPQty, 0) / commonUtils.isNull(commonUtils.nullIf(tableDataRow.dSinglePQty, 0), 1);
tableDataRow.iStick = Math.ceil(tableDataRow.dPlateQty / 2);
}
tableDataRow.dSumPlateQty = tableDataRow.iStick * (
commonUtils.isNull(tableDataRow.iPositiveColor, 0) +
commonUtils.isNull(tableDataRow.iPositiveSpecialColor, 0) +
commonUtils.isNull(tableDataRow.iOppositeColor, 0) +
commonUtils.isNull(tableDataRow.iOppositeSpecialColor, 0));
}
} else {
if (tableDataRow.iPrintModePo !== 2) { // 单面样本
tableDataRow.dPlateQty = (commonUtils.isNull(tableDataRow.dSumPQty, 0) * 0.5) / tableDataRow.dSinglePQty;
} else {
tableDataRow.dPlateQty = commonUtils.isNull(tableDataRow.dSumPQty, 0) / commonUtils.isNull(commonUtils.nullIf(tableDataRow.dSinglePQty, 0), 1);
}
tableDataRow.iStick = Math.ceil(tableDataRow.dPlateQty);
tableDataRow.dSumPlateQty = tableDataRow.iStick * (
commonUtils.isNull(tableDataRow.iPositiveColor, 0) +
commonUtils.isNull(tableDataRow.iPositiveSpecialColor, 0));
}
if (tableDataRow.iStick > 0 && tableDataRow.dSinglePQty > 0) {
tableDataRow.dMachineQty = commonUtils.convertFixNum((commonUtils.isNull(tableDataRow.dPartsQty, 0) * commonUtils.isNull(tableDataRow.dSumPQty, 0) * 0.5) / tableDataRow.dSinglePQty / tableDataRow.iStick, 0);
tableDataRow.dSumMachineQty = tableDataRow.dMachineQty * tableDataRow.iStick;
}
} else {
tableDataRow.iStick = 1;
tableDataRow.dSumPlateQty = tableDataRow.iStick * (
commonUtils.isNull(tableDataRow.iPositiveColor, 0) +
commonUtils.isNull(tableDataRow.iPositiveSpecialColor, 0) +
commonUtils.isNull(tableDataRow.iOppositeColor, 0) +
commonUtils.isNull(tableDataRow.iOppositeSpecialColor, 0));
if (bZfZf && tableDataRow.iPrintModePo === 2) {
tableDataRow.dPlateQty = 2;
tableDataRow.dSumPlateQty = tableDataRow.iStick * (commonUtils.isNull(tableDataRow.iPositiveColor, 0) +
commonUtils.isNull(tableDataRow.iPositiveSpecialColor, 0) + commonUtils.isNull(tableDataRow.iOppositeColor, 0) +
commonUtils.isNull(tableDataRow.iOppositeSpecialColor, 0));
} else {
tableDataRow.dPlateQty = 1;
tableDataRow.dSumPlateQty = tableDataRow.iStick * (commonUtils.isNull(tableDataRow.iPositiveColor, 0) +
commonUtils.isNull(tableDataRow.iPositiveSpecialColor, 0));
}
if (tableDataRow.dSinglePQty > 0) {
if (tableDataRow.iPage > 1) { // 笔记本 用 非样本 来做, 倍率是每页都一样才可以用 原先 /2 是指页数, 现在直接按张数
tableDataRow.dMachineQty = commonUtils.convertFixNum((tableDataRow.dPartsQty * tableDataRow.iPage) / tableDataRow.dSinglePQty, 0);
} else {
tableDataRow.dMachineQty = commonUtils.convertFixNum(commonUtils.isNull(tableDataRow.dPartsQty, 0) / tableDataRow.dSinglePQty, 0);
tableDataRow.dSumMachineQty = tableDataRow.dMachineQty * tableDataRow.iStick;
}
}
}
return tableDataRow;
};
/** 表格数据更改 */
// name 不写完整的state名称作用为了要用到total // (name, changeValue, sId, dropDownData)
handleTableChange = async (name, sFieldName, changeValue, sId, dropDownData, isWait) => {
/* 从CommonBase获取默认参数 */
const {
sModelsType, sModelsId, token, app, slaveConfig, slaveChildData,
} = this.props;
let { [`${name}Data`]: tableData } = this.props;
if (name === 'slave' && window.tmpSlaveData) {
tableData = window.tmpSlaveData;
}
const { dNetMoney } = app.decimals;
if (name === 'control' && sModelsType.includes('sales/salesOrder')) {
const { [`${name}Data`]: tableData, materialsData: materialsDataOld, processData: processDataOld } = this.props;
let tableDataRow = await this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, true);
if (tableDataRow === undefined) return;
if (sFieldName === 'dSinglePQty' || sFieldName === 'dSumPQty' || sFieldName === 'iPrintModePo' || sFieldName === 'iPrintMode' || sFieldName === 'iPrintModePo' || sFieldName === 'iPositiveColor' ||
sFieldName === 'iPositiveSpecialColor' || sFieldName === 'iOppositeColor' || sFieldName === 'iOppositeSpecialColor') {
if (sFieldName === 'iPrintModePo') {
if (tableDataRow.iPrintModePo === 0) {
tableDataRow.iPrintMode = 3;
if (tableDataRow.iPositiveColor === 0) {
tableDataRow.iPositiveColor = tableDataRow.iPositiveColor === 0 ? 4 : tableDataRow.iPositiveColor;
tableDataRow.iOppositeColor = 0;
tableDataRow.iOppositeSpecialColor = 0;
} else {
tableDataRow.iOppositeColor = 0;
tableDataRow.iOppositeSpecialColor = 0;
}
} else if (tableDataRow.iPrintModePo === 1) {
tableDataRow.iPrintMode = 3;
if (tableDataRow.iPositiveColor === 0) {
tableDataRow.iPositiveColor = 0;
tableDataRow.iPositiveSpecialColor = 0;
tableDataRow.iOppositeColor = tableDataRow.iOppositeColor === 0 ? 4 : tableDataRow.iOppositeColor;
} else {
tableDataRow.iPositiveColor = 0;
tableDataRow.iPositiveSpecialColor = 0;
}
} else {
tableDataRow.iPositiveColor = tableDataRow.iPositiveColor === 0 ? 4 : tableDataRow.iPositiveColor;
tableDataRow.iOppositeColor = tableDataRow.iOppositeColor === 0 ? tableDataRow.iPositiveColor : tableDataRow.iOppositeColor;
}
} else if (sFieldName === 'iPrintMode') {
if (tableDataRow.iPrintMode === 0 || tableDataRow.iPrintMode === 1) {
tableDataRow.iPositiveColor = commonUtils.isEmpty(tableDataRow.iPositiveColor) || tableDataRow.iPositiveColor === 0 ? 4 : tableDataRow.iPositiveColor;
tableDataRow.iOppositeColor = tableDataRow.iPositiveColor;
tableDataRow.iOppositeSpecialColor = tableDataRow.iPositiveSpecialColor;
} else if (tableDataRow.iPrintMode === 2) {
tableDataRow.iPositiveColor = tableDataRow.iPositiveColor === 0 ? 4 : tableDataRow.iPositiveColor;
tableDataRow.iOppositeColor = tableDataRow.iOppositeColor === 0 ? tableDataRow.iPositiveColor : tableDataRow.iOppositeColor;
} else if (tableDataRow.iPrintMode === 3) {
tableDataRow.iPositiveColor = tableDataRow.iPositiveColor === 0 ? 4 : tableDataRow.iPositiveColor;
tableDataRow.iOppositeColor = 0;
tableDataRow.iOppositeSpecialColor = 0;
} else if (tableDataRow.iPrintMode === 4) {
tableDataRow.iPositiveColor = 0;
tableDataRow.iPositiveSpecialColor = 0;
tableDataRow.iOppositeColor = 0;
tableDataRow.iOppositeSpecialColor = 0;
}
} else if (sFieldName === 'iPositiveColor' || sFieldName === 'iPositiveSpecialColor') {
if (tableDataRow.iPrintMode === 0 || tableDataRow.iPrintMode === 1) {
tableDataRow.iOppositeColor = tableDataRow.iPositiveColor;
tableDataRow.iOppositeSpecialColor = tableDataRow.iPositiveSpecialColor;
}
}
tableDataRow = this.singlePQtyChange(tableDataRow);
}
const materialsData = [];
const processData = [];
materialsDataOld.forEach((item) => {
const itemNew = { ...item };
if (itemNew.sControlId === sId) {
itemNew.sPartsName = tableDataRow.sPartsName;
}
materialsData.push(itemNew);
});
processDataOld.forEach((item) => {
const itemNew = { ...item };
if (itemNew.sControlId === sId) {
itemNew.sPartsName = tableDataRow.sPartsName;
}
processData.push(itemNew);
});
const materialsDataNew = this.sortData(tableData, materialsData);
const processDataNew = this.sortData(tableData, processData);
if (sModelsType === 'sales/salesOrderPack') {
if (sFieldName === 'sPartsName') { /* 部件名称与子部件同步 */
const { sPartsName } = tableDataRow;
const { treeSelectedKeys, treeData } = this.props;
if (commonUtils.isNotEmptyArr(treeSelectedKeys)) {
this.handleSearchNodes(treeSelectedKeys[0], treeData, sPartsName);
}
} else if (sFieldName === 'dMachineQty') { /* 上机数量改变时,子级部件数量同步改变 */
const { dMachineQty } = tableDataRow;
/* 查找该节的所有子节点,将上机数量改为部件数量 */
tableData.forEach((item, index) => {
if (commonUtils.isNotEmptyObject(item.sAllId) && item.sAllId.indexOf(tableDataRow.sId) > -1 && item.sId !== tableDataRow.sId) {
const addstate = {};
addstate.dPartsQty = dMachineQty;
tableData[index] = { ...tableData[index], ...addstate };
}
});
}
}
const iIndex = tableData.findIndex(item => item.sId === sId);
tableData[iIndex] = tableDataRow;
this.props.onSaveState({
[`${name}Data`]: tableData, materialsData: materialsDataNew, processData: processDataNew,
});
} else {
const addStata = {};
let { masterData } = this.props;
const iIndex = tableData.findIndex(item => item.sId === sId);
// if (sFieldName.substring(0, 1) === 'd' && commonUtils.convertToNum(tableData[iIndex][sFieldName]) === commonUtils.convertToNum(changeValue[sFieldName])) {
// if (!(tableData[iIndex][sFieldName] === undefined && commonUtils.convertToNum(changeValue[sFieldName]) === 0)) return;
// }
if (sFieldName === 'sProductName' && name === 'slave' && (sModelsType.includes('sales/salesOrder') || sModelsType.includes('manufacture/workOrder') || sModelsType.includes('quotation/quotation'))) {
if (commonUtils.isNotEmptyObject(changeValue) && Object.keys(changeValue).length === 1 && Object.keys(changeValue)[0] === sFieldName) {
changeValue.sProductId = changeValue.sProductName;
}
}
let tableDataRow = this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, true);
/* 添加备货数自动计算 */
if ((sFieldName === 'dProductQty' || sFieldName === 'dGiveQty') && name === 'slave' && (sModelsType.includes('sales/salesOrderPack') || sModelsType.includes('sales/salesOrder'))) {
if (commonUtils.isNotEmptyObject(changeValue) && Object.keys(changeValue).length === 1 && Object.keys(changeValue)[0] === sFieldName) {
const dProductQty = commonUtils.isEmptyNumber(tableDataRow.dProductQty) ? 0 : tableDataRow.dProductQty;
const dGiveQty = commonUtils.isEmptyNumber(tableDataRow.dGiveQty) ? 0 : tableDataRow.dGiveQty;
const dStockupRate = commonUtils.isEmptyNumber(masterData.dStockupRate) ? 0 : masterData.dStockupRate;
if (dStockupRate !== 0) { /* 备货率不为0时,按照备货率计算,否则按照手填的算 */
tableDataRow.dStockupQty = Math.round((dProductQty + dGiveQty) * dStockupRate);
}
}
}
if ((sFieldName === 'sProductId' || sFieldName === 'sProductName' || sFieldName === 'sProductStyle' || sFieldName === 'sProductUnit' || sFieldName === 'sProductNo'
|| sFieldName === 'sCustomerProductNo' || sFieldName === 'sProductClassifyId' || sFieldName === 'sProductClassifyName') && !commonUtils.isEmpty(tableDataRow.sProductId)) {
let productIdDropDown = [];
if (sFieldName === 'sProductStyle') {
const iIndex = slaveConfig.gdsconfigformslave.findIndex(item => item.sName === 'sProductName');
if (iIndex > -1) {
if (this.inputSearch) {
clearTimeout(this.inputSearch);
}
this.inputSearch = setTimeout(async () => {
const sqlDropDownData = await this.props.getSqlDropDownData(sModelsId, 'slave', slaveConfig.gdsconfigformslave[iIndex], tableDataRow, tableDataRow.sProductName, 1);
productIdDropDown = sqlDropDownData.dropDownData;
}, 500);
}
} else {
productIdDropDown = dropDownData;
}
const iProductIdIndex = commonUtils.isEmptyArr(productIdDropDown) ? -1 : productIdDropDown.findIndex(item => item.sId === tableDataRow.sProductId && item.sProductStyle === tableDataRow.sProductStyle);
if (iProductIdIndex === -1 && !(commonUtils.isNotEmptyObject(sModelsType) && sModelsType.includes('sales/materials'))) {
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,
});
} else {
tableDataRow.sProductInfo = '';
}
tableDataRow.sMaterialsStyle = tableDataRow.sProductStyle;
if ((sFieldName === 'sProductId' || sFieldName === 'sProductName' || sFieldName === 'sProductNo') && !commonUtils.isEmpty(changeValue.sProductId) && tableDataRow.sProductId !== tableDataRow.sProductName) {
const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
const { sCustomerId } = masterData; /* 增加客户id参数 */
const value = {
sProName: 'Sp_Cashier_GetProductPrice',
paramsMap: {
sProductGuid: changeValue.sProductId,
sCustomerId,
},
};
const returnData = (await commonServices.postValueService(app.token, value, url)).data;
if (returnData.code === 1) {
tableDataRow.dNProductPrice = returnData.dataset.rows[0].dataSet.outData[0].dPrice; /* 产品单价 */
const dProofingMoney = commonUtils.convertToNum(tableDataRow.dProofingMoney); /* 打样金额 */
const dPlateMoney = commonUtils.convertToNum(tableDataRow.dPlateMoney); /* 制版金额 */
const dKnifeMouldMoney = commonUtils.convertToNum(tableDataRow.dKnifeMouldMoney); /* 刀模金额 */
const dProductQty = commonUtils.convertToNum(tableDataRow.dProductQty); /* 数量 */
const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
const { dNetPrice } = app.decimals;
if (dProductQty === 0 || (dProofingMoney === 0 && dPlateMoney === 0 && dKnifeMouldMoney === 0)) {
const dProductForeignPrice = returnData.dataset.rows[0].dataSet.outData[0].dPrice;
tableDataRow.dProductForeignPrice = dProductForeignPrice;
tableDataRow.dProductPrice = commonUtils.convertFixNum(dProductForeignPrice * dCurrencyRate, dNetPrice);
}
}
const models = name === 'materials' ? 'Materials' :
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.handleMaterialsChange(tableDataRow, sModelsId, masterData, changeValue, 'dProductQty', app, token, models);
}
tableDataRow = commonBusiness.getCalculateAllMoney(app, models, 'dProductQty', masterData, tableDataRow);
// else {
// this.props.getServiceError(returnData);
// }
}
} else if (sModelsType.includes('sales/salesOrder') && (sFieldName === 'sProductClassifyId' || sFieldName === 'sProductClassifyName') && name === 'slave') {
const { controlData } = this.props;
if (controlData !== undefined && !commonUtils.isEmpty(tableData.sProductInfo)) {
const controlDataFilter = controlData.filter(item => item.sSlaveId === tableData[iIndex].sId);
const tableSelectedRowKeys = [];
controlDataFilter.forEach((item) => {
tableSelectedRowKeys.push(item.sId);
});
const materialsReturnData = this.otherTableDel('materials', tableSelectedRowKeys);
const processReturnData = this.otherTableDel('process', tableSelectedRowKeys);
const controlReturnData = this.props.onDataRowDel('control', true, tableSelectedRowKeys);
this.props.onSaveState({
...materialsReturnData,
...processReturnData,
...controlReturnData,
});
}
} else if ((sModelsType.includes('cashier/') || sModelsType.includes('sales/salesInvoice') || sModelsType.includes('purchase/purchaseInvoice') || sModelsType.includes('purchase/outsideInvoice')) && (sFieldName === 'dTotalMoney' || sFieldName === 'dRoundingMoney')) { /* 付款单、收款单,从表付款/收款金额改变,会自动汇总到主表付款金额中 */
const addStata = {};
let { handleType } = masterData;
handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
addStata.handleType = handleType;
const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
const { dNetMoney } = app.decimals;
if (sFieldName === 'dTotalMoney') {
addStata.dTotalMoney = 0;
if (iIndex > -1) { /* 选中行 */
let dMoney = commonUtils.isNotEmptyNumber(tableDataRow.dTotalMoney) ? tableDataRow.dTotalMoney : 0;
dMoney = commonUtils.convertStrToNumber(dMoney);
addStata.dTotalMoney = dMoney + commonUtils.convertStrToNumber(addStata.dTotalMoney);
tableDataRow.dTotalForeignMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? dMoney / dCurrencyRate : 0, dNetMoney);
}
// if (commonUtils.isNotEmptyNumber(tableDataRow.dBalanceMoney) && (tableDataRow.dTotalMoney > tableDataRow.dBalanceMoney)) { // 发外发票,采购发票,销售发票 付款单、收款单总金额不能大于余额
// const dTotalMoneyName = slaveConfig.gdsconfigformslave.filter(item => item.sName === sFieldName)[0].showName;
// const dBalanceMoneyName = slaveConfig.gdsconfigformslave.filter(item => item.sName === 'dBalanceMoney')[0].showName;
// message.error(`${dTotalMoneyName}不能大于${dBalanceMoneyName}!`);
// tableDataRow = { ...tableDataRow, dTotalMoney: tableDataRow.dBalanceMoney };
// // tableDataRow.dTotalMoney = commonUtils.convertStrToNumber(masterData.dTotalMoney);
// addStata.dTotalMoney = commonUtils.convertStrToNumber(masterData.dTotalMoney);
// }
tableData.forEach((item, index) => { /* 非选中行 */
if (index !== iIndex) {
const dMoney = commonUtils.isNotEmptyNumber(item.dTotalMoney) ? item.dTotalMoney : 0;
addStata.dTotalMoney = commonUtils.convertFixNum(dMoney, 6) + commonUtils.convertFixNum(addStata.dTotalMoney, 6);
}
});
/* 计算外币金额 */
if (commonUtils.isNotEmptyNumber(addStata.dTotalMoney)) {
addStata.dProductForeignMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? addStata.dTotalMoney / dCurrencyRate : 0, dNetMoney);
}
} else if (sFieldName === 'dRoundingMoney') {
addStata.dRoundingMoney = 0;
if (iIndex > -1) { /* 选中行 */
let dMoney = commonUtils.isNotEmptyNumber(tableDataRow.dRoundingMoney) ? tableDataRow.dRoundingMoney : 0;
dMoney = commonUtils.convertStrToNumber(dMoney);
addStata.dRoundingMoney = dMoney + commonUtils.convertStrToNumber(addStata.dRoundingMoney);
}
tableData.forEach((item, index) => { /* 非选中行 */
if (index !== iIndex) {
const dMoney = commonUtils.isNotEmptyNumber(item.dRoundingMoney) ? item.dRoundingMoney : 0;
addStata.dRoundingMoney = commonUtils.convertFixNum(dMoney, 6) + commonUtils.convertFixNum(addStata.dRoundingMoney, 6);
}
});
}
masterData = { ...masterData, ...addStata };
this.props.onSaveState({ masterData });
} else if (sModelsType === 'purchase/purchaseOrder' && sFieldName === 'dProcurementCycle') {
/* 交货周期改变时,交货时间等于制单时间 +交货周期 */
const dProcurementCycle = commonUtils.isNull(tableDataRow.dProcurementCycle, 0);
const tCreateDate = commonUtils.isNotEmptyObject(tableDataRow.tCreateDate) ? tableDataRow.tCreateDate : new Date();
const tDeliverDate = moment(tCreateDate).add(dProcurementCycle, 'days').format(commonUtils.dateFormatA);
tableDataRow.tDeliverDate = tDeliverDate;
}
// 取工艺卡数据
if (sModelsType.includes('sales/salesOrder') && (sFieldName === 'sProductId' || sFieldName === 'sProductNo' || sFieldName === 'sProductName') && name === 'slave') {
const {
controlConfig, materialsConfig, processConfig,
} = this.props;
let { controlData, materialsData, processData } = this.props;
const sId = tableData[iIndex].sId;
const bCkxCopyFromTechnology = '1'; // app.systemData.filter(item => item.sName === 'CkxCopyFromTechnology')[0].sValue;
if (bCkxCopyFromTechnology === '1' && tableDataRow.sProductId !== tableDataRow.sProductName) {
const controlSelectedData = controlData.filter(item => item.sSlaveId === sId);
if (commonUtils.isNotEmptyObject(controlSelectedData)) {
const controlSelectedRowKeys = [];
controlSelectedData.forEach((item) => {
controlSelectedRowKeys.push(item.sId);
});
const materialsReturnData = this.otherTableDel('materials', controlSelectedRowKeys);
const processReturnData = this.otherTableDel('process', controlSelectedRowKeys);
const controlReturnData = this.props.onDataRowDel('control', true, controlSelectedRowKeys);
controlData = controlReturnData.controlData;
materialsData = materialsReturnData.materialsData;
processData = processReturnData.processData;
this.props.onSaveState({
...materialsReturnData,
...processReturnData,
...controlReturnData,
});
}
const sCustomerId = masterData.sCustomerId;
const sProductId = changeValue.sProductId;
const sProductIdArray = [];
sProductIdArray.push(sProductId);
const sProductIds = sProductIdArray.toString();
const condition = { sCustomerId, sProductIds };
const dataUrl = `${commonConfig.server_host}salesorder/getProcessCardDataByCustomIdProductId/?sModelsId=${sModelsId}`;
const dataReturn = (await commonServices.postValueService(token, condition, dataUrl)).data;
const config = this.props.masterConfig.gdsconfigformslave.filter(item => item.sControlName.includes('BtnCopyFrom.ActProcessCard'));
if (dataReturn.code === 1) {
const returnData = dataReturn.dataset.rows[0];
const copyToControlConfig = config.filter(item => item.sControlName.toLowerCase() === 'BtnCopyFrom.ActProcessCard.Control'.toLowerCase());
const copyToMaterialsConfig = config.filter(item => item.sControlName.toLowerCase() === 'BtnCopyFrom.ActProcessCard.Materials'.toLowerCase());
const copyToProcessConfig = config.filter(item => item.sControlName.toLowerCase() === 'BtnCopyFrom.ActProcessCard.Process'.toLowerCase());
const controlAssignField = commonUtils.isNotEmptyArr(copyToControlConfig) ? copyToControlConfig[0].sAssignField : '';
const materialsAssignField = commonUtils.isNotEmptyArr(copyToMaterialsConfig) ? copyToMaterialsConfig[0].sAssignField : '';
const processAssignField = commonUtils.isNotEmptyArr(copyToProcessConfig) ? copyToProcessConfig[0].sAssignField : '';
const newCopyTo = {};
newCopyTo.master = masterData;
newCopyTo.slave = commonUtils.isEmptyArr(tableData) ? {} : tableData;
if (commonUtils.isNotEmptyArr(returnData.controlData)) {
const treeCopyNodes = new Map();
// eslint-disable-next-line no-loop-func
returnData.controlData.forEach((controlItem) => {
newCopyTo.control = controlItem;
const newSid = commonUtils.createSid();
let controlRow = commonFunc.getDefaultData(controlConfig, newCopyTo, { newSid }); // 取默认值
controlRow = { ...controlRow, ...commonFunc.getAssignFieldValue(controlAssignField, controlItem, newCopyTo) }; // 取赋值字段
controlRow.handleType = 'add';
controlRow.sId = newSid;
controlRow.sSlaveId = tableDataRow.sId;
controlRow.sParentId = masterData.sId;
if (sModelsType === 'sales/salesOrderPack') { /* 树形 */
/* CopyTo时sAllId,sControlParentId 设置 */
const sAllOldId = controlItem.sAllId;
let arr = [];
if (commonUtils.isNotEmptyObject(sAllOldId)) {
arr = sAllOldId.split(',');
}
const newId = controlRow.sId;
let sOldParentId = '';
let sNewParentAllId = '';
if (arr.length < 2) { /* 根节点复制 */
controlRow.sAllId = newId;
sOldParentId = newId;
sNewParentAllId = newId;
} else {
sOldParentId = arr[arr.length - 2];
if (treeCopyNodes.has(sOldParentId)) {
sNewParentAllId = treeCopyNodes.get(sOldParentId);
} else {
const obj = arr[arr.length - 1];
sNewParentAllId = sAllOldId.replace((`,${obj}`), '');
}
const sNewArr = sNewParentAllId.split(',');
controlRow.sControlParentId = sNewArr[sNewArr.length - 1];
sNewParentAllId = `${sNewParentAllId},${newId}`;
controlRow.sAllId = sNewParentAllId;
}
treeCopyNodes.set(controlItem.sId, sNewParentAllId);
}
controlData.push(controlRow);
if (commonUtils.isNotEmptyArr(returnData.materialsData)) {
returnData.materialsData.filter(item => item.sControlId === controlItem.sId).forEach((materialsItem) => {
newCopyTo.materials = materialsItem;
const newSid = commonUtils.createSid();
let materialsRow = commonFunc.getDefaultData(materialsConfig, newCopyTo, { newSid }); // 取默认值
materialsRow = { ...materialsRow, ...commonFunc.getAssignFieldValue(materialsAssignField, materialsItem, newCopyTo) }; // 取赋值字段
materialsRow.handleType = 'add';
materialsRow.sId = newSid;
materialsRow.sSlaveId = tableDataRow.sId;
materialsRow.sParentId = masterData.sId;
materialsRow.sControlId = controlRow.sId;
materialsRow.sPartsName = controlRow.sPartsName;
materialsData.push(materialsRow);
});
}
if (commonUtils.isNotEmptyArr(returnData.processData)) {
returnData.processData.filter(item => item.sControlId === controlItem.sId).forEach((processItem) => {
newCopyTo.process = processItem;
const newSid = commonUtils.createSid();
let processRow = commonFunc.getDefaultData(processConfig, newCopyTo, { newSid }); // 取默认值
processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
processRow.handleType = 'add';
processRow.sId = newSid;
processRow.sSlaveId = tableDataRow.sId;
processRow.sParentId = masterData.sId;
processRow.sControlId = controlRow.sId;
processRow.sPartsName = controlRow.sPartsName;
processData.push(processRow);
});
}
});
}
if (commonUtils.isNotEmptyArr(returnData.materialsData)) {
// eslint-disable-next-line no-loop-func
returnData.materialsData.filter(item => item.sType === '2').forEach((materialsItem) => {
newCopyTo.materials = materialsItem;
const newSid = commonUtils.createSid();
let materialsRow = commonFunc.getDefaultData(materialsConfig, newCopyTo, { newSid }); // 取默认值
materialsRow = { ...materialsRow, ...commonFunc.getAssignFieldValue(materialsAssignField, materialsItem, newCopyTo) }; // 取赋值字段
materialsRow.handleType = 'add';
materialsRow.sId = newSid;
materialsRow.sSlaveId = tableDataRow.sId;
materialsRow.sParentId = masterData.sId;
materialsData.push(materialsRow);
});
}
if (commonUtils.isNotEmptyArr(returnData.processData)) {
// eslint-disable-next-line no-loop-func
returnData.processData.filter(item => item.sType === '3').forEach((processItem) => {
newCopyTo.process = processItem;
const newSid = commonUtils.createSid();
let processRow = commonFunc.getDefaultData(processConfig, newCopyTo, { newSid }); // 取默认值
processRow = { ...processRow, ...commonFunc.getAssignFieldValue(processAssignField, processItem, newCopyTo) }; // 取赋值字段
processRow.handleType = 'add';
processRow.sId = newSid;
processRow.sSlaveId = tableDataRow.sId;
processRow.sParentId = masterData.sId;
processData.push(processRow);
});
}
/* 包装订单 生成树形 */
let treeState = {};
if (sModelsType === 'sales/salesOrderPack') {
treeState = this.handleGetControlTreeData(controlData, true);
}
this.props.onSaveState({
controlData, materialsData, processData, ...treeState,
});
}
}
} else if (sModelsType.includes('sales/salesOrder') && (sFieldName === 'dProductQty' || sFieldName === 'dGiveQty' || sFieldName === 'dStockupQty') && name === 'slave') {
const {
controlData, slaveSelectedRowKeys,
} = this.props;
const controlSelectedData = controlData.filter(item => item.sSlaveId === slaveSelectedRowKeys[0]);
for (const one of controlSelectedData) {
one.handleType = commonUtils.isEmpty(one.handleType) ? 'update' : one.handleType;
one.dPartsQty = commonUtils.isNull(tableDataRow.dProductQty, 0) + commonUtils.isNull(tableDataRow.dGiveQty, 0) + commonUtils.isNull(tableDataRow.dStockupQty, 0);
}
this.props.onSaveState({ controlData });
} else if (sModelsType.includes('purchase/') && (sFieldName === 'sMaterialsId' || sFieldName === 'sMaterialsNo' || sFieldName === 'sMaterialsName') && name === 'slave') {
const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
const value = {
sProName: 'Sp_Cashier_GetMaterialsPrice',
paramsMap: {
sMaterialsGuid: changeValue.sMaterialsId,
sSupplyGuid: masterData.sSupplyId,
},
};
const returnData = (await commonServices.postValueService(app.token, value, url)).data;
if (returnData.code === 1) {
tableDataRow.dMaterialsPrice = returnData.dataset.rows[0].dataSet.outData[0].dPrice;
}
const models = name === 'materials' ? 'Materials' :
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.handleMaterialsChange(tableDataRow, sModelsId, masterData, changeValue, 'dAuxiliaryQty', app, token, models);
}
tableDataRow = commonBusiness.getCalculateAllMoney(app, models, 'dAuxiliaryQty', masterData, tableDataRow);
if (Object.keys(changeValue).length > 0 && Object.keys(changeValue).findIndex(item => item === 'dMaterialsStockAuxiliaryQty') > -1) {
const urlMaterialsStock = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
const valueMaterialsStock = {
sProName: 'Sp_Inventory_MaterialsInventoryV56',
paramsMap: {
sMaterialsGuid: tableDataRow.sMaterialsId,
sMaterialsStyle: tableDataRow.sMaterialsStyle,
sWarehouseGuid: tableDataRow.sWarehouseId,
sLocationalGuid: tableDataRow.sLocationId,
sWarehouseLocationGuid: tableDataRow.sWarehouseLocationId,
sDefine_no: tableDataRow.sDefineNo,
sDefine_no2: tableDataRow.sDefineNo2,
iGetQty: 1,
iHasZero: 1,
},
};
const returnDataMaterialsStock = (await commonServices.postValueService(app.token, valueMaterialsStock, urlMaterialsStock)).data;
if (returnDataMaterialsStock.code === 1) {
tableDataRow.dMaterialsStockAuxiliaryQty = returnDataMaterialsStock.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
}
}
if (Object.keys(changeValue).length > 0 && Object.keys(changeValue).findIndex(item => item === 'dMaterialsStockAvailableQty') > -1) {
const urlMaterialsAvailableQty = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
const valueMaterialsAvailableQty = {
sProName: 'Sp_Inventory_MaterialsInventoryV56',
paramsMap: {
sMaterialsGuid: tableDataRow.sMaterialsId,
sMaterialsStyle: tableDataRow.sMaterialsStyle,
sWarehouseGuid: tableDataRow.sWarehouseId,
sLocationalGuid: tableDataRow.sLocationId,
sWarehouseLocationGuid: tableDataRow.sWarehouseLocationId,
sDefine_no: tableDataRow.sDefineNo,
sDefine_no2: tableDataRow.sDefineNo2,
iGetQty: 2,
iHasZero: 1,
},
};
const returnDataMaterialsAvailableQty = (await commonServices.postValueService(app.token, valueMaterialsAvailableQty, urlMaterialsAvailableQty)).data;
if (returnDataMaterialsAvailableQty.code === 1) {
tableDataRow.dMaterialsStockAvailableQty = returnDataMaterialsAvailableQty.dataset.rows[0].dataSet.outData[0].dAuxiliaryQty;
}
}
/* 选择材料后 交货周期改变 则交货时间等于制单时间+交货周期 */
const dProcurementCycle = commonUtils.isNull(tableDataRow.dProcurementCycle, 0);
const tCreateDate = commonUtils.isNotEmptyObject(tableDataRow.tCreateDate) ? tableDataRow.tCreateDate : new Date();
const tDeliverDate = moment(tCreateDate).add(dProcurementCycle, 'days').format(commonUtils.dateFormatA);
tableDataRow.tDeliverDate = tDeliverDate;
// else {
// this.props.getServiceError(returnData);
// }
} else if (sModelsType === 'sales/salesCheck' && sFieldName === 'dLossMoney' && name === 'slave') {
const dPmoney = this.props.getFloatNum('dProductMoney');
const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
if (commonUtils.isNotEmptyNumber(tableDataRow.dSrcNoCheckMoney) && commonUtils.isNotEmptyNumber(tableDataRow.dLossMoney)) {
const dProductForeignMoney = commonUtils.convertFixNum(tableDataRow.dSrcNoCheckMoney - tableDataRow.dLossMoney, dPmoney);
const dProductMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? dProductForeignMoney * dCurrencyRate : 0, dPmoney); /* 本位币金额 */
tableDataRow.dProductForeignMoney = dProductForeignMoney;
tableDataRow.dProductMoney = dProductMoney;
} else if (commonUtils.isNotEmptyNumber(tableDataRow.dSrcNoCheckMoney) && commonUtils.isEmptyNumber(tableDataRow.dLossMoney)) {
const dProductForeignMoney = commonUtils.isNull(tableDataRow.dSrcNoCheckMoney, 0);
const dProductMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? dProductForeignMoney * dCurrencyRate : 0, dPmoney); /* 本位币金额 */
tableDataRow.dProductForeignMoney = dProductForeignMoney;
tableDataRow.dProductMoney = dProductMoney;
tableDataRow.dLossMoney = 0;
}
} else if (sModelsType === 'purchase/purchasecheck' && sFieldName === 'dLossMoney' && name === 'slave') {
const dPmoney = this.props.getFloatNum('dProductMoney');
if (commonUtils.isNotEmptyNumber(tableDataRow.dSrcNoCheckMoney) && commonUtils.isNotEmptyNumber(tableDataRow.dLossMoney)) {
const dMoney = commonUtils.convertFixNum(tableDataRow.dSrcNoCheckMoney - tableDataRow.dLossMoney, dPmoney);
tableDataRow.dMaterialsMoney = dMoney;
} else if (commonUtils.isNotEmptyNumber(tableDataRow.dSrcNoCheckMoney) && commonUtils.isEmptyNumber(tableDataRow.dLossMoney)) {
tableDataRow.dMaterialsMoney = commonUtils.isNull(tableDataRow.dSrcNoCheckMoney, 0);
tableDataRow.dLossMoney = 0;
}
} else if (sModelsType === 'cost/cosexpenseshare') { /* 改变费用分摊单据从表成本中心金额,总金额随之改变 */
if (sFieldName.indexOf('dCostCenter') > -1) {
const { slaveColumn } = this.props;
let dAllMoney = 0;
slaveColumn.forEach((item) => {
const sName = item.dataIndex;
if (sName.indexOf('dCostCenter') > -1) {
dAllMoney += commonUtils.isNotEmptyNumber(tableDataRow[sName]) ? commonUtils.convertFixNum(tableDataRow[sName], dNetMoney) : 0;
}
});
tableDataRow.dShareMoney = commonUtils.convertFixNum(dAllMoney, dNetMoney);
}
} else if (sModelsType === 'purchase/purchaseInstore' && name === 'slave') { /* 采购入库 材料批次=材料生产日期tSReserve1(此客户手输)+当前日期 */
if (sFieldName === 'tProductionDate') {
tableDataRow.sDefineNo = moment(tableDataRow.tProductionDate).format('YYYYMMDDHHmm') + moment(new Date()).format('YYYYMMDDHHmm');
}
}
/* 各种金额,税额,价格计算 */
let models = name === 'materials' ? 'Materials' :
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/') || sModelsType.includes('semigoodsStock/') || sModelsType.includes('sales/materials') || sModelsType === 'sales/salesCheck') {
if (sModelsType.includes('sales/materials') || sModelsType === 'sales/salesCheck') {
tableDataRow.dAuxiliaryQty = tableDataRow.dProductQty;
}
tableDataRow = await this.handleMaterialsChange(tableDataRow, sModelsId, masterData, changeValue, sFieldName, app, token, models);
if (sModelsType.includes('sales/materials') || sModelsType === 'sales/salesCheck') { /* 如果是材料销售模块/销售对账 如果是材料 则用换算数量*单价 算金额 */
/* 材料逻辑计算 */
if (commonUtils.isNotEmptyNumber('dMaterialsQty') && tableDataRow.dMaterialsQty !== 0 && commonUtils.isNotEmptyObject(tableDataRow.sMaterialsUnit)) {
let modelsNew = '';
if (models === 'Product') { /* 计算前将Product替换为Materials */
modelsNew = 'Materials';
const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
const { dNetPrice } = app.decimals;
const dForeignPrice = tableDataRow[`d${models}ForeignPrice`];
if (commonUtils.isNotEmptyNumber(dForeignPrice)) {
/* 只有外币单价情況下 要算本位币单价 */
const dProductPrice = commonUtils.convertFixNum(dForeignPrice * dCurrencyRate, dNetPrice);
tableDataRow[`d${models}Price`] = dProductPrice;
}
tableDataRow[`dN${modelsNew}Price`] = tableDataRow[`d${models}ForeignPrice`];
tableDataRow[`d${modelsNew}ForeignPrice`] = tableDataRow[`d${models}ForeignPrice`];
tableDataRow[`d${modelsNew}Price`] = tableDataRow[`d${models}Price`];
tableDataRow[`dN${modelsNew}Money`] = tableDataRow[`dN${models}Price`];
tableDataRow[`dN${modelsNew}Money`] = tableDataRow[`d${models}ForeignMoney`];
tableDataRow[`d${modelsNew}ForeignMoney`] = tableDataRow[`d${models}ForeignMoney`];
tableDataRow[`d${modelsNew}Money`] = tableDataRow[`d${models}Money`];
tableDataRow.bSalesMaterials = true;/* 材料销售 销售对账 材料计算 */
models = 'Materials';
sFieldName = commonUtils.isNotEmptyObject(sFieldName) ? sFieldName.replace('Product', 'Materials') : sFieldName;
}
}
}
}
tableDataRow = commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, tableDataRow);
let dMaterialsMoney = '';
if (sModelsType.includes('outside/')) { /* 工序发外 && (sFieldName === 'sSupplyName' || sFieldName === 'sProcessName' || sFieldName === 'dAuxiliaryQty') */
let sComputeId = {};
const sSupplyId = masterData.sSupplyId;
const sProcessId = tableDataRow.sProcessId;
if (commonUtils.isNotEmptyObject(sProcessId)) {
/* 根据客户id,工序id获取公式ID */
sComputeId = await commonBusiness.getOutSideProcessFormula({
token, sModelsId, sSupplyId, sProcessId,
});
if (!commonUtils.isEmpty(sComputeId)) {
dMaterialsMoney = await commonBusiness.getFormulaValue({
token, sModelsId, masterData, tableDataRow, sComputeId,
});
tableDataRow.dMaterialsMoney = dMaterialsMoney;
tableDataRow = commonBusiness.getCalculateMoney(app, masterData, tableDataRow, 'Materials');
}
}
} else if (sModelsType.includes('purchase/purchasecheck') && name === 'slave' && sFieldName === 'dMaterialsPrice') {
/* 从表单价改变时 每个字表都对应改 */
const slaveFilterData = slaveChildData.filter(item => item.sSqlConditionId === tableDataRow.sSqlConditionId);
if (commonUtils.isNotEmptyArr(slaveFilterData)) {
slaveFilterData.forEach((item) => {
const iIndexC = slaveChildData.findIndex(itemC => itemC.sId === item.sId);
if (iIndexC > -1) {
const handleTypeNew = commonUtils.isEmpty(slaveChildData[iIndexC].handleType) ? 'update' : slaveChildData[iIndexC].handleType;
slaveChildData[iIndexC] = { ...slaveChildData[iIndexC], dMaterialsPrice: tableDataRow.dMaterialsPrice, handleType: handleTypeNew };
slaveChildData[iIndexC] = commonBusiness.getCalculateAllMoney(app, 'Materials', 'dMaterialsPrice', masterData, slaveChildData[iIndexC]);
}
});
addStata.slaveChildData = slaveChildData;
}
}
if (this.props.sModelsId !== '101251240115016270323854760' ) { // 运费对账单不需要
if (name === 'slaveChild') {
const params = {
sFieldName: 'dAuxiliaryQty',
tableDataRow,
}
// 汇总到从表方法
this.handleWriteBack(params);
} else if (name === 'slaveChild' && sFieldName === 'dAuxiliaryQty') {
const {
slaveChildSelectedRowKeys: tableSelectedRowKeys, slaveSelectedRowKeys, slaveData,
} = this.props;
// eslint-disable-next-line no-unused-vars
/* 子表删除后 重新获取选中行的子表库存数量汇总到选中从表的产品数量上 */
if (commonUtils.isNotEmptyArr(tableSelectedRowKeys)) {
let iSlaveIndex = -1;
if (commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) {
iSlaveIndex = slaveData.findIndex(item => item.sId === slaveSelectedRowKeys[0]);
} else if (slaveData.length === 1) {
iSlaveIndex = 0;
}
if (iSlaveIndex > -1) {
if (commonUtils.isNotEmptyObject(slaveChildData)) {
const slaveChildFilter = slaveChildData.filter(item => item.sSqlConditionId === slaveData[iSlaveIndex].sSqlConditionId);
if (commonUtils.isNotEmptyArr(slaveChildFilter)) {
// let dMaterialsQty = 0;
let dAuxiliaryQty = 0;
let dMaterialsMoney = 0;
slaveChildFilter.forEach((item) => {
if (item.sId === tableDataRow.sId) {
// dMaterialsQty += commonUtils.isNull(tableDataRow.dMaterialsQty, 0); /* 赠送数量叠加 */
dAuxiliaryQty += commonUtils.isNull(tableDataRow.dAuxiliaryQty, 0); /* 赠送数量叠加 */
dMaterialsMoney += commonUtils.isNull(tableDataRow.dMaterialsMoney, 0); /* 赠送数量叠加 */
} else {
/* 库存数量叠加到从表的送货数量中 */
// dMaterialsQty += commonUtils.isNull(item.dMaterialsQty, 0); /* 赠送数量叠加 */
dAuxiliaryQty += commonUtils.isNull(item.dAuxiliaryQty, 0); /* 赠送数量叠加 */
dMaterialsMoney += commonUtils.isNull(item.dMaterialsMoney, 0); /* 赠送数量叠加 */
}
});
/* 找到选中从表行 */
const addState = {};
// addState.dMaterialsQty = dMaterialsQty;
addState.dAuxiliaryQty = dAuxiliaryQty;
addState.dMaterialsMoney = commonUtils.convertFixNum(dMaterialsMoney, dNetMoney);
addState.handleType = commonUtils.isEmpty(slaveData[iSlaveIndex].handleType) ? 'update' : slaveData[iSlaveIndex].handleType;
slaveData[iSlaveIndex] = { ...slaveData[iSlaveIndex], ...addState };
// slaveData[iSlaveIndex] = commonBusiness.getCalculateAllMoney(app, 'Materials', 'dAuxiliaryQty', masterData, slaveData[iSlaveIndex]);
addStata.slaveData = slaveData;
}
}
}
}
}
}
// 【特殊处理】合计误工、计件、计时工时
if (
[
"12710101117223881783540",
"12710101116993263909870",
"12710101117223395116420",
"12710101117247220162040",
"12710101117223889425720",
"12710101117223890411980",
"12710101117241578202960"
].includes(this.props.sModelsId)
) {
const { dLossHour = 0, dWageHour = 0, dTimeHour = 0, sSqlConditionId } = tableDataRow;
const { slaveChild0Data = [], slave1Data = [] } = this.props;
const slaveChild0DataFilter = slaveChild0Data.filter(item => item.sSqlConditionId === sSqlConditionId);
slaveChild0DataFilter.forEach(item => {
const iIndex = slaveChild0Data.findIndex(item1 => item1.sId === item.sId);
slaveChild0Data[iIndex].dLossHour = dLossHour;
slaveChild0Data[iIndex].dWageHour = dWageHour;
slaveChild0Data[iIndex].dTimeHour = dTimeHour;
slaveChild0Data[iIndex].handleType = slaveChild0Data[iIndex].handleType || 'update';
});
addStata.slaveChild0Data = slaveChild0Data;
slave1Data.forEach(item => {
const dataFilter = slaveChild0Data.filter(item1 => item1.sActualEmployeeNo === item.sActualEmployeeNo);
const { dLossHourSum, dWageHourSum, dTimeHourSum } = dataFilter.reduce((pre, item) => {
const { dLossHour = 0, dWageHour = 0, dTimeHour = 0 } = item;
return {
dLossHourSum: pre.dLossHourSum + dLossHour,
dWageHourSum: pre.dWageHourSum + dWageHour,
dTimeHourSum: pre.dTimeHourSum + dTimeHour
};
}, {
dLossHourSum: 0,
dWageHourSum: 0,
dTimeHourSum: 0
});
item.dLossHour = dLossHourSum;
item.dWageHour = dWageHourSum;
item.dTimeHour = dTimeHourSum;
item.dSumHour = dLossHourSum + dWageHourSum + dTimeHourSum;
item.handleType = item.handleType || 'update';
});
addStata.slave1Data = slave1Data;
}
if (isWait) {
return tableDataRow;
} else {
tableData[iIndex] = tableDataRow;
if (name === 'report') { // 报表设计r
this.props.onSaveState({ reportPropsEnabled: true });
} else {
this.props.onSaveState({ enabled: true });
}
this.props.onSaveState({ [`${name}Data`]: tableData, ...addStata });
}
}
};
// 子从表数据汇总到从表
handleWriteBack = async (params) => {
const {
sFieldName,
tableDataRow,
} = params;
const {
slaveSelectedRowKeys,
slaveData,
slaveChildConfig,
slaveChildData,
slave0SelectedRowKeys,
slave0Data,
} = this.props;
if (commonUtils.isEmptyArr(slaveData)) {
return;
}
const addState = {};
const sId = tableDataRow.sSqlConditionId || slaveSelectedRowKeys[0] || slaveData[0].sId;
const iSlaveIndex = slaveData.findIndex(item => item.sId === sId);
const slaveDataRow = slaveData[iSlaveIndex];
const slaveChildFilter = slaveChildData.filter(item => item.sSqlConditionId === slaveDataRow.sSqlConditionId);
let iSlave0Index = commonUtils.isNotEmptyArr(slave0Data)? (commonUtils.isNotEmptyArr(slave0SelectedRowKeys) ?
slave0Data.findIndex(item => slave0SelectedRowKeys.includes(item.sId)):0) : -1;
const slave0DataRow = iSlave0Index > -1 ? slave0Data[iSlave0Index] : {};
// 需要汇总的字段
const writeBackFields = ['dAuxiliaryQty', 'dProductQty', 'dArrivalQty', 'sBarcode', 'sDefineNo'];
const bHasiType = slaveChildConfig.gdsconfigformslave.find(item => ['itype', 'iType'].includes(item.sName));
if (bHasiType && ['dAuxiliaryQty', 'itype', 'iType', 'dProductQty'].includes(sFieldName)) {
// 需要汇总到从表的字段 1:dAuxiliaryQty,2:dEscrowQty,3:dGiveAuxiliaryQty
let dAuxiliaryQty = 0;
let dEscrowAuxiliaryQty = 0;
let dGiveAuxiliaryQty = 0;
let dProductQty = 0;
slaveChildFilter.forEach(item => {
const dataRow = item.sId === params.tableDataRow.sId ? params.tableDataRow : item;
const { itype, iType } = dataRow;
const type = itype !== undefined ? itype : iType !== undefined ? iType : 11;
console.log('s', dataRow.sId, type);
if (type === 1) {
dAuxiliaryQty += commonUtils.isNull(dataRow.dAuxiliaryQty, 0);
} else if (type === 2) {
dEscrowAuxiliaryQty += commonUtils.isNull(dataRow.dAuxiliaryQty, 0);
} else if (type === 3) {
dGiveAuxiliaryQty += commonUtils.isNull(dataRow.dAuxiliaryQty, 0);
} else if (type === 10) {
dAuxiliaryQty += commonUtils.isNull(dataRow.dProductQty, 0);
} else if (type === 11) {
dProductQty += commonUtils.isNull(dataRow.dAuxiliaryQty, 0);
} else if (type === 12) {
dProductQty += commonUtils.isNull(dataRow.dProductQty, 0);
}
});
const iIndex = slaveData.findIndex(item => item.sId === sId);
let tableDataRow = {};
tableDataRow = await this.handleTableChange('slave', 'dEscrowAuxiliaryQty', { dEscrowAuxiliaryQty }, sId, [], true);
slaveData[iIndex] = tableDataRow;
window.tmpSlaveData = slaveData;
tableDataRow = await this.handleTableChange('slave', 'dGiveAuxiliaryQty', { dGiveAuxiliaryQty }, sId, [], true);
slaveData[iIndex] = tableDataRow;
window.tmpSlaveData = slaveData;
tableDataRow = await this.handleTableChange('slave', 'dAuxiliaryQty', { dAuxiliaryQty }, sId, [], true);
slaveData[iIndex] = tableDataRow;
if(commonUtils.isNotEmptyObject(slave0DataRow)) {
const dSlave0AuxiliaryQty = slave0DataRow['dAuxiliaryQty'];
const table0DataRow = await this.handleTableChange('slave0', 'dAuxiliaryQty', { dSlave0AuxiliaryQty }, slave0DataRow.sId, [], true);
slave0Data[iSlave0Index] = table0DataRow;
addState.slave0Data = slave0Data;
}
if (slaveChildFilter.some(item => item.itype === 11 || item.iType === 11 || item.itype === 12 || item.iType === 12) || commonUtils.isEmptyArr(slaveChildFilter)) {
window.tmpSlaveData = slaveData;
tableDataRow = await this.handleTableChange('slave', 'dProductQty', { dProductQty }, sId, [], true);
slaveData[iIndex] = tableDataRow;
}
window.tmpSlaveData = null;
this.props.onSaveState({ slaveData, ...addState });
} else if (bHasiType && writeBackFields.includes(sFieldName)) {
let dQty = 0;
slaveChildFilter.forEach(item => {
const dataRow = item.sId === tableDataRow.sId ? tableDataRow : item;
dQty += commonUtils.isNull(dataRow[sFieldName], 0);
});
this.handleTableChange('slave', sFieldName, { [sFieldName]: dQty }, sId, [], false);
}
}
/** 删除表格数据 */
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`]: [] };
};
handleMaterialsChange = async (tableDataRow, sModelsId, masterData, changeValue, sFieldName, app, token, models) => {
const { auxiliaryQty = {} } = app;
const { sComputeId, sConversionComputeId, sReConversionComputeId } = tableDataRow;
if (sFieldName === 'sMaterialsNo' || sFieldName === 'sMaterialsName' || sFieldName === 'dAuxiliaryQty' || sFieldName === 'dReelAuxiliaryQty' || sFieldName === 'dConversionQty' || sFieldName === 'sMaterialsStyle' || sFieldName === 'dProductQty') {
if (sFieldName === 'dReelAuxiliaryQty') {
if (tableDataRow.sMaterialsUnit === '吨' && tableDataRow.bReel && tableDataRow.dGramWeight > 0) {
tableDataRow = commonBusiness.getMaterialsQty(app, { ...tableDataRow, sMaterialsStyle: tableDataRow.sReelMaterialsStyle }, 'dReelAuxiliaryQty', 'dMaterialsQty');
tableDataRow.dAuxiliaryQty = tableDataRow.dMaterialsQty;
tableDataRow.sMaterialsStyle = tableDataRow.sMaterialsStyle !== undefined && tableDataRow.sMaterialsStyle.split('*').length > 1 ? tableDataRow.sMaterialsStyle.split('*')[0] : tableDataRow.sMaterialsStyle;
tableDataRow.sAuxiliaryUnit = tableDataRow.sMaterialsUnit;
} else if (tableDataRow.sMaterialsUnit.toUpper() === 'M2' && tableDataRow.bReel) {
tableDataRow = commonBusiness.getMaterialsQty(app, tableDataRow, 'dReelAuxiliaryQty', 'dMaterialsQty');
tableDataRow.dAuxiliaryQty = tableDataRow.dReelAuxiliaryQty;
} else {
tableDataRow.dAuxiliaryQty = tableDataRow.dReelAuxiliaryQty;
}
}
if (commonUtils.isEmpty(sComputeId) && sFieldName !== 'dConversionQty') {
if (sFieldName === 'dProductQty') {
tableDataRow = commonBusiness.getMaterialsQty(app, tableDataRow, 'dProductQty', 'dMaterialsQty');
if (commonUtils.isNotEmptyObject(tableDataRow.sMaterialsUnit)) {
const decimal = auxiliaryQty[tableDataRow.sMaterialsUnit];
if(decimal > 0) {
tableDataRow.dMaterialsQty = commonUtils.convertFixNum(tableDataRow.dMaterialsQty, decimal);
}
}
} else {
tableDataRow.dMaterialsQty = await commonBusiness.getFormulaValue({
token, sModelsId, masterData, tableDataRow, sComputeId, sFormulaIdType: 'sComputeId',
});
}
} else if (!commonUtils.isEmpty(sComputeId)) {
tableDataRow.dMaterialsQty = await commonBusiness.getFormulaValue({
token, sModelsId, masterData, tableDataRow, sComputeId,
});
}
if (sFieldName !== 'dConversionQty' && !commonUtils.isEmpty(sConversionComputeId)) {
tableDataRow.dConversionQty = await commonBusiness.getFormulaValue({
token, sModelsId, masterData, tableDataRow, sComputeId: sConversionComputeId,
});
}
} else if (sFieldName === 'dMaterialsQty') {
const { sReComputeId } = tableDataRow;
if (commonUtils.isEmpty(sReComputeId) && tableDataRow.bInverse) {
tableDataRow = commonBusiness.getAuxiliaryQty(app, tableDataRow, sFieldName, 'dAuxiliaryQty');
} else if (tableDataRow.bInverse) {
tableDataRow.dAuxiliaryQty = await commonBusiness.getFormulaValue({
token, sModelsId, masterData, tableDataRow, sComputeId: sReComputeId,
});
if (commonUtils.isNotEmptyArr(tableDataRow.dAuxiliaryQty) && tableDataRow.dAuxiliaryQty !== 0) {
tableDataRow.dProductQty = tableDataRow.dAuxiliaryQty;
}
}
if (!commonUtils.isEmpty(sReConversionComputeId)) {
tableDataRow.dConversionQty = await commonBusiness.getFormulaValue({
token, sModelsId, masterData, tableDataRow, sComputeId: sReConversionComputeId,
});
}
} else if (sFieldName === 'dAuxiliaryLossQty') {
if (commonUtils.isEmpty(sComputeId)) {
tableDataRow = commonBusiness.getMaterialsQty(app, tableDataRow, sFieldName, 'dLossQty');
} else {
tableDataRow.dLossQty = await commonBusiness.getFormulaValue({
token, sModelsId, masterData, tableDataRow, sComputeId,
});
}
if (!commonUtils.isEmpty(tableDataRow.dSrcSurplusAuxiliaryQty)) {
tableDataRow.dAuxiliaryQty = tableDataRow.dSrcSurplusAuxiliaryQty - tableDataRow.dAuxiliaryLossQty;
tableDataRow.dMaterialsQty = commonUtils.convertFixNum(tableDataRow.dSrcSurplusQty - tableDataRow.dLossQty, 6);
}
} else if (sFieldName === 'dLossQty') {
const { sReComputeId } = tableDataRow;
if (commonUtils.isEmpty(sReComputeId)) {
tableDataRow = commonBusiness.getAuxiliaryQty(app, tableDataRow, sFieldName, 'dAuxiliaryLossQty');
} else {
tableDataRow.dAuxiliaryLossQty = await commonBusiness.getFormulaValue({
token, sModelsId, masterData, tableDataRow, sComputeId: sReComputeId,
});
}
if (!commonUtils.isEmpty(tableDataRow.dSrcSurplusAuxiliaryQty)) {
tableDataRow.dAuxiliaryQty = tableDataRow.dSrcSurplusAuxiliaryQty - tableDataRow.dAuxiliaryLossQty;
tableDataRow.dMaterialsQty = tableDataRow.dSrcSurplusQty - tableDataRow.dLossQty;
}
} else if (sFieldName === 'sProcessId' || sFieldName === 'sProcessNo' || sFieldName === 'sProcessName') {
const sProcessId = changeValue.sProcessId;
const url = `${commonConfig.server_host}process/outsideprocess?sModelsId=${sModelsId}&sProcessId=${sProcessId}`;
const dataReturn = (await commonServices.getService(token, url)).data;
if (dataReturn.code === 1) {
if (commonUtils.isNotEmptyArr(dataReturn.dataset.rows)) {
tableDataRow.dMaterialsPrice = dataReturn.dataset.rows[0].dMaterialsPrice;
}
tableDataRow = commonBusiness.getCalculateAllMoney(app, models, 'dMaterialsPrice', masterData, tableDataRow);
}
}
const sFieldNameJson = {
dPurchaseArrivalQty: 'dPurchaseQty',
dEscrowAuxiliaryQty: 'dEscrowQty',
dGiveAuxiliaryQty: 'dGiveQty',
dAuxiliaryQty: 'dReelQty',
}
if (Object.keys(sFieldNameJson).includes(sFieldName)) {
tableDataRow.dPurchaseArrivalQty = commonUtils.isNull(tableDataRow.dEscrowAuxiliaryQty, 0) + commonUtils.isNull(tableDataRow.dGiveAuxiliaryQty, 0) + commonUtils.isNull(tableDataRow.dAuxiliaryQty, 0);
tableDataRow = commonBusiness.getMaterialsQty(app, tableDataRow, sFieldName, sFieldNameJson[sFieldName]);
if (sFieldName !== 'dPurchaseArrivalQty') {
tableDataRow = commonBusiness.getMaterialsQty(app, tableDataRow, 'dPurchaseArrivalQty', 'dPurchaseQty');
}
} else if (sFieldName === 'dFqkd' || sFieldName === 'dFqcd') {
tableDataRow = commonBusiness.getMaterialsQty(app, tableDataRow, 'dAuxiliaryQty', 'dReelQty');
}
return tableDataRow;
}
/* 材料销售模块金额价格逻辑处理 */
handleCalculateMaterialsProductMoney= (tableDataRow, sModelsId, masterData, changeValue, sFieldName, app, token, models) => {
if (sFieldName === `d${models}Qty` || sFieldName === `d${models}Price` || sFieldName === `dN${models}Price` || sFieldName === `d${models}ForeignPrice` || sFieldName === `d${models}ForeignMoney` || sFieldName === `d${models}Money` || sFieldName === 'sTaxId' || sFieldName === 'sTaxName') {
const { dNetMoney } = app.decimals; /* 设定金额保留的小数位 */
let modelsNew = models;
if (models === 'Product') { /* 计算前将Product替换为Materials */
modelsNew = 'Materials';
}
let sFiledNameNew = sFieldName;
if (sFieldName === 'dProductQty') { /* 材料销售中的订单数量 等同于 dAuxiliaryQty */
sFiledNameNew = 'dAuxiliaryQty';
} else if (sFieldName === `d${models}Price`) {
sFiledNameNew = `d${modelsNew}Price`;
} else if (sFieldName === `dN${models}Price`) {
sFiledNameNew = `dN${modelsNew}Price`;
} else if (sFieldName === `d${models}ForeignPrice`) {
sFiledNameNew = `d${modelsNew}ForeignPrice`;
} else if (sFieldName === `d${models}Money`) {
sFiledNameNew = `d${modelsNew}Money`;
} else if (sFieldName === `dN${models}Money`) {
sFiledNameNew = `dN${modelsNew}Money`;
} else if (sFieldName === `d${models}ForeignMoney`) {
sFiledNameNew = `d${modelsNew}ForeignMoney`;
}
tableDataRow[`dN${modelsNew}Price`] = tableDataRow[`dN${models}Price`];
tableDataRow[`d${modelsNew}ForeignPrice`] = tableDataRow[`d${models}ForeignPrice`];
tableDataRow[`d${modelsNew}Price`] = tableDataRow[`d${models}Price`];
tableDataRow[`dN${modelsNew}Money`] = tableDataRow[`dN${models}Price`];
tableDataRow[`d${modelsNew}ForeignMoney`] = tableDataRow[`d${models}ForeignMoney`];
tableDataRow[`d${modelsNew}Money`] = tableDataRow[`d${models}Money`];
tableDataRow = commonBusiness.getCalculateAllMoney(app, modelsNew, sFiledNameNew, masterData, tableDataRow);
let dMoney = tableDataRow[`d${modelsNew}Money`]; /* 金额 */
let dForeignMoney = tableDataRow[`d${modelsNew}ForeignMoney`]; /* 外币金额 */
let dPrice = tableDataRow[`d${modelsNew}Price`]; /* 单价 */
const dQty = tableDataRow[`d${modelsNew}Qty`]; /* 换算数量 */
let dTaxMoney = tableDataRow[`d${modelsNew}TaxMoney`]; /* 税额 */
let dTaxNoMoney = tableDataRow[`d${modelsNew}NoTaxMoney`]; /* 税额 */
dMoney = commonUtils.isNotEmptyNumber(dMoney) ? dMoney : 0;
dForeignMoney = commonUtils.isNotEmptyNumber(dForeignMoney) ? dForeignMoney : 0;
dPrice = commonUtils.isNotEmptyNumber(dPrice) ? dPrice : 0;
dTaxMoney = commonUtils.isNotEmptyNumber(dTaxMoney) ? dTaxMoney : 0;
dTaxNoMoney = commonUtils.isNotEmptyNumber(dTaxNoMoney) ? dTaxNoMoney : 0;
tableDataRow[`d${models}Money`] = dMoney;
tableDataRow[`d${models}ForeignMoney`] = dForeignMoney;
tableDataRow[`d${models}Price`] = dPrice;
tableDataRow[`d${models}TaxMoney`] = dTaxMoney;
tableDataRow[`d${models}NoTaxMoney`] = dTaxNoMoney;
/* 单价计算 */
let dForeignPrice = tableDataRow[`d${models}Price`];
if (sFieldName === `d${models}ForeignMoney` || sFieldName === `d${models}Money`) {
dForeignPrice = commonUtils.isNotEmptyNumber(dQty) && dQty !== 0 ? commonUtils.convertFixNum(dForeignMoney / dQty, dNetMoney) : dPrice;
}
tableDataRow[`d${models}ForeignPrice`] = dForeignPrice;
}
return tableDataRow;
}
handleCustomerChange = (name, changeValue) => {
if (commonUtils.isNotEmptyObject(changeValue)) {
if (changeValue.sCustomerId !== this.state.changleCustomerId) {
const sCustomerId = [];
sCustomerId.push(changeValue.sCustomerId);
this.handleTableSelectRowChange(name, sCustomerId, changeValue);
}
}
this.setState({ changleCustomerId: changeValue.sCustomerId });
}
handleMasterChange = async (name, sFieldName, changeValue, sId, dropDownData, isWait, masterDataNew) => {
// this.handleCustomerChange(name, changeValue);
const {
sModelsId, sModelsType, masterData: masterDataOld, slaveData, app, masterConfig, slaveConfig, token, slaveChildData,
} = this.props;
const addState = {};
const masterData = masterDataNew === undefined ? masterDataOld === undefined ? {} : masterDataOld : masterDataNew;
let bNewSlaveData = false;
if (sFieldName === 'sCustomerId' || sFieldName === 'sCustomerNo' || sFieldName === 'sCustomerName') {
if (commonUtils.isNotEmptyArr(slaveData)) {
// 从表有数据,请删除后修改客户!不能去掉
if (slaveData.length === 1 && commonUtils.isEmpty(slaveData[0].sProductId)) {
bNewSlaveData = true;
} else {
message.warn(commonFunc.showMessage(app.commonConst, 'slaveHasDataPleaseDel'));
return;
}
}
changeValue.tGetPayDate = commonBusiness.getGeyPayDate({ ...masterData, ...changeValue });
// commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sProductId', []);
// commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sProductNo', []);
// commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sProductName', []);
//
// commonUtils.setStoreDropDownData(sModelsId, 'master', 'sProductId', []);
// commonUtils.setStoreDropDownData(sModelsId, 'master', 'sProductNo', []);
// commonUtils.setStoreDropDownData(sModelsId, 'master', 'sProductName', []);
} if (sFieldName === 'sSupplyId' || sFieldName === 'sSupplyNo' || sFieldName === 'sSupplyName') {
changeValue.tGetPayDate = commonBusiness.getGeyPayDate({ ...masterData, ...changeValue });
} else if (sFieldName === 'sWareHouseId' || sFieldName === 'sWareHouseNo' || sFieldName === 'sWareHouseName') {
commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sMaterialsId', []);
commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sMaterialsNo', []);
commonUtils.setStoreDropDownData(sModelsId, 'slave', 'sMaterialsName', []);
if (sModelsType === 'materialsStock/materialsCheck' || sModelsType === 'productStock/productCheck') {
let value = {};
if (sModelsType === 'materialsStock/materialsCheck') {
value = {
sProName: 'Sp_System_AccountSquareCheck',
paramsMap: {
iType2: 1,
sWareHouseGuid: commonUtils.isNotEmptyObject(changeValue.sWareHouseId) ? changeValue.sWareHouseId : '',
},
};
} else if (sModelsType === 'productStock/productCheck') {
value = {
sProName: 'Sp_System_AccountSquareCheck',
paramsMap: {
iType2: 2,
sWareHouseGuid: commonUtils.isNotEmptyObject(changeValue.sWareHouseId) ? changeValue.sWareHouseId : '',
},
};
}
const url = `${commonConfig.server_host}business/getProData?sModelsId=${sModelsId}`;
const returnData = (await commonServices.postValueService(app.token, value, url)).data;
if (returnData.code === 1) {
const outData = returnData.dataset.rows[0].dataSet.outData[0];
if (outData.sCode === -1) {
message.error(outData.sReturn);
return;
}
} else {
this.props.getServiceError(returnData);
return;
}
}
} else if (sModelsType.includes('cashier/') && sFieldName === 'sBillType') {
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerId', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerNo', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sCustomerName', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyId', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyNo', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sSupplyName', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyId', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyNo', []);
commonUtils.setStoreDropDownData(sModelsId, 'master', 'sFamilyName', []);
changeValue.sCustomerId = '';
const iIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sCustomerId');
if (iIndex > -1) {
masterConfig.gdsconfigformslave[iIndex].bReGetDropDown = true;
}
changeValue.sSupplyId = '';
const iSupplyIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sSupplyId');
if (iSupplyIndex > -1) {
masterConfig.gdsconfigformslave[iSupplyIndex].bReGetDropDown = true;
}
/* 财务调整中切换调整类型后,对象名称清空 */
const sBillTypeIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sFamilyName');
if (sBillTypeIndex > -1) {
masterData.sFamilyName = '';
}
this.props.onSaveState({ masterConfig });
} else if (sFieldName === 'sGetPayId' || sFieldName === 'sGetPayName') {
changeValue.tGetPayDate = commonBusiness.getGeyPayDate({ ...masterData, ...changeValue });
} else if (sFieldName === 'tInvoiceDate') {
changeValue.tGetPayDate = commonBusiness.getGeyPayDate({ ...masterData, ...changeValue });
} else if (sFieldName === 'sSettlementId') {
if (changeValue.sSettlementId === 'cash') {
const sBankAccountIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sBankAccount');
if (sBankAccountIndex > -1) {
masterConfig.gdsconfigformslave[sBankAccountIndex].iTag = 1;
masterData.sBankAccount = '';
}
const sInvoiceNoIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sInvoiceNo');
if (sInvoiceNoIndex > -1) {
masterConfig.gdsconfigformslave[sInvoiceNoIndex].iTag = 1;
masterData.sInvoiceNo = '';
}
const sBankIdIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sBankId' || item.sName === 'sBankName');
if (sBankIdIndex > -1) {
masterConfig.gdsconfigformslave[sBankIdIndex].iTag = 1;
masterData.sBankId = '';
masterData.sBankName = '';
}
}
if (changeValue.sSettlementId === 'bank') {
const sInvoiceNoIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sInvoiceNo');
if (sInvoiceNoIndex > -1) {
masterConfig.gdsconfigformslave[sInvoiceNoIndex].iTag = 1;
masterData.sInvoiceNo = '';
}
const sBankAccountIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sBankAccount');
if (sBankAccountIndex > -1) {
masterConfig.gdsconfigformslave[sBankAccountIndex].iTag = 0;
}
const sBankIdIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sBankId' || item.sName === 'sBankName');
if (sBankIdIndex > -1) {
masterConfig.gdsconfigformslave[sBankIdIndex].iTag = 0;
}
}
if (changeValue.sSettlementId === 'bill') {
const sBankAccountIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sBankAccount');
if (sBankAccountIndex > -1) {
masterConfig.gdsconfigformslave[sBankAccountIndex].iTag = 1;
masterData.sBankAccount = '';
}
const sInvoiceNoIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sInvoiceNo');
if (sInvoiceNoIndex > -1) {
masterConfig.gdsconfigformslave[sInvoiceNoIndex].iTag = 0;
}
const sBankIdIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'sBankId');
if (sBankIdIndex > -1) {
masterConfig.gdsconfigformslave[sBankIdIndex].iTag = 0;
}
const tDueDateIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sName === 'tDueDate');
if (tDueDateIndex > -1) {
masterConfig.gdsconfigformslave[tDueDateIndex].iTag = 0;
}
}
}
let returnData = this.props.onChange(name, sFieldName, changeValue, sId, dropDownData, true, masterData);
const tableAllData = {
master: masterData,
slave: slaveData,
slaveChild: slaveChildData,
}
const masterDataAfter = commonBusiness.getKeyUpEvent(name, sFieldName, masterConfig, returnData.masterData, {}, true, tableAllData);
if (commonUtils.isNotEmptyObject(masterDataAfter)) {
if(masterDataAfter.bMultiTable) {
returnData.masterData = masterDataAfter.master;
}else {
returnData.masterData = masterDataAfter;
}
}
if (sFieldName === 'sSupplyId' || sFieldName === 'sSupplyNo' || sFieldName === 'sSupplyName' || sFieldName === 'sWareHouseId' || sFieldName === 'sWareHouseNo' || sFieldName === 'sWareHouseName' ||
sFieldName === 'sLocationId' || sFieldName === 'sLocationNo' || sFieldName === 'sLocationName' ||
sFieldName === 'sWareHouseLocationId' || sFieldName === 'sWareHouseLocationNo' || sFieldName === 'sWareHouseLocationName' || sFieldName === 'tDeliverDate' ||
sFieldName === 'sCurrency' || sFieldName === 'dCurrencyRate' || sFieldName === 'sCurrencyName' ) {
const slaveDataNew = [];
const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
for (const item of slaveData) {
let tableDataRow = ((sFieldName === 'sWareHouseId' || sFieldName === 'sWareHouseNo' || sFieldName === 'sWareHouseName' ||
sFieldName === 'sLocationId' || sFieldName === 'sLocationNo' || sFieldName === 'sLocationName' ||
sFieldName === 'sWareHouseLocationId' || sFieldName === 'sWareHouseLocationNo' || sFieldName === 'sWareHouseLocationName') && (sModelsType.includes('materialsStock/productionmaterialsadjust'))) ?
{ ...item } : { ...item, [sFieldName]: changeValue[sFieldName] };
if (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;
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: returnData.masterData, tableDataRow, sComputeId,
});
tableDataRow.dMaterialsMoney = dMaterialsMoney;
tableDataRow = commonBusiness.getCalculateMoney(app, returnData.masterData, tableDataRow, 'Materials');
} else {
tableDataRow = commonBusiness.getCalculateMoney(app, returnData.masterData, tableDataRow, 'Materials'); /* 没有发外公式情况下 进行计算 */
}
}
} else {
tableDataRow = commonBusiness.getCalculateAllMoney(app, models, 'sTaxId', returnData.masterData, tableDataRow);
}
} else if (sFieldName === 'sCurrency' || sFieldName === 'dCurrencyRate' || sFieldName === 'sCurrencyName') {
tableDataRow = commonBusiness.getCalculateAllMoney(app, models, `d${models}ForeignPrice`, returnData.masterData, tableDataRow);
tableDataRow.handleType = commonUtils.isEmpty(tableDataRow.handleType) ? 'update' : tableDataRow.handleType;
}
if ((sFieldName === 'sWareHouseId' || sFieldName === 'sWareHouseNo' || sFieldName === 'sWareHouseName' ||
sFieldName === 'sLocationId' || sFieldName === 'sLocationNo' || sFieldName === 'sLocationName' ||
sFieldName === 'sWareHouseLocationId' || sFieldName === 'sWareHouseLocationNo' || sFieldName === 'sWareHouseLocationName') && (!sModelsType.includes('materialsStock/productionmaterialsadjust'))) {
if (sFieldName === 'sWareHouseId' || sFieldName === 'sWareHouseNo' || sFieldName === 'sWareHouseName') {
tableDataRow.sWareHouseId = changeValue.sWareHouseId;
tableDataRow.sWareHouseNo = changeValue.sWareHouseNo;
tableDataRow.sWareHouseName = changeValue.sWareHouseName;
} else if (sFieldName === 'sLocationId' || sFieldName === 'sLocationNo' || sFieldName === 'sLocationName') {
tableDataRow.sLocationId = changeValue.sLocationId;
tableDataRow.sLocationNo = changeValue.sLocationNo;
tableDataRow.sLocationName = changeValue.sLocationName;
} else if (sFieldName === 'sWareHouseLocationId' || sFieldName === 'sWareHouseLocationNo' || sFieldName === 'sWareHouseLocationName') {
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 });
} else if ((sFieldName === 'sCustomerId' || sFieldName === 'sCustomerNo' || sFieldName === 'sCustomerName')) {
if (bNewSlaveData) {
const slaveDataNew = [];
const allTableData = {};
allTableData.master = returnData.masterData;
const newSid = commonUtils.createSid();
const tableDataRowAdd = commonFunc.getDefaultData(slaveConfig, allTableData, { newSid });
tableDataRowAdd.handleType = 'add';
tableDataRowAdd.sId = newSid;
tableDataRowAdd.sParentId = masterData && masterData.sId ? masterData.sId : null;
tableDataRowAdd.key = tableDataRowAdd.sId;
tableDataRowAdd.bDefault = false;
tableDataRowAdd.iOrder = 1;
slaveDataNew.push(tableDataRowAdd);
addState.slaveData = slaveDataNew;
// this.props.onSaveState({ slaveData: slaveDataNew });
} else if (sModelsType.includes('sales/') || sModelsType.includes('cashier/') || sModelsType.includes('manufacture/')) { // 获取应收款
if (commonUtils.isNotEmptyObject(masterData)) {
this.getCustomerReceipt({ masterData: returnData.masterData });
}
}
} else if (sFieldName === 'sTestStandardId' || sFieldName === 'sTestStandardName') {
const { slaveDelData: slaveDelDataOld, slaveConfig, masterConfig } = this.props;
const dataUrl = `${commonConfig.server_host}eleteamemployee/getObtainInspectionStandards?sModelsId=${sModelsId}&sParentId=${returnData.masterData.sTestStandardId}`;
const dataReturn = (await commonServices.getService(this.props.app.token, dataUrl)).data;
const slaveDelData = commonUtils.isEmptyArr(slaveDelDataOld) ? [] : slaveDelDataOld;
if (dataReturn.code === 1) {
const returnSlaveData = dataReturn.dataset.rows;
slaveData.forEach((item) => {
item.handleType = 'del';
slaveDelData.push(item);
});
const slaveDataNew = [];
const newCopyTo = {};
newCopyTo.master = masterData;
const iConfigIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'sTestStandardName');
returnSlaveData.forEach((item, iIndex) => {
const newSid = commonUtils.createSid();
let tableDataRow = commonFunc.getDefaultData(slaveConfig, {}, { newSid });
tableDataRow.handleType = 'add';
tableDataRow.sId = newSid;
tableDataRow.sParentId = masterData && masterData.sId ? masterData.sId : null;
tableDataRow.key = tableDataRow.sId;
tableDataRow.iOrder = iIndex;
if (iConfigIndex > -1) {
tableDataRow = { ...tableDataRow, ...commonFunc.getAssignFieldValue(masterConfig.gdsconfigformslave[iConfigIndex].sAssignField, item, newCopyTo) }; // 取赋值字段
}
slaveDataNew.push(tableDataRow);
});
addState.slaveData = slaveDataNew;
} else {
this.props.getServiceError(dataReturn);
}
} else if (sFieldName === 'sPeriodID') {
const master = returnData.masterData;
let { handleType } = master;
handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
if (handleType === 'add') { /* 费用分摊单据新增时,选择不同月份,自动获取从表的数据 */
const { sModelsId } = this.props;
let url = `${commonConfig.server_host}costCenter/getCostCenterData?sModelsId=${sModelsId}`;
const body = {
sPeriodId: changeValue.sPeriodID,
};
/**
* 修改日期:2021-03-26
* 修改人:吕杰
* 区域:以下 4 行
* BUG:2168
* 说明:凭证导入表下主表月份切换从后台获取数据
* 原代码:
*/
if (sModelsType === 'cashier/voucher') {
url = `${commonConfig.server_host}costCenter/getCosvoucherImportData?sModelsId=${sModelsId}`;
body.sWeek = masterDataOld.sWeek;
}
const dataReturn = (await commonServices.postValueService(app.token, body, url)).data;
if (dataReturn.code === 1) {
/* 获取数据集 */
const { rows } = dataReturn.dataset;
const slaveDataNew = [];
rows.forEach((row) => {
/**
* 修改日期:2021-03-26
* 修改人:吕杰
* 区域:以下 13 行
* BUG:2168
* 说明:凭证导入表下主表月份切换从后台获取数据
* 原代码:
*/
let tableDataRowAdd = row;
if (sModelsType === 'cashier/voucher') {
// 当主表中配置了转换信息时,对数据字段进行转换
const index = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'Btnimport');
if (index > -1) {
const newCopyTo = {};
newCopyTo.master = masterData;
newCopyTo.slave = row;
const config = masterConfig.gdsconfigformslave[index];
const slaveAssignField = config.sAssignField || '';
tableDataRowAdd = { ...row, ...commonFunc.getAssignFieldValue(slaveAssignField, row, newCopyTo) };
}
}
tableDataRowAdd.handleType = handleType;
tableDataRowAdd.sId = commonUtils.createSid();
tableDataRowAdd.sParentId = masterData && masterData.sId ? masterData.sId : null;
tableDataRowAdd.key = tableDataRowAdd.sId;
tableDataRowAdd.bDefault = false;
slaveDataNew.push(tableDataRowAdd);
});
addState.slaveData = slaveDataNew;
} else { /* 失败 */
this.props.getServiceError(dataReturn);
return [];
}
}
} else if (sFieldName === 'sWeek' && sModelsType === 'cashier/voucher') {
/**
* 修改日期:2021-03-26
* 修改人:吕杰
* 区域:此if内
* BUG:2168
* 说明:凭证导入表下主表周期切换从后台获取数据
* 原代码:
*/
const master = returnData.masterData;
let { handleType } = master;
handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
if (handleType === 'add') { /* 费用分摊单据新增时,选择不同月份,自动获取从表的数据 */
const { sModelsId } = this.props;
const url = `${commonConfig.server_host}costCenter/getCosvoucherImportData?sModelsId=${sModelsId}`;
const body = {
sWeek: changeValue.sWeek,
sPeriodId: masterDataOld.sPeriodId,
};
const dataReturn = (await commonServices.postValueService(app.token, body, url)).data;
if (dataReturn.code === 1) {
/* 获取数据集 */
const { rows } = dataReturn.dataset;
const slaveDataNew = [];
rows.forEach((row) => {
let tableDataRowAdd = row;
// 当主表中配置了转换信息时,对数据字段进行转换
const index = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'Btnimport');
if (index > -1) {
const newCopyTo = {};
newCopyTo.master = masterData;
newCopyTo.slave = row;
const config = masterConfig.gdsconfigformslave[index];
const slaveAssignField = config.sAssignField || '';
tableDataRowAdd = { ...row, ...commonFunc.getAssignFieldValue(slaveAssignField, row, newCopyTo) };
}
tableDataRowAdd.handleType = handleType;
tableDataRowAdd.sId = commonUtils.createSid();
tableDataRowAdd.sParentId = masterData && masterData.sId ? masterData.sId : null;
tableDataRowAdd.key = tableDataRowAdd.sId;
tableDataRowAdd.bDefault = false;
slaveDataNew.push(tableDataRowAdd);
});
addState.slaveData = slaveDataNew;
} else { /* 失败 */
this.props.getServiceError(dataReturn);
return [];
}
}
}
const models = name === 'materials' ? 'Materials' :
sModelsType.includes('sales/') || sModelsType.includes('manufacture/') || sModelsType.includes('print/') || sModelsType.includes('quotation/') || sModelsType.includes('productStock/') ? 'Product' : 'Materials';
if (sModelsType.includes('purchase/') || sModelsType.includes('print/') || sModelsType.includes('quotation/') || sModelsType.includes('manufacture/') || sModelsType.includes('materialsStock/') || sModelsType.includes('outside/') || sModelsType.includes('quality/')) {
let masterData = await this.handleMaterialsChange(returnData.masterData, sModelsId, masterData, changeValue, sFieldName, app, token, models);
masterData = commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, masterData);
if (sFieldName !== 'dPackQty') {
if (changeValue.dPackQty !== this.state.dPackQtyChange && changeValue.dPackQty !== undefined) {
masterData = commonBusiness.getCalculateAllMoney(app, models, 'dPackQty', masterData, masterData);
this.setState({ dPackQtyChange: changeValue.dPackQty });
}
}
returnData = { ...returnData, masterData };
}
if (isWait) {
return { ...returnData, ...addState, enabled: true };
} else {
this.props.onSaveState({ ...returnData, ...addState, enabled: true });
return returnData;
}
}
handleBtnPrint = (sActiveId, checked, eKey) => {
const {
app, sModelsId, masterConfig, masterData, slaveConfig, sModelsType, reportData, menuChildData, formRoute, controlConfig,
} = this.props;
if (sModelsType.includes('manufacture/workOrder')) {
this.handleUpdateProduction();
}
const { token } = app;
const queryFilter = {};
queryFilter[masterConfig.sId] = { sId: masterData.sId };
if (commonUtils.isNotEmptyObject(slaveConfig)) {
queryFilter[slaveConfig.sId] = { sSqlCondition: { sParentId: masterData.sId } };
}
const queryFilterJson = JSON.stringify(queryFilter);
// const masterDataJson = JSON.stringify(masterData);
/* 拿到打印报表名称 */
let printReportName = 'report';
let printCustomerReportName = 'report';
if (commonUtils.isNotEmptyArr(reportData)) {
const iIndex = reportData.findIndex(item => item.sId === sActiveId);
if (iIndex > -1) {
printReportName = reportData[iIndex].sReportName;
}
}
if (commonUtils.isNotEmptyArr(menuChildData)) {
const iIndex = menuChildData.findIndex(item => item.sId === sActiveId);
if (iIndex > -1) {
printCustomerReportName = menuChildData[iIndex].sReportName;
}
}
let urlPrint = '';
if (formRoute === '/indexPage/printlabel') {
if (commonUtils.isNotEmptyObject(masterData) && masterData.dTrunkQty !== undefined && masterData.dFractionQty !== undefined && masterData.dPackQty !== undefined) { // masterData中必填的三个字段
// const param = masterDataJson;
/* 把masterData放在数组中 */
const ListData = [];
ListData.push(masterData);
const param = JSON.stringify(ListData);
if (eKey.indexOf('BtnPrint.') > -1) {
urlPrint = `${commonConfig.file_host}printReport/printPdf/${sActiveId}/${printReportName}.pdf?${checked ? 'fileType=.xlsx&' : ''}printType=noquery&sModelsId=${sModelsId}&token=${encodeURIComponent(token)}`;
} else if (eKey.indexOf('BtnPrintCus.') > -1) {
urlPrint = `${commonConfig.file_host}printReport/printPdf/${printCustomerReportName}?${checked ? 'fileType=.xlsx&' : ''}printType=noquery&sModelsId=${sModelsId}&token=${encodeURIComponent(token)}`;
}
/* Get提交地址栏参数过多,更改Get提交为Post提交 */
this.handleOpenPost(urlPrint, param);
} else {
const dTrunkQtyName = masterConfig.gdsconfigformslave.filter(item => item.sName === 'dTrunkQty');
const dFractionQtyName = masterConfig.gdsconfigformslave.filter(item => item.sName === 'dFractionQty');
const dPackQtyName = masterConfig.gdsconfigformslave.filter(item => item.sName === 'dPackQty');
if (masterData.dTrunkQty === undefined && commonUtils.isNotEmptyObject(dTrunkQtyName)) {
message.error(`${dTrunkQtyName[0].showName} 必填项!`);
} else if (masterData.dFractionQty === undefined && commonUtils.isNotEmptyObject(dFractionQtyName)) {
message.error(`${dFractionQtyName[0].showName} 必填项!`);
} else if (masterData.dPackQty === undefined && commonUtils.isNotEmptyObject(dPackQtyName)) {
message.error(`${dPackQtyName[0].showName} 必填项!`);
}
return;
}
} else if (eKey.indexOf('BtnPrint.') > -1) {
let { controlSelectedRowKeys } = this.props;
/* 不出现选择框,则打印全部;出现选择框,则打印勾选的 */
let bisMutiSelect = false;
if (commonUtils.isNotEmptyObject(controlConfig) && commonUtils.isNotEmptyArr(controlConfig.gdsconfigformslave)) {
const filterData = controlConfig.gdsconfigformslave.filter(item => item.sControlName === 'bisMutiSelect');
if (commonUtils.isNotEmptyArr(filterData)) {
bisMutiSelect = filterData[0].bVisible;
}
}
if (bisMutiSelect === false || bisMutiSelect === undefined) {
controlSelectedRowKeys = [];
}
urlPrint = `${commonConfig.file_host}printReport/printPdf/${sActiveId}/${printReportName}.pdf?${checked ? 'fileType=.xlsx&' : ''}sModelsId=${sModelsId}&sMaintableId=${masterConfig.sId}&sControlIds=${commonUtils.isNotEmptyArr(controlSelectedRowKeys) ? controlSelectedRowKeys : []}`;
} else if (eKey.indexOf('BtnPrintCus.') > -1) {
urlPrint = `${commonConfig.file_host}printReport/printPdf/${printCustomerReportName}?${checked ? 'fileType=.xlsx&' : ''}sModelsId=${sModelsId}&sMaintableId=${masterConfig.sId}`;
}
if (formRoute !== '/indexPage/printlabel') {
window.open(`${encodeURI(`${urlPrint}&queryFilter=${queryFilterJson}`)}&token=${encodeURIComponent(token)}`);
}
};
handleOpenPost= (url, params) => {
const newWin = window.open();
let formStr = '';
formStr = `';
newWin.document.body.innerHTML = formStr;
newWin.document.forms[0].submit();
return newWin;
}
handleUpdateProduction = async () => {
const { sModelsId, masterData } = this.props;
const { sBillNo, sId } = masterData || {};
const dataUrl = `${commonConfig.server_host}business/addUpdateDelBusinessData?sModelsId=${sModelsId}&sBillNo=${sBillNo}&sSysLogSrcId=${sId}`;
const value = {
data: [{
sTable: 'mftworkordermaster',
column: [{ handleType: 'update', sId: masterData.sId, bProduction: 1 }],
}],
sClientType: '1',
};
const dataReturn = (await commonServices.postValueService(this.props.app.token, value, dataUrl)).data;
if (dataReturn.code === 1) {
message.success(dataReturn.msg);
} else {
this.props.getServiceError(dataReturn);
}
};
handleTitleChange = (name, slavePagination) => {
this.props.onSaveState({ [`${name}Pagination`]: slavePagination });
};
/* 工单、工艺卡、报价单控制表回带图片地址 */
handleFilfileManageOk= async (controlFilfileData, controlFilfileDelData, sSrcSlaveId) => {
const {
controlData: tableData, app, sModelsId, token, controlConfig,
} = this.props;
if (commonUtils.isNotEmptyObject(sSrcSlaveId)) {
if (commonUtils.isNotEmptyArr(controlFilfileDelData)) {
const addState = {};
const iIndex = tableData.findIndex(item => item.sId === sSrcSlaveId);
if (iIndex > -1) {
const tableDataNewRow = tableData[iIndex];
const { sMaterialsPicturePath, sMachinePicturePath } = tableDataNewRow;
const controlsMaterialsPictureDelData = controlFilfileDelData.filter(item => item.sType === '3'); /* 开料 */
if (commonUtils.isNotEmptyArr(controlsMaterialsPictureDelData)) {
controlsMaterialsPictureDelData.forEach((slaveItem) => {
if (slaveItem.sPicturePath === sMaterialsPicturePath) {
addState.sMaterialsPicturePath = '';
}
});
}
const sMachinePictureDelPath = controlFilfileDelData.filter(item => item.sType === '4'); /* 联版 */
if (commonUtils.isNotEmptyArr(sMachinePictureDelPath)) {
sMachinePictureDelPath.forEach((slaveItem) => {
if (slaveItem.sPicturePath === sMachinePicturePath) {
addState.sMachinePicturePath = '';
}
});
}
if (commonUtils.isNotEmptyObject(addState) && (addState.sMachinePicturePath === '' || addState.sMaterialsPicturePath === '')) {
tableData[iIndex] = { ...tableDataNewRow, ...addState };
const data = [];
const updataData = {};
const updateWhere = {};
const column = {};
if (addState.sMaterialsPicturePath === '') {
column.sMaterialsPicturePath = addState.sMaterialsPicturePath;
}
if (addState.sMachinePicturePath === '') {
column.sMachinePicturePath = addState.sMachinePicturePath;
}
if (commonUtils.isNotEmptyObject(tableDataNewRow.sId) && commonUtils.isNotEmptyObject(column)) {
updateWhere.sId = tableDataNewRow.sId;
updataData.sTable = controlConfig.sTbName;
updataData.sWhere = updateWhere;
updataData.column = column;
data.push(updataData);
/* 调用接口将图片地址存入控制表 */
const configUrl = `${commonConfig.server_host}business/updateBusinessData?sModelsId=${sModelsId}`;
const value = {
data,
sClientType: '1',
};
const dataReturn = (await commonServices.postValueService(token, value, configUrl)).data;
if (dataReturn.code === 1) {
/* 刷新 */
if (this.props.app.currentPane.refresh !== undefined) {
this.props.app.currentPane.refresh();
}
} else {
this.getServiceError(dataReturn);
}
}
}
}
}
if (commonUtils.isNotEmptyArr(controlFilfileData)) {
const addState = {};
const iIndex = tableData.findIndex(item => item.sId === sSrcSlaveId);
if (iIndex > -1) {
const tableDataNewRow = tableData[iIndex];
const { sMaterialsPicturePath, sMachinePicturePath } = tableDataNewRow;
const controlsMaterialsPictureData = controlFilfileData.filter(item => item.sType === '3');
if (commonUtils.isNotEmptyArr(controlsMaterialsPictureData)) {
addState.sMaterialsPicturePath = commonUtils.isNotEmptyObject(controlsMaterialsPictureData[0].sPicturePath) ? controlsMaterialsPictureData[0].sPicturePath : ''; /* 上机默认取上传图片的第一条 */
}
const controlsMachinePictureData = controlFilfileData.filter(item => item.sType === '4');
if (commonUtils.isNotEmptyArr(controlsMachinePictureData)) {
addState.sMachinePicturePath = commonUtils.isNotEmptyObject(controlsMachinePictureData[0].sPicturePath) ? controlsMachinePictureData[0].sPicturePath : '';
}
if (commonUtils.isNotEmptyObject(addState)) {
tableData[iIndex] = { ...tableDataNewRow, ...addState };
const data = [];
const updataData = {};
const updateWhere = {};
const column = {};
if (commonUtils.isNotEmptyObject(addState.sMaterialsPicturePath) && addState.sMaterialsPicturePath !== sMaterialsPicturePath) {
column.sMaterialsPicturePath = addState.sMaterialsPicturePath;
}
if (commonUtils.isNotEmptyObject(addState.sMachinePicturePath) && addState.sMachinePicturePath !== sMachinePicturePath) {
column.sMachinePicturePath = addState.sMachinePicturePath;
}
if (commonUtils.isNotEmptyObject(tableDataNewRow.sId) && commonUtils.isNotEmptyObject(column)) {
updateWhere.sId = tableDataNewRow.sId;
updataData.sTable = controlConfig.sTbName;
updataData.sWhere = updateWhere;
updataData.column = column;
data.push(updataData);
/* 调用接口将图片地址存入控制表 */
const configUrl = `${commonConfig.server_host}business/updateBusinessData?sModelsId=${sModelsId}`;
const value = {
data,
sClientType: '1',
};
const dataReturn = (await commonServices.postValueService(token, value, configUrl)).data;
if (dataReturn.code === 1) {
this.props.onSaveState({ tableData });
/* 刷新 */
if (this.props.app.currentPane.refresh !== undefined) {
this.props.app.currentPane.refresh();
}
} else {
this.getServiceError(dataReturn);
}
}
}
}
}
} else {
return message.warning(commonFunc.showMessage(app.commonConst, 'selectedRowKeysNo'));
}
}
// 收付款分摊
handleShare = () => {
/* 分摊 */
const {
sModelsType, masterData: masterDataOld, slaveData: slaveDataOld, app,
} = this.props;
if ((sModelsType.includes('cashier/receipt') && masterDataOld.sBillType !== 'customer') ||
(sModelsType.includes('cashier/payment') && masterDataOld.sBillType !== 'supply')) {
return masterDataOld;
}
const { dNetMoney } = app.decimals;
const masterData = { ...masterDataOld };
const slaveData = [];
if (commonUtils.isNotEmptyArr(slaveDataOld) && slaveDataOld.length > 0) {
slaveDataOld.forEach((item) => {
slaveData.push({ ...item });
});
}
const dTotalMoney = masterData.dTotalMoney !== undefined ? masterData.dTotalMoney : 0;
let minusSum = 0; /* 负数求和 */
let minusRoundingSum = 0; /* 负数舍入求和 */
const minusData = []; /* 负数集 */
let positiveSum = 0; /* 正数求和 */
let positiveRoundingSum = 0; /* 正数舍入求和 */
const positiveData = []; /* 正数集 */
if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) {
slaveData.forEach((child) => {
child.dTotalMoney = 0;
child.dRoundingMoney = commonUtils.isNum(child.dRoundingMoney) ? child.dRoundingMoney : 0;
if (child.dBalanceMoney < 0) {
minusSum -= Math.abs(child.dBalanceMoney);
minusRoundingSum -= Math.abs(child.dRoundingMoney);
minusData.push(child);
} else {
const positiveSumTemp = commonUtils.convertFixNum(child.dBalanceMoney, dNetMoney) + commonUtils.convertFixNum(positiveSum, dNetMoney);
positiveSum = commonUtils.convertFixNum(positiveSumTemp, dNetMoney);
const positiveRoundingSumTemp = commonUtils.convertFixNum(child.dRoundingMoney, dNetMoney) + commonUtils.convertFixNum(positiveRoundingSum, dNetMoney);
positiveRoundingSum = commonUtils.convertFixNum(positiveRoundingSumTemp, dNetMoney);
positiveData.push(child);
}
});
}
if (commonUtils.convertFixNum(((minusSum - minusRoundingSum) + (positiveSum - positiveRoundingSum)) - dTotalMoney, dNetMoney) <= 0) {
/* 够扣 */
positiveSum -= minusRoundingSum;
positiveSum -= positiveRoundingSum;
positiveSum -= dTotalMoney; /* 去除分摊金额 */
if (positiveSum >= 0) {
for (let i = 0; i < minusData.length; i += 1) {
/* 负数遍历 */
const dBalanceMoney = Math.abs(minusData[i].dBalanceMoney); /* 余额正数 */
const dRoundingMoney = minusData[i].dRoundingMoney !== undefined
? minusData[i].dRoundingMoney
: 0;
if (positiveSum <= dBalanceMoney) {
minusData[i].dTotalMoney = commonUtils.convertFixNum(-(positiveSum) - (dRoundingMoney * 1), dNetMoney);
if (minusData[i].handleType === undefined) {
minusData[i].handleType = commonUtils.isEmpty(minusData[i].handleType) ? 'update' : minusData[i].handleType;
}
break;
} else {
minusData[i].dTotalMoney = commonUtils.convertFixNum(-(dBalanceMoney * 1) - (dRoundingMoney * 1), dNetMoney);
positiveSum -= dBalanceMoney - (dRoundingMoney * 1);
if (minusData[i].handleType === undefined) {
minusData[i].handleType = commonUtils.isEmpty(minusData[i].handleType) ? 'update' : minusData[i].handleType;
}
}
}
for (let i = 0; i < positiveData.length; i += 1) {
/* 正数遍历 */
const { dBalanceMoney } = positiveData[i]; /* 余额正数 */
const dRoundingMoney = positiveData[i].dRoundingMoney !== undefined
? positiveData[i].dRoundingMoney
: 0;
positiveData[i].dTotalMoney = commonUtils.convertFixNum((dBalanceMoney * 1) - (dRoundingMoney * 1), dNetMoney);
if (positiveData[i].handleType === undefined) {
positiveData[i].handleType = commonUtils.isEmpty(positiveData[i].handleType) ? 'update' : positiveData[i].handleType;
}
}
masterData.dAdvanceMoney = 0;
masterData.bAdvance = false;
} else {
/* 有预收 */
for (let i = 0; i < positiveData.length; i += 1) {
/* 正数遍历 */
const { dBalanceMoney } = positiveData[i]; /* 余额正数 */
const dRoundingMoney = positiveData[i].dRoundingMoney !== undefined
? positiveData[i].dRoundingMoney
: 0;
positiveData[i].dTotalMoney = commonUtils.convertFixNum((dBalanceMoney * 1) - (dRoundingMoney * 1), dNetMoney);
positiveData[i].handleType = commonUtils.isEmpty(positiveData[i].handleType) ? 'update' : positiveData[i].handleType;
}
for (let i = 0; i < minusData.length; i += 1) {
/* 负数遍历 */
minusData[i].dRoundingMoney = 0;
minusData[i].handleType = commonUtils.isEmpty(minusData[i].handleType) ? 'update' : minusData[i].handleType;
}
masterData.dAdvanceMoney = commonUtils.convertFixNum(Math.abs(positiveSum), dNetMoney);
masterData.bAdvance = true;
}
const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
/* 分摊算外币金额 */
if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) {
slaveData.forEach((item, index) => {
slaveData[index].dTotalForeignMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? item.dTotalMoney / dCurrencyRate : 0, dNetMoney);
});
}
masterData.handleType = commonUtils.isEmpty(masterData.handleType) ? 'update' : masterData.handleType;
if (commonUtils.isNotEmptyNumber(masterData.dTotalMoney)) {
masterData.dProductForeignMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? masterData.dTotalMoney / dCurrencyRate : 0, dNetMoney);
}
this.props.onSaveState({ masterData, slaveData });
} else if (((minusSum - minusRoundingSum) + (positiveSum - positiveRoundingSum)) - dTotalMoney > 0) {
/* 不够扣情况 */
minusSum -= minusRoundingSum;
minusSum -= positiveRoundingSum;
minusSum -= dTotalMoney; /* 去除分摊金额 */
for (let i = 0; i < minusData.length; i += 1) {
/* 负数遍历 */
const dBalanceMoney = Math.abs(minusData[i].dBalanceMoney); /* 余额正数 */
const dRoundingMoney = minusData[i].dRoundingMoney !== undefined
? minusData[i].dRoundingMoney
: 0;
minusData[i].dTotalMoney = commonUtils.convertFixNum(-(dBalanceMoney * 1) - (dRoundingMoney * 1), dNetMoney);
minusData[i].handleType = commonUtils.isEmpty(minusData[i].handleType) ? 'update' : minusData[i].handleType;
}
for (let i = 0; i < positiveData.length; i += 1) {
/* 正数遍历 */
const { dBalanceMoney } = positiveData[i]; /* 余额正数 */
const dRoundingMoney = positiveData[i].dRoundingMoney !== undefined
? positiveData[i].dRoundingMoney
: 0;
if (Math.abs(minusSum) <= dBalanceMoney) {
positiveData[i].dTotalMoney = commonUtils.convertFixNum(Math.abs(minusSum) - (dRoundingMoney * 1), dNetMoney);
positiveData[i].handleType = commonUtils.isEmpty(positiveData[i].handleType) ? 'update' : positiveData[i].handleType;
break;
} else {
positiveData[i].dTotalMoney = commonUtils.convertFixNum((dBalanceMoney * 1) - (dRoundingMoney * 1), dNetMoney);
minusSum = -(Math.abs(minusSum) - (dBalanceMoney * 1)); // - (dRoundingMoney * 1)
positiveData[i].handleType = commonUtils.isEmpty(positiveData[i].handleType) ? 'update' : positiveData[i].handleType;
}
}
const dCurrencyRate = commonUtils.convertIsNotNumToNumber1(masterData.dCurrencyRate); /* 汇率 */
/* 分摊算外币金额 */
if (commonUtils.isNotEmptyArr(slaveData) && slaveData.length > 0) {
slaveData.forEach((item, index) => {
slaveData[index].dTotalForeignMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? item.dTotalMoney / dCurrencyRate : 0, dNetMoney);
});
}
masterData.dAdvanceMoney = 0;
masterData.bAdvance = false;
masterData.handleType = commonUtils.isEmpty(masterData.handleType) ? 'update' : masterData.handleType; /* 主表分摊算外币金额 */
if (commonUtils.isNotEmptyNumber(masterData.dTotalMoney)) {
masterData.dProductForeignMoney = commonUtils.convertFixNum(dCurrencyRate !== 0 ? masterData.dTotalMoney / dCurrencyRate : 0, dNetMoney);
}
this.props.onSaveState({ masterData, slaveData });
}
// let allTotalMoney = 0;
// let allRoundingMoney = 0;
// slaveData.forEach((child) => {
// if (child.dTotalMoney !== undefined) {
// allTotalMoney += child.dTotalMoney * 1;
// }
// if (child.dRoundingMoney !== undefined) {
// allRoundingMoney += child.dRoundingMoney * 1;
// }
// });
// this.props.onSaveState({ allTotalMoney, allRoundingMoney });
return masterData;
};
handleImport = async (num) => {
const {
sModelsId, sModelsType, masterConfig, masterData, slaveData, slaveDelData: slaveDelDataOld, app,
} = this.props;
if (commonUtils.isEmpty(masterData.sWareHouseId)) {
message.error(commonFunc.getConfigShowName(masterConfig, 'sWareHouseId') + commonFunc.showMessage(app.commonConst, 'isNotNull')); // 不能为空!
return;
}
let url;
if (sModelsType.includes('productStock/')) {
url = `${commonConfig.server_host}eleProductStock/getEleProductStock?sModelsId=${sModelsId}&sWareHouseId=${masterData.sWareHouseId}&num=${num}`;
} else {
url = `${commonConfig.server_host}eleMaterialsStock/getEleMaterialsStock?sModelsId=${sModelsId}&sWareHouseId=${masterData.sWareHouseId}&num=${num}`;
}
const dataReturn = (await commonServices.getService(this.props.app.token, url)).data;
if (dataReturn.code === 1) {
const returnData = dataReturn.dataset.rows;
const slaveDelData = commonUtils.isEmptyArr(slaveDelDataOld) ? [] : slaveDelDataOld;
slaveData.forEach((item) => {
item.handleType = 'del';
slaveDelData.push({ ...item });
});
returnData.forEach((item, index) => {
const tableDataRow = this.props.onDataRowAdd('slave', true);
item.handleType = 'add';
item.sParentId = masterData.sId;
item.iOrder = index + 1;
returnData[index] = { ...tableDataRow, ...item };
});
this.props.onSaveState({ slaveData: returnData, slaveDelData });
} else {
this.props.getServiceError(dataReturn);
}
this.props.onSaveState({ isGetDataVisible: false });
};
handleOutTemplate = async () => {
const {
token, formData,
} = this.props;
const slaveConfig = formData.filter(item => item.sGrd === 'importTemplate')[0];
window.location.href = `${commonConfig.server_host}import/exportTemplet?gdsconfigformmasterId=${slaveConfig.sId}&token=${token}`;
};
/* 导出模版数据 */
handleOutTemplateData = async (name) => {
const {
formRoute, masterData, sortedInfo,
} = this.props;
const sort = commonUtils.isNotEmptyObject(sortedInfo) ? sortedInfo.order === 'ascend' ? 'asc' : 'desc' : '';
const slaveOrderBy = commonUtils.isNotEmptyObject(sortedInfo) && Object.keys(sortedInfo).length > 0 ? { [sortedInfo.columnKey]: sort } : ''; //
const sId = commonUtils.isNotEmptyObject(masterData) ? masterData.sId : '';
const baseName = name?.toString().split('_')[1] || 'slave';
const baseConfig = this.props[`${baseName}Config`];
if (commonUtils.isNotEmptyObject(sId)) {
const sSqlCondition = { sParentId: sId };
let url = `${commonConfig.server_host}excel/export/${baseConfig.sId}?sModelsId=${baseConfig.sParentId}&token=${this.props.app.token}&sName=${formRoute}&sControlName=${name}`;
if (commonUtils.isNotEmptyObject(sSqlCondition)) {
url = `${url}&sSqlCondition=${encodeURIComponent(JSON.stringify(sSqlCondition))}`;
}
if (slaveOrderBy !== undefined && slaveOrderBy !== '' && Object.keys(slaveOrderBy).length > 0) {
url = `${url}&sFilterOrderBy=${encodeURIComponent(JSON.stringify(slaveOrderBy))}`;
}
window.open(url);
} else {
message.warn('没有主表数据!');
}
};
/* 导入未清数据 */
handleImportFormData = () => {
const { masterData, sModelsType } = this.props;
if (commonUtils.isNotEmptyObject(masterData)) {
let bFilterProValue = '';
let bFilterProName = '';
if (sModelsType === 'cashier/payment') { /* 付款单 */
const { sSupplyName, sSupplyId } = masterData;
if (commonUtils.isEmptyObject(sSupplyName)) {
message.error('供应商名称不能为空!');
return;
} else {
bFilterProName = 'sSupplyGuid_pro';
bFilterProValue = sSupplyId;
}
} else if (sModelsType === 'cashier/receipt') { /* 收款单 */
const { sCustomerName, sCustomerId } = masterData;
if (commonUtils.isEmptyObject(sCustomerName)) {
message.error('客户名称不能为空!');
return;
} else {
bFilterProName = 'sCustomerGuid_pro';
bFilterProValue = sCustomerId;
}
}
this.props.onSaveState({ importFormDataVisible: true, bFilterProName, bFilterProValue });
}
}
handleDesignFunction = () => {
this.props.onSaveState({ visibleStatement: true });
};
handleBatchPriceUpdate = () => {
const { slaveData, slaveSelectedRowKeys, app } = this.props;
if (slaveSelectedRowKeys === undefined || slaveSelectedRowKeys.length !== 1) {
return message.warning(commonFunc.showMessage(app.commonConst, 'selectedRowKeysNo'));/* 请选择一条数据进行操作 */
} else {
const batchPriceUpdateData = slaveData.filter(item => item.sId === slaveSelectedRowKeys[0]);
this.props.onSaveState({ batchPriceUpdateData, visibleBatchPriceUpdate: true });
}
};
/* 有外币时,配置BtnBatchNPriceUpdate, 会调用这个方法 */
handleBatchNPriceUpdate = () => {
const { slaveData, slaveSelectedRowKeys, app } = this.props;
if (slaveSelectedRowKeys === undefined || slaveSelectedRowKeys.length !== 1) {
return message.warning(commonFunc.showMessage(app.commonConst, 'selectedRowKeysNo'));/* 请选择一条数据进行操作 */
} else {
const batchNPriceUpdateData = slaveData.filter(item => item.sId === slaveSelectedRowKeys[0]);
this.props.onSaveState({ batchNPriceUpdateData, visibleBatchNPriceUpdate: true });
}
};
/* 解析消息 */
handleGetMsg = (str) => {
const msgArr = commonUtils.isNotEmptyObject(str) ? str.split('xpm'): '';
const divStr = [];
if(commonUtils.isNotEmptyArr(msgArr)) {
for (let i = 0; i < msgArr.length; i ++) {
divStr.push({msgArr[i]}
);
}
}
return divStr;
}
/* 导出Excel */
handleOut = async () => {
const {
slaveConfig, formRoute, masterData,
} = this.props;
/* 导出使用Post提交 */
const url = `${commonConfig.server_host}excel/export/${slaveConfig.sId}?sModelsId=${slaveConfig.sParentId}&sName=${formRoute}&token=${encodeURIComponent(this.props.app.token)}`;
const conditionValuesStr = JSON.stringify({ sId: masterData?.sId, sBillNo: masterData?.sBillNo });
this.handleOpenOut(url, '', '', undefined, conditionValuesStr);
};
/* Get提交地址栏参数过多,更改Get提交为Post提交 */
handleOpenOut = (url, bFilter, slaveOrderBy, sGroupByList, conditionValues) => {
const newWin = window.open();
let formStr = '';
// 设置样式为隐藏,打开新标签再跳转页面前,如果有可现实的表单选项,用户会看到表单内容数据
formStr = `';
newWin.document.body.innerHTML = formStr;
newWin.document.forms[0].submit();
return newWin;
}
/** 按钮操作事件 */
handleButtonClick = async (name) => {
if (name === 'BtnOut') {
this.handleOut();
} else if (name === 'BtnDesignFunction') {
this.handleDesignFunction();
} else if (name === 'BtnBatchPriceUpdate') {
this.handleBatchPriceUpdate();
} else if (name === 'BtnBatchNPriceUpdate') {
this.handleBatchNPriceUpdate();
} else if (name === 'BtnOutTemplate') {
this.handleOutTemplate();
} else if (name.startsWith('BtnOutTemplateData')) { /* 导出模版数据 */
this.handleOutTemplateData(name);
} else if (name && name.includes('BtnCalc')) { /* 实现通用计算功能 */
const { masterConfig, masterData, sModelsId, } = this.props;
this.props.onSaveState({ pageLoading:true });
const btnConfig = commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave.filter(item => (item.sControlName === name))) ?
masterConfig.gdsconfigformslave.filter(item => (item.sControlName === name))[0] : {};// sButtonEnabled sButtonParam
if(commonUtils.isNotEmptyObject(btnConfig)) {
/* 组装allTableData */
const allTableMap ={};
const allReturnMap ={};
const slaveNameList = [];
/* 从props找到 所有的Config */
if(commonUtils.isNotEmptyArr(this.props)) {
for (const key of Object.keys(this.props)) {
if(key.includes('Config') && !key.includes('onGet') && !key.includes('report')) {
const tablename = key.replace('Config', '').trim();
slaveNameList.push(tablename);
}
}
}
if (commonUtils.isNotEmptyArr(slaveNameList)) {
slaveNameList.forEach((name, index) => {
const tableConfig = this.props[name +'Config']; /* 动态配置 */
const tableData = this.props[name +'Data']; /* 动态配置 */
const tableSelectedRowKeys = this.props[name + 'SelectedRowKeys']; /* 选中Key */
if(commonUtils.isNotEmptyObject(tableConfig)) {
allTableMap[name +'.'+ tableConfig.sTbName] = tableData
}
})
const masterTbName = masterConfig.sTbName;
allTableMap['master.'+ masterTbName] = masterData;
}
const sButtonParam = btnConfig.sButtonParam;
const btn = commonUtils.isJSON(sButtonParam) ? JSON.parse(sButtonParam) : '';
const sProName = btn.sproName;
const url = `${commonConfig.server_host}calcprocedure/calc?sModelsId=${sModelsId}`;
const value = {
sProName,
sButtonParam,
allTableMap
};
const dataReturn = (await commonServices.postValueService(this.props.app.token, value, url)).data;
if (dataReturn.code === 1) {
/* 数据操作 数据回传页面 */
message.success('操作成功!');
const returnData = dataReturn.dataset.rows[0];
if (commonUtils.isNotEmptyArr(slaveNameList) && commonUtils.isNotEmptyObject(returnData)) {
slaveNameList.forEach((name, index) => {
const tableConfig = this.props[name +'Config']; /* 动态配置 */
let tableDelData = this.props[name +'DelData'];
if(commonUtils.isEmptyArr(tableDelData)) {
tableDelData = [];
}
let tableDelDataNew = []
let tableData = [];
if(commonUtils.isNotEmptyObject(tableConfig)) {
tableData = returnData[name +'.'+ tableConfig.sTbName]; /* 动态配置 */
if(commonUtils.isNotEmptyArr(tableData) && Array.isArray(tableData)) {
tableDelDataNew = tableData.filter(item => item.handleType === 'del');
tableData = tableData.filter(item => item.handleType !== 'del');
tableDelData = tableDelData.concat(tableDelDataNew);
}
}
allReturnMap[name +'Data'] = tableData;
allReturnMap[name +'DelData'] = tableDelData;
});
const masterTbName = masterConfig.sTbName;
allReturnMap.masterData = returnData['master.'+ masterTbName];
allReturnMap.masterData.enabled = true;
}
this.props.onSaveState({ ...allReturnMap, pageLoading:false });
}else if (dataReturn.code === -8 || dataReturn.code === 2) {
Modal.info({
title: '温馨提示:',
content: (
{this.handleGetMsg(dataReturn.msg)}
),
okText: '确认',
onOk() {},
});
this.props.onSaveState({ pageLoading:false });
} else { /* 失败 */
this.props.getServiceError(dataReturn);
this.props.onSaveState({ pageLoading:false });
}
}
} else if (name === 'BtnTmpInfoBySql') { /* 自定义数据源 */
this.handleBtnTmpInfoBySql(name);
} else if (name === 'BtnRefresh') {
if (this.props.app.currentPane.refresh !== undefined) {
this.props.app.currentPane.refresh();
}
const { masterConfig, slaveConfig, checkConfig } = this.props;
this.handleGetData(masterConfig, slaveConfig, checkConfig);
}
const { sModelsType } = this.props;
// 收付款分摊
if (sModelsType.includes('cashier/') || sModelsType.includes('sales/') || sModelsType.includes('purchase/')) {
if (name === 'BtnShare') {
this.handleShare();
}
if (sModelsType.includes('cashier/') && name === 'BtnImportFormData') { /* 导入未清数据 */
this.handleImportFormData(name);
}
} else if (sModelsType.includes('materialsStock/') || sModelsType.includes('productStock/')) {
if (name === 'BtnImport') {
this.props.onSaveState({ isGetDataVisible: true });
}
}
};
handleBtnTmpInfoBySql = async (btnName) => {
const { masterConfig, masterData, slaveData, slaveSelectedRowKeys, token, sModelsId} = this.props;
let slaveRow = {};
if(commonUtils.isNotEmptyArr(slaveSelectedRowKeys)) {
const iIndex = slaveData.findIndex(item => slaveSelectedRowKeys.includes(item.sId));
if(iIndex > -1) {
slaveRow = slaveData[iIndex];
}
} else {
slaveRow = slaveData[0];
}
const tableConfig = commonUtils.isNotEmptyArr(masterConfig.gdsconfigformslave.filter(item => item.sControlName === btnName)) ?
masterConfig.gdsconfigformslave.filter(item => item.sControlName === btnName)[0] : {};
const sTmpInfoConfig = tableConfig;
const sButtonParam = tableConfig.sButtonParam;
const btn = commonUtils.isNotEmptyObject(sButtonParam) ? JSON.parse(sButtonParam) : '';
if(commonUtils.isNotEmptyObject(btn)) {
const sProName = commonUtils.isNotEmptyObject(btn) ? btn.sproName : '';
const sTmpInfoBySqlBtnName = btn.sControlName;
const newCopyTo = {};
newCopyTo.master = masterData;
/* 找到自定义TempInfo配置 */
const sTmpInfoBySqlBtnConfig = masterConfig.gdsconfigformslave.filter(item => item.sControlName.includes(sTmpInfoBySqlBtnName));
const dataUrl = `${commonConfig.server_host}salesorder/getTmpInfoBySql/?sModelsId=${sModelsId}`;
const sConfigformId = commonUtils.isEmpty(sTmpInfoBySqlBtnConfig) ? '' : sTmpInfoBySqlBtnConfig[0].sParentId;
const sControlName = commonUtils.isNotEmptyObject(sTmpInfoBySqlBtnName) ? sTmpInfoBySqlBtnName : 'TmpInfoBySql';
const sAssignField = sTmpInfoBySqlBtnConfig[0].sAssignField;
const sRowData = [slaveRow];
/* 如果sqlCondition条件 不在rowData中 则添加 */
const sSqlCondition = sTmpInfoBySqlBtnConfig[0].sSqlCondition;
if(commonUtils.isNotEmptyObject(sSqlCondition)) {
let name = ''; /* 拿到条件表名 */
let conditionValues = {};
if(sSqlCondition.includes('.')) {
let newRow = {};
const name = sSqlCondition.split('.')[0];
if(name === 'master') {
newRow = masterData;
}
conditionValues = this.props.getSqlCondition(sTmpInfoBySqlBtnConfig[0], name, newRow);
if(commonUtils.isNotEmptyObject(conditionValues)) {
for (const key of Object.keys(conditionValues)) {
if(commonUtils.isNotEmptyArr(sRowData)) {
if(commonUtils.isEmptyObject(sRowData[0][key])) {
sRowData[0][key] = conditionValues[key];
}
}
}
}
}
}
const values = { sConfigformId, sControlName, sRowData };
if (true) {
const dataReturn = (await commonServices.postValueService(token, values, dataUrl)).data;
const allReturnMap = {};
if (dataReturn.code === 1) {
const returnData = dataReturn.dataset.rows[0];
if (commonUtils.isNotEmptyObject(returnData)) {
for (const key of Object.keys(returnData)) {
const sName = `${key}Data`;
const sDelName = `${key}DelData`;
// allReturnMap[sName] = returnData[key];
let { [`${key}Data`]: oldData, [`${key}Data`]: oldDelData } = this.props;
if (commonUtils.isEmptyArr(oldDelData)) {
oldDelData = [];
}
if (commonUtils.isEmptyArr(oldData)) {
oldData = [];
}
if (sTmpInfoBySqlBtnName.includes('_edit')) { /* 替换 根据对应字段对比 相同的不管 不同的插入 */
/* 对应字段 */
const sActiveKey = sTmpInfoBySqlBtnConfig[0].sActiveKey;
const keyData = returnData[key];
let newData = [];
if (commonUtils.isNotEmptyArr(keyData)) {
keyData.forEach((child) => {
const filterData = oldData.filter(item => item[sActiveKey] !== child[sActiveKey]);
if (commonUtils.isNotEmptyArr(filterData) && filterData.length === oldData.length) {
let tableRow = {};
tableRow = { ...tableRow, ...commonFunc.getAssignFieldValue(sAssignField, child) }; // 取赋值字段
tableRow.sId = commonUtils.createSid();
tableRow.sParentId = masterData.sId;
tableRow.handleType = 'add';
newData.push(tableRow);
}
});
newData = oldData.concat(newData)
}
allReturnMap[sName] = newData;
} else if (sTmpInfoBySqlBtnName.includes('_del')) { /* 替换 根据对应字段对比 相同的不管 不同的插入 */
/* 对应字段 */
oldData.forEach((child) => {
child.handleType ='del';
oldDelData.push(child);
});
allReturnMap[sDelName] = oldDelData;
oldData = [];
console.log('returnData', returnData[key]);
const keyData = returnData[key];
if (commonUtils.isNotEmptyArr(keyData)) {
keyData.forEach((child) => {
oldData.push(child);
});
}
allReturnMap[sName] = oldData;
} else {
allReturnMap[sName] = returnData[key];
}
}
if (commonUtils.isNotEmptyArr(allReturnMap.masterData) && Array.isArray(allReturnMap.masterData)) {
allReturnMap.masterData = allReturnMap.masterData[0];
}
console.log('allReturnMap:', allReturnMap);
this.props.onSaveState({ ...allReturnMap });
}
} else {
this.props.getServiceError(dataReturn);
}
}
} else {
message.error('配置错误,没有配置对应字段!');
}
}
handleBtnChoose = async (name, sControlName, chooseConfig, recordIndex, tableName) => {
const { token } = this.props;
const url = `${commonConfig.server_host}/gdsmodule/getGdsmoduleById/${chooseConfig.sActiveId}?sModelsId=${chooseConfig.sActiveId}`;
const dataReturn = (await commonServices.getService(token, url)).data;
if (dataReturn.code === 1) {
const [returnData] = dataReturn.dataset.rows;
this.props.onSaveState({
[`${name}ChooseVisible`]: true, [`${name}ChooseData`]: returnData, slaveSelectedIndex: recordIndex, tableName,
});
} else {
this.props.getServiceError(dataReturn);
}
};
handleSelect = (name, selectConfig, selectData) => {
const {
[`${name}Data`]: tableData, [`${name}Config`]: tableConfig, masterData, slaveSelectedIndex, slaveSelectedRowKeys, slaveData,
} = this.props;
if (commonUtils.isNotEmptyArr(selectData)) {
selectData.forEach((item, index) => {
const newCopyTo = {};
newCopyTo.master = masterData;
// newCopyTo.slave = item;
const newSid = commonUtils.createSid();
let tableDataRow = commonFunc.getDefaultData(tableConfig, newCopyTo, { newSid }); // 取默认值
if (name === 'slave') {
tableDataRow.sSqlConditionId = tableDataRow.sId;
}
if (name === 'slaveChild') {
/* 找到从表的sSqlConditionId */
if(commonUtils.isEmptyArr(slaveSelectedRowKeys)) {
message.error('请选择父级!');
return ;
}
let iIndex = slaveData.findIndex(item => slaveSelectedRowKeys.includes(item.sId));
if (iIndex > -1) {
tableDataRow.sSqlConditionId = slaveData[iIndex].sSqlConditionId;
}
}
tableDataRow = { ...tableDataRow, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo) }; // 取赋值字段
tableDataRow.handleType = 'add';
tableDataRow.sId = newSid;
tableDataRow.sParentId = masterData.sId;
if (name === 'slave' && selectConfig.sControlName === 'BtnChooseMaterials' && index === 0 && (commonUtils.isEmpty(tableData[slaveSelectedIndex].sProductName) || tableData[slaveSelectedIndex].sProductName === '')) {
tableData[slaveSelectedIndex] = { ...tableData[slaveSelectedIndex], ...tableDataRow };
} else {
tableData.push(tableDataRow);
}
});
}
this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}ChooseVisible`]: false });
};
handleSelectCancel = (name) => {
this.props.onSaveState({ [`${name}ChooseVisible`]: false });
};
/* 双击弹出Memo */
// handleGetMemo = (name, sValue, sMemoFiled, sRecord) => {
// const { sCurrMemoProps } = this.props;
// let { [`${name}Data`]: tableData } = this.props;
// const addStata = { [`${sMemoFiled}`]: sValue };
// if (name !== 'master') {
// const iIndex = tableData.findIndex(item => item.sId === sRecord.sId);
// let handleType = tableData[iIndex].handleType;/* 获取操作类型 */
// handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
// addStata.handleType = handleType;
// tableData[iIndex] = { ...tableData[iIndex], ...addStata };
// } else {
// let handleType = tableData.handleType;/* 获取操作类型 */
// handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
// addStata.handleType = handleType;
// tableData = { ...tableData, ...addStata };
// }
// sCurrMemoProps.bVisibleMemo = false;
// this.props.onSaveState({ ...sCurrMemoProps, [`${name}Data`]: tableData });
// };
// handleGetMemoCancel = () => {
// const { sCurrMemoProps } = this.props;
// sCurrMemoProps.bVisibleMemo = false;
// this.props.onSaveState({ ...sCurrMemoProps });
// };
// async await
handleEleMaterialsStoreCurrQty = async (slaveData) => {
const { sModelsId, app } = this.props;
let flag = true;
const InsufficientInventory = commonFunc.showMessage(app.commonConst, 'InsufficientInventory');/* 库存不足,不能领料 */
const MateriaTransferQuantityVerificationFailed = commonFunc.showMessage(app.commonConst, 'MateriaTransferQuantityVerificationFailed');/* 材料调拨数量校验失败,请稍后操作 */
const url = `${commonConfig.server_host}eleMaterialsStock/getEleMaterialsStoreCurrQty?sModelsId=${sModelsId}`;
for (const item of slaveData) {
const body = {
sMaterialsId: item.sMaterialsId, /* 查询条件 */
sMaterialsStyle: item.sMaterialsStyle,
sWareHouseId: item.sWareHouseId,
};
if (commonUtils.isNotEmptyStr(item.sLocationId)) {
body.sLocationId = item.sLocationId;
}
if (commonUtils.isNotEmptyStr(item.sWarehouseLocationId)) {
body.sWarehouseLocationId = item.sWarehouseLocationId;
}
if (commonUtils.isNotEmptyStr(item.sDefineNo)) {
body.sDefineNo = item.sDefineNo;
}
if (commonUtils.isNotEmptyStr(item.sDefineNo2)) {
body.sDefineNo2 = item.sDefineNo2;
}
const dataReturn = (await commonServices.postValueService(this.props.app.token, body, url)).data;
if (dataReturn.code === 1) {
if (commonUtils.isNotEmptyArr(dataReturn.dataset.rows)) {
const materials = dataReturn.dataset.rows[0];
if (materials.dAuxiliaryQty < item.dAuxiliaryQty) {
const sMaterialsName = commonUtils.isEmpty(item.sMaterialsName) ? item.sMaterialsName1 : item.sMaterialsName;
message.error(`[${sMaterialsName}${item.sMaterialsStyle}], ${InsufficientInventory}`);
flag = false;
break;
}
} else {
const sMaterialsName = commonUtils.isEmpty(item.sMaterialsName) ? item.sMaterialsName1 : item.sMaterialsName;
message.error(`[${sMaterialsName}${item.sMaterialsStyle}], ${InsufficientInventory}`);
flag = false;
break;
}
} else {
message.error(MateriaTransferQuantityVerificationFailed);
flag = false;
break;
}
}
return flag;
}
handleTableSelectRowChange = async (name, selectedRowKeys, changeValue) => {
if (name === 'slave' || name === 'master') {
const { token, sModelsId, [`${name}Data`]: tableData } = this.props;
if (commonUtils.isNotEmptyArr(tableData) && commonUtils.isNotEmptyArr(selectedRowKeys)) {
let url = '';
let sCustomerId = '';
if (sModelsId === '192116810113315228246447250' || sModelsId === '101251240115015952245193980') {
if (name === 'master') {
sCustomerId = changeValue.sCustomerId;
} else if (name === 'slave') {
const sCustomerIdIndex = tableData.findIndex(item => item.sId === selectedRowKeys[0]);
if (sCustomerIdIndex > -1) {
sCustomerId = tableData[sCustomerIdIndex].sCustomerId;
}
}
if (commonUtils.isNotEmptyObject(sCustomerId)) {
url = `${commonConfig.file_host_ebc}printReport/getReportByCustomerId/${sCustomerId}?sModelsId=${sModelsId}`;
const values = {};
const masterReturn = (await commonServices.postValueService(token, values, url)).data;
if (masterReturn.code === 1) {
const menuChildData = masterReturn.dataset.rows;
this.props.onSaveState({ menuChildData });
}
}
} else {
let sProcessId = '';
if (name === 'master') {
sProcessId = changeValue.sProcessClassifyId;
} else if (name === 'slave') {
const sProcessIdIndex = tableData.findIndex(item => item.sId === selectedRowKeys[0]);
if (sProcessIdIndex > -1) {
sProcessId = tableData[sProcessIdIndex].sProcessClassifyId;
}
}
if (commonUtils.isNotEmptyObject(sProcessId)) {
url = `${commonConfig.file_host_ebc}printReport/getReportByProcessId/${sProcessId}?sModelsId=${sModelsId}`;
const values = {};
const masterReturn = (await commonServices.postValueService(token, values, url)).data;
if (masterReturn.code === 1) {
const menuChildData = masterReturn.dataset.rows;
this.props.onSaveState({ menuChildData });
}
}
}
}
} else if (name === 'control') {
const { treeData, sModelsType } = this.props; /* 赋值给树组件节点 */
if (sModelsType === 'sales/salesOrderPack') {
let { treeSelectedKeys } = this.props; /* 赋值给树组件节点 */
if (treeData !== undefined) {
treeSelectedKeys = selectedRowKeys; /* 把树形选中节点赋值给表格部件选中节点 */
this.props.onSaveState({ treeSelectedKeys });
}
}
}
/* 点按钮删除时,会触发行点击事件 导致selectedRowKeys为删除行的sId */
const { [`${name}Data`]: tableData, slaveChildData, slaveChildTotal: totalData, [`slaveChildAllTotal`]: totalAllData, slaveChildConfig:tableConfig, app } = this.props;
if (Array.isArray(tableData) && tableData.length > 0 && selectedRowKeys.length) {
const iIndex = tableData.findIndex(item => item.sId === selectedRowKeys[0]);
if (iIndex === -1) {
if (commonUtils.isNotEmptyArr(tableData) && tableData.length > 0) {
selectedRowKeys = commonUtils.isNotEmptyArr(tableData) ? [tableData[0].sId] : [];
}
}
}
if (name === 'slave' && commonUtils.isNotEmptyArr(tableData) && commonUtils.isNotEmptyArr(selectedRowKeys)) {
const iSlaveIndex = tableData.findIndex(item => item.sId === selectedRowKeys[0]);
let slaveRow = {};
if(iSlaveIndex > -1) {
slaveRow = tableData[iSlaveIndex];
}
const { dNetMoney, dNetPrice } = app.decimals;
const selectedTotalData = [];
/* 根据sSqlConditonid 汇总勾选行字段 */
if (commonUtils.isNotEmptyArr(totalData) && commonUtils.isNotEmptyObject(slaveRow)) {
if (commonUtils.isNotEmptyArr(slaveChildData)) {
const tableConfigSum = tableConfig.gdsconfigformslave.filter(item => commonUtils.isNotEmptyObject(item.sName) && item.bSum && item.bVisible);
const tableFilterData = slaveChildData.filter(item => item.sSqlConditionId === slaveRow.sSqlConditionId);
if (commonUtils.isNotEmptyArr(tableConfigSum) && commonUtils.isNotEmptyArr(tableFilterData)) {
const selectedTotal = {};
selectedTotal.bSum = true;
selectedTotal.key = '0000';
tableConfigSum.forEach((itemConfig) => {
const sName = itemConfig.sName;
const dPoint = this.props.getFloatNum(sName);
if (commonUtils.isNotEmptyObject(sName)) {
tableFilterData.forEach((child) => {
if (commonUtils.isNotEmptyNumber(child[sName])) {
/* 金额、单价 保留系统设置小数位 */
if (sName.toLowerCase().endsWith('price')) { /* 价格 */
selectedTotal[sName] = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(child[sName], 0),dNetPrice) + commonUtils.convertFixNum(commonUtils.isNull(selectedTotal[sName], 0),dNetPrice),dNetPrice);
} else if (sName.toLowerCase().endsWith('money')) { /* 金额 */
selectedTotal[sName] = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(child[sName], 0),dNetMoney) + commonUtils.convertFixNum(commonUtils.isNull(selectedTotal[sName], 0),dNetMoney),dNetMoney);
} else{
selectedTotal[sName] = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(child[sName], 0), dPoint) + commonUtils.convertFixNum(commonUtils.isNull(selectedTotal[sName], 0), dPoint), dPoint);
}
}
});
}
});
if (commonUtils.isNotEmptyObject(selectedTotal)) {
selectedTotalData.push(selectedTotal);
}
}
}
}
this.props.onSaveState({ [`slaveChildTotal`]: commonUtils.isNotEmptyArr(selectedRowKeys) ? selectedTotalData : totalAllData });
}
this.props.onTableSelectRowChange(name, selectedRowKeys);
}
// 获取重量
handleGetWeight = async () => {
const { masterConfig, app } = this.props;
const url = app.rxtx.sUrl;
const returnData = (await commonServices.getService(app.token, url)).data;
if (returnData.code === 1) {
const iConfigIndex = masterConfig.gdsconfigformslave.findIndex(item => item.sControlName === 'BtnGetWeight');
const sAssignField = masterConfig.gdsconfigformslave[iConfigIndex].sAssignField;
const sAssignFieldStr = sAssignField.split(':')[0];
const sAssignFieldName = sAssignFieldStr.split('.')[0];
const sAssignFieldKey = sAssignFieldStr.split('.')[1];
const dWeight = returnData.dataset.rows[0].dWeight;
if (commonUtils.isNotEmptyObject([`${sAssignFieldName}Data`])) {
const { [`${sAssignFieldName}Data`]: tableData } = this.props;
tableData[tableData.length - 1][sAssignFieldKey] = dWeight;
this.props.onSaveState({ tableData: [`${sAssignFieldName}Data`] });
}
} else {
this.props.getServiceError(returnData);
}
}
handleViewClick = (name, sName, record, index, myConfig) => {
if (name === 'process' && sName === 'sProcessParamStr') { // process sProcessParam
const { processConfig, enabled, sModelsType } = this.props;
const slaveSelectOneData = record;
let modalVisible = false;
const sProcessParamsSelects = [];
let paramType = '';
if (commonUtils.isNotEmptyObject(slaveSelectOneData)) {
if (sModelsType.includes('manufacture/')) {
paramType = slaveSelectOneData.sWorkOrderParam;
} else if (sModelsType.includes('quotation/')) {
paramType = slaveSelectOneData.sProcessParam;
}
}
if (commonUtils.isNotEmptyObject(paramType) && enabled) {
const sProcessParam = JSON.parse(paramType);
modalVisible = true;
// eslint-disable-next-line no-plusplus
for (let i = 1; i < 7; i++) {
const iIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === `sParamValue${i.toString()}`);
if (iIndex > -1 && !commonUtils.isEmpty(sProcessParam[`sParam${i.toString()}`])) {
processConfig.gdsconfigformslave[iIndex].showName = sProcessParam[`sParam${i.toString()}`];
processConfig.gdsconfigformslave[iIndex].bVisible = !sProcessParam[`sParam${i.toString()}`].includes('参数值');
record[`sParam${i.toString()}`] = sProcessParam[`sParam${i.toString()}`];
sProcessParamsSelects.push(processConfig.gdsconfigformslave[iIndex]);
} else if (iIndex > -1) {
// processConfig.gdsconfigformslave[iIndex].showName = `sParamValue${i.toString()}`;
processConfig.gdsconfigformslave[iIndex].bVisible = true;
}
}
} else {
modalVisible = false;
// eslint-disable-next-line no-plusplus
for (let i = 1; i < 7; i++) {
const iIndex = processConfig.gdsconfigformslave.findIndex(item => item.sName === `sParamValue${i.toString()}`);
if (iIndex > -1) {
processConfig.gdsconfigformslave[iIndex].bVisible = true;
}
}
}
this.props.onSaveState({
processRecord: record,
sProcessParamsSelects,
sProcessParamsModalVisible: modalVisible,
});
} else if (sName === 'myTableConfig') {
this.handleQuickViewClick(name, sName, record, index, myConfig);
} else {
this.props.onViewClick(name, sName, record, index, myConfig);
}
};
/* 获取表格数据 */
handleGetTableConfig = async (name, sModelsId) => {
if (commonUtils.isNotEmptyObject(sModelsId)) {
const newConfig = await this.props.onGetTableConfig(name, sModelsId);
if (commonUtils.isNotEmptyObject(newConfig)) {
const newColumn = commonFunc.getHeaderConfig(newConfig);
this.props.onSaveState({ [`${[name]}Config`]: newConfig, [`${[name]}Column`]: newColumn });
}
}
}
/* 快捷键跳转 */
handleQuickViewClick = async (name, sName, record, index, myConfigArr) => {
const {
slaveData,
slaveFilterCondition,
slavePagination,
formRoute,
sModelsId,
// slaveSelectedData,
// masterData,
// employeeConfig,
} = this.props;
console.log('myConfigArr', myConfigArr);
let picArr = [];
if (commonUtils.isNotEmptyArr(myConfigArr)) {
picArr = myConfigArr;
}
if (picArr.length > 0) {
const getConfig = this.handleGetTableConfig;
const tableDataRow = record;
const iIndex = index;
const [{ sActiveId }] = picArr;
let [{ sActiveKey }] = picArr;
const sFormId = sActiveId === '1' ? commonUtils.isEmpty(tableDataRow.sFormId) ? tableDataRow.sSrcFormId : tableDataRow.sFormId : sActiveId;
if (commonUtils.isNotEmptyObject(sActiveKey) && sActiveKey.includes('.')) { /* 接口按钮跳转 如果有slave.对应字段 则需要取出对应字段 */
const index = sActiveKey.lastIndexOf('.');
sActiveKey = sActiveKey.substring(index + 1, sActiveKey.length);
}
const sNameUrl = `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sFormId}?sModelsId=${sFormId}&sName=${formRoute}`;
const filterCondition = [];
const conditionValues = this.props.getSqlCondition(picArr[0], name, tableDataRow);
if (!commonUtils.isEmpty(conditionValues)) {
Object.keys(conditionValues).forEach((item) => {
if ((item === 'tStartDate_pro' || item.substring(0, 1) === 'p')) {
if (!commonUtils.isEmpty(conditionValues[item]) && conditionValues[item].length >= 2) {
const tStartDate = moment(conditionValues[item][0]).format(this.sDateFormat);
const tEndDate = moment(conditionValues[item][1]).add(1, 'days').format(this.sDateFormat);
filterCondition.push({
bFilterName: item,
bFilterCondition: '=',
bFilterValue: `${tStartDate},${tEndDate}`,
});
}
} else if ((item === 'mStartDate_pro' || item.substring(0, 1) === 'm')) {
if (!commonUtils.isEmpty(conditionValues[item])) {
const tStartDate = moment(conditionValues[item]).startOf('month').format(this.sDateFormat);
const tEndDate = moment(conditionValues[item]).endOf('month').add(1, 'days').format(this.sDateFormat);
filterCondition.push({
bFilterName: `t${item.substring(1, item.length)}`,
bFilterCondition: '=',
bFilterValue: `${tStartDate},${tEndDate}`,
});
}
} else if (item.substring(0, 1) === 't') {
filterCondition.push({
bFilterName: item,
bFilterCondition: '=',
bFilterValue: moment(conditionValues[item]).format(this.sDateFormat),
});
} else {
filterCondition.push({
bFilterName: item,
bFilterCondition: '=',
bFilterValue: conditionValues[item],
});
}
});
}
this.props.dispatch({
type: 'content/onRouter',
payload: {
url: sNameUrl,
refresh: getConfig.bind(this, name, sModelsId), /* 刷新方法 */
sTabId: commonUtils.createSid(),
// sParentId: this.state.sTabId,
urlDataType: 'newPane',
checkedId: myConfigArr[0].sId,
sName: myConfigArr[0].sName,
bFilter: slaveFilterCondition,
pageSize: commonConfig.pageSize,
pages: slavePagination,
currentData: [tableDataRow],
conditonValues: conditionValues,
newKey: tableDataRow[sActiveKey],
currentIndex: iIndex,
filterCondition,
sSrcModelsId: this.props.sModelsId,
},
});
}
};
/* 选择基础颜色 */
handleSelectSisColor = async (name, selectConfig, selectData) => {
const { enabled, processData, processSelectedRowId } = this.props;
if (enabled) {
let sColorSerialMemoStr = '';
const jsonData = [];
if (commonUtils.isNotEmptyArr(selectData)) {
selectData.forEach((item) => {
const {
sId, sName, dColor, CreateDate, sMakePerson,
} = item;
const jsonObj = {};
jsonObj.sId = sId;
jsonObj.sName = sName; /* 名称 */
jsonObj.dColor = dColor; /* 色序 */
jsonObj.CreateDate = CreateDate;
jsonObj.sMakePerson = sMakePerson;
sColorSerialMemoStr += `${sName}-${dColor},`;
jsonData.push(jsonObj);
});
if (commonUtils.isNotEmptyObject(sColorSerialMemoStr)) {
sColorSerialMemoStr = commonUtils.isNotEmptyArr(jsonData) ? JSON.stringify(jsonData) : ''; /* JSON对象转换为字符串存放到合版信息中 */
}
}
const iIndex = processData.findIndex(item => item.sId === processSelectedRowId);
if (iIndex > -1) {
const addState = {};
let { handleType } = processData[iIndex];
handleType = commonUtils.isEmpty(handleType) ? 'update' : handleType;
addState.handleType = handleType;
addState.sColorSerialMemo = sColorSerialMemoStr;
processData[iIndex] = { ...processData[iIndex], ...addState };
}
}
this.props.onSaveState({
sisColorChooseVisible: false,
});
}
handleViewChoose= (name, sName, record) => {
const { sId } = record; /* 控制表主键 */
const { enabled } = this.props;
const sisColorSelectedRowKeys = [];
let jsonData = [];
if (name === 'process' && sName === 'sColorSerialMemo') {
const { [`${name}Data`]: tableData } = this.props;
const iIndex = tableData.findIndex(item => item.sId === sId);
if (iIndex > -1) {
const sColorSerialMemo = tableData[iIndex].sColorSerialMemo;
if (commonUtils.isNotEmptyObject(sColorSerialMemo)) {
try {
jsonData = JSON.parse(sColorSerialMemo);
jsonData.forEach((item) => {
sisColorSelectedRowKeys.push(item.sId);
});
} catch (ex) {
console.log('ex', ex);
}
}
}
this.props.onSaveState({
sisColorChooseVisible: true,
processSelectedRowId: sId, /* 工序表选中行sId */
enabled,
sisColorSelectedRowKeys,
sisColorSelectedData: jsonData,
});
}
}
handleCancelModal = (modelVisible) => {
this.props.onSaveState({
[modelVisible]: false,
});
}
/* 根据上机长、上机宽,材料长,材料宽 计算自动排版数 */
handleResolveMachineComposing = (productLength, productWidth, maxMachineLength, maxMachineWidth) => {
let result1 = {};
const productLengthTemp = commonUtils.convertStrToNumber(commonUtils.isNull(productLength, 0)); /* 产品长 */
const productWidthTemp = commonUtils.convertStrToNumber(commonUtils.isNull(productWidth, 0)); /* 产品宽 */
const maxMachineLengthTemp = commonUtils.convertStrToNumber(commonUtils.isNull(maxMachineLength, 0)); /* 材料长 */
const maxMachineWidthTemp = commonUtils.convertStrToNumber(commonUtils.isNull(maxMachineWidth, 0)); /* 材料宽 */
if (isNaN(productLengthTemp) || productLengthTemp === 0 || isNaN(productWidthTemp) || productWidthTemp === 0 || isNaN(maxMachineLengthTemp) || maxMachineLengthTemp === 0 || isNaN(maxMachineWidthTemp) || maxMachineWidthTemp === 0) {
return result1;
}
const vh = this.handleDescVerticalComposing(productLength, productWidth, maxMachineLength, maxMachineWidth);
const hv = this.handleDescHorizonalComposing(productLength, productWidth, maxMachineLength, maxMachineWidth);
const totalNumVH = vh.totalNum;
const totalNumHV = hv.totalNum;
if (totalNumVH === totalNumHV) {
if (vh.remaining === 0) {
result1 = vh;
} else {
result1 = hv;
}
} else if (totalNumVH > totalNumHV) {
result1 = vh;
} else {
result1 = hv;
}
return result1;
};
handleDescHorizonalComposing = (productLength, productWidth, maxMachineLength, maxMachineWidth) => {
let horizonalWWNum = 0;
let horizonalLWNum = 0;
let verticalLLNum = 0;
let verticalLWNum = 0;
let totalNum = 0;// 总的排列数目
let totalLength = 0;// 上机长,即最大排列占据的长度
let totalWidth = 0;// 上机宽,即最大排列占据的宽度
let mLength = 0;
let mWidth = 0;
let horizonalRemaining = 0;
// let fTempmarginW = 0;
// let fTempmarginL = 0;
// const mTemp = 0;
const dmargin = 0;
const result1 = {};
if (maxMachineLength > maxMachineWidth || maxMachineLength === maxMachineWidth) {
mLength = maxMachineLength;
} else {
mLength = maxMachineWidth;
}
if (maxMachineLength < maxMachineWidth || maxMachineLength === maxMachineWidth) {
mWidth = maxMachineLength;
} else {
mWidth = maxMachineWidth;
}
maxMachineLength = mLength;
maxMachineWidth = mWidth;
// 按机器优先横排--竖向横排数量,即上述竖向横排一共排几行
verticalLLNum = Math.floor(maxMachineLength / this.handleZeroToOne(productWidth + commonUtils.convertFixNum(dmargin, 2)));
// 按机器优先横排--横向横排数量,即横向排列的时候,一行最多能排几个
verticalLWNum = Math.floor(maxMachineWidth / this.handleZeroToOne(productLength + commonUtils.convertFixNum(dmargin, 2)));
totalNum += verticalLLNum * verticalLWNum;
// 画册类,不能混排,而且只能是偶数,如果是奇数,则首选在长方向去掉一列,
horizonalRemaining = 0;
// fTempmarginW = 0;// 宽方向 需减少的出血
// fTempmarginL = 0;// 长方向 需减少的出血
horizonalWWNum = 0;
horizonalLWNum = 0;
if (totalNum > 0) {
// 上述横排完成之后,剩余的右边宽度,用于竖向排列
horizonalRemaining = maxMachineWidth - (verticalLWNum * (productLength + commonUtils.convertFixNum(dmargin, 2)));
// 按机器优先长排--竖向横排一行能排的数量,即排完竖向之后,剩余的排横向的,看一行能排多少个
// / 剩余空间 横向 排数量
horizonalWWNum = Math.floor(horizonalRemaining / (productWidth + commonUtils.convertFixNum(dmargin, 2)));
// 剩余空间 竖向 排数量
horizonalLWNum = Math.floor(maxMachineLength / (productLength + commonUtils.convertFixNum(dmargin, 2)));
}
if (horizonalWWNum * horizonalLWNum === 0) {
// 不是混排的情况
totalLength = verticalLLNum * (productWidth + commonUtils.convertFixNum(dmargin, 2));
totalWidth = verticalLWNum * (productLength + commonUtils.convertFixNum(dmargin, 2));
} else {
totalNum += horizonalWWNum * horizonalLWNum;
// 有可能是左边横向排列占用的长度更长,也有可能是剩余右侧的竖向排列方式占用的长度更长,最终更长的那个作为上机尺寸
if (verticalLLNum * (productWidth + dmargin) > horizonalLWNum * (productLength + commonUtils.convertFixNum(dmargin, 2))) {
totalLength = verticalLLNum * (productWidth + dmargin);
} else {
totalLength = horizonalLWNum * (productLength + dmargin);
}
// 最终宽度是所有左侧横向排列占据的宽度以及右侧剩余空间竖向排列占据的宽度之和
totalWidth = (verticalLWNum * (productLength + dmargin)) + (horizonalWWNum * (productWidth + commonUtils.convertFixNum(dmargin, 2)));
}
result1.remaining = horizonalLWNum * horizonalWWNum;
result1.iLengthComposing = verticalLLNum;
result1.iWidthComposing = verticalLWNum;
result1.sMethod = `W#${commonUtils.convertNumberToStr(verticalLLNum)}*${commonUtils.convertNumberToStr(verticalLWNum)}+L#${commonUtils.convertNumberToStr(horizonalWWNum)}*${commonUtils.convertNumberToStr(horizonalLWNum)}`;
result1.sMaterialMethod = `W#${commonUtils.convertNumberToStr(verticalLLNum)}*${commonUtils.convertNumberToStr(verticalLWNum)}+L#${commonUtils.convertNumberToStr(horizonalWWNum)}*${commonUtils.convertNumberToStr(horizonalLWNum)}`;
// 最终要保存排列之后的长和宽,按机器排的时候获取的是上机尺寸;按材料排的时候,就是最优材料排版
if (totalLength > totalWidth) {
result1.totalLength = totalLength;
result1.totalWidth = totalWidth;
} else {
result1.totalLength = totalWidth;
result1.totalWidth = totalLength;
}
// 最终保存最大数目,以便比较最优排版数
result1.totalNum = totalNum;
return result1;
};
handleDescVerticalComposing = (productLength, productWidth, maxMachineLength, maxMachineWidth) => {
let horizonalWWNum = 0;
let horizonalLWNum = 0;
let verticalLLNum = 0;
let verticalLWNum = 0;
let mLength = 0;
let mWidth = 0;
let verticalRemaining = 0;
// eslint-disable-next-line no-unused-vars
let fTempmarginW = 0;
// eslint-disable-next-line no-unused-vars
let fTempmarginL = 0;
const result1 = {};
// eslint-disable-next-line no-unused-vars
const TYHLLookupList = 0;
const dmargin = 0;
let totalNum = 0;// 总的排列数目
let totalLength = 0;// 上机长,即最大排列占据的长度
let totalWidth = 0; // 上机宽,即最大排列占据的宽度
if (maxMachineLength >= maxMachineWidth) {
mLength = maxMachineLength;
} else {
mLength = maxMachineWidth;
}
if (maxMachineLength <= maxMachineWidth) {
mWidth = maxMachineLength;
} else {
mWidth = maxMachineWidth;
}
maxMachineLength = mLength;
maxMachineWidth = mWidth;
// 画册类,不能混排,而且只能是偶数,如果是奇数,则首选在长方向去掉一列,
verticalRemaining = 0;
fTempmarginW = 0;// 宽方向 需减少的出血
fTempmarginL = 0;// 长方向 需减少的出血
horizonalWWNum = 0;
horizonalLWNum = 0;
// 按机器优先长排--竖排竖方向排多少个
verticalLLNum = Math.floor(maxMachineLength / this.handleZeroToOne(commonUtils.convertFixNum(productLength, 2) + commonUtils.convertFixNum(dmargin, 2)));
// 竖排横方向排多少个
verticalLWNum = Math.floor(maxMachineWidth / this.handleZeroToOne(commonUtils.convertFixNum(productWidth, 2) + commonUtils.convertFixNum(dmargin, 2)));
totalNum += verticalLLNum * verticalLWNum;
if (totalNum > 0) {
// 上述竖排完成之后,剩余的长度
verticalRemaining = maxMachineLength - (verticalLLNum * (commonUtils.convertFixNum(productLength, 2) + commonUtils.convertFixNum(dmargin, 2)));
// 剩余下面 竖向 排数量
horizonalLWNum = Math.floor(verticalRemaining / this.handleZeroToOne(productWidth + commonUtils.convertFixNum(dmargin, 2)));
// 剩余下面 横向 排数量
horizonalWWNum = Math.floor(maxMachineWidth / this.handleZeroToOne(productLength + commonUtils.convertFixNum(dmargin, 2)));
}
if (horizonalWWNum * horizonalLWNum === 0) {
totalLength = verticalLLNum * (productLength + commonUtils.convertFixNum(dmargin, 2));
totalWidth = verticalLWNum * (productWidth + commonUtils.convertFixNum(dmargin, 2));
} else {
totalNum += horizonalLWNum * horizonalWWNum;
totalLength = (verticalLLNum * (productLength + commonUtils.convertFixNum(dmargin, 2))) + ((productWidth + commonUtils.convertFixNum(dmargin, 2)) * horizonalLWNum);
// 最终宽度是所有左侧横向排列占据的宽度以及右侧剩余空间竖向排列占据的宽度之和
if (verticalLWNum * (productWidth + dmargin) > horizonalWWNum * (productLength + commonUtils.convertFixNum(dmargin, 2))) {
totalWidth = verticalLWNum * (productWidth + commonUtils.convertFixNum(dmargin, 2));
} else {
totalWidth = horizonalWWNum * (productLength + commonUtils.convertFixNum(dmargin, 2));
}
}
result1.remaining = horizonalLWNum * horizonalWWNum;
result1.iLengthComposing = verticalLLNum;
result1.iWidthComposing = verticalLWNum;
result1.sMethod = `L#${commonUtils.convertNumberToStr(verticalLLNum)}*${commonUtils.convertNumberToStr(verticalLWNum)}+W#${commonUtils.convertNumberToStr(horizonalLWNum)}*${commonUtils.convertNumberToStr(horizonalWWNum)}`;
result1.sMaterialMethod = `L#${commonUtils.convertNumberToStr(verticalLLNum)}*${commonUtils.convertNumberToStr(verticalLWNum)}+W#${commonUtils.convertNumberToStr(horizonalWWNum)}*${commonUtils.convertNumberToStr(horizonalLWNum)}`;
// 最终要保存排列之后的长和宽,按机器排的时候获取的是上机尺寸;按材料排的时候,就是最优材料排版
if (totalLength > totalWidth) {
result1.totalLength = totalLength;
result1.totalWidth = totalWidth;
} else {
result1.totalLength = totalWidth;
result1.totalWidth = totalLength;
}
// 最终保存最大数目,以便比较最优排版数
result1.totalNum = Math.floor(totalNum);
return result1;
};
handleZeroToOne = (num) => {
if (commonUtils.isEmptyNumber(num) && num === 0) {
num = 1;
}
return num;
};
/* 单据字段单击右键全部更新,弹出窗选择后,更新此列所有数据。(只更新非只读字段) */
handleContextMenuOk= async (contextMenuValue, contextMenuData, contextMenuType) => {
const {
contextMenuConfig, contextMenuTbName, [`${contextMenuTbName}Data`]: tableData, [`${contextMenuTbName}SelectedRowKeys`]: selectedRowKeys,
} = this.props;
if (commonUtils.isNotEmptyObject(contextMenuTbName) && commonUtils.isNotEmptyArr(tableData)) {
if (commonUtils.isNotEmptyArr(contextMenuConfig) && commonUtils.isNotEmptyObject(contextMenuConfig[0])) {
const tableConfig = contextMenuConfig[0];
const tableFilterData = tableData.filter(item => selectedRowKeys.includes(item.sId));
if (commonUtils.isNotEmptyArr(tableFilterData)) {
let changeData = [];
const chooseType = commonUtils.isNotEmptyNumber(contextMenuType) ? contextMenuType : 1;
if(chooseType === 1) {
changeData = tableData;
} else if(chooseType === 2) {
const iIndex = tableData.findIndex(item => selectedRowKeys.includes(item.sId));
changeData = tableData.filter((_, index) => index >= iIndex);
}
// const tableDataRow = tableFilterData[0];
if (commonUtils.isNotEmptyArr(changeData) && commonUtils.isNotEmptyObject(tableConfig.sName) && !commonUtils.isEmpty(contextMenuValue)) {
const sName = tableConfig.sName;
for (let i = 0; i < changeData.length; i++) {
const child = changeData[i];
const addState = {};
addState[sName] = contextMenuValue;
const iIndex = tableData.findIndex(row => row.sId === child.sId);
const bShowProcess = [
'sMaterialsNo',
'sMaterialsName',
'dAuxiliaryQty',
'dReelAuxiliaryQty',
'dConversionQty',
'sMaterialsStyle',
'sMaterialsStyle',
'dMaterialsQty',
'dAuxiliaryLossQty',
'dLossQty',
'sProcessId',
'sProcessNo',
'sProcessName'
].includes(sName);
bShowProcess && message.loading({ content: , key: "xlyProcess", duration: 0, className: styles.xlyProcess});
if(iIndex > -1) {
addState.handleType = commonUtils.isEmpty(tableData[iIndex].handleType) ? 'update' : tableData[iIndex].handleType;
tableData[iIndex] = { ...tableData[iIndex], ...addState, ...contextMenuData };
const changeValue = { ...contextMenuData };
changeValue[sName] = contextMenuValue;
this.xlyProcessPercent = ((i + 1) / changeData.length * 100).toFixed(2);
const duration = i === changeData.length - 1 ? 1 : 0;
bShowProcess && message.loading({ content: , key: "xlyProcess", duration, className: styles.xlyProcess});
/* 手动触发改变事件 */
const result = await this.handleTableChange(contextMenuTbName, sName, changeValue, child.sId, [], true);
tableData[iIndex] = { ...tableData[iIndex], ...result };
}
}
}
}
}
}
this.props.onSaveState({
[`${contextMenuTbName}Data`]: tableData,
contextMenuModalVisible: false, /* 右击全部更新弹窗 */
});
}
/* 工单、工艺卡、报价单上移下移排序 */
orderNum = (tableData, controlSelectedRowKeys) => {
/* 部件工序排序 */
const tableFilterData = tableData.filter(item => controlSelectedRowKeys.includes(item.sControlId));
if (commonUtils.isNotEmptyArr(tableFilterData)) {
tableFilterData.forEach((item, index) => {
item.iOrder = index + 1;
item.handleType = commonUtils.isEmpty(item.handleType) ? 'update' : item.handleType;
const index1 = tableData.findIndex(item1 => item1.sId === item.sId);
if (index1 > -1) {
tableData[index1] = { ...tableData[index1], ...item };
}
});
}
/* 成品工序 */
const tableFilterCPData = tableData.filter(item => item.sType === '3');
if (commonUtils.isNotEmptyArr(tableFilterCPData)) {
let num = 1001;
tableFilterCPData.forEach((item) => {
item.iOrder = num;
item.handleType = commonUtils.isEmpty(item.handleType) ? 'update' : item.handleType;
const index1 = tableData.findIndex(item1 => item1.sId === item.sId);
num += 1;
if (index1 > -1) {
tableData[index1] = { ...tableData[index1], ...item };
}
});
}
return tableData;
};
/* 送货单个性化弹窗 选择数据带到从表字表 */
handleSelectCommonPopup = async (currentPaneName, selectConfig, selectData, tbName) => {
const {
[`${tbName}SelectedRowKeys`]: tableSelectedRowKeys, masterData, sModelsId, sModelsType, slaveSelectedRowKeys, slaveData,
} = this.props;
let { slaveChildData, [`${tbName}Data`]: tableData, app, token } = this.props;
const iIndex = commonUtils.isNotEmptyArr(tableSelectedRowKeys) ? tableData.findIndex(item => item.sId === tableSelectedRowKeys[0]) : -1;
let dProductQty = 0;
if (selectConfig && (selectConfig.sControlName.includes('BtnPopup1Deliver') || selectConfig?.sControlName.includes('Sub'))) {
if (commonUtils.isNotEmptyArr(selectData)) {
// eslint-disable-next-line no-unused-vars
selectData.forEach(async (item, index) => {
if (commonUtils.isEmpty(slaveChildData)) {
slaveChildData = [];
}
const newCopyTo = {};
newCopyTo.master = masterData;
if (iIndex > -1) {
newCopyTo.slaveChild = item;
}
/* 库存数量叠加到从表的送货数量中 */
// dProductQty += commonUtils.isNull(item.dProductQty, 0); /* 赠送数量叠加 */
let tableDataRowAdd = this.handleTableAdd('slaveChild', true);
item.handleType = 'add';
tableDataRowAdd = { ...tableDataRowAdd, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo) }; // 取赋值字段
tableDataRowAdd.sId = commonUtils.createSid();
tableDataRowAdd.sParentId = masterData.sId;
tableDataRowAdd.sParentSlaveId = tableData[iIndex].sId; /* 选中从表的sId */
tableDataRowAdd.sSqlConditionId = tableData[iIndex].sSqlConditionId; /* 选中从表的sId */
slaveChildData.push(tableDataRowAdd);
});
let slaveChildFilterData = commonUtils.isNotEmptyArr(slaveChildData) ? slaveChildData.filter(item => item.sSqlConditionId === tableData[iIndex].sSqlConditionId ) : [];
if(commonUtils.isNotEmptyArr(slaveChildFilterData)) {
slaveChildFilterData.forEach( (item, index) => {
if(sModelsType && sModelsType.includes('purchase/purchaseInstore') && commonUtils.isNotEmptyNumber(item.dAuxiliaryQty) && commonUtils.isEmptyNumber(item.dProductQty)) {
dProductQty += commonUtils.isNull(item.dAuxiliaryQty, 0);
} else {
dProductQty += commonUtils.isNull(item.dProductQty, 0);
}
})
}
if (commonUtils.isNotEmptyNumber(dProductQty) && dProductQty !== 0) {
const addState = {};
addState.dProductQty = dProductQty;
if(sModelsType && sModelsType.includes('outside/')) {
tableData[iIndex].dAuxiliaryQty = dProductQty;
tableData[iIndex] = await this.handleMaterialsChange(tableData[iIndex], sModelsId, masterData, {}, 'dAuxiliaryQty', app, token, 'Materials');
}
addState.handleType = commonUtils.isEmpty(tableData[iIndex].handleType) ? 'update' : tableData[iIndex].handleType;
tableData[iIndex] = { ...tableData[iIndex], ...addState };
}
if(sModelsType && sModelsType.includes('purchase/purchaseInstore')) {
this.props.onSaveState({[`${tbName}Data`]: tableData, slaveChildData}, () => {
const params = {
sFieldName: 'dAuxiliaryQty',
tableDataRow: commonUtils.isNotEmptyArr(slaveChildData) ? slaveChildData[0] : {},
}
// 汇总到从表方法
this.handleWriteBack(params);
})
} else {
this.props.onSaveState({ [`${tbName}Data`]: tableData, slaveChildData });
}
}
} else if(tbName === 'slaveChild') {
if (commonUtils.isNotEmptyArr(selectData)) {
selectData.forEach((item, index) => {
const sName = selectConfig.sKeyUpFilter; /* 将后台配置筛选字段作为 列字段 */
const newCopyTo = {};
newCopyTo.master = masterData;
let sValue = '';
if (iIndex > -1) {
newCopyTo.slaveChild = item;
sValue = tableData[iIndex][sName];
}
/* 第一条数据若字段值为空或者只有一条数据时 则添加到该行 否则新增一行 */
let tableDataRow = {}; // 取默认值
if (tbName === 'slaveChild') {
/* 找到从表的sSqlConditionId */
if(commonUtils.isEmptyArr(slaveSelectedRowKeys)) {
message.error('请选择父级!');
return ;
}
let iIndex = slaveData.findIndex(item => slaveSelectedRowKeys.includes(item.sId));
if (iIndex > -1) {
tableDataRow.sSqlConditionId = slaveData[iIndex].sSqlConditionId;
}
}
if (selectData.length === 1 || (index === 0 && commonUtils.isEmptyObject(sValue))) {
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;
}
} else {
let tableDataRowAdd = this.handleTableAdd(tbName, true);
tableDataRowAdd = {...tableDataRowAdd, ...commonFunc.getAssignFieldValue(selectConfig.sAssignField, item, newCopyTo)}; // 取赋值字段
tableDataRow = tableDataRowAdd;
tableData.push(tableDataRowAdd);
}
this.props.onSaveState({ [`${tbName}Data`]: tableData},() => {
const params = {
sFieldName: 'dAuxiliaryQty',
tableDataRow,
}
// 汇总到从表方法
this.handleWriteBack(params);
});
});
}
} else {
this.props.onSelectCommonPopup(currentPaneName, selectConfig, selectData, tbName);
}
};
render() {
const { masterData, sModelsType, app } = this.props;
const imgSrc = commonBusiness.handleAddIcon(masterData, sModelsType, app);
return (
);
}
};
};