doctorList.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Input, Button, Table, Select, Pagination, Space, TreeSelect, Tag } from 'antd';
  3. import { DownOutlined, PlusOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
  4. import apiObj from '@api/index';
  5. import { useSelector } from 'react-redux'
  6. import utils from '@utils/index'
  7. import { getOverflowOptions } from 'antd/lib/tooltip/placements';
  8. const { post, api, xPost } = apiObj;
  9. const { Option } = Select;
  10. const { SHOW_PARENT } = TreeSelect;
  11. const { organizationData } = utils;
  12. function DoctorList(props) {
  13. useEffect(() => {
  14. getDoctorPage();
  15. getHospitalTree()
  16. }, []);
  17. const { data,checkDoct} = props;
  18. const [form] = Form.useForm();
  19. const [doctorList, setDoctorList] = useState([]);
  20. const [name, setName] = useState("");
  21. const [phone, setPhone] = useState("");
  22. const [pages, setPages] = useState("1");
  23. const [current, setCurrent] = useState("5");
  24. const [treeData, setTreeData] = useState([]);
  25. // const [selectedRowKeys, setSelectedRowKeys] = useState([]);
  26. const [addHospitalTreeVO, setAddHospitalTreeVO] = useState({
  27. depts: [],
  28. hospitals: []
  29. });
  30. const selectedRowKeys = data
  31. //获取可看医生列表
  32. function getDoctorPage() {
  33. const param = {
  34. pages: pages,
  35. current: current,
  36. mobilePhone: phone,
  37. name: name,
  38. depts: addHospitalTreeVO.depts,
  39. hospitals: unique(addHospitalTreeVO.hospitals)
  40. }
  41. post(api.getDoctorPage, param).then((res) => {
  42. if (res.data.code === 200) {
  43. const data = res.data.data;
  44. setDoctorList(data.records);
  45. }
  46. })
  47. }
  48. //获取当前用户组织
  49. function getHospitalTree() {
  50. post(api.getHospitalTree).then((res) => {
  51. if (res.data.code === 200) {
  52. const data = res.data.data;
  53. let arr = data ? data : []
  54. arr = organizationData(arr)
  55. setTreeData(arr)
  56. }
  57. })
  58. }
  59. // 去重
  60. function unique(arr) {
  61. return arr.filter(function (item, index, arr) {
  62. return arr.indexOf(item, 0) === index;
  63. });
  64. }
  65. const onFinish = (value) => {
  66. getDoctorPage(value);
  67. };
  68. const onReset = () => {
  69. form.resetFields();
  70. getDoctorPage();
  71. };
  72. const handleName = (event) => {
  73. setName(event.target.value)
  74. }
  75. const handlePhone = (event) => {
  76. setPhone(event.target.value)
  77. }
  78. const columns = [
  79. { title: '姓名', dataIndex: 'name', key: 'index' },
  80. { title: '电话号码', dataIndex: 'mobilePhone', key: 'index' },
  81. { title: '所属组织', dataIndex: 'hospitalName', key: 'index' },
  82. ]
  83. const onChange = value => {
  84. let addHospitalTreeVO = {
  85. depts: [],
  86. hospitals: []
  87. }
  88. value.forEach(it => {
  89. let arr = it.split('-')
  90. let len = arr.length
  91. if (len == 3) {
  92. addHospitalTreeVO.depts.push(arr[2])
  93. } else {
  94. addHospitalTreeVO.hospitals.push(arr[1])
  95. treeData.forEach(item => {
  96. if (item.value.split('-')[1] == arr[1]) {
  97. item.children.forEach(its => {
  98. addHospitalTreeVO.depts.push(its.value.split('-')[2])
  99. })
  100. }
  101. })
  102. }
  103. })
  104. setAddHospitalTreeVO(addHospitalTreeVO)
  105. };
  106. function onSelectChange(selectedRowKeys){
  107. console.log(selectedRowKeys);
  108. checkDoct(selectedRowKeys)
  109. }
  110. function submit(){
  111. getDoctorPage()
  112. }
  113. return (
  114. <div className="wrapper">
  115. <div className="doctor_header">
  116. <div className="doctor_header_left">
  117. <div className="left_item">
  118. 姓名:<Input placeholder="用户名" onChange={e => handleName(e)} style={{ width: 160 }} />
  119. </div>
  120. <div className="left_item">
  121. 手机号码:<Input placeholder="用户名" onChange={e => handlePhone(e)} style={{ width: 160 }} />
  122. </div>
  123. <div className="left_item">
  124. 所属组织:
  125. <TreeSelect
  126. showSearch={false}
  127. treeData={treeData}
  128. onChange={onChange}
  129. treeCheckable
  130. maxTagCount={1}
  131. showCheckedStrategy={SHOW_PARENT}
  132. placeholder="请选择组织"
  133. style={{ width: 160 }}
  134. />
  135. </div>
  136. <div className="left_item">
  137. <Space size="middle">
  138. <Button onClick={onReset}>
  139. 重置
  140. </Button>
  141. <Button type="primary" onClick={submit}>
  142. 查询
  143. </Button>
  144. </Space>
  145. </div>
  146. </div>
  147. </div>
  148. <div className="table">
  149. <div className="table-header">
  150. <span className="table-header-title">医生列表</span>
  151. </div>
  152. <Table
  153. rowSelection={{
  154. selectedRowKeys,
  155. onChange: onSelectChange,
  156. }}
  157. columns={columns}
  158. dataSource={doctorList}
  159. rowKey={record => record.id +'-'+ record.name}
  160. pagination={{
  161. showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条数据`,
  162. pageSizeOptions: ['15', '30', '60', '120'],
  163. pageSize: 5,
  164. }} />
  165. </div>
  166. </div>
  167. )
  168. }
  169. export default DoctorList;