SelectContact.jsx 6.4KB

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