Files
scrm.antd/src/pages/DepartmentsList/index.tsx

301 lines
9.3 KiB
TypeScript
Raw Normal View History

2023-04-07 17:38:15 +08:00
import { SearchBarPlugin, SearchBottonsCardPlugin } from '@/components/SearchBarPlugin';
import { post } from '@/services/ajax';
import { PageContainer } from '@ant-design/pro-components';
2023-04-11 15:29:40 +08:00
import { Button, Col, Form, Input, Pagination, Row, Spin, Table, Tree } from 'antd';
import { stringify } from 'qs';
import React, { useEffect, useState } from 'react';
2023-04-07 17:38:15 +08:00
import styles from './index.module.scss';
2023-04-11 15:29:40 +08:00
interface IDepartment {
children: null | IDepartment[];
department_leader: string;
id: number;
name: string;
parent_id: number;
sort: number;
2023-04-07 17:38:15 +08:00
}
2023-04-11 15:29:40 +08:00
interface IStaffsItem {
user_id: string | number;
name: string;
telephone: string;
dep_name: string[];
position: string;
}
interface IStaffsData {
count: number;
data?: IStaffsItem[];
}
type Param = {
curr_page: number;
page_count: number;
dep_id: number;
name?: string;
position?: string;
telephone?: string;
};
2023-04-07 17:38:15 +08:00
const DepartmentsList: React.FC = () => {
2023-04-11 15:29:40 +08:00
const [param] = useState<Param>({
2023-04-07 17:38:15 +08:00
curr_page: 1,
page_count: 20,
2023-04-11 15:29:40 +08:00
dep_id: 0,
2023-04-07 17:38:15 +08:00
});
2023-04-11 15:29:40 +08:00
const [departmentID, setDepartmentsID] = useState<number>(0);
const [departmentsList, setDepartmentsList] = useState<IDepartment[]>([]);
const [staffsData, setStaffsData] = useState<IStaffsData>({ count: 0, data: [] });
const [loadingL, setLoadingL] = useState(false);
const [loading, setLoading] = useState(false);
const getDepartmentsList = () => {
setLoadingL(true);
post({ url: '/Departments/List' }).then((res) => {
setLoadingL(false);
if (res.err_code == 0) {
if (Array.isArray(res.data)) {
param.dep_id = res.data[0].id;
setDepartmentsID(param.dep_id);
setDepartmentsList(res.data);
getStaffsList();
}
}
});
};
const getStaffsList = () => {
setLoading(true);
post({ url: '/Staffs/List', data: stringify(param) }).then((res) => {
setLoading(false);
if (res.err_code == 0) {
if (!Array.isArray(res.data)) {
res.data = [];
}
setStaffsData(res as IStaffsData);
}
});
};
2023-04-07 17:38:15 +08:00
2023-04-11 15:29:40 +08:00
const page = (page: number) => {
param.curr_page = page;
getStaffsList();
};
2023-04-07 17:38:15 +08:00
2023-04-11 15:29:40 +08:00
useEffect(() => {
getDepartmentsList();
}, []);
2023-04-07 17:38:15 +08:00
2023-04-11 15:29:40 +08:00
// const [open, setOpen] = useState(false);
// const [popOpen, setPopOpen] = useState(-1);
2023-04-07 17:38:15 +08:00
return (
<PageContainer>
<div style={{ display: 'flex' }}>
<div
style={{
width: 260,
flexShrink: 0,
minHeight: 'calc(100vh - 55px - 60px - 96px)',
maxHeight: 'calc(100vh - 55px - 60px)',
overflow: 'auto',
marginRight: 12,
background: '#fff',
position: 'sticky',
top: 64,
padding: '12px 0',
}}
>
2023-04-11 15:29:40 +08:00
<Spin spinning={loadingL} style={{ display: 'block' }}>
{departmentsList.length ? (
<Tree
className={'department-tree'}
blockNode
selectedKeys={[departmentID]}
defaultExpandAll
treeData={departmentsList}
fieldNames={{ title: 'name', key: 'id' }}
onSelect={(selectedKeys) => {
if (selectedKeys.length) {
setDepartmentsID(Number(selectedKeys[0]));
param.dep_id = Number(selectedKeys[0]);
page(1);
}
}}
titleRender={(nodeData: any) => {
// console.log(nodeData);
return (
<div className={styles.departmentItem}>
<div className={styles.name} title={nodeData.name}>
{nodeData.name}
</div>
{/* <div className={styles.btnsBox}>
2023-04-07 17:38:15 +08:00
<FormOutlined
title="修改"
onClick={(e) => {
e.stopPropagation();
setOpen(true);
}}
className={styles.edit}
/>
<Popconfirm
title="确认删除?"
open={popOpen == nodeData.id}
onCancel={(e) => {
setPopOpen(-1);
e?.stopPropagation();
}}
onConfirm={(e) => {
e?.stopPropagation();
console.log(nodeData.id);
}}
>
<DeleteOutlined
title="删除"
onClick={(e) => {
e.stopPropagation();
setPopOpen(nodeData.id);
}}
className={styles.del}
/>
</Popconfirm>
2023-04-11 15:29:40 +08:00
</div> */}
</div>
);
}}
></Tree>
) : null}
</Spin>
2023-04-07 17:38:15 +08:00
</div>
2023-04-11 15:29:40 +08:00
{/* <Modal
2023-04-07 17:38:15 +08:00
open={open}
title="修改部门"
onCancel={() => setOpen(false)}
centered
onOk={() => {}}
>
<Form>
<Form.Item label="名称">
<Input type="text"></Input>
</Form.Item>
</Form>
2023-04-11 15:29:40 +08:00
</Modal> */}
2023-04-07 17:38:15 +08:00
<div style={{ flexGrow: 1, minWidth: 0 }}>
<SearchBarPlugin>
2023-04-11 15:29:40 +08:00
<Form autoComplete="off">
2023-04-07 17:38:15 +08:00
<Row gutter={{ xs: 0, sm: 16 }}>
2023-04-11 15:29:40 +08:00
<Col xs={24} sm={12} md={8}>
<Form.Item label="姓名">
<Input
autoComplete="off"
onChange={(e) => {
param.name = e.target.value.trim();
}}
allowClear
onPressEnter={() => page(1)}
></Input>
2023-04-07 17:38:15 +08:00
</Form.Item>
</Col>
2023-04-11 15:29:40 +08:00
<Col xs={24} sm={12} md={8}>
<Form.Item label="职位">
<Input
autoComplete="off"
onChange={(e) => {
param.position = e.target.value.trim();
}}
allowClear
onPressEnter={() => page(1)}
></Input>
2023-04-07 17:38:15 +08:00
</Form.Item>
</Col>
2023-04-11 15:29:40 +08:00
<Col xs={24} sm={12} md={8}>
<Form.Item label="手机号">
<Input
autoComplete="off"
onChange={(e) => {
param.telephone = e.target.value.trim();
}}
allowClear
onPressEnter={() => page(1)}
></Input>
2023-04-07 17:38:15 +08:00
</Form.Item>
</Col>
2023-04-11 15:29:40 +08:00
{/* <Col xs={24} sm={12} md={6}>
2023-04-07 17:38:15 +08:00
<Form.Item label="用户名">
<Select
defaultValue="lucy"
style={{ width: '100%' }}
onChange={() => {}}
options={[
{ value: 'jack', label: 'Jack' },
{ value: 'lucy', label: 'Lucy' },
{ value: 'Yiminghe', label: 'yiminghe' },
]}
/>
</Form.Item>
2023-04-11 15:29:40 +08:00
</Col> */}
2023-04-07 17:38:15 +08:00
</Row>
</Form>
</SearchBarPlugin>
<SearchBottonsCardPlugin>
<Row justify={'center'}>
<Button
type="primary"
onClick={() => {
2023-04-11 15:29:40 +08:00
page(1);
2023-04-07 17:38:15 +08:00
}}
>
</Button>
</Row>
</SearchBottonsCardPlugin>
<Table
2023-04-11 15:29:40 +08:00
tableLayout="fixed"
2023-04-07 17:38:15 +08:00
size="middle"
2023-04-11 15:29:40 +08:00
dataSource={staffsData.data}
2023-04-07 17:38:15 +08:00
style={{ padding: 16, borderRadius: 6, background: '#fff', marginTop: 16 }}
pagination={false}
bordered={true}
2023-04-11 15:29:40 +08:00
rowKey={'user_id'}
loading={loading}
2023-04-07 17:38:15 +08:00
>
2023-04-11 15:29:40 +08:00
<Table.Column title="姓名" dataIndex={'name'}></Table.Column>
<Table.Column title="职位" dataIndex={'position'}></Table.Column>
<Table.Column title="部门" dataIndex={'dep_name'}></Table.Column>
<Table.Column title="手机号" dataIndex={'telephone'}></Table.Column>
2023-04-07 17:38:15 +08:00
</Table>
<Pagination
style={{
background: '#fff',
borderRadius: 6,
marginTop: 16,
padding: 16,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
current={param.curr_page}
pageSize={param.page_count}
2023-04-11 15:29:40 +08:00
total={staffsData.count}
2023-04-07 17:38:15 +08:00
pageSizeOptions={[10, 20, 50, 100]}
onShowSizeChange={(current, size) => {
param.page_count = size;
2023-04-11 15:29:40 +08:00
// setParam({ ...param });
page(1);
2023-04-07 17:38:15 +08:00
}}
showTotal={(total, range) => {
return <span style={{ lineHeight: 1 }}>{total}</span>;
}}
2023-04-11 15:29:40 +08:00
onChange={(curr, pageSize) => {
page(curr);
2023-04-07 17:38:15 +08:00
}}
/>
</div>
</div>
</PageContainer>
);
};
export default DepartmentsList;