SelectContact.jsx 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 router from 'umi/router';
  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. useEffect(() => {
  12. }, [props.value])
  13. // 查询列表
  14. const getList = (params) => {
  15. request({ ...apis.contact.list, params: { ...params } }).then((data) => {
  16. console.log(data)
  17. setData(data)
  18. })
  19. }
  20. useEffect(() => {
  21. getList({ pageNum: 1, pageSize: 10, })
  22. }, []);
  23. const handleChange = val => {
  24. }
  25. // 提交事件
  26. const handleSubmit = (e, props) => {
  27. e.preventDefault();
  28. e.stopPropagation();
  29. props.form.validateFields((err, values) => {
  30. if (!err) {
  31. getList({ pageNum: 1, pageSize: 10, ...values })
  32. }
  33. });
  34. }
  35. function handleReset() {
  36. props.form.resetFields();
  37. getList({ pageNum: 1, pageSize: 10 })
  38. }
  39. const changePageNum = (pageNumber) => {
  40. getList({ pageNum: pageNumber, pageSize: 10, ...props.form.getFieldsValue() })
  41. }
  42. const toAdd = () => {
  43. router.push({
  44. pathname: '/contact/contact/add',
  45. });
  46. }
  47. const columns = [
  48. {
  49. title: '姓名',
  50. dataIndex: 'contactName',
  51. key: 'contactName',
  52. align: 'center',
  53. ellipsis: true,
  54. },
  55. {
  56. title: '性别',
  57. dataIndex: 'sex',
  58. key: 'sex',
  59. align: 'center',
  60. ellipsis: true,
  61. render: text => <span>{text == 1 ? '男' : text == 2 ? '女' : ''}</span>,
  62. },
  63. {
  64. title: '头像',
  65. dataIndex: 'avatar',
  66. key: 'avatar',
  67. align: 'center',
  68. ellipsis: true,
  69. render: text => <img src={text} width="40px" height="40px" />,
  70. },
  71. {
  72. title: '固话',
  73. dataIndex: 'telephone',
  74. key: 'telephone',
  75. align: 'center',
  76. ellipsis: true,
  77. },
  78. {
  79. title: '手机号',
  80. dataIndex: 'phone',
  81. key: 'phone',
  82. align: 'center',
  83. ellipsis: true,
  84. },
  85. {
  86. title: '对外头衔',
  87. dataIndex: 'job',
  88. key: 'job',
  89. align: 'center',
  90. ellipsis: true,
  91. },
  92. {
  93. title: '操作',
  94. align: 'center',
  95. width: '20%',
  96. render: (text, record) => (
  97. <span>
  98. <a onClick={() => selectData(record)} style={{ color: 'blue' }}>选择</a>
  99. </span>
  100. ),
  101. },
  102. ];
  103. const { getFieldDecorator } = props.form
  104. return (
  105. <div>
  106. <span style={{ color: '#fff' }} onClick={() => setVisible(true)}>{group.groupName}</span>
  107. <Modal
  108. title="选择联系人"
  109. width="1200px"
  110. visible={visible}
  111. onCancel={() => setVisible(false)}
  112. footer={[]}
  113. >
  114. <Form layout="inline" onSubmit={e => handleSubmit(e, props)} style={{ marginBottom: '16px' }}>
  115. <Form.Item>
  116. {getFieldDecorator('contactName')(
  117. <Input
  118. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  119. placeholder="姓名"
  120. />,
  121. )}
  122. </Form.Item>
  123. <Form.Item>
  124. {getFieldDecorator('telephone')(
  125. <Input
  126. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  127. placeholder="固话"
  128. />,
  129. )}
  130. </Form.Item>
  131. <Form.Item>
  132. {getFieldDecorator('phone')(
  133. <Input
  134. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  135. placeholder="手机号"
  136. />,
  137. )}
  138. </Form.Item>
  139. <Form.Item>
  140. {getFieldDecorator('job')(
  141. <Input
  142. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  143. placeholder="对外头衔"
  144. />,
  145. )}
  146. </Form.Item>
  147. <Form.Item>
  148. <Button type="primary" htmlType="submit" >
  149. 搜索
  150. </Button>
  151. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  152. 重置
  153. </Button>
  154. </Form.Item>
  155. </Form>
  156. <div style={{ marginBottom: '20px', textAlign: 'right' }}>没有想要的联系人? <a onClick={() => toAdd()}>去新增</a> </div>
  157. <Table dataSource={data.records || []} columns={columns} pagination={false} />
  158. <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
  159. <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} current={data.current} />
  160. </div>
  161. </Modal>
  162. </div>
  163. )
  164. }
  165. const WrappedRegistrationForm = Form.create()(SelectContact);
  166. export default WrappedRegistrationForm;