Commit adcfb38f authored by 皮倩雯's avatar 皮倩雯

解决事件管理全选失效问题

parent 9658e275
Pipeline #39379 skipped with stages
...@@ -11,7 +11,9 @@ import { Form, Modal, Divider, Checkbox } from 'antd'; ...@@ -11,7 +11,9 @@ import { Form, Modal, Divider, Checkbox } from 'antd';
import DragTable from '@/components/DragTable/DragTable'; import DragTable from '@/components/DragTable/DragTable';
import Sortable from 'sortablejs'; import Sortable from 'sortablejs';
import { add } from 'lodash-es';
import styles from './incident.less'; import styles from './incident.less';
import { setServiceType } from '@/services/webConfig/api';
const CheckboxGroup = Checkbox.Group; const CheckboxGroup = Checkbox.Group;
const AddModal = props => { const AddModal = props => {
const { const {
...@@ -38,6 +40,7 @@ const AddModal = props => { ...@@ -38,6 +40,7 @@ const AddModal = props => {
const [arrValue, setArrValue] = useState([]); const [arrValue, setArrValue] = useState([]);
const [data, setData] = useState([]); const [data, setData] = useState([]);
const [flagg, setFlagg] = useState(0); const [flagg, setFlagg] = useState(0);
const [type, setType] = useState();
let objArr = []; let objArr = [];
const onChangeList = (list, index, title) => { const onChangeList = (list, index, title) => {
...@@ -165,6 +168,75 @@ const AddModal = props => { ...@@ -165,6 +168,75 @@ const AddModal = props => {
isType, isType,
}); });
}; };
const onCheckAllChange1 = e => {
console.log(11212123213);
setData(1);
const indeterminateArr = [...indeterminate];
const checkAllArr = [...checkAll];
const checkedListArr = [...checkedList];
checkAllArr[e.target.index] = e.target.checked;
console.log(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);
// console.log(checkedListArr);
// console.log(arrValue);
// let objArr = [];
// checkedListArr.map((item, index) => {
// objArr = objArr.concat(item);
// });
// console.log(objArr);
// let newArr = [];
// let lastArr = [];
// arrValue.map(item => {
// if (item.name == undefined) {
// newArr = arrValue;
// } else {
// newArr = arrValue.map(item => item.name);
// }
// });
// console.log(newArr);
// if (e.target.checked == 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 = [];
// }
// console.log(newArr1);
// setSelectData(newArr1);
// setArrValue(lastArr);
// } else {
// let addArr = [];
// objArr.map(item => {
// if (newArr.indexOf(item) == -1) {
// addArr.push(item);
// }
// });
// console.log(addArr);
// addArr.map(item => {
// newArr.push(item);
// });
// console.log(newArr);
// let newArr1 = newArr.map(item => ({ name: item }));
// if (newArr1.length === 1 && newArr1[0].name === '') {
// newArr1 = [];
// }
// console.log(newArr1);
// setSelectData(newArr1);
// setArrValue(newArr);
// }
setCheckedList(checkedListArr);
setIndeterminate(indeterminateArr);
setCheckAll(checkAllArr);
};
const onCheckAllChange = e => { const onCheckAllChange = e => {
const indeterminateArr = [...indeterminate]; const indeterminateArr = [...indeterminate];
const checkAllArr = [...checkAll]; const checkAllArr = [...checkAll];
...@@ -182,9 +254,14 @@ const AddModal = props => { ...@@ -182,9 +254,14 @@ const AddModal = props => {
if (flagg == 0) { if (flagg == 0) {
selectAll(); selectAll();
} }
if (data == 1) {
selectAll();
}
setData(0);
}, [checkedList]); }, [checkedList]);
const selectAll = () => { const selectAll = () => {
console.log(data);
console.log(checkedList); console.log(checkedList);
objArr = []; objArr = [];
let lastArr = []; let lastArr = [];
...@@ -193,25 +270,71 @@ const AddModal = props => { ...@@ -193,25 +270,71 @@ const AddModal = props => {
}); });
console.log(arrValue); console.log(arrValue);
console.log(objArr); console.log(objArr);
arrValue.map(item => { if (data == 1) {
if (objArr.indexOf(item) != -1) { let newArr = [];
lastArr.push(item); arrValue.map(item => {
if (item.name == undefined) {
newArr = arrValue;
} else {
newArr = arrValue.map(item => item.name);
}
});
console.log(newArr);
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 = [];
}
console.log(newArr1);
setSelectData(newArr1);
setArrValue(lastArr);
} else {
let addArr = [];
objArr.map(item => {
if (newArr.indexOf(item) == -1) {
addArr.push(item);
}
});
console.log(addArr);
addArr.map(item => {
newArr.push(item);
});
console.log(newArr);
let newArr1 = newArr.map(item => ({ name: item }));
if (newArr1.length === 1 && newArr1[0].name === '') {
newArr1 = [];
}
console.log(newArr1);
setSelectData(newArr1);
setArrValue(newArr);
} }
}); } else {
let newArr1 = lastArr.map(item => ({ name: item })); arrValue.map(item => {
if (newArr1.length === 1 && newArr1[0].name === '') { if (objArr.indexOf(item) != -1) {
newArr1 = []; lastArr.push(item);
}
});
let newArr1 = lastArr.map(item => ({ name: item }));
if (newArr1.length === 1 && newArr1[0].name === '') {
newArr1 = [];
}
console.log(lastArr);
console.log(newArr1);
setSelectData(newArr1);
setArrValue(lastArr);
} }
console.log(newArr1);
setSelectData(newArr1);
setArrValue(lastArr);
}; };
useEffect(() => { useEffect(() => {
if (visible) { if (visible) {
setFlagg(1); setFlagg(1);
if (isType != '' && isType === 'add') { if (isType != '' && isType === 'add') {
console.log(filed);
let arr = Object.keys(filed); let arr = Object.keys(filed);
console.log(arr, 'arr'); console.log(arr, 'arr');
setTitle(arr); setTitle(arr);
...@@ -232,23 +355,6 @@ const AddModal = props => { ...@@ -232,23 +355,6 @@ const AddModal = props => {
); );
checkAllArr.push(checkArr[index].length === filed[item].length); checkAllArr.push(checkArr[index].length === filed[item].length);
}); });
// newCheckedList.map((item, index) => {
// if (b.includes(item) == false) {
// if(item == ''){
// a=[]
// }else{
// a.push(item)
// }
// }
// })
// if(a.length >0){
// filed.外部字段 = a
// console.log(filed)
// arr.push('外部字段')
// }
// setTitle(arr)
// checkArr.push(a)
setCheckedList(checkArr); setCheckedList(checkArr);
setIndeterminate(indeterminateArr); setIndeterminate(indeterminateArr);
setCheckAll(checkAllArr); setCheckAll(checkAllArr);
...@@ -261,6 +367,7 @@ const AddModal = props => { ...@@ -261,6 +367,7 @@ const AddModal = props => {
} }
console.log(newArr1); console.log(newArr1);
setSelectData(newArr1); setSelectData(newArr1);
setArrValue(newArr1);
} else if (isType === 'app') { } else if (isType === 'app') {
console.log(filed1); console.log(filed1);
let arr = Object.keys(filed1); let arr = Object.keys(filed1);
...@@ -288,23 +395,6 @@ const AddModal = props => { ...@@ -288,23 +395,6 @@ const AddModal = props => {
); );
checkAllArr.push(checkArr[index].length === filed1[item].length); checkAllArr.push(checkArr[index].length === filed1[item].length);
}); });
// newCheckedList.map((item, index) => {
// if (b.includes(item) == false) {
// if(item == ''){
// a=[]
// }else{
// a.push(item)
// }
// }
// })
// if(a.length >0){
// filed1.外部字段 = a
// console.log(filed1)
// arr.push('外部字段')
// }
// setTitle(arr)
// checkArr.push(a)
setCheckedList(checkArr); setCheckedList(checkArr);
setIndeterminate(indeterminateArr); setIndeterminate(indeterminateArr);
setCheckAll(checkAllArr); setCheckAll(checkAllArr);
...@@ -320,27 +410,6 @@ const AddModal = props => { ...@@ -320,27 +410,6 @@ const AddModal = props => {
} }
}, [visible]); }, [visible]);
// eslint-disable-next-line spaced-comment
//拖拽初始化及逻辑
// const draftSort = () => {
// let el = document.getElementById('doctor-drag-items');
// if (el) {
// let sortable = Sortable.create(el, {
// animation: 100, // 动画参数
// onEnd(evt) {
// // 拖拽完毕之后发生,只需关注该事件
// let arr = [];
// let len = evt.from.children.length;
// for (let i = 0; i < len; i++) {
// arr.push(evt.from.children[i].getAttribute('drag-id'));
// }
// console.log(arr);
// setSelectData(arr);
// },
// });
// }
// };
const dragCallBack = arr => { const dragCallBack = arr => {
if (arr) { if (arr) {
setSelectData(arr); setSelectData(arr);
...@@ -428,7 +497,7 @@ const AddModal = props => { ...@@ -428,7 +497,7 @@ const AddModal = props => {
> >
<Checkbox <Checkbox
indeterminate={indeterminate[index]} indeterminate={indeterminate[index]}
onChange={onCheckAllChange} onChange={onCheckAllChange1}
index={index} index={index}
checkvalue={filed[item]} checkvalue={filed[item]}
checked={checkAll[index]} checked={checkAll[index]}
...@@ -458,34 +527,6 @@ const AddModal = props => { ...@@ -458,34 +527,6 @@ const AddModal = props => {
</Divider> </Divider>
<div className={styles.cardContent}> <div className={styles.cardContent}>
<div className={styles.doctorTable}> <div className={styles.doctorTable}>
{/* <table>
<thead>
<tr>
<td>字段名</td>
</tr>
</thead>
<tbody id="doctor-drag-items">
{selectData && selectData.length > 0 ? (
selectData.map((item, index) => (
<tr
drag-id={item}
key={index}
style={{ cursor: 'move' }}
>
<td>
<span title={item}>{item}</span>
</td>
</tr>
))
) : (
<tr>
<td colSpan="10" style={{ textAlign: 'center' }}>
暂无数据
</td>
</tr>
)}
</tbody>
</table> */}
<DragTable <DragTable
bordered bordered
style={{ marginBottom: '10px' }} style={{ marginBottom: '10px' }}
...@@ -563,46 +604,6 @@ const AddModal = props => { ...@@ -563,46 +604,6 @@ const AddModal = props => {
))} ))}
</div> </div>
</div> </div>
{/* <div className={styles.cardItem}>
<Divider
orientation="left"
style={{ margin: '0 0 10px 0', backgroundColor: '#dfe8f6' }}
>
已选列表
</Divider>
<div className={styles.cardContent}>
<div className={styles.doctorTable}>
<table>
<thead>
<tr>
<td>字段名</td>
</tr>
</thead>
<tbody id="doctor-drag-items">
{selectData && selectData.length > 0 ? (
selectData.map((item, index) => (
<tr
drag-id={item}
key={index}
style={{ cursor: 'move' }}
>
<td>
<span title={item}>{item}</span>
</td>
</tr>
))
) : (
<tr>
<td colSpan="10" style={{ textAlign: 'center' }}>
暂无数据
</td>
</tr>
)}
</tbody>
</table>
</div>
</div>
</div> */}
</div> </div>
)} )}
</Modal> </Modal>
......
...@@ -226,24 +226,6 @@ ...@@ -226,24 +226,6 @@
} }
.doctorTable { .doctorTable {
margin-bottom: 16px; margin-bottom: 16px;
table {
width: 100%;
td {
padding: 6px;
border: 1px solid #e8e8e8;
}
thead {
tr {
font-weight: 600;
background: #fafafa;
}
}
tbody {
tr:hover {
background-color: #ededed;
}
}
}
} }
.ant-drawer-footer { .ant-drawer-footer {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment