index.jsx
10.9 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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/* eslint-disable */
import React, { PureComponent } from "react";
import { Form } from "@ant-design/compatible";
// import "@ant-design/compatible/assets/index.css";
import { Layout, Spin, Button, Row, Col } from "antd-v4";
import * as commonFunc from "@/components/Common/commonFunc"; /* 通用单据方法 */ /* 通用单据方法 */
import StaticEditTable from "@/components/Common//CommonTable"; /* 可编辑表格 */
import StaticEditTree from "@/components/Common/Tree/StaticTree";
import CommonBase from "@/components/Common/CommonBase"; /* 获取配置及数据 */
import * as commonBusiness from "@/components/Common//commonBusiness"; /* 单据业务功能 */
import SearchComponent from "@/components/Common/SearchComponent";
import * as commonUtils from "@/utils/utils";
import CommonListEvent from "@/components/Common/CommonListEvent";
import { cloneDeep } from "lodash";
const { Content } = Layout;
class CommonList extends PureComponent {
constructor(props) {
super(props);
this.state = {
filterTreeData: [],
filterTreeDataKey: [],
filterTreeDetailData: [],
filterTreeDetailDataKey: [],
slaveFilterKeys: null,
};
}
componentDidUpdate(prevProps, prevState) {
const { props } = this;
if (Array.isArray(props.slaveData) && props.slaveData.length) {
if (!this.hasUpdate) {
this.hasUpdate = true;
this.replaceData();
}
}
if (Array.isArray(props.treeData) && props.treeData.length) {
if (!this.hastreeUpdate) {
this.hastreeUpdate = true;
this.setState({
filterTreeData: props.treeData?.slice(0, 1),
filterTreeDataKey: [props.treeData?.[0]?.key],
filterTreeDetailData: props.treeData?.slice(1, 2),
filterTreeDetailDataKey: [props.treeData?.[1]?.key],
})
}
}
}
// 更新数据
replaceData = () => {
const { props } = this;
const { slaveSelectedRowKeys = [] } = props;
if (props.app?.currentPane?.config?.sControlName?.startsWith('BtnPopupEdit')) {
const selectData = props.app?.sMemoData;
const showHasEditData = [];
if (Array.isArray(selectData)) {
selectData.forEach((i) => {
const index = props.slaveData?.findIndex(j => j && j.sId === i.sId);
if (index >= 0) {
props.slaveData[index] = i;
} else {
showHasEditData.push(i);
}
});
const slaveData = [...props.slaveData || [], ...showHasEditData];
const slaveSelectedRowKeysNew = Array.isArray(selectData) ? selectData.map(i => i && i.sSlaveId).filter(Boolean) : [];
props.onSaveState({ slaveSelectedRowKeys: [...slaveSelectedRowKeysNew, ...slaveSelectedRowKeys], slaveData, slaveSelectedData: selectData || [] });
}
}
};
handleSelect = () => {
const { slaveSelectedRowKeys, app, slaveData } = this.props;
this.props.app.currentPane.select(
app.currentPane.name,
app.currentPane.config,
slaveData.filter(item => slaveSelectedRowKeys.includes(item.sSlaveId)),
);
this.props.app.currentPane.selectCancel(app.currentPane.name);
};
handleDoubleClickSelect = () => {
const { slaveConfig } = this.props;
if (commonUtils.isNotEmptyObject(slaveConfig) && !slaveConfig.bMutiSelect) {
// 单选时双击选中数据
this.handleSelect();
}
};
/** 关闭 */
handleCancelModal = () => {
const { app } = this.props;
this.props.app.currentPane.selectCancel(app.currentPane.name);
};
/** 树节点多选框选中 */
handleTreeCheck = (checkedKeys, e) => {
this.props.onCheck(checkedKeys, e); /* 调用CommonListEvent通用处理 */
};
filterData = (data, selectKeys) => {
if (!selectKeys) return data;
if (Array.isArray(data)) {
return data.filter(i => {
if (i) {
if (selectKeys === i.sSqlConditionId) {
return true
}
if (i.children && i.children.length) {
const value = this.filterData(i.children, selectKeys);
if (value.length) {
i.children = value;
return true;
}
}
}
return false;
})
}
return [];
}
/** 树节点选中 */
handleTreeSelect = (name, checkedKeys, e, treeName) => {
if (treeName === 'filterTreeData' && Array.isArray(this.props.treeData)) {
if (['sOffsetwaste'].includes(this.props.app?.currentPane?.config?.sName)) {
const value = this.filterData(cloneDeep(this.props.treeData.slice(1,2)), checkedKeys?.[0]?.split('_')[1]);
this.setState({ filterTreeDetailData: value });
return;
}
if (['sFilmwaste'].includes(this.props?.app?.currentPane?.config?.sName)) {
this.setState({ slaveFilterKeys: checkedKeys?.[0]?.split('_')[1] });
return;
}
}
if (treeName === 'filterTreeDetailData') {
this.setState({ slaveFilterKeys: checkedKeys?.[0]?.split('_')[1] });
}
};
onExpandTree = (key, name) => {
this.setState({
[name]: key,
});
}
// ----------------------------数据修改回带end ---------------------------- //
render() {
const { pageLoading } = this.props;
const filterSpan = this.props.treeData?.length >= 2 ? this.props.filterSpan || 4 : 0;
const treeSpan = this.props.treeData?.length >= 1 ? this.props.treeSpan || 4 : 0;
const tableSpan = this.props.treeData?.length >= 2 ? this.props.tableSpan : 24 - filterSpan - treeSpan;
return (
<div style={{ height: "100%" }}>
<Spin spinning={pageLoading}>
<div style={{ height: "100%" }}>
<CommonListComponent
{...this.props}
{...this.state}
onSelect={this.handleSelect}
onCancel={this.handleCancelModal}
onDoubleClick={this.handleDoubleClickSelect}
onCheck={this.handleTreeCheck}
onSelectTree={this.handleTreeSelect}
onExpandTree={this.onExpandTree}
filterData={this.filterData}
filterTreeDetailSelectKeys={this.state.filterTreeDetailSelectKeys}
tableSpan={tableSpan}
treeSpan={treeSpan}
filterSpan={filterSpan}
/>
</div>
</Spin>
</div>
);
}
}
const CommonListComponent = Form.create({
mapPropsToFields(props) {
const { masterData } = props;
const obj = commonFunc.mapPropsToFields(masterData, Form);
return obj;
}
})(props => {
const {
form,
onReturnForm,
slavePagination,
app,
} = props;
/* 回带表单 */
onReturnForm(form);
const pagination = {
...slavePagination,
size: "large",
pageSize: 1000,
showQuickJumper: true,
hideOnSinglePage: true
};
const bEdit = commonUtils.isNotEmptyObject(app.currentPane) && commonUtils.isNotEmptyObject(app.currentPane.name) && app.currentPane.bEdit; /* 是否可编辑 */
const tableProps = {
...commonBusiness.getTableTypes("slave", props),
tableProps: {
rowKey: "sSlaveId",
pagination,
onChange: props.onTitleChange,
AutoTableHeight: 375,
},
bRowClick: bEdit,
enabled: bEdit,
onDelRow: (name, isWait, tableSelectedRowKeys, callback, index) => props.onDataRowDel(name, isWait, tableSelectedRowKeys, callback, index, props?.app?.currentPane?.config?.sControlName),
onAddRow: (name, isWait) => props.onDataRowAdd(name, isWait, props?.app?.currentPane?.config?.sControlName),
};
const treeProps = {
...commonBusiness.getTreeTypes("tree", props),
isSearch: false,
checkable: false,
disabled: false,
checkedAll: false,
unChecked: false,
defaultExpandAll: true,
multiple: false,
onSaveState: props.onSaveState
};
const tableBelone =
commonUtils.isNotEmptyObject(app.currentPane) &&
commonUtils.isNotEmptyObject(app.currentPane.name) &&
app.currentPane.bEdit
? "none"
: "list";
let slaveDataShow = props.slaveData || [];
if (props.slaveFilterKeys) {
slaveDataShow = props.slaveData.filter(i => i && i.sSqlConditionId === props.slaveFilterKeys);
}
return (
<div className="modalChooseProcessContent">
<Form>
<Layout>
<Layout>
<div>
<div style={{ maxHeight: "100%", zIndex: 20 }}>
<SearchComponent {...props} />
</div>
<Content
className="xly-normal-list"
style={{ paddingLeft: "10px" }}
>
<Row gutter={[8, 0]}>
<Col span={props.treeSpan}>
<div className="xly-tree-box">
<div className="xly-tree-title">过滤项</div>
<StaticEditTree
{...treeProps}
expandedKeys={props.filterTreeDataKey}
onExpandTree={(_, expandedKeys) => props.onExpandTree(expandedKeys, 'filterTreeDataKey')}
treeData={props.filterTreeData}
onSelect={(name, checkedKeys, e) => props.onSelectTree(name, checkedKeys, e, 'filterTreeData')}
/>
</div>
</Col>
<Col span={props.filterSpan}>
<div className="xly-tree-box">
<div className="xly-tree-title">过滤项</div>
<StaticEditTree
{...treeProps}
expandedKeys={props.filterTreeDetailDataKey}
onExpandTree={(_, expandedKeys) => props.onExpandTree(expandedKeys,'filterTreeDetailDataKey')}
treeData={props.filterTreeDetailData}
onSelect={(name, checkedKeys, e) => props.onSelectTree(name, checkedKeys, e, 'filterTreeDetailData')}
/>
</div>
</Col>
<Col span={props.tableSpan || 16}>
<StaticEditTable
{...tableProps}
data={slaveDataShow}
footer="hidden"
tableBelone={tableBelone}
noVlist
showConfig={props.showConfig}
setOpterationColumn={props.setOpterationColumn || 'Y'}
/>
</Col>
</Row>
</Content>
</div>
</Layout>
<div
style={{
textAlign: "right",
marginRight: "9px",
marginBottom: "9px"
}}
>
<Button
key="back"
style={{ marginRight: "8px" }}
onClick={props.onCancel}
>
取消
</Button>
<Button type="primary" onClick={props.onSelect}>
确认
</Button>
</div>
</Layout>
</Form>
</div>
);
});
export default CommonBase(CommonListEvent(CommonList));