Commit faf8c69f25b6cca6061515f43385daaf1b2aa76e

Authored by Min
1 parent 9f9a1a47

1.手机端单据支持下拉后 调用tmpinfobysql调用存储过程插入数据功能

src/mobile/common/CommobileBase.js
@@ -12,6 +12,7 @@ import * as commonUtils from '../../utils/utils'; @@ -12,6 +12,7 @@ import * as commonUtils from '../../utils/utils';
12 import * as commonServices from '../../services/services'; 12 import * as commonServices from '../../services/services';
13 import * as commonFunc from '../../components/Common/commonFunc'; 13 import * as commonFunc from '../../components/Common/commonFunc';
14 import * as commonBusiness from '../../components/Common/commonBusiness'; 14 import * as commonBusiness from '../../components/Common/commonBusiness';
  15 +import { message } from "@/utils/common/message";
15 // import * as commonFunc from './commonFunc'; /* 通用单据方法 */ 16 // import * as commonFunc from './commonFunc'; /* 通用单据方法 */
16 17
17 export default (ChildComponent) => { 18 export default (ChildComponent) => {
@@ -718,6 +719,258 @@ export default (ChildComponent) => { @@ -718,6 +719,258 @@ export default (ChildComponent) => {
718 }; 719 };
719 } 720 }
720 721
  722 + /* 下拉多选离开事件 */
  723 + handleTableBlur = async (name, sFileName, record, tableConfig, other) => {
  724 + const { sModelsId, app } = this.props;
  725 + console.log('handleTableBlur',name, sFileName, record, tableConfig,);
  726 + const { controlData, slaveConfig,[`${name}Data`]: tableData , [`${name}Config`]: tempConfig } = this.state;
  727 + let { slaveData: slaveDataOld, masterData, slaveDelData, } = this.state;
  728 + const addState = {};
  729 + if(commonUtils.isEmptyArr(slaveDelData)) {
  730 + slaveDelData = [];
  731 + }
  732 + if (sFileName === 'sPartsNameNew') {
  733 + if(commonUtils.isNotEmptyArr(controlData)) {
  734 + /* 离开时 把sPartsNameNewId数据挂载到sControlParentId */
  735 + let iIndex = controlData.findIndex(item => item.sId === record.sId);
  736 + if(iIndex === -1) {
  737 + if(record.sId && record.sId.split('-').length > 1) {
  738 + iIndex = controlData.findIndex(item => item.sId === record.sId.split('-')[0]);
  739 + }
  740 + }
  741 + if (iIndex > -1) {
  742 + addState.sControlParentId = controlData[iIndex].sPartsNameNewId;
  743 + if(commonUtils.isNotEmptyObject(controlData[iIndex].sPartsNameNewId)) {
  744 + controlData[iIndex] = {...controlData[iIndex], ...addState};
  745 + this.props.onSaveState({ controlData: controlData });
  746 + }
  747 + }
  748 + }
  749 + } else if (tableConfig.sDropDownType === 'movesql') { /* 通用字段离开调下拉事件 */
  750 + let slaveRow = record;
  751 + const sqlDropDownData = await this.getSqlDropDownData(sModelsId, name, tableConfig, slaveRow);
  752 + const dDropDownData = sqlDropDownData.dropDownData;
  753 + const iIndex = tableData.findIndex(item => item.sId === record.sId);
  754 + if (commonUtils.isNotEmptyArr(dDropDownData) && iIndex > -1) {
  755 + slaveRow = { ...slaveRow, ...commonFunc.getAssignFieldValue(tableConfig.sAssignField, dDropDownData[0]) }; // 取赋值字段
  756 + slaveRow.handleType = commonUtils.isEmpty(slaveRow.handleType) ? 'update' : slaveRow.handleType;
  757 + const sButtonParam = tableConfig.sButtonParam; /* 设置多级联动 */
  758 + if(commonUtils.isNotEmptyObject(sButtonParam)) {
  759 + let sLinkFieldName = 'dMaterialsPrice';
  760 + if (commonUtils.isJSON(sButtonParam)) { /* 按钮条件 */
  761 + const linkObj = JSON.parse(sButtonParam); /* 联动配置 */
  762 + let models = 'Materials';
  763 + if (linkObj.linkMaterials) {
  764 + sLinkFieldName = linkObj.linkMaterials;
  765 + models = 'Materials';
  766 + } else if (linkObj.linkProduct) {
  767 + sLinkFieldName = linkObj.linkProduct;
  768 + models = 'Product';
  769 + }
  770 + slaveRow = commonBusiness.getCalculateAllMoney(app, models, sLinkFieldName, masterData, slaveRow);
  771 + }
  772 + }
  773 +
  774 + tableData[iIndex] = { ...tableData[iIndex] , ...slaveRow };
  775 + this.setState({ ...addState });
  776 + }
  777 + } else if(commonUtils.isNotEmptyObject(tableConfig) && commonUtils.isNotEmptyObject(tableConfig.sButtonParam)) {
  778 + let slaveNewData = [];
  779 + const allConfig = { slaveConfig };
  780 + // console.log('sTmpInfoConfigArr', sTmpInfoConfigArr);
  781 + const sTmpInfoConfig = tableConfig;
  782 + const sButtonParam = tableConfig.sButtonParam;
  783 + const btn = commonUtils.isNotEmptyObject(sButtonParam) && commonUtils.isJSON(sButtonParam)? JSON.parse(sButtonParam) : {};;
  784 + const sProName = commonUtils.isNotEmptyObject(btn) ? btn.sproName : '';
  785 + const sTmpInfoBySqlBtnName = commonUtils.isNotEmptyObject(btn) ? btn.sControlName : '';
  786 + const sActiveKey = sTmpInfoConfig.sActiveKey;
  787 + if (commonUtils.isNotEmptyObject(sTmpInfoConfig)) {
  788 + if (commonUtils.isEmptyObject(sTmpInfoBySqlBtnName)) {
  789 + const newCopyTo = {};
  790 + newCopyTo.master = masterData;
  791 + // newCopyTo.slave = commonUtils.isEmpty(slaveData) ? [] : slaveData[0];
  792 + // const sRowData = copyTo.slaveData;
  793 + const sRowData = masterData;
  794 + const value = { sProName, sProInParam: JSON.stringify({ params: sRowData }) };
  795 + if (other?.iFlag === 1) {
  796 + value.iFlag = 1;
  797 + }
  798 + const url = `${commonConfig.server_host}procedureCall/doGenericProcedureCall?sModelsId=${sModelsId}`;
  799 + const dataReturn = (await commonServices.postValueService(app.token, value, url)).data;
  800 + if (dataReturn.code === 1) {
  801 + if (commonUtils.isNotEmptyArr(slaveDataOld)) {
  802 + slaveDataOld.forEach((item) => {
  803 + item.handleType = 'del';
  804 + slaveDelData.push(item);
  805 + });
  806 + addState.slaveDelData = slaveDelData;
  807 + }
  808 + const returnData = dataReturn.dataset.rows[0];
  809 + const slaveReturn = returnData.dataSet.proData;
  810 + if (commonUtils.isNotEmptyArr(slaveReturn)) {
  811 + slaveReturn.forEach((slaveItem) => {
  812 + newCopyTo.slave = slaveItem;
  813 + let slaveRow = commonFunc.getDefaultData(allConfig.slaveConfig, newCopyTo); // 取默认值
  814 + // if (salveDetailAssignField) {
  815 + // slaveRow = {...slaveRow, ...commonFunc.getAssignFieldValue(salveDetailAssignField, copyTo.masterData, newCopyTo)};
  816 + // } else if (salveAssignField) {
  817 + // slaveRow = {...slaveRow, ...commonFunc.getAssignFieldValue(salveAssignField, slaveItem, newCopyTo)}; // 取赋值字段
  818 + // }
  819 + slaveRow = { ...slaveRow, ...slaveItem };
  820 + slaveRow.handleType = 'add';
  821 + slaveRow.sId = commonUtils.createSid();
  822 + slaveRow.sParentId = masterData.sId;
  823 + slaveNewData.push(slaveRow);
  824 + });
  825 + }
  826 + addState.slaveData = slaveNewData;
  827 + this.setState({ ...addState });
  828 + } else {
  829 + this.getServiceError({ ...dataReturn, fn: () => this.handleTableBlur(name, sFileName, record, tableConfig, { iFlag: 1 }) });
  830 + }
  831 + } else if(sTmpInfoBySqlBtnName.includes('sTmpInfoBySql')) { /* 走TmpInfo逻辑 */
  832 + const newCopyTo = {};
  833 + newCopyTo.master = masterData;
  834 + /* 找到自定义TempInfo配置 */
  835 + const btnConfig = tempConfig.gdsconfigformslave.filter(item => item.sControlName.includes(sTmpInfoBySqlBtnName)) || [];
  836 + console.log('btnConfig', btnConfig, sTmpInfoBySqlBtnName);
  837 + const dataUrl = `${commonConfig.server_host}salesorder/getTmpInfoBySql/?sModelsId=${sModelsId}`;
  838 + const sConfigformId = commonUtils.isEmpty(btnConfig) ? '' : btnConfig[0].sParentId;
  839 + const sControlName = commonUtils.isNotEmptyObject(sTmpInfoBySqlBtnName) ? sTmpInfoBySqlBtnName : 'TmpInfoBySql';
  840 + const sAssignField = btnConfig[0].sAssignField;
  841 + const sActiveKeyNew = btnConfig[0].sActiveKey;
  842 + let sRowData = [record];
  843 + if (name === 'master' && sTmpInfoBySqlBtnName.includes('_update')) {
  844 + const { slaveData } = this.state;
  845 + if (commonUtils.isNotEmptyArr(slaveData)) {
  846 + sRowData = [...sRowData, ...slaveData];
  847 + }
  848 + }
  849 + const values = { sConfigformId, sControlName, sRowData };
  850 + if (true){
  851 + const dataReturn = (await commonServices.postValueService(app.token, values, dataUrl)).data;
  852 + const allReturnMap = {};
  853 + if (dataReturn.code === 1) {
  854 + const returnData = dataReturn.dataset.rows[0];
  855 + if (commonUtils.isNotEmptyObject(returnData)) {
  856 + for (const key of Object.keys(returnData)) {
  857 + const sName = `${key}Data`;
  858 + const sDelName = `${key}DelData`;
  859 + // allReturnMap[sName] = returnData[key];
  860 + let {[`${key}Data`]: oldData, [`${key}Data`]: oldDelData } = this.state;
  861 + if(commonUtils.isEmptyArr(oldDelData)) {
  862 + oldDelData = [];
  863 + }
  864 + if(commonUtils.isEmptyArr(oldData)) {
  865 + oldData = [];
  866 + }
  867 + if(sTmpInfoBySqlBtnName.includes('_edit')) { /* 替换 根据对应字段对比 相同的不管 不同的插入 */
  868 + /* 对应字段 */
  869 + const sActiveKey = sTmpInfoConfig.sActiveKey;
  870 + const keyData = returnData[key];
  871 + let newData = [];
  872 + if(commonUtils.isNotEmptyArr(keyData)) {
  873 + keyData.forEach((child) => {
  874 + const filterData = oldData.filter(item => item[sActiveKeyNew] !== child[sActiveKeyNew]);
  875 + if(commonUtils.isNotEmptyArr(filterData) && filterData.length === oldData.length) {
  876 + const tableRow = { ...child, ...commonFunc.getAssignFieldValue(sAssignField, child) }; // 取赋值字段111
  877 + tableRow.sId = commonUtils.createSid();
  878 + tableRow.sParentId = masterData.sId;
  879 + tableRow.handleType = 'add';
  880 + newData.push(tableRow);
  881 + } else { /* 相同的根据赋值字段覆盖 */
  882 + const iIndex = oldData.findIndex(item => item[sActiveKeyNew] === child[sActiveKeyNew]);
  883 + if(iIndex > -1) {
  884 + if(sAssignField) {
  885 + oldData[iIndex] ={...oldData[iIndex], ...commonFunc.getAssignFieldValue(sAssignField, child) };
  886 + } else {
  887 + oldData[iIndex] ={...oldData[iIndex], ...child };
  888 + }
  889 + oldData[iIndex].handleType = commonUtils.isEmpty(oldData[iIndex].handleType) ? 'update' : oldData[iIndex].handleType;
  890 + }
  891 + }
  892 + });
  893 + newData = oldData.concat(newData)
  894 + }
  895 +
  896 + }else if(sTmpInfoBySqlBtnName.includes('_del')) { /* 替换 根据对应字段对比 相同的不管 不同的插入 */
  897 + /* 对应字段 */
  898 + oldData.forEach((child) => {
  899 + child.handleType ='del';
  900 + oldDelData.push(child);
  901 + });
  902 + allReturnMap[sDelName] = oldDelData;
  903 + oldData = [];
  904 + const keyData = returnData[key];
  905 + if(commonUtils.isNotEmptyArr(keyData)) {
  906 + keyData.forEach((child) => {
  907 + const tableRow = { ...child, ...commonFunc.getAssignFieldValue(sAssignField, child) }; // 取赋值字段111
  908 + tableRow.sId = commonUtils.createSid();
  909 + if (sName === 'slave' && !tableRow.sSqlConditionId) {
  910 + tableRow.sSqlConditionId = tableRow.sId;
  911 + }
  912 + tableRow.sParentId = masterData.sId;
  913 + tableRow.handleType = 'add';
  914 + oldData.push(tableRow);
  915 + });
  916 + }
  917 + if(sName === 'slaveData'){
  918 + allReturnMap['slaveChildData'] = oldData
  919 + } else{
  920 + allReturnMap[sName] = oldData;
  921 + }
  922 + // allReturnMap[sName] = oldData;
  923 + } else if(sTmpInfoBySqlBtnName.includes('_update')) { /* 更新字段 */
  924 + const keyData = returnData[key];
  925 + if(commonUtils.isNotEmptyArr(keyData) && sActiveKeyNew) {
  926 + const [linkField, onchangeField] = sActiveKeyNew.split(',');
  927 + const tableName = key.split('_update')[0];
  928 + const { [`${tableName}Data`]: tableData = [] } = this.state;
  929 +
  930 + for (let i = 0; i < keyData.length; i++) {
  931 + const child = keyData[i];
  932 + const tableDataFilter = tableData.filter(item => item[linkField] === child[linkField]);
  933 + for (let j = 0; j < tableDataFilter.length; j++) {
  934 + const item = tableDataFilter[j];
  935 + const iIndex = tableData.findIndex(row => row.sId === item.sId);
  936 + tableData[iIndex] = { ...item, ...child };
  937 + if (onchangeField && this.state.onEventDataChange) {
  938 + const { sId, [onchangeField]: fieldsValue } = tableData[iIndex];
  939 + window.tmpSlaveData = tableData;
  940 + tableData[iIndex] = await this.state.onEventDataChange('slave', onchangeField, { [onchangeField]: fieldsValue }, sId, [], true);
  941 + window.tmpSlaveData = null;
  942 + }
  943 + }
  944 + }
  945 + allReturnMap[`${tableName}Data`] = tableData;
  946 + }
  947 + } else {
  948 + // if(sName ==='slave'){
  949 + // allReturnMap['slaveChild'] = returnData[key];
  950 + // }else{
  951 + // allReturnMap[sName] = returnData[key];
  952 + // }
  953 + allReturnMap[sName] = returnData[key];
  954 +
  955 + }
  956 +
  957 + }
  958 + if (commonUtils.isNotEmptyArr(allReturnMap.masterData) && Array.isArray(allReturnMap.masterData)) {
  959 + allReturnMap.masterData = allReturnMap.masterData[0];
  960 + }
  961 + this.setState({ ...allReturnMap });
  962 + }
  963 + } else {
  964 + this.getServiceError(dataReturn);
  965 + }
  966 + }
  967 + }
  968 + } else {
  969 + message.error('请正确配置自定义按钮!');
  970 + }
  971 + }
  972 + };
  973 +
721 render() { 974 render() {
722 return ( 975 return (
723 <ChildComponent 976 <ChildComponent
@@ -739,6 +992,7 @@ export default (ChildComponent) =&gt; { @@ -739,6 +992,7 @@ export default (ChildComponent) =&gt; {
739 onFilterDropDownData={this.handleFilterDropDownData} 992 onFilterDropDownData={this.handleFilterDropDownData}
740 onTmpInfoBySql={this.handleTmpInfoBySql} 993 onTmpInfoBySql={this.handleTmpInfoBySql}
741 handleMasterDefaultData={this.handleMasterDefaultData} 994 handleMasterDefaultData={this.handleMasterDefaultData}
  995 + onDropTableBlur ={this.handleTableBlur}
742 /> 996 />
743 ); 997 );
744 } 998 }
src/mobile/common/CommobileComponent.js
@@ -449,7 +449,11 @@ export default class CommonComponent extends Component { @@ -449,7 +449,11 @@ export default class CommonComponent extends Component {
449 sTitle={sTitle} 449 sTitle={sTitle}
450 {...outFormItemProps} 450 {...outFormItemProps}
451 className="forss" 451 className="forss"
  452 + showConfig ={this.props.showConfig}
  453 + record ={this.props.record}
  454 + tbName = {this.props.name}
452 iconSettingShow={this.props.iconSettingShow} 455 iconSettingShow={this.props.iconSettingShow}
  456 + onDropTableBlur={this.props.onDropTableBlur}
453 /> 457 />
454 458
455 ) 459 )
src/mobile/common/CommobileSubBillEvent.js
@@ -2027,6 +2027,10 @@ export default (ChildComponent) =&gt; { @@ -2027,6 +2027,10 @@ export default (ChildComponent) =&gt; {
2027 } 2027 }
2028 2028
2029 } 2029 }
  2030 +
  2031 + handleDropDownBlur = (name, sFileName, record, tableConfig ) =>{
  2032 + this.props.onDropTableBlur(name,sFileName, record, tableConfig)
  2033 + }
2030 render() { 2034 render() {
2031 return ( 2035 return (
2032 <ChildComponent 2036 <ChildComponent
@@ -2048,6 +2052,7 @@ export default (ChildComponent) =&gt; { @@ -2048,6 +2052,7 @@ export default (ChildComponent) =&gt; {
2048 onMobileFilterTable={this.handleMobileFilterTable} 2052 onMobileFilterTable={this.handleMobileFilterTable}
2049 handleNameToIndex={this.handleNameToIndex} 2053 handleNameToIndex={this.handleNameToIndex}
2050 onButtonClick = {this.handleButtonClick} 2054 onButtonClick = {this.handleButtonClick}
  2055 + onDropTableBlur = {this.handleDropDownBlur}
2051 /> 2056 />
2052 ); 2057 );
2053 } 2058 }
src/mobile/common/CommobileViewMaster.js
@@ -22,6 +22,10 @@ export default class CommobileViewMaster extends Component { @@ -22,6 +22,10 @@ export default class CommobileViewMaster extends Component {
22 this.props.onFocus(fieldConfig); 22 this.props.onFocus(fieldConfig);
23 } 23 }
24 24
  25 + handleDropTableBlur =(name, sFileName, record, tableConfig) =>{
  26 + this.props.onDropTableBlur(name, sFileName, record, tableConfig);
  27 + }
  28 +
25 handleBlur = (fieldConfig) => { 29 handleBlur = (fieldConfig) => {
26 this.props.onBlur(fieldConfig); 30 this.props.onBlur(fieldConfig);
27 } 31 }
@@ -80,6 +84,7 @@ export default class CommobileViewMaster extends Component { @@ -80,6 +84,7 @@ export default class CommobileViewMaster extends Component {
80 onFieldScan: this.handleMasterFieldScan, 84 onFieldScan: this.handleMasterFieldScan,
81 onMobileScan: this.handleMobileScan, 85 onMobileScan: this.handleMobileScan,
82 onMobileFilterTable:this.handleMobileFilterTable, /* 主表筛选从表 */ 86 onMobileFilterTable:this.handleMobileFilterTable, /* 主表筛选从表 */
  87 + onDropTableBlur:this.handleDropTableBlur,
83 bOpenKeyboard, 88 bOpenKeyboard,
84 }; 89 };
85 if (child.iTag === 1) { 90 if (child.iTag === 1) {
src/mobile/components/searchPicker.jsx
@@ -5,7 +5,7 @@ import styles from &quot;./selectInput.less&quot;; @@ -5,7 +5,7 @@ import styles from &quot;./selectInput.less&quot;;
5 import iconSetting from '../../assets/mobile/setting.png'; 5 import iconSetting from '../../assets/mobile/setting.png';
6 6
7 export default function SearchablePicker(props) { 7 export default function SearchablePicker(props) {
8 - const { onConfirm, initialValue, data, sTitle, onChange, value:newValue, onVisibleChange } = props; 8 + const { onConfirm, initialValue, data, sTitle, onChange, value:newValue, onVisibleChange, onDropTableBlur } = props;
9 9
10 const [searchValue, setSearchValue] = useState(''); 10 const [searchValue, setSearchValue] = useState('');
11 const [visible, setVisible] = useState(false) 11 const [visible, setVisible] = useState(false)
@@ -34,7 +34,7 @@ export default function SearchablePicker(props) { @@ -34,7 +34,7 @@ export default function SearchablePicker(props) {
34 ); 34 );
35 }, [searchValue, data]); // ✅ 必须包含 data 35 }, [searchValue, data]); // ✅ 必须包含 data
36 const label = filteredOptions?.find(x=>x.value === newValue[0])?.label || '' 36 const label = filteredOptions?.find(x=>x.value === newValue[0])?.label || ''
37 - 37 +
38 const handleOpen = () => { 38 const handleOpen = () => {
39 setVisible(true); 39 setVisible(true);
40 // 调用onVisibleChange回调 40 // 调用onVisibleChange回调
@@ -44,12 +44,24 @@ export default function SearchablePicker(props) { @@ -44,12 +44,24 @@ export default function SearchablePicker(props) {
44 }; 44 };
45 45
46 const handleConfirm = () => { 46 const handleConfirm = () => {
  47 + const selectedValue = values[0];
47 onChange(values); 48 onChange(values);
48 setVisible(false); 49 setVisible(false);
49 // 调用onVisibleChange回调 50 // 调用onVisibleChange回调
50 if (onVisibleChange) { 51 if (onVisibleChange) {
51 onVisibleChange(false); 52 onVisibleChange(false);
52 } 53 }
  54 + const {showConfig:tableConfig, tbName, record} = props;
  55 + const sName = tableConfig.sName;
  56 + // 构造包含新选中值的 record,避免闭包里捕获的旧 record2222
  57 + const updatedRecord = { ...record, [sName]: selectedValue };
  58 + // 延迟调用:确保 React 先完成渲染,父组件拿到最新的 record 值
  59 + setTimeout(() => {
  60 + if(onDropTableBlur){
  61 + onDropTableBlur('master', sName, updatedRecord, tableConfig);
  62 + }
  63 +
  64 + }, 0);
53 }; 65 };
54 66
55 const handleCancel = () => { 67 const handleCancel = () => {
@@ -105,4 +117,8 @@ export default function SearchablePicker(props) { @@ -105,4 +117,8 @@ export default function SearchablePicker(props) {
105 </div> 117 </div>
106 118
107 ); 119 );
108 -}  
109 \ No newline at end of file 120 \ No newline at end of file
  121 +}
  122 +
  123 +
  124 +
  125 +