|
|
@ -1,14 +1,17 @@ |
|
|
|
import { connect } from 'react-redux'; |
|
|
|
import './protable.less' |
|
|
|
import { Card, Button, DatePicker, Input, Modal, Spin, Image, message, Popover } from 'antd'; |
|
|
|
import { Card, Button, DatePicker, Input, Modal, Spin, Image, message, Popover, Tree, Tooltip } from 'antd'; |
|
|
|
import { DownOutlined, RightOutlined, CaretDownOutlined, CaretRightOutlined } from '@ant-design/icons'; |
|
|
|
import ProTable from '@ant-design/pro-table'; |
|
|
|
import { getReportList, getReportDetail } from '../actions/patrol'; |
|
|
|
import React, { useEffect, useState } from 'react'; |
|
|
|
import React, { useEffect, useState, useMemo } from 'react'; |
|
|
|
import { httpDel } from '@peace/utils' |
|
|
|
import { PinyinHelper } from '@peace/utils'; |
|
|
|
// @ts-ignore
|
|
|
|
import styles from './protable.less'; |
|
|
|
import moment from 'moment'; |
|
|
|
import { getAllDepUsers } from '../actions/allDepUsers' |
|
|
|
import { getDepMessage, getDepUser, createUser, updateUser, delUser, resetPwd, createDep, delDep, updateDep } from '../../organization/actions/user' |
|
|
|
import { reportTypeText } from './patrolTable' |
|
|
|
|
|
|
|
const DetailForm = (props) => { |
|
|
@ -219,9 +222,162 @@ const DetailList = (props) => { |
|
|
|
|
|
|
|
|
|
|
|
const PatrolNameList = (props) => { |
|
|
|
const { Search } = Input; |
|
|
|
const [users, setUsers] = useState([]); |
|
|
|
const { onChange, record, userList, loading } = props; |
|
|
|
const { onChange, record, userList, loading, depMessage, depUser, clientHeight, dispatch } = props; |
|
|
|
const [selectRoad, setSelectRoad] = useState(); |
|
|
|
const [selectedTree, setSelectedTree] = useState(); |
|
|
|
const [depSelectedKeys, setDepSelectedKeys] = useState([]) |
|
|
|
const [depAllUser, setDepAllUser] = useState([]) |
|
|
|
const [depMessagedata, setdepMessagedata] = useState(depMessage) |
|
|
|
const [expandedKeys, setExpandedKeys] = useState([]); |
|
|
|
const [searchValue, setSearchValue] = useState(''); |
|
|
|
const [autoExpandParent, setAutoExpandParent] = useState(true); |
|
|
|
//const [departments, setDepartments] = useState([])
|
|
|
|
|
|
|
|
// useEffect(() => {
|
|
|
|
// if (depAllUser && depAllUser.length > 0) {
|
|
|
|
// depAllUser.map((item) => {
|
|
|
|
// item.expanded = false
|
|
|
|
// departments.push(item)
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
// console.log('departments1', departments)
|
|
|
|
// }, [depAllUser])
|
|
|
|
const departments = [ |
|
|
|
{ |
|
|
|
id: 1, |
|
|
|
name: '部门A', |
|
|
|
users: [{ id: 1, name: '癌病' }, { id: 2, name: 'zjah' }], |
|
|
|
expanded: true, // 初始状态展开
|
|
|
|
}, |
|
|
|
{ |
|
|
|
id: 2, |
|
|
|
name: '部门B', |
|
|
|
users: [{ id: 3, name: '癌病' }, { id: 4, name: 'zjah' }], |
|
|
|
expanded: false, // 初始状态折叠
|
|
|
|
}, |
|
|
|
]; |
|
|
|
const defaultData = []; |
|
|
|
const generateData = (data, _preKey, _tns) => { |
|
|
|
const preKey = _preKey || '0'; |
|
|
|
const tns = _tns || defaultData; |
|
|
|
const children = []; |
|
|
|
data.forEach(department => { |
|
|
|
const key = `${preKey}-${department.id}`; |
|
|
|
const node = { |
|
|
|
title: department.name, |
|
|
|
key, |
|
|
|
children: [], |
|
|
|
}; |
|
|
|
console.log('lenght', department) |
|
|
|
if (department.users.length > 0) { // 仅当部门有用户时添加子节点
|
|
|
|
department.users.forEach(user => { |
|
|
|
node.children.push({ |
|
|
|
title: user.name, |
|
|
|
key: `${key}-${user.id}`, |
|
|
|
isLeaf: true, // 用户节点为叶子节点
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
if (department.children && department.children.length > 0) { |
|
|
|
node.children = generateData(department.children, key, node.children); |
|
|
|
} |
|
|
|
|
|
|
|
tns.push(node); |
|
|
|
if (node.children.length > 0 && department.expanded) { // 仅当部门展开时添加子节点
|
|
|
|
children.push(key); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
return children; |
|
|
|
}; |
|
|
|
console.log(depAllUser, 'sssllg') |
|
|
|
generateData(depAllUser); |
|
|
|
|
|
|
|
const dataList = []; |
|
|
|
const generateList = (data) => { |
|
|
|
for (let i = 0; i < data.length; i++) { |
|
|
|
const item = data[i]; |
|
|
|
const { key, title } = item; |
|
|
|
dataList.push({ |
|
|
|
key, |
|
|
|
title, |
|
|
|
}); |
|
|
|
if (item.children && item.children.length > 0) { |
|
|
|
generateList(item.children); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
generateList(defaultData); |
|
|
|
|
|
|
|
const getParentKey = (key, tree) => { |
|
|
|
let parentKey; |
|
|
|
for (let i = 0; i < tree.length; i++) { |
|
|
|
const node = tree[i]; |
|
|
|
if (node.children) { |
|
|
|
if (node.children.some((item) => item.key === key)) { |
|
|
|
parentKey = node.key; |
|
|
|
} else if (getParentKey(key, node.children)) { |
|
|
|
parentKey = getParentKey(key, node.children); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return parentKey; |
|
|
|
}; |
|
|
|
|
|
|
|
const handleSearch = (value) => { |
|
|
|
const expandedKeys = dataList |
|
|
|
.map((item) => { |
|
|
|
if (item.title.indexOf(value) > -1) { |
|
|
|
return getParentKey(item.key, defaultData); |
|
|
|
} |
|
|
|
return null; |
|
|
|
}) |
|
|
|
.filter((item, i, self) => item && self.indexOf(item) === i); |
|
|
|
|
|
|
|
setSearchValue(value); |
|
|
|
setExpandedKeys(expandedKeys); |
|
|
|
}; |
|
|
|
|
|
|
|
const handleExpand = (expandedKeys) => { |
|
|
|
setExpandedKeys(expandedKeys); |
|
|
|
}; |
|
|
|
const treeData = useMemo(() => { |
|
|
|
const loop = (data) => |
|
|
|
data.map((item) => { |
|
|
|
const { title, key, children } = item; |
|
|
|
const strTitle = title.toString(); |
|
|
|
const index = strTitle.indexOf(searchValue); |
|
|
|
const beforeStr = strTitle.substring(0, index); |
|
|
|
const afterStr = strTitle.slice(index + searchValue.length); |
|
|
|
const titleNode = index > -1 ? ( |
|
|
|
<span> |
|
|
|
{beforeStr} |
|
|
|
<span style={{ color: '#f50' }}>{searchValue}</span> |
|
|
|
{afterStr} |
|
|
|
</span> |
|
|
|
) : ( |
|
|
|
<span>{strTitle}</span> |
|
|
|
); |
|
|
|
|
|
|
|
if (children && children.length > 0) { |
|
|
|
return { |
|
|
|
title: titleNode, |
|
|
|
key, |
|
|
|
children: loop(children), |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
title: titleNode, |
|
|
|
key, |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
return loop(defaultData); |
|
|
|
}, [searchValue]); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
if (userList && userList instanceof Array && userList.length) { |
|
|
@ -229,67 +385,32 @@ const PatrolNameList = (props) => { |
|
|
|
// onChange(userList[0]);
|
|
|
|
} |
|
|
|
}, [userList]) |
|
|
|
const columns = [ |
|
|
|
{ |
|
|
|
title: '养护人员', |
|
|
|
key: 'name', |
|
|
|
dataIndex: 'name', |
|
|
|
align: 'center' |
|
|
|
}, |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
dispatch(getAllDepUsers()).then((res) => { |
|
|
|
if (res.success) setDepAllUser(res?.payload?.data) |
|
|
|
}) |
|
|
|
}, []) |
|
|
|
useEffect(() => { |
|
|
|
if (userList && userList instanceof Array) { |
|
|
|
let users = userList.filter(user => user.remark != 'sp'); |
|
|
|
setUsers(users); |
|
|
|
} |
|
|
|
}, [userList]) |
|
|
|
|
|
|
|
var timer = null; |
|
|
|
const doUserNameSearch = (e) => { |
|
|
|
const name = e.target.value; |
|
|
|
if (timer) { |
|
|
|
clearTimeout(timer) |
|
|
|
} else { |
|
|
|
setTimeout(() => { |
|
|
|
let users = userList.filter(user => PinyinHelper.isSearchMatched(user.name, name) && user.remark != 'sp'); |
|
|
|
setUsers(users); |
|
|
|
}, 500); |
|
|
|
} |
|
|
|
if (loading) { |
|
|
|
return <div>Loading...</div> |
|
|
|
} |
|
|
|
|
|
|
|
return ( |
|
|
|
<div className='spilce'> |
|
|
|
<ProTable |
|
|
|
columns={columns} |
|
|
|
dataSource={users} |
|
|
|
loading={loading} |
|
|
|
rowKey="name" |
|
|
|
rowClassName={(record) => { |
|
|
|
return record.id == selectRoad ? 'list-row-actived' : ''; |
|
|
|
}} |
|
|
|
toolBarRender={() => [ |
|
|
|
<Input placeholder='输入养护人员名称' onChange={doUserNameSearch} ></Input> |
|
|
|
]} |
|
|
|
options={false} |
|
|
|
pagination={false} |
|
|
|
search={false} |
|
|
|
onRow={(record) => { |
|
|
|
return { |
|
|
|
onClick: () => { |
|
|
|
if (record) { |
|
|
|
let id = record.id |
|
|
|
if (selectRoad == record.id) { |
|
|
|
id = null |
|
|
|
} |
|
|
|
setSelectRoad(id); |
|
|
|
onChange(id ? record : null); |
|
|
|
} |
|
|
|
}, |
|
|
|
}; |
|
|
|
}} |
|
|
|
/></div> |
|
|
|
<Search |
|
|
|
placeholder="搜索" |
|
|
|
value={searchValue} |
|
|
|
onChange={(e) => handleSearch(e.target.value)} |
|
|
|
/> |
|
|
|
{depAllUser.length > 0 && depAllUser && ( |
|
|
|
<Tree expandedKeys={expandedKeys} onExpand={handleExpand} treeData={treeData}> |
|
|
|
</Tree> |
|
|
|
)} |
|
|
|
</div> |
|
|
|
|
|
|
|
); |
|
|
|
}; |
|
|
@ -297,7 +418,7 @@ const PatrolNameList = (props) => { |
|
|
|
|
|
|
|
|
|
|
|
const MaintenanceTable = (props) => { |
|
|
|
const { userList, user, reportList, dispatch, reportListLoading, reportDetail, reportDetailLoading, userLoading, exports } = props; |
|
|
|
const { userList, user, reportList, dispatch, reportListLoading, reportDetail, reportDetailLoading, userLoading, exports, depMessage, depUser, clientHeight } = props; |
|
|
|
const [record, setRecord] = useState(); |
|
|
|
const [dateRange, setDateRange] = useState(); |
|
|
|
const [detailVisible, setDetailVisible] = useState(false) |
|
|
@ -360,7 +481,9 @@ const MaintenanceTable = (props) => { |
|
|
|
return ( |
|
|
|
<div className='card-protable'> |
|
|
|
<Card > |
|
|
|
<PatrolNameList onChange={(record) => setRecord(record)} record={record} userList={userList} loading={userLoading} handelRefresh={handelRefresh} /> |
|
|
|
<PatrolNameList |
|
|
|
depMessage={depMessage} depUser={depUser} clientHeight={clientHeight} dispatch={dispatch} |
|
|
|
onChange={(record) => setRecord(record)} record={record} userList={userList} loading={userLoading} handelRefresh={handelRefresh} /> |
|
|
|
</Card> |
|
|
|
<Card style={{ flex: 1 }} > |
|
|
|
<div style={{ marginBottom: 20 }}> |
|
|
@ -386,8 +509,8 @@ const MaintenanceTable = (props) => { |
|
|
|
); |
|
|
|
}; |
|
|
|
|
|
|
|
function mapStateToProps (state) { |
|
|
|
const { auth, depMessage, userList, reportList, reportDetail } = state; |
|
|
|
function mapStateToProps(state) { |
|
|
|
const { auth, depMessage, userList, reportList, reportDetail, depUser, global } = state; |
|
|
|
const pakData = (dep) => { |
|
|
|
return dep.map((d) => { |
|
|
|
return { |
|
|
@ -399,6 +522,7 @@ function mapStateToProps (state) { |
|
|
|
} |
|
|
|
let depData = pakData(depMessage.data || []) |
|
|
|
return { |
|
|
|
clientHeight: global.clientHeight, |
|
|
|
user: auth.user, |
|
|
|
depMessage: depMessage.data || [], |
|
|
|
depLoading: depMessage.isRequesting, |
|
|
@ -409,6 +533,8 @@ function mapStateToProps (state) { |
|
|
|
reportListLoading: reportList.isRequesting, |
|
|
|
reportDetail: reportDetail.data, |
|
|
|
reportDetailLoading: reportDetail.isRequesting, |
|
|
|
depUser: depUser.data || [], |
|
|
|
|
|
|
|
}; |
|
|
|
} |
|
|
|
export default connect(mapStateToProps)(MaintenanceTable); |