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

fix: '默认承办人支持搜索'

parent d8cdec6b
Pipeline #81850 passed with stages
/* eslint-disable no-lonely-if */
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { GetRoleUser } from '@/services/workflow/workflow'; import { GetRoleUser } from '@/services/workflow/workflow';
import { Modal, Checkbox, notification, Empty, Divider } from 'antd'; import { Modal, Checkbox, notification, Empty, Divider, Input } from 'antd';
import './Undertaker.less'; import './Undertaker.less';
const { Search } = Input;
const Undertaker = props => { const Undertaker = props => {
const { onSubumit, handleCancel, visible, chooseUser } = props; const { onSubumit, handleCancel, visible, chooseUser } = props;
const [checkedList, setCheckedList] = useState([]); // 选中的数据 const [checkedList, setCheckedList] = useState([]); // 选中的数据
...@@ -9,9 +12,11 @@ const Undertaker = props => { ...@@ -9,9 +12,11 @@ const Undertaker = props => {
const [indeterminate, setIndeterminate] = useState(false); // 全选框的有选择但是没有全选的样式 const [indeterminate, setIndeterminate] = useState(false); // 全选框的有选择但是没有全选的样式
const [checkAll, setCheckAll] = useState(false); // 全选框全选样式 const [checkAll, setCheckAll] = useState(false); // 全选框全选样式
const CheckboxGroup = Checkbox.Group; const CheckboxGroup = Checkbox.Group;
const [searchValue, setSearchValue] = useState();
const [keepCheckedList, setKeepCheckedList] = useState([]);
useEffect(() => { useEffect(() => {
if (visible) { if (visible) {
getData(); getData('', '1');
} else { } else {
setCheckedList([]); setCheckedList([]);
setPlainOptions([]); setPlainOptions([]);
...@@ -19,24 +24,59 @@ const Undertaker = props => { ...@@ -19,24 +24,59 @@ const Undertaker = props => {
setIndeterminate(false); setIndeterminate(false);
} }
}, [visible]); }, [visible]);
useEffect(() => { // useEffect(() => {
// 选中列表回显 // // 选中列表回显
if (chooseUser && plainOptions.length > 0) { // console.log(keepCheckedList);
onChange(chooseUser.defaultUserId); // debugger;
} // if (chooseUser && plainOptions.length > 0) {
}, [plainOptions]); // if (keepCheckedList) {
// // onChange(chooseUser.defaultUserId);
// } else {
// onChange(chooseUser.defaultUserId);
// }
// }
// }, [plainOptions]);
// 获取可选默认承办人数据 // 获取可选默认承办人数据
const getData = () => { const getData = (val, flag) => {
GetRoleUser({ GetRoleUser({
pageIndex: 1, pageIndex: 1,
pageSize: 1, pageSize: 1,
roleId: chooseUser.roleId, roleId: chooseUser.roleId,
Type: Number(chooseUser.type), Type: Number(chooseUser.type),
keyword: val ? val : searchValue,
}).then(res => { }).then(res => {
if (res.code === 0) { if (res.code === 0) {
let data = res.data.data[0].userList.map(item => ({ value: item.id, label: item.name })); let arr = [];
let data = res.data.data[0].userList.map(item => {
arr.push(item.id);
return { value: item.id, label: item.name };
});
setPlainOptions(data); setPlainOptions(data);
if (flag) {
setCheckedList(chooseUser.defaultUserId);
setKeepCheckedList(chooseUser.defaultUserId);
setIndeterminate(
!!chooseUser.defaultUserId.length && chooseUser.defaultUserId.length < data.length,
);
setCheckAll(chooseUser.defaultUserId.length === data.length);
} else {
if (val) {
let list = [];
checkedList.forEach(i => {
if (arr.indexOf(i) !== -1) {
list.push(i);
}
});
setCheckedList(list);
setIndeterminate(!!list.length && list.length < data.length);
setCheckAll(list.length === data.length);
} else {
setCheckedList(keepCheckedList);
setIndeterminate(!!keepCheckedList.length && keepCheckedList.length < data.length);
setCheckAll(keepCheckedList.length === data.length);
}
}
} else { } else {
notification.error({ notification.error({
message: '提示', message: '提示',
...@@ -46,6 +86,7 @@ const Undertaker = props => { ...@@ -46,6 +86,7 @@ const Undertaker = props => {
} }
}); });
}; };
// 保存选择默认承办人 // 保存选择默认承办人
const onSave = () => { const onSave = () => {
let userName = []; let userName = [];
...@@ -60,18 +101,54 @@ const Undertaker = props => { ...@@ -60,18 +101,54 @@ const Undertaker = props => {
}); });
onSubumit(userName.join(','), checkedList); onSubumit(userName.join(','), checkedList);
}; };
// 复选框全选监听 // 复选框全选监听
const onCheckAllChange = e => { const onCheckAllChange = e => {
let allOptions = plainOptions.map(item => item.value); let allOptions = plainOptions.map(item => item.value);
if (e.target.checked) {
let data = Array.from(new Set([...keepCheckedList, ...allOptions]));
setKeepCheckedList(data);
} else {
let arr = [...keepCheckedList];
allOptions.forEach(i => {
if (arr.indexOf(i) !== -1) {
arr = arr.filter(item => item !== i);
}
});
setKeepCheckedList(arr);
}
setCheckedList(e.target.checked ? allOptions : []); setCheckedList(e.target.checked ? allOptions : []);
setIndeterminate(false); setIndeterminate(false);
setCheckAll(e.target.checked); setCheckAll(e.target.checked);
}; };
// 复选框监听事件 // 复选框监听事件
const onChange = list => { const onChange = list => {
setCheckedList(list); setCheckedList(list);
setIndeterminate(!!list.length && list.length < plainOptions.length); setIndeterminate(!!list.length && list.length < plainOptions.length);
setCheckAll(list.length === plainOptions.length); setCheckAll(list.length === plainOptions.length);
if (list.length > checkedList.length) {
let data = Array.from(new Set([...keepCheckedList, ...list]));
setKeepCheckedList(data);
} else {
let arr = [...keepCheckedList];
checkedList.forEach(i => {
if (list.indexOf(i) === -1) {
arr = arr.filter(item => item !== i);
}
});
setKeepCheckedList(arr);
}
};
// 获取搜索框的值
const handleSearch = e => {
setSearchValue(e.target.value);
};
const submitSearchUser = e => {
getData(e);
}; };
return ( return (
<div> <div>
...@@ -85,9 +162,20 @@ const Undertaker = props => { ...@@ -85,9 +162,20 @@ const Undertaker = props => {
destroyOnClose destroyOnClose
> >
<div> <div>
<Checkbox indeterminate={indeterminate} onChange={onCheckAllChange} checked={checkAll}> <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
<span style={{ fontWeight: 700 }}>用户列表</span> <Checkbox indeterminate={indeterminate} onChange={onCheckAllChange} checked={checkAll}>
</Checkbox> <span style={{ fontWeight: 700 }}>用户列表</span>
</Checkbox>
<Search
style={{
width: '180px',
}}
placeholder="请输入用户名称"
value={searchValue}
onSearch={submitSearchUser}
onChange={e => handleSearch(e)}
/>
</div>
<Divider style={{ margin: '10px 0' }} /> <Divider style={{ margin: '10px 0' }} />
<div style={{ height: '380px', overflowY: 'scroll' }}> <div style={{ height: '380px', overflowY: 'scroll' }}>
{plainOptions.length > 0 ? ( {plainOptions.length > 0 ? (
......
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