知与行后台管理端

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, Table, Avatar } from 'antd';
  3. import moment from 'moment';
  4. import request from '../../../utils/request';
  5. import apis from '../../../services/apis';
  6. import Styles from './style.less';
  7. import BuildSelect from '../../../components/SelectButton/BuildSelect'
  8. import AuthButton from '@/components/AuthButton';
  9. const { Option } = Select;
  10. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  11. const { Meta } = Card;
  12. const tempDate = [{ code: 's101' }]
  13. /**
  14. *
  15. *
  16. * @param {*} props
  17. * @returns
  18. */
  19. function body(props) {
  20. const { getFieldDecorator } = props.form
  21. // eslint-disable-next-line react-hooks/rules-of-hooks
  22. const [dataSource, setDataSource] = useState({ records: [] })
  23. // eslint-disable-next-line react-hooks/rules-of-hooks
  24. useEffect(() => {
  25. getList({ pageNumber: 1, pageSize: 9 })
  26. }, [])
  27. function getList(params) {
  28. // 网路请求
  29. request({ ...apis.customer.report, params: { ...params } }).then(res => {
  30. setDataSource(res)
  31. }).catch(err => {
  32. // eslint-disable-next-line no-unused-expressions
  33. <Alert
  34. style={{
  35. marginBottom: 24,
  36. }}
  37. message={err}
  38. type="error"
  39. showIcon
  40. />
  41. })
  42. }
  43. // 提交事件
  44. function handleSubmit(e) {
  45. e.preventDefault();
  46. props.form.validateFields((err, values) => {
  47. if (!err) {
  48. getList({ pageNum: 1, pageSize: 10, ...values })
  49. }
  50. });
  51. }
  52. // Change 事件
  53. function handleSelectChange(e) {
  54. // eslint-disable-next-line no-console
  55. console.log(e)
  56. }
  57. // 分页
  58. function onChange(pageNum) {
  59. // eslint-disable-next-line react-hooks/rules-of-hooks
  60. getList({ pageNumber: pageNum, pageSize: 9 })
  61. }
  62. /**
  63. * 重置搜索
  64. */
  65. function handleReset() {
  66. props.form.resetFields();
  67. getList({ pageNumber: 1, pageSize: 9 })
  68. }
  69. function exportReport() {
  70. request({ ...apis.customer.customerRecommendReportExport, params: { ...props.form.getFieldsValue() }, responseType: 'blob' })
  71. .then(response => {
  72. download(response)
  73. })
  74. }
  75. function download(data) {
  76. if (!data) {
  77. return
  78. }
  79. const url = window.URL.createObjectURL(new Blob([data]))
  80. const link = document.createElement('a')
  81. link.style.display = 'none'
  82. link.href = url
  83. link.setAttribute('download', '报备客户.xlsx')
  84. document.body.append(link)
  85. link.click()
  86. }
  87. const columns = [
  88. {
  89. title: '头像',
  90. dataIndex: 'picture',
  91. key: 'picture',
  92. render: (_, record) => <Avatar shape="square" src={record.picture} size={64} icon="user" />,
  93. },
  94. {
  95. title: '姓名',
  96. dataIndex: 'name',
  97. key: 'name',
  98. },
  99. {
  100. title: '电话',
  101. dataIndex: 'phone',
  102. key: 'phone',
  103. },
  104. {
  105. title: '性别',
  106. dataIndex: 'sex',
  107. key: 'sex',
  108. // eslint-disable-next-line no-nested-ternary
  109. render: (_, record) => <><span>{record.sex === 1 ? '男' : record.sex === 2 ? '女' : '未知'}</span></>,
  110. },
  111. {
  112. title: '意向项目',
  113. dataIndex: 'intentionName',
  114. key: 'intentionName',
  115. },
  116. {
  117. title: '置业顾问',
  118. dataIndex: 'consultantName',
  119. key: 'consultantName',
  120. },
  121. {
  122. title: '置业顾问手机号',
  123. dataIndex: 'consultTel',
  124. key: 'consultTel',
  125. },
  126. ]
  127. return (
  128. <>
  129. <Form layout="inline" onSubmit={e => handleSubmit(e, props)} >
  130. <Row>
  131. <Col span={21}>
  132. <Form.Item>
  133. {getFieldDecorator('name')(
  134. <Input
  135. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  136. placeholder="姓名"
  137. />,
  138. )}
  139. </Form.Item>
  140. <Form.Item>
  141. {getFieldDecorator('tel')(
  142. <Input
  143. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  144. placeholder="电话"
  145. />,
  146. )}
  147. </Form.Item>
  148. <Form.Item>
  149. {getFieldDecorator('consultName')(
  150. <Input placeholder="置业顾问" />,
  151. )}
  152. </Form.Item>
  153. <Form.Item>
  154. {getFieldDecorator('consultTel')(
  155. <Input placeholder="置业顾问电话" />,
  156. )}
  157. </Form.Item>
  158. <Form.Item>
  159. {getFieldDecorator('sex')(
  160. <Select style={{ width: '180px' }} placeholder="性别" onChange={handleSelectChange}>
  161. <Option value="1">男</Option>
  162. <Option value="0">女</Option>
  163. </Select>,
  164. )}
  165. </Form.Item>
  166. <Form.Item>
  167. {getFieldDecorator('buildingId')(
  168. <BuildSelect />,
  169. )}
  170. </Form.Item>
  171. </Col>
  172. <div style={{minWidth:'150px',position: 'absolute', right: '-12px', }}>
  173. <Form.Item >
  174. <Button type="primary" htmlType="submit">
  175. 搜索
  176. </Button>
  177. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  178. 重置
  179. </Button>
  180. </Form.Item>
  181. </div>
  182. </Row>
  183. <div >
  184. </div>
  185. </Form>
  186. <Button type="primary" onClick={() => exportReport()} style={{ float: 'right', margin: '20px 0', zIndex: 1 }}>
  187. 导出
  188. </Button>
  189. <Table rowKey="report" style={{ marginTop: '40px' }} dataSource={dataSource.records} columns={columns} pagination={{ total: dataSource.total, onChange }} />
  190. </>
  191. );
  192. }
  193. const WrappedBody = Form.create({ name: 'body' })(body);
  194. export default WrappedBody