diff --git a/src/mobile/common/CommobileBase.js b/src/mobile/common/CommobileBase.js index d1a55f1..394ca67 100644 --- a/src/mobile/common/CommobileBase.js +++ b/src/mobile/common/CommobileBase.js @@ -12,6 +12,7 @@ import * as commonUtils from '../../utils/utils'; import * as commonServices from '../../services/services'; import * as commonFunc from '../../components/Common/commonFunc'; import * as commonBusiness from '../../components/Common/commonBusiness'; +import { message } from "@/utils/common/message"; // import * as commonFunc from './commonFunc'; /* 通用单据方法 */ export default (ChildComponent) => { @@ -718,6 +719,258 @@ export default (ChildComponent) => { }; } + /* 下拉多选离开事件 */ + handleTableBlur = async (name, sFileName, record, tableConfig, other) => { + const { sModelsId, app } = this.props; + console.log('handleTableBlur',name, sFileName, record, tableConfig,); + const { controlData, slaveConfig,[`${name}Data`]: tableData , [`${name}Config`]: tempConfig } = this.state; + let { slaveData: slaveDataOld, masterData, slaveDelData, } = this.state; + const addState = {}; + if(commonUtils.isEmptyArr(slaveDelData)) { + slaveDelData = []; + } + if (sFileName === 'sPartsNameNew') { + if(commonUtils.isNotEmptyArr(controlData)) { + /* 离开时 把sPartsNameNewId数据挂载到sControlParentId */ + let iIndex = controlData.findIndex(item => item.sId === record.sId); + if(iIndex === -1) { + if(record.sId && record.sId.split('-').length > 1) { + iIndex = controlData.findIndex(item => item.sId === record.sId.split('-')[0]); + } + } + if (iIndex > -1) { + addState.sControlParentId = controlData[iIndex].sPartsNameNewId; + if(commonUtils.isNotEmptyObject(controlData[iIndex].sPartsNameNewId)) { + controlData[iIndex] = {...controlData[iIndex], ...addState}; + this.props.onSaveState({ controlData: controlData }); + } + } + } + } else if (tableConfig.sDropDownType === 'movesql') { /* 通用字段离开调下拉事件 */ + let slaveRow = record; + const sqlDropDownData = await this.getSqlDropDownData(sModelsId, name, tableConfig, slaveRow); + const dDropDownData = sqlDropDownData.dropDownData; + const iIndex = tableData.findIndex(item => item.sId === record.sId); + if (commonUtils.isNotEmptyArr(dDropDownData) && iIndex > -1) { + slaveRow = { ...slaveRow, ...commonFunc.getAssignFieldValue(tableConfig.sAssignField, dDropDownData[0]) }; // 取赋值字段 + slaveRow.handleType = commonUtils.isEmpty(slaveRow.handleType) ? 'update' : slaveRow.handleType; + const sButtonParam = tableConfig.sButtonParam; /* 设置多级联动 */ + if(commonUtils.isNotEmptyObject(sButtonParam)) { + let sLinkFieldName = 'dMaterialsPrice'; + if (commonUtils.isJSON(sButtonParam)) { /* 按钮条件 */ + const linkObj = JSON.parse(sButtonParam); /* 联动配置 */ + let models = 'Materials'; + if (linkObj.linkMaterials) { + sLinkFieldName = linkObj.linkMaterials; + models = 'Materials'; + } else if (linkObj.linkProduct) { + sLinkFieldName = linkObj.linkProduct; + models = 'Product'; + } + slaveRow = commonBusiness.getCalculateAllMoney(app, models, sLinkFieldName, masterData, slaveRow); + } + } + + tableData[iIndex] = { ...tableData[iIndex] , ...slaveRow }; + this.setState({ ...addState }); + } + } else if(commonUtils.isNotEmptyObject(tableConfig) && commonUtils.isNotEmptyObject(tableConfig.sButtonParam)) { + let slaveNewData = []; + const allConfig = { slaveConfig }; + // console.log('sTmpInfoConfigArr', sTmpInfoConfigArr); + const sTmpInfoConfig = tableConfig; + const sButtonParam = tableConfig.sButtonParam; + const btn = commonUtils.isNotEmptyObject(sButtonParam) && commonUtils.isJSON(sButtonParam)? JSON.parse(sButtonParam) : {};; + const sProName = commonUtils.isNotEmptyObject(btn) ? btn.sproName : ''; + const sTmpInfoBySqlBtnName = commonUtils.isNotEmptyObject(btn) ? btn.sControlName : ''; + const sActiveKey = sTmpInfoConfig.sActiveKey; + if (commonUtils.isNotEmptyObject(sTmpInfoConfig)) { + if (commonUtils.isEmptyObject(sTmpInfoBySqlBtnName)) { + const newCopyTo = {}; + newCopyTo.master = masterData; + // newCopyTo.slave = commonUtils.isEmpty(slaveData) ? [] : slaveData[0]; + // const sRowData = copyTo.slaveData; + const sRowData = masterData; + const value = { sProName, sProInParam: JSON.stringify({ params: sRowData }) }; + if (other?.iFlag === 1) { + value.iFlag = 1; + } + const url = `${commonConfig.server_host}procedureCall/doGenericProcedureCall?sModelsId=${sModelsId}`; + const dataReturn = (await commonServices.postValueService(app.token, value, url)).data; + if (dataReturn.code === 1) { + if (commonUtils.isNotEmptyArr(slaveDataOld)) { + slaveDataOld.forEach((item) => { + item.handleType = 'del'; + slaveDelData.push(item); + }); + addState.slaveDelData = slaveDelData; + } + const returnData = dataReturn.dataset.rows[0]; + const slaveReturn = returnData.dataSet.proData; + if (commonUtils.isNotEmptyArr(slaveReturn)) { + slaveReturn.forEach((slaveItem) => { + newCopyTo.slave = slaveItem; + let slaveRow = commonFunc.getDefaultData(allConfig.slaveConfig, newCopyTo); // 取默认值 + // if (salveDetailAssignField) { + // slaveRow = {...slaveRow, ...commonFunc.getAssignFieldValue(salveDetailAssignField, copyTo.masterData, newCopyTo)}; + // } else if (salveAssignField) { + // slaveRow = {...slaveRow, ...commonFunc.getAssignFieldValue(salveAssignField, slaveItem, newCopyTo)}; // 取赋值字段 + // } + slaveRow = { ...slaveRow, ...slaveItem }; + slaveRow.handleType = 'add'; + slaveRow.sId = commonUtils.createSid(); + slaveRow.sParentId = masterData.sId; + slaveNewData.push(slaveRow); + }); + } + addState.slaveData = slaveNewData; + this.setState({ ...addState }); + } else { + this.getServiceError({ ...dataReturn, fn: () => this.handleTableBlur(name, sFileName, record, tableConfig, { iFlag: 1 }) }); + } + } else if(sTmpInfoBySqlBtnName.includes('sTmpInfoBySql')) { /* 走TmpInfo逻辑 */ + const newCopyTo = {}; + newCopyTo.master = masterData; + /* 找到自定义TempInfo配置 */ + const btnConfig = tempConfig.gdsconfigformslave.filter(item => item.sControlName.includes(sTmpInfoBySqlBtnName)) || []; + console.log('btnConfig', btnConfig, sTmpInfoBySqlBtnName); + const dataUrl = `${commonConfig.server_host}salesorder/getTmpInfoBySql/?sModelsId=${sModelsId}`; + const sConfigformId = commonUtils.isEmpty(btnConfig) ? '' : btnConfig[0].sParentId; + const sControlName = commonUtils.isNotEmptyObject(sTmpInfoBySqlBtnName) ? sTmpInfoBySqlBtnName : 'TmpInfoBySql'; + const sAssignField = btnConfig[0].sAssignField; + const sActiveKeyNew = btnConfig[0].sActiveKey; + let sRowData = [record]; + if (name === 'master' && sTmpInfoBySqlBtnName.includes('_update')) { + const { slaveData } = this.state; + if (commonUtils.isNotEmptyArr(slaveData)) { + sRowData = [...sRowData, ...slaveData]; + } + } + const values = { sConfigformId, sControlName, sRowData }; + if (true){ + const dataReturn = (await commonServices.postValueService(app.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.state; + if(commonUtils.isEmptyArr(oldDelData)) { + oldDelData = []; + } + if(commonUtils.isEmptyArr(oldData)) { + oldData = []; + } + if(sTmpInfoBySqlBtnName.includes('_edit')) { /* 替换 根据对应字段对比 相同的不管 不同的插入 */ + /* 对应字段 */ + const sActiveKey = sTmpInfoConfig.sActiveKey; + const keyData = returnData[key]; + let newData = []; + if(commonUtils.isNotEmptyArr(keyData)) { + keyData.forEach((child) => { + const filterData = oldData.filter(item => item[sActiveKeyNew] !== child[sActiveKeyNew]); + if(commonUtils.isNotEmptyArr(filterData) && filterData.length === oldData.length) { + const tableRow = { ...child, ...commonFunc.getAssignFieldValue(sAssignField, child) }; // 取赋值字段111 + tableRow.sId = commonUtils.createSid(); + tableRow.sParentId = masterData.sId; + tableRow.handleType = 'add'; + newData.push(tableRow); + } else { /* 相同的根据赋值字段覆盖 */ + const iIndex = oldData.findIndex(item => item[sActiveKeyNew] === child[sActiveKeyNew]); + if(iIndex > -1) { + if(sAssignField) { + oldData[iIndex] ={...oldData[iIndex], ...commonFunc.getAssignFieldValue(sAssignField, child) }; + } else { + oldData[iIndex] ={...oldData[iIndex], ...child }; + } + oldData[iIndex].handleType = commonUtils.isEmpty(oldData[iIndex].handleType) ? 'update' : oldData[iIndex].handleType; + } + } + }); + newData = oldData.concat(newData) + } + + }else if(sTmpInfoBySqlBtnName.includes('_del')) { /* 替换 根据对应字段对比 相同的不管 不同的插入 */ + /* 对应字段 */ + oldData.forEach((child) => { + child.handleType ='del'; + oldDelData.push(child); + }); + allReturnMap[sDelName] = oldDelData; + oldData = []; + const keyData = returnData[key]; + if(commonUtils.isNotEmptyArr(keyData)) { + keyData.forEach((child) => { + const tableRow = { ...child, ...commonFunc.getAssignFieldValue(sAssignField, child) }; // 取赋值字段111 + tableRow.sId = commonUtils.createSid(); + if (sName === 'slave' && !tableRow.sSqlConditionId) { + tableRow.sSqlConditionId = tableRow.sId; + } + tableRow.sParentId = masterData.sId; + tableRow.handleType = 'add'; + oldData.push(tableRow); + }); + } + if(sName === 'slaveData'){ + allReturnMap['slaveChildData'] = oldData + } else{ + allReturnMap[sName] = oldData; + } + // allReturnMap[sName] = oldData; + } else if(sTmpInfoBySqlBtnName.includes('_update')) { /* 更新字段 */ + const keyData = returnData[key]; + if(commonUtils.isNotEmptyArr(keyData) && sActiveKeyNew) { + const [linkField, onchangeField] = sActiveKeyNew.split(','); + const tableName = key.split('_update')[0]; + const { [`${tableName}Data`]: tableData = [] } = this.state; + + for (let i = 0; i < keyData.length; i++) { + const child = keyData[i]; + const tableDataFilter = tableData.filter(item => item[linkField] === child[linkField]); + for (let j = 0; j < tableDataFilter.length; j++) { + const item = tableDataFilter[j]; + const iIndex = tableData.findIndex(row => row.sId === item.sId); + tableData[iIndex] = { ...item, ...child }; + if (onchangeField && this.state.onEventDataChange) { + const { sId, [onchangeField]: fieldsValue } = tableData[iIndex]; + window.tmpSlaveData = tableData; + tableData[iIndex] = await this.state.onEventDataChange('slave', onchangeField, { [onchangeField]: fieldsValue }, sId, [], true); + window.tmpSlaveData = null; + } + } + } + allReturnMap[`${tableName}Data`] = tableData; + } + } else { + // if(sName ==='slave'){ + // allReturnMap['slaveChild'] = returnData[key]; + // }else{ + // allReturnMap[sName] = returnData[key]; + // } + allReturnMap[sName] = returnData[key]; + + } + + } + if (commonUtils.isNotEmptyArr(allReturnMap.masterData) && Array.isArray(allReturnMap.masterData)) { + allReturnMap.masterData = allReturnMap.masterData[0]; + } + this.setState({ ...allReturnMap }); + } + } else { + this.getServiceError(dataReturn); + } + } + } + } else { + message.error('请正确配置自定义按钮!'); + } + } + }; + render() { return ( { onFilterDropDownData={this.handleFilterDropDownData} onTmpInfoBySql={this.handleTmpInfoBySql} handleMasterDefaultData={this.handleMasterDefaultData} + onDropTableBlur ={this.handleTableBlur} /> ); } diff --git a/src/mobile/common/CommobileComponent.js b/src/mobile/common/CommobileComponent.js index 08d26a3..5a3ff51 100644 --- a/src/mobile/common/CommobileComponent.js +++ b/src/mobile/common/CommobileComponent.js @@ -449,7 +449,11 @@ export default class CommonComponent extends Component { sTitle={sTitle} {...outFormItemProps} className="forss" + showConfig ={this.props.showConfig} + record ={this.props.record} + tbName = {this.props.name} iconSettingShow={this.props.iconSettingShow} + onDropTableBlur={this.props.onDropTableBlur} /> ) diff --git a/src/mobile/common/CommobileSubBillEvent.js b/src/mobile/common/CommobileSubBillEvent.js index 25f278a..c4b9e5f 100644 --- a/src/mobile/common/CommobileSubBillEvent.js +++ b/src/mobile/common/CommobileSubBillEvent.js @@ -2027,6 +2027,10 @@ export default (ChildComponent) => { } } + + handleDropDownBlur = (name, sFileName, record, tableConfig ) =>{ + this.props.onDropTableBlur(name,sFileName, record, tableConfig) + } render() { return ( { onMobileFilterTable={this.handleMobileFilterTable} handleNameToIndex={this.handleNameToIndex} onButtonClick = {this.handleButtonClick} + onDropTableBlur = {this.handleDropDownBlur} /> ); } diff --git a/src/mobile/common/CommobileViewMaster.js b/src/mobile/common/CommobileViewMaster.js index 03d0ae2..b567c5c 100644 --- a/src/mobile/common/CommobileViewMaster.js +++ b/src/mobile/common/CommobileViewMaster.js @@ -22,6 +22,10 @@ export default class CommobileViewMaster extends Component { this.props.onFocus(fieldConfig); } + handleDropTableBlur =(name, sFileName, record, tableConfig) =>{ + this.props.onDropTableBlur(name, sFileName, record, tableConfig); + } + handleBlur = (fieldConfig) => { this.props.onBlur(fieldConfig); } @@ -80,6 +84,7 @@ export default class CommobileViewMaster extends Component { onFieldScan: this.handleMasterFieldScan, onMobileScan: this.handleMobileScan, onMobileFilterTable:this.handleMobileFilterTable, /* 主表筛选从表 */ + onDropTableBlur:this.handleDropTableBlur, bOpenKeyboard, }; if (child.iTag === 1) { diff --git a/src/mobile/components/searchPicker.jsx b/src/mobile/components/searchPicker.jsx index 6d79d02..9398677 100644 --- a/src/mobile/components/searchPicker.jsx +++ b/src/mobile/components/searchPicker.jsx @@ -5,7 +5,7 @@ import styles from "./selectInput.less"; import iconSetting from '../../assets/mobile/setting.png'; export default function SearchablePicker(props) { - const { onConfirm, initialValue, data, sTitle, onChange, value:newValue, onVisibleChange } = props; + const { onConfirm, initialValue, data, sTitle, onChange, value:newValue, onVisibleChange, onDropTableBlur } = props; const [searchValue, setSearchValue] = useState(''); const [visible, setVisible] = useState(false) @@ -34,7 +34,7 @@ export default function SearchablePicker(props) { ); }, [searchValue, data]); // ✅ 必须包含 data const label = filteredOptions?.find(x=>x.value === newValue[0])?.label || '' - + const handleOpen = () => { setVisible(true); // 调用onVisibleChange回调 @@ -44,12 +44,24 @@ export default function SearchablePicker(props) { }; const handleConfirm = () => { + const selectedValue = values[0]; onChange(values); setVisible(false); // 调用onVisibleChange回调 if (onVisibleChange) { onVisibleChange(false); } + const {showConfig:tableConfig, tbName, record} = props; + const sName = tableConfig.sName; + // 构造包含新选中值的 record,避免闭包里捕获的旧 record2222 + const updatedRecord = { ...record, [sName]: selectedValue }; + // 延迟调用:确保 React 先完成渲染,父组件拿到最新的 record 值 + setTimeout(() => { + if(onDropTableBlur){ + onDropTableBlur('master', sName, updatedRecord, tableConfig); + } + + }, 0); }; const handleCancel = () => { @@ -105,4 +117,8 @@ export default function SearchablePicker(props) { ); -} \ No newline at end of file +} + + + +