CommonSystemSettingEvent.js
13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/* eslint-disable array-callback-return,no-undef,prefer-destructuring */
import moment from 'moment';
import React, { Component } from 'react';
import { Modal, message } from 'antd-v4';
import * as commonFunc from './commonFunc';
import * as commonBusiness from './commonBusiness'; /* 单据业务功能 */
import * as commonUtils from '../../utils/utils'; /* 通用方法 */
import commonConfig from '../../utils/config';
import * as commonServices from '../../services/services';
const { confirm } = Modal;
export default (ChildComponent) => {
return class extends Component {
constructor(props) {
super(props);
this.state = {
};
this.form = {};
/* 表单对象 */
}
componentWillReceiveProps(nextProps) {
const { formData, currentId } = nextProps;
let { masterConfig } = nextProps;
if (commonUtils.isEmptyArr(masterConfig) && formData.length > 0) {
const sId = currentId !== undefined ? currentId : '';
masterConfig = formData.filter(item => !item.bGrd)[0];
const sysaccountperiodConfig = formData.filter(item => item.bGrd && item.sTbName === 'sysaccountperiod')[0];
const sysaccountperiodColumn = commonFunc.getHeaderConfig(sysaccountperiodConfig);
const sysbillnosettingsConfig = formData.filter(item => item.bGrd && item.sTbName === 'sysbillnosettings')[0];
const sysbillnosettingsColumn = commonFunc.getHeaderConfig(sysbillnosettingsConfig);
const syspushMsgConfig = commonUtils.isNotEmptyArr(formData.filter(item => item.bGrd && item.sTbName === 'sysafteroperationmsg')) ?
formData.filter(item => item.bGrd && item.sTbName === 'sysafteroperationmsg')[0] : {};
let syspushMsgColumn = [];
if (commonUtils.isNotEmptyObject(syspushMsgConfig)) {
syspushMsgColumn = commonFunc.getHeaderConfig(syspushMsgConfig);
}
this.handleGetData(masterConfig, sysaccountperiodConfig, sysbillnosettingsConfig, syspushMsgConfig);
this.props.onSaveState({
masterConfig,
sysaccountperiodConfig,
sysaccountperiodColumn,
sysbillnosettingsConfig,
sysbillnosettingsColumn,
syspushMsgConfig,
syspushMsgColumn,
sId,
pageLoading: false,
});
}
}
shouldComponentUpdate(nextProps) {
const { masterConfig, masterData } = nextProps;
return commonUtils.isNotEmptyObject(masterConfig) && commonUtils.isNotEmptyObject(masterData);
}
handleGetData = (masterConfig, sysaccountperiodConfig, sysbillnosettingsConfig, syspushMsgConfig) => {
const { currentId, year } = this.props;
const sId = currentId !== undefined ? currentId : '';
const condition = {
sSqlCondition: {
sParentId: masterConfig.sId,
},
bFilter: [{
bFilterName: 'sPeriodId',
bFilterValue: commonUtils.isEmpty(year) ? new Date().getFullYear().toString() : year,
bFilterCondition: 'like',
}],
};
this.handleGetMasterDataSet({
configData: masterConfig, condition: { sId, pageSize: '', pageNum: '' },
});
this.props.handleGetDataSet({
name: 'sysaccountperiod', configData: sysaccountperiodConfig, condition,
});
this.props.handleGetDataSet({
name: 'sysbillnosettings', configData: sysbillnosettingsConfig, condition: { sId, pageSize: '', pageNum: '' },
});
if (commonUtils.isNotEmptyObject(syspushMsgConfig)) {
this.props.handleGetDataSet({
name: 'syspushMsg', configData: syspushMsgConfig, condition: { sId, pageSize: '', pageNum: '' },
});
}
};
/* 获取后台数据(数据集) */
handleGetMasterDataSet = async (params) => {
const { token, sModelsId } = this.props;
const {
configData, condition,
} = params;
const configDataId = configData.sId;
const dataUrl = `${commonConfig.server_host}syssystem/getSyssystemDataByFormcustomId/${configDataId}?sModelsId=${sModelsId}`;
const dataReturn = (await commonServices.postValueService(token, condition, dataUrl)).data;
if (dataReturn.code === 1) {
const masterData = {};
const returnData = dataReturn.dataset.rows[0].dataSet;
await configData.gdsconfigformslave.forEach(async (itemConfig) => {
const iIndex = returnData.findIndex(itemData => itemData.sName === itemConfig.sControlName.substring(1));
if (iIndex > -1) {
masterData[itemConfig.sControlName] = returnData[iIndex].sValue;
if (itemConfig.sControlName.substring(0, 1) === 'b') {
if (returnData[iIndex].sValue === '0') {
masterData[itemConfig.sControlName] = false;
} else if (returnData[iIndex].sValue === '1') {
masterData[itemConfig.sControlName] = true;
}
}
}
});
this.props.onSaveState({
masterData,
syssystemsettingsData: returnData,
});
} else {
this.props.getServiceError(dataReturn.msg);
}
};
/* 取消操作 */
handleCancel = () => {
/* 待用数据声明 */
const {
masterConfig, sysaccountperiodConfig, sysbillnosettingsConfig, syspushMsgConfig,
} = this.props;
const onGetDataOk = this.handleGetData;
const onSaveStateOk = this.props.onSaveState;
confirm({
title: '确定要取消',
onOk() {
onGetDataOk(masterConfig, sysaccountperiodConfig, sysbillnosettingsConfig, syspushMsgConfig);
onSaveStateOk({ enabled: false });
},
onCancel() {
},
});
};
/** toolbar校验保存 */
handleValidateSave = async () => {
this.form.validateFields((err) => {
/* 验证通过与不通过走不同的流程 */
if (err) { /* 验证失败 */
/* 直接渲染显示错误提示 */
for (const key of Object.keys(err)) {
message.warning(err[key].errors[0].message);
}
this.props.onSaveState({
loading: false,
});
} else { /* 验证成功 */
const {
masterConfig, masterData, sysaccountperiodConfig, sysaccountperiodData, sysbillnosettingsConfig, sysbillnosettingsData, syssystemsettingsData, sysbillnosettingsDelData, syspushMsgConfig, syspushMsgData, syspushMsgDelData,
} = this.props;
const data = [];
for (const key of Object.keys(masterData)) {
if (key !== 'handleType') {
const systemRow = {};
systemRow.sValue = masterData[key];
if (key.substring(0, 1) === 'b') {
if (masterData[key] === true) {
systemRow.sValue = '1';
} else if (masterData[key] === false) {
systemRow.sValue = '0';
}
} else if (key.substring(0, 1) === 's') {
if (commonUtils.isNotEmptyStr(masterData[key])) {
systemRow.sValue = masterData[key].toString();
}
} else if (key.substring(0, 1) === 'd' || key.substring(0, 1) === 'i') {
if (commonUtils.isNotEmptyNumber(masterData[key])) {
systemRow.sValue = masterData[key].toString();
}
}
const iIndex = syssystemsettingsData.findIndex(item => item.sName === key.substring(1));
if (iIndex > -1) {
systemRow.handleType = 'update';
syssystemsettingsData[iIndex] = { ...syssystemsettingsData[iIndex], ...systemRow };
} else {
systemRow.sId = commonUtils.createSid();
systemRow.sName = key.substring(1);
systemRow.handleType = 'add';
syssystemsettingsData.push(systemRow);
}
}
}
data.push(commonBusiness.mergeData('syssystemsettings', masterConfig.sTbName, syssystemsettingsData));
data.push(commonBusiness.mergeData('sysaccountperiod', sysaccountperiodConfig.sTbName, sysaccountperiodData));
data.push(commonBusiness.mergeData('sysbillnosettings', sysbillnosettingsConfig.sTbName, sysbillnosettingsData, sysbillnosettingsDelData));
if (commonUtils.isNotEmptyObject(syspushMsgConfig)) {
data.push(commonBusiness.mergeData('syspushMsg', syspushMsgConfig.sTbName, syspushMsgData, syspushMsgDelData));
}
this.handleSaveData({ data, sClientType: '1', sSysLogSrcId: masterData.sId });
}
});
};
/** toolbar保存 */
handleSaveData = async (params) => {
const {
token, sModelsId, masterConfig, sysaccountperiodConfig, sysbillnosettingsConfig, syspushMsgConfig, masterData,
} = this.props;
const returnData = await commonBusiness.saveData({ token, value: params, sModelsId });
if (commonUtils.isNotEmptyObject(returnData)) {
this.props.onSaveState({
enabled: false, currentId: masterData.sId, loading: false,
});
this.handleGetData(masterConfig, sysaccountperiodConfig, sysbillnosettingsConfig, syspushMsgConfig);
return true;
} else {
this.props.onSaveState({
loading: false,
});
return false;
}
};
/** 表单回带 */
handleForm = (form) => {
this.form = form;
};
/** 表格数据更改 */
// name 不写完整的state名称作用为了要用到total // (name, changeValue, sId, dropDownData)
handleTableChange = (name, sFieldName, changeValue, sId, dropDownData) => {
/* 从CommonBase获取默认参数 */
const {
[`${name}Data`]: tableData, masterData, sModelsType, app,
} = this.props;
const iIndex = tableData.findIndex(item => item.sId === sId);
if (name === 'sysaccountperiod' && (sFieldName === 'tStartDate' || sFieldName === 'tEndDate')) {
if (sFieldName === 'tEndDate' || iIndex !== 0) {
message.warning('请选择第一条数据的开始日期');
return;
}
tableData[iIndex].tEndDate = moment(changeValue.tStartDate, 'YYYY-MM-DD HH:mm:ss').add(1, 'months').subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss');
tableData.forEach((itemData) => {
if (itemData.sId !== sId) {
const subscript = tableData.indexOf(itemData);
itemData.tStartDate = moment(changeValue.tStartDate, 'YYYY-MM-DD HH:mm:ss').add(subscript, 'months').format('YYYY-MM-DD HH:mm:ss');
itemData.tEndDate = moment(changeValue.tStartDate, 'YYYY-MM-DD HH:mm:ss').add(subscript + 1, 'months').subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss');
itemData.handleType = 'update';
}
});
}
const tableDataRow = this.props.onDataChange(name, sFieldName, changeValue, sId, dropDownData, true);
const models = sModelsType.includes('sales/') || sModelsType.includes('manufacture/') ? 'Product' : 'Materials';
tableData[iIndex] = commonBusiness.getCalculateAllMoney(app, models, sFieldName, masterData, tableDataRow);
if (commonUtils.isEmptyStr(tableData[iIndex].handleType)) {
tableData[iIndex].handleType = 'update';
}
this.props.onSaveState({ [`${name}Data`]: tableData, masterData });
};
/** 点击修改按钮操作 */
handleEdit = () => {
const {
masterConfig, sysaccountperiodConfig, sysbillnosettingsConfig, syspushMsgConfig,
} = this.props;
this.handleGetData(masterConfig, sysaccountperiodConfig, sysbillnosettingsConfig, syspushMsgConfig);
this.props.onSaveState({ enabled: true, loading: false });
};
/** 添加表格空行 */
handleTableAdd = (name, isWait) => {
/* 从CommonBase获取默认参数 */
let { [`${name}Data`]: tableData } = this.props;
tableData = commonUtils.isEmptyObject(tableData) ? [] : tableData;
const tableDataRow = this.props.onDataRowAdd(name, true);
if (name === 'syspushMsg') {
if (commonUtils.isEmptyArr(this.props.sysbillnosettingsSelectedRowKeys)) {
message.error('请选择数据行!');
return;
} else {
tableDataRow.sParentId = this.props.sysbillnosettingsSelectedRowKeys[0];
}
}
if (isWait) {
return tableDataRow;
} else if (commonUtils.isNotEmptyObject(tableDataRow)) {
tableData.push(tableDataRow);
this.props.onSaveState({ [`${name}Data`]: tableData, [`${name}Pagination`]: { total: tableData.length, current: 9999 }, [`${name}SelectedRowKeys`]: [tableDataRow.sId] });
}
};
handleTreeSelect = (name, selectedKeys, e) => {
const { treeNode } = e.node.props;
this.props.onTreeSelect(name, selectedKeys, e);
this.props.onSaveState({ selectedId: treeNode.sId, selectedName: treeNode.sName });
};
render() {
return (
<ChildComponent
{...this.props}
{...this.state}
onEdit={this.handleEdit}
onCancel={this.handleCancel}
onSubmit={this.handleValidateSave}
onReturnForm={this.handleForm}
onDataChange={this.handleTableChange}
onDataRowAdd={this.handleTableAdd}
onTreeSelect={this.handleTreeSelect}
/>
);
}
};
};