123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import React, { useState, useEffect } from 'react';
  2. import { PageHeaderWrapper } from '@ant-design/pro-layout';
  3. import { Form, Pagination, Button, Icon, message, Modal, Table, Input } from 'antd';
  4. import router from 'umi/router';
  5. import moment from 'moment';
  6. import className from 'classnames';
  7. import Cell from '../../components/Cell';
  8. import styles from './style.less';
  9. import { fetch, apis } from '../../utils/request';
  10. import request from '../../utils/request';
  11. import AuthButton from '@/components/AuthButton';
  12. import SelectContact from './components/SelectContact';
  13. function header(props) {
  14. // 获取初始化数据
  15. const [data, setData] = useState({})
  16. const [contactList, setContactList] = useState([])
  17. useEffect(() => {
  18. getList({ pageNum: 1, pageSize: 10 });
  19. }, [])
  20. // 查询列表
  21. const getList = (params) => {
  22. request({ ...apis.fund.contactList, params: { ...params, contentType: 'finance' } }).then((data) => {
  23. console.log(data)
  24. setData(data)
  25. })
  26. }
  27. // 提交事件
  28. const handleSubmit = (e, props) => {
  29. e.preventDefault();
  30. props.form.validateFields((err, values) => {
  31. if (!err) {
  32. let { ...submitValue } = values
  33. getList({ pageNum: 1, pageSize: 10, ...submitValue })
  34. }
  35. });
  36. }
  37. const changePageNum = (pageNumber) => {
  38. let { ...submitValue } = props.form.getFieldsValue()
  39. getList({ pageNum: pageNumber, pageSize: 10, ...submitValue })
  40. }
  41. /**
  42. *
  43. *
  44. * @param {*} props
  45. * @returns
  46. */
  47. const columns = [
  48. {
  49. title: '姓名',
  50. dataIndex: 'contactName',
  51. key: 'contactName',
  52. align: 'center',
  53. },
  54. {
  55. title: '性别',
  56. dataIndex: 'sex',
  57. key: 'sex',
  58. align: 'center',
  59. render: (text, record) => <span>{record.sex == '1' ? '男' : record.sex == '2' ? '女' : '未知'}</span>
  60. },
  61. {
  62. title: '头像',
  63. dataIndex: 'avatar',
  64. key: 'avatar',
  65. align: 'center',
  66. render: (text, record) => <img src={record.avatar} className={styles.touxiang} />,
  67. },
  68. {
  69. title: '固话',
  70. dataIndex: 'telephone',
  71. key: 'telephone',
  72. align: 'center',
  73. },
  74. {
  75. title: '手机号',
  76. dataIndex: 'phone',
  77. key: 'phone',
  78. align: 'center',
  79. },
  80. {
  81. title: '对外头衔',
  82. dataIndex: 'appellation',
  83. key: 'appellation',
  84. align: 'center',
  85. },
  86. {
  87. title: '权重',
  88. dataIndex: 'orderNo',
  89. key: 'orderNo',
  90. align: 'center',
  91. },
  92. ];
  93. function handleReset() {
  94. props.form.resetFields();
  95. getList({ pageNum: 1, pageSize: 10 })
  96. }
  97. const rowSelection = {
  98. onChange: (selectedRowKeys, selectedRows) => {
  99. console.log('selectedRowKeys:', selectedRowKeys, 'selectedRows: ', selectedRows);
  100. setContactList(selectedRows)
  101. },
  102. };
  103. const toDel = () => {
  104. if (contactList.length < 1) {
  105. message.info('请至少选择一条数据')
  106. return
  107. }
  108. Modal.confirm({
  109. title: `确认将所选的${contactList.length}条数据删除`,
  110. okText: '确定',
  111. cancelText: '取消',
  112. onOk() {
  113. request({ ...apis.fund.delContact, data: contactList, }).then((data) => {
  114. message.info("操作成功")
  115. getList({ pageNum: 1, pageSize: 10 });
  116. setContactList([])
  117. }).catch((err) => {
  118. })
  119. },
  120. onCancel() { },
  121. });
  122. }
  123. const { getFieldDecorator } = props.form
  124. return (
  125. <>
  126. <Form layout="inline" onSubmit={e => handleSubmit(e, props)} >
  127. <Form.Item>
  128. {getFieldDecorator('contactName')(
  129. <Input
  130. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  131. placeholder="姓名"
  132. />,
  133. )}
  134. </Form.Item>
  135. <Form.Item>
  136. {getFieldDecorator('telephone')(
  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('phone')(
  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('appellation')(
  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. <Button type="primary" htmlType="submit" className={styles.searchBtn}>
  161. 搜索
  162. </Button>
  163. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  164. 重置
  165. </Button>
  166. </Form.Item>
  167. </Form>
  168. <div style={{ margin: '10px 0 16px 0' }}>
  169. <Button type="danger" className={styles.addBtn} style={{ padding: '0' }} ><SelectContact onClick={() => getList({ pageNum: 1, pageSize: 10 })} /></Button>
  170. <Button type="primary" className={styles.addBtn} onClick={() => toDel()} style={{ marginLeft: '30px' }} >删除</Button>
  171. </div>
  172. <Table rowSelection={rowSelection} rowKey={r => r.contactId} dataSource={data.records} columns={columns} pagination={false} />
  173. <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
  174. <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} current={data.current} />
  175. </div>
  176. </>
  177. )
  178. }
  179. const WrappedHeader = Form.create({ name: 'header' })(header);
  180. export default WrappedHeader