SelectContact.jsx 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Select, Modal, Button, Table, Divider, Tag, Input,Row,Col,Icon,Pagination } from 'antd';
  3. import request from '../../../../utils/request';
  4. import apis from '../../../../services/apis';
  5. import styles from '../style.less';
  6. const { Column, ColumnGroup } = Table;
  7. const SelectContact = props => {
  8. const [data, setData] = useState([]);
  9. const [visible, setVisible] = useState(false);
  10. const [group, setGroup] = useState({ groupId: undefined, groupName: '请选择' })
  11. const [selectedData, setSelectedData ] = useState([]);
  12. useEffect(() => {
  13. if (props.value && props.value != selectedData) {
  14. setSelectedData(props.value)
  15. }
  16. }, [props.value])
  17. // 查询列表
  18. const getList = (params) => {
  19. request({ ...apis.contact.list, params: { ...params } }).then((data) => {
  20. console.log(data)
  21. setData(data)
  22. })
  23. }
  24. useEffect(() => {
  25. getList({ pageNum: 1, pageSize: 10,})
  26. }, []);
  27. const handleChange = val => {
  28. }
  29. const selectData = val => {
  30. const list = selectedData.filter(x => x.contactId !== val.contactId).concat(val)
  31. setSelectedData(list)
  32. props.onSelected(list)
  33. setVisible(false)
  34. }
  35. // 提交事件
  36. const handleSubmit = (e, props) => {
  37. e.preventDefault();
  38. e.stopPropagation();
  39. props.form.validateFields((err, values) => {
  40. if (!err) {
  41. getList({ pageNum: 1, pageSize: 10, ...values })
  42. }
  43. });
  44. }
  45. function handleReset() {
  46. props.form.resetFields();
  47. getList({ pageNum: 1, pageSize: 10 })
  48. }
  49. const changePageNum = (pageNumber) => {
  50. getList({ pageNum: pageNumber, pageSize: 10 })
  51. }
  52. const removeSelected = (val) => {
  53. const list = selectedData.filter(x => x.contactId !== val.contactId)
  54. setSelectedData(list)
  55. props.onSelected(list)
  56. }
  57. const columns = [
  58. {
  59. title: '姓名',
  60. dataIndex: 'contactName',
  61. key: 'drainageId',
  62. align: 'center',
  63. ellipsis: true,
  64. },
  65. {
  66. title: '性别',
  67. dataIndex: 'sex',
  68. key: 'drainageId',
  69. align: 'center',
  70. ellipsis: true,
  71. render: text => <span>{text == 1 ? '男' : text == 2 ? '女' : '' }</span>,
  72. },
  73. {
  74. title: '头像',
  75. dataIndex: 'avatar',
  76. key: 'drainageId',
  77. align: 'center',
  78. ellipsis: true,
  79. render: text => <img src={text} width="40px" height="40px"/>,
  80. },
  81. {
  82. title: '固话',
  83. dataIndex: 'telephone',
  84. key: 'drainageId',
  85. align: 'center',
  86. ellipsis: true,
  87. render: text => <a>{text}</a>,
  88. },
  89. {
  90. title: '手机号',
  91. dataIndex: 'phone',
  92. key: 'drainageId',
  93. align: 'center',
  94. ellipsis: true,
  95. render: text => <a>{text}</a>,
  96. },
  97. {
  98. title: '内部岗位',
  99. dataIndex: 'job',
  100. key: 'drainageId',
  101. align: 'center',
  102. ellipsis: true,
  103. render: text => <a>{text}</a>,
  104. },
  105. {
  106. title: '操作',
  107. align: 'center',
  108. width: '20%',
  109. render: (text, record) => (
  110. <span>
  111. <a onClick={() => selectData(record)} style={{ color: 'blue' }}>选择</a>
  112. </span>
  113. ),
  114. },
  115. ];
  116. const { getFieldDecorator } = props.form
  117. return (
  118. <div>
  119. <Row gutter={24}>
  120. <Col span={2}><div onClick={() => setVisible(true)}><a>{group.groupName}</a></div></Col>
  121. <Col span={16}><div>
  122. {selectedData.map(x => {
  123. return <Tag size="large" key={x.contactId} closable onClose={() => removeSelected(x)}>{x.contactName}</Tag>
  124. })}
  125. </div></Col>
  126. </Row>
  127. <Modal
  128. title="请选择"
  129. width="1200px"
  130. visible={visible}
  131. onCancel={() => setVisible(false)}
  132. footer={[]}
  133. >
  134. <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
  135. <Form.Item>
  136. {getFieldDecorator('contactName')(
  137. <Input
  138. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  139. placeholder="姓名"
  140. />,
  141. )}
  142. </Form.Item>
  143. <Form.Item>
  144. {getFieldDecorator('telephone')(
  145. <Input
  146. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  147. placeholder="固话"
  148. />,
  149. )}
  150. </Form.Item>
  151. <Form.Item>
  152. {getFieldDecorator('phone')(
  153. <Input
  154. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  155. placeholder="手机号"
  156. />,
  157. )}
  158. </Form.Item>
  159. <Form.Item>
  160. {getFieldDecorator('job')(
  161. <Input
  162. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  163. placeholder="内部岗位"
  164. />,
  165. )}
  166. </Form.Item>
  167. <Form.Item>
  168. <Button type="primary" htmlType="submit" className={styles.searchBtn}>
  169. 搜索
  170. </Button>
  171. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  172. 重置
  173. </Button>
  174. </Form.Item>
  175. </Form>
  176. <Table dataSource={data.records || []} columns={columns} pagination={false} />
  177. <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
  178. <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} current={data.current}/>
  179. </div>
  180. </Modal>
  181. </div>
  182. )
  183. }
  184. const WrappedRegistrationForm = Form.create()(SelectContact);
  185. export default WrappedRegistrationForm;