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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/* eslint-disable no-undef */
/* eslint-disable guard-for-in */
/* eslint-disable no-restricted-syntax */
/* eslint-disable camelcase */
/* eslint-disable react/jsx-no-undef */
/* eslint-disable valid-typeof */
/* eslint-disable no-unused-vars */
/* eslint-disable consistent-return */
/* eslint-disable no-shadow */
/* eslint-disable indent */
/* eslint-disable no-unused-expressions */
/* eslint-disable array-callback-return */
/* eslint-disable eqeqeq */
/* eslint-disable no-plusplus */
import React, { useState, useEffect, useCallback, useRef } from 'react';
import { Form, Modal, Divider, Checkbox, Tabs, Empty } from 'antd';
import DragTable from '@/components/DragTable/DragTable';
import classnames from 'classnames';
import styles from '../incident.less';
const CheckboxGroup = Checkbox.Group;
const EditModal = props => {
const { callBackSubmit = () => { }, pickItem, visible, filed, newCheckedList, flag } = props;
const [loading, setLoading] = useState(false);
const [value, setValue] = useState('');
const [checkValue, setCheckValue] = useState([]);
const [form] = Form.useForm();
const [title, setTitle] = useState([]);
const { Item } = Form;
const [checkedList, setCheckedList] = useState([]); // 选中复选框内容
const [indeterminate, setIndeterminate] = useState([]);
const [checkAll, setCheckAll] = useState([]);
const [selectData, setSelectData] = useState([]);
const [arrValue, setArrValue] = useState([]);
const [data, setData] = useState(0);
const [flagg, setFlagg] = useState(0);
const [type, setType] = useState(); // 是否全选
let objArr = [];
const onChangeList = (list, index, title) => {
const checkedListArr = [...checkedList];
checkedListArr[index] = list;
// 将第一次打开回显数据先存成数组
let oldArr = [];
let addArr = [];
let newArr = [];
// if (flagg == 0) {
arrValue.map((item, index) => {
oldArr = oldArr.concat(item);
});
console.log(oldArr);
// 将第一次打开回显数据存入已选择数组里
oldArr.map(item => {
newArr.push(item);
});
console.log(newArr);
// 获取本次新增数据后的数组
let objArr = [];
checkedListArr.map(item => {
objArr = objArr.concat(item);
});
console.log(checkedListArr);
console.log(objArr); // 本次增加数据后数组
console.log(arrValue); // 上次数组
// 获取新增数据
objArr.map((item1, index1) => {
if (arrValue.indexOf(item1) == -1) {
addArr.push(item1);
}
});
// 将每次新增数据从尾部写入已选择数组里
if (addArr.length != 0) {
addArr.map(item => {
newArr.push(item);
});
}
// 保存此次所有数据顺序
setArrValue(newArr);
setCheckedList(checkedListArr);
const indeterminateArr = [...indeterminate];
const checkAllArr = [...checkAll];
indeterminateArr[index] = !!list.length && list.length < filed[title].length;
checkAllArr[index] = list.length === filed[title].length;
setIndeterminate(indeterminateArr);
setCheckAll(checkAllArr);
setFlagg(0);
};
const onSubmit1 = () => {
let aRR = [];
selectData.map(item => {
if (typeof item == 'string') {
aRR = selectData;
} else {
aRR.push(item.name);
}
});
let newArr = selectData.map(item => item.name);
let valueArr = [];
if (filed.外部字段) {
newArr.forEach(item => {
if (filed.外部字段.indexOf(item) != -1) {
valueArr.push(item);
}
});
}
callBackSubmit({
valueArr,
checkedList,
str: aRR.join(','),
pickItem,
stt: aRR,
title,
});
};
const onCheckAllChange1 = e => {
setData(1);
const indeterminateArr = [...indeterminate];
const checkAllArr = [...checkAll];
const checkedListArr = [...checkedList];
checkAllArr[e.target.index] = e.target.checked;
indeterminateArr[e.target.index] = false;
e.target.checked
? (checkedListArr[e.target.index] = e.target.checkvalue)
: (checkedListArr[e.target.index] = []);
setType(e.target.checked);
setCheckedList(checkedListArr);
setIndeterminate(indeterminateArr);
setCheckAll(checkAllArr);
};
useEffect(() => {
selectAll();
// console.log(flagg);
// // 不是第一次
// if (flagg == 0) {
// console.log(12121);
// selectAll();
// }
// // 是否是全选
// if (data == 1) {
// selectAll();
// }
setData(0);
}, [checkedList]);
const selectAll = () => {
objArr = [];
let lastArr = [];
// 处理未排序的勾选数据扁平化
checkedList.map(item => {
objArr = objArr.concat(item);
});
// 判断是否操作全部勾选的复选框
if (data == 1) {
// 处理上次选中改变顺序后的数据扁平化
let newArr = [];
arrValue.map(item => {
if (item.name == undefined) {
newArr = arrValue;
} else {
newArr = arrValue.map(item => item.name);
}
});
// 判断是否为全选
if (type == false) {
// 判断上次有顺序的数据是否包含这次未排序已选列表数据
newArr.map(item => {
if (objArr.indexOf(item) != -1) {
lastArr.push(item);
}
});
let newArr1 = lastArr.map(item => ({ name: item }));
if (newArr1.length === 1 && newArr1[0].name === '') {
newArr1 = [];
}
setSelectData(newArr1);
setArrValue(lastArr);
} else {
// 全选状态时
let addArr = [];
objArr.map(item => {
if (newArr.indexOf(item) == -1) {
addArr.push(item);
}
});
addArr.map(item => {
newArr.push(item);
});
let newArr1 = newArr.map(item => ({ name: item }));
if (newArr1.length === 1 && newArr1[0].name === '') {
newArr1 = [];
}
setSelectData(newArr1);
setArrValue(newArr);
}
} else {
// 判断扁平处理后的选中未排序列表数据是否存在于上次已选数组中
arrValue.map(item => {
if (objArr.indexOf(item) != -1) {
lastArr.push(item);
}
});
let newArr1 = lastArr.map(item => ({ name: item }));
if (newArr1.length === 1 && newArr1[0].name === '') {
newArr1 = [];
}
setSelectData(newArr1);
setArrValue(lastArr);
}
};
useEffect(() => {
if (visible) {
setFlagg(1);
let arr = Object.keys(filed);
console.log(arr, 'arr');
setTitle(arr);
let checkArr = [];
let indeterminateArr = [];
let checkAllArr = [];
arr.map((item, index) => {
checkArr[index] = [];
newCheckedList.map(checkItem => {
if (filed[item].includes(checkItem)) {
checkArr[index].push(checkItem);
}
});
indeterminateArr.push(
!!checkArr[index].length && checkArr[index].length < filed[item].length,
);
checkAllArr.push(checkArr[index].length === filed[item].length);
});
setCheckedList(checkArr);
setIndeterminate(indeterminateArr);
setCheckAll(checkAllArr);
let newArr1 = newCheckedList.map(item => ({ name: item }));
if (newArr1.length === 1 && newArr1[0].name === '') {
newArr1 = [];
}
setSelectData(newArr1);
setArrValue(newArr1);
}
}, [visible]);
const dragCallBack = arr => {
if (arr) {
setSelectData(arr);
let newArr = [];
arr.map(item => {
newArr.push(item.name);
});
setArrValue(newArr);
}
};
const columns = [
{
title: '已选列表',
dataIndex: 'name',
width: 150,
key: 'name',
},
];
return (
<Modal
title="字段集选择"
bodyStyle={{ width: '100%', minHeight: '100px' }}
width="750px"
destroyOnClose
centered
cancelText="取消"
okText="确认"
{...props}
onOk={() => onSubmit1()}
forceRender
getContainer={false}
>
{visible && (
<div className={styles.listCard}>
<div className={styles.cardItem} style={{ borderRight: '1px solid #99bbe8' }}>
{flag === 0 ? (
<>
<div className={styles.cardContent}>
<span
style={{
color: 'red',
fontSize: '1rem',
marginLeft: '25px',
}}
>
请先选择事件主表
</span>
</div>
</>
) : (
<>
{JSON.stringify(filed) == '{}' ? (
<>
<div className={styles.cardContent}>
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
description="表字段缺失请先配置表/字段"
/>
</div>
</>
) : (
<>
<div className={styles.cardContent}>
{title.map((item, index) => (
<div
className={classnames({
[styles.cardItemData]: true,
[styles.cardItemData1]: item == '外部字段',
})}
key={index}
>
<Divider
orientation="left"
style={{
margin: '0 0 10px 0',
color: '#15428b',
borderTopColor: '#99bbe8',
}}
>
<Checkbox
indeterminate={indeterminate[index]}
onChange={onCheckAllChange1}
index={index}
checkvalue={filed[item]}
checked={checkAll[index]}
style={{ marginRight: '7px' }}
/>
{item == '外部字段' && <span style={{ color: 'red' }}>{item}</span>}
{item == '内置字段' && <span>{`${item}(谨慎选择)`}</span>}
{item != '外部字段' && item != '内置字段' && <span>{item}</span>}
</Divider>
<CheckboxGroup
options={filed[item]}
value={checkedList[index]}
onChange={e => onChangeList(e, index, item)}
/>
</div>
))}
</div>
</>
)}
</>
)}
</div>
<div className={styles.cardItem}>
<div className={styles.cardContent}>
<div className={styles.doctorTable}>
<DragTable
bordered
style={{ marginBottom: '10px' }}
rowKey={record => record.name}
columns={columns}
dataSource={selectData}
pagination={false}
size="small"
dragCallBack={dragCallBack}
ItemTypes="stadingOrder"
/>
</div>
</div>
</div>
</div>
)}
</Modal>
);
};
export default EditModal;