知与行后台管理端

index.jsx 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, Table, Avatar, notification, Modal } 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 { router } from 'umi';
  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. /**
  13. * 推荐客户
  14. */
  15. class ModalTable extends React.Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. dataSource: { records: [] },
  20. visibleData: { visible: false, customerId: '', realtyConsultant: '' },
  21. }
  22. }
  23. // 挂载之后
  24. componentDidMount () {
  25. this.getList({ pageNumber: 1, pageSize: 5 })
  26. }
  27. componentDidUpdate (preProps, preState) {
  28. if (this.props.visibleData.customerId !== preState.visibleData.customerId) {
  29. this.getList({ pageNumber: 1, pageSize: 5 })
  30. this.setState({ visibleData: this.props.visibleData });
  31. }
  32. }
  33. // 弹框确定按钮
  34. // eslint-disable-next-line react/sort-comp
  35. handleOk () {
  36. this.setState({ visibleData: { visible: false, customerId: '', realtyConsultant: '' } })
  37. }
  38. // 弹框取消按钮
  39. handleCancel () {
  40. this.setState({ visibleData: { visible: false, customerId: '', realtyConsultant: '' } })
  41. }
  42. getList (params) {
  43. console.log('this.state.visibleData', this.state.visibleData)
  44. const { customerId } = this.state.visibleData
  45. if (customerId === '' || customerId === undefined) {
  46. return
  47. }
  48. // 网路请求
  49. // 网路请求
  50. request({ ...apis.customer.recommend, urlData: { id: customerId }, params: { ...params } }).then(res => {
  51. this.setState({ dataSource: res })
  52. }).catch(err => {
  53. // eslint-disable-next-line no-unused-expressions
  54. <Alert
  55. style={{
  56. marginBottom: 24,
  57. }}
  58. message={err}
  59. type="error"
  60. showIcon
  61. />
  62. })
  63. }
  64. // 分页
  65. onChange (pageNum) {
  66. this.getList({ pageNumber: pageNum, pageSize: 5 })
  67. }
  68. render () {
  69. const columns = [
  70. {
  71. title: '头像',
  72. // eslint-disable-next-line jsx-a11y/alt-text
  73. render: (text, records) => <img src={records.picture} width={50} height={50} />,
  74. },
  75. {
  76. title: '用户名',
  77. dataIndex: 'name',
  78. key: 'name',
  79. },
  80. {
  81. title: '电话',
  82. dataIndex: 'phone',
  83. key: 'phone',
  84. },
  85. {
  86. title: '性别',
  87. dataIndex: 'sex',
  88. key: 'sex',
  89. render: (text, records) => <span>{records.sex === 1 ? '男' : '女'}</span>,
  90. },
  91. {
  92. title: '意向项目',
  93. dataIndex: 'intention',
  94. key: 'intention',
  95. },
  96. {
  97. title: '推荐时间',
  98. dataIndex: 'createDate',
  99. key: 'createDate',
  100. },
  101. {
  102. title: '状态',
  103. // eslint-disable-next-line consistent-return
  104. render: (text, records) => {
  105. if (records.status === 1) { return '报备' }
  106. if (records.status === 2) { return '到访' }
  107. if (records.status === 3) { return '认购' }
  108. if (records.status === 4) { return '签约' }
  109. if (records.verifyStatus === 1) { return '待审核' }
  110. if (records.verifyStatus === 2) { return '审核同意' }
  111. if (records.verifyStatus === 3) { return '签约' }
  112. },
  113. },
  114. ]
  115. return (
  116. <>
  117. <Modal
  118. title="推荐客户"
  119. destroyOnClose="true"
  120. width={900}
  121. footer={null}
  122. visible={this.state.visibleData.visible}
  123. // onOk={() => this.handleOk()}
  124. onCancel={(e) => this.handleCancel(e)}
  125. >
  126. <Table rowKey="independentList" dataSource={this.state.dataSource.records} columns={columns} pagination={{ total: this.state.dataSource.total, onChange: e => this.onChange(e) }} />
  127. </Modal>
  128. </>
  129. );
  130. }
  131. }
  132. /**
  133. * 邀请客户
  134. */
  135. class InviteTable extends React.Component {
  136. constructor(props) {
  137. super(props);
  138. this.state = {
  139. dataSource: { records: [] },
  140. visibleData: { visible: false, customerId: '', realtyConsultant: '' },
  141. }
  142. }
  143. // 挂载之后
  144. componentDidMount () {
  145. const { customerId } = this.state.visibleData
  146. this.getList({ id: customerId, pageNumber: 1, pageSize: 5 })
  147. }
  148. componentDidUpdate (preProps, preState) {
  149. const { customerId } = this.state.visibleData
  150. if (this.props.visibleData.customerId !== preState.visibleData.customerId) {
  151. this.getList({ id: customerId, pageNumber: 1, pageSize: 5 })
  152. this.setState({ visibleData: this.props.visibleData });
  153. }
  154. }
  155. // 弹框确定按钮
  156. // eslint-disable-next-line react/sort-comp
  157. handleOk () {
  158. this.setState({ visibleData: { visible: false, customerId: '', realtyConsultant: '' } })
  159. }
  160. // 弹框取消按钮
  161. handleCancel () {
  162. this.setState({ visibleData: { visible: false, customerId: '', realtyConsultant: '' } })
  163. }
  164. getList (params) {
  165. const { customerId } = this.props.visibleData
  166. if (customerId === '' || customerId === undefined) {
  167. return
  168. }
  169. request({ ...apis.customer.InviteClientsList, params: { ...params } }).then(res => {
  170. this.setState({ dataSource: res })
  171. }).catch(err => {
  172. // eslint-disable-next-line no-unused-expressions
  173. <Alert
  174. style={{
  175. marginBottom: 24,
  176. }}
  177. message={err}
  178. type="error"
  179. showIcon
  180. />
  181. })
  182. }
  183. // 分页
  184. onChange (pageNum) {
  185. this.getList({ pageNumber: pageNum, pageSize: 5 })
  186. }
  187. render () {
  188. const columns = [
  189. {
  190. title: '头像',
  191. dataIndex: 'img',
  192. key: 'img',
  193. align: 'center',
  194. render: (text, record) => <img src={record.avatarurl} width={50} height={50} />,
  195. },
  196. {
  197. title: '用户姓名',
  198. dataIndex: 'name',
  199. key: 'name',
  200. align: 'center',
  201. render: text => <a>{text}</a>,
  202. },
  203. {
  204. title: '电话',
  205. dataIndex: 'tel',
  206. key: 'tel',
  207. align: 'center',
  208. },
  209. {
  210. title: '性别',
  211. dataIndex: 'sex',
  212. key: 'sex',
  213. align: 'center',
  214. render: (text, list) => <span>{list.sex === 1 ? '男' : '女'}</span>,
  215. },
  216. ]
  217. return (
  218. <>
  219. <Modal
  220. title="推荐客户"
  221. destroyOnClose="true"
  222. width={900}
  223. footer={null}
  224. visible={this.state.visibleData.visible}
  225. // onOk={() => this.handleOk()}
  226. onCancel={(e) => this.handleCancel(e)}
  227. >
  228. <Table rowKey="independent" dataSource={this.state.dataSource.records} columns={columns} pagination={{ total: this.state.dataSource.total, onChange: e => this.onChange(e) }} />
  229. </Modal>
  230. </>
  231. );
  232. }
  233. }
  234. /**
  235. *
  236. *主题列表
  237. * @param {*} props
  238. * @returns
  239. */
  240. function body (props) {
  241. const { getFieldDecorator } = props.form
  242. // eslint-disable-next-line react-hooks/rules-of-hooks
  243. const [dataSource, setDataSource] = useState({ records: [] })
  244. // eslint-disable-next-line react-hooks/rules-of-hooks
  245. useEffect(() => {
  246. getList({ pageNumber: 1, pageSize: 10 })
  247. }, [])
  248. function openNotificationWithIcon (type, message) {
  249. notification[type]({
  250. message,
  251. description:
  252. '',
  253. });
  254. }
  255. function getList (params) {
  256. // 网路请求
  257. request({ ...apis.customer.agents, params: { ...params } }).then(res => {
  258. setDataSource(res)
  259. }).catch(err => {
  260. openNotificationWithIcon('error', err)
  261. })
  262. }
  263. // 提交事件
  264. function handleSubmit (e) {
  265. e.preventDefault();
  266. props.form.validateFields((err, values) => {
  267. if (!err) {
  268. getList({ pageNum: 1, pageSize: 10, ...values })
  269. }
  270. });
  271. }
  272. // eslint-disable-next-line react-hooks/rules-of-hooks
  273. const [gVisibleData, setGVisibleData] = useState({ visible: false, customerId: '', realtyConsultant: '' })
  274. // eslint-disable-next-line react-hooks/rules-of-hooks
  275. const [gInviteData, setGInviteData] = useState({ visible: false, customerId: '', realtyConsultant: '' })
  276. // Change 事件
  277. function handleSelectChange (e) {
  278. // eslint-disable-next-line no-console
  279. console.log(e)
  280. }
  281. function gM (row) {
  282. setGVisibleData({ visible: true, customerId: row.personId, realtyConsultant: row.realtyConsultant })
  283. setGInviteData({ visible: false })
  284. }
  285. function Invite (row) {
  286. setGInviteData({ visible: true, customerId: row.personId, realtyConsultant: row.realtyConsultant })
  287. setGVisibleData({ visible: false })
  288. }
  289. // 分页
  290. function onChange (pageNum) {
  291. // eslint-disable-next-line react-hooks/rules-of-hooks
  292. getList({ pageNumber: pageNum, pageSize: 10 })
  293. }
  294. /**
  295. * 重置搜索
  296. */
  297. function handleReset () {
  298. props.form.resetFields();
  299. }
  300. function toAudit (cuurentId) {
  301. router.push({
  302. pathname: '/customer/recommendCustomer/audit',
  303. query: {
  304. id: cuurentId,
  305. },
  306. })
  307. }
  308. function exportIndependen () {
  309. request({ ...apis.customer.customerRecommendAgentsExport, responseType: 'blob' })
  310. .then(response => {
  311. download(response)
  312. }).catch(error => {
  313. })
  314. }
  315. function download (data) {
  316. if (!data) {
  317. return
  318. }
  319. const url = window.URL.createObjectURL(new Blob([data]))
  320. const link = document.createElement('a')
  321. link.style.display = 'none'
  322. link.href = url
  323. link.setAttribute('download', '经纪人.xlsx')
  324. document.body.append(link)
  325. link.click()
  326. }
  327. const columns = [
  328. {
  329. title: '头像',
  330. dataIndex: 'avatarurl',
  331. key: 'avatarurl',
  332. render: (_, record) => <Avatar shape="square" src={record.avatarurl} size={64} icon="user" />,
  333. },
  334. {
  335. title: '姓名',
  336. dataIndex: 'nickname',
  337. key: 'nickname',
  338. },
  339. {
  340. title: '电话',
  341. dataIndex: 'phone',
  342. key: 'phone',
  343. },
  344. {
  345. title: '性别',
  346. dataIndex: 'gender',
  347. key: 'gender',
  348. // eslint-disable-next-line no-nested-ternary
  349. render: (_, record) => <><span>{record.gender === '1' ? '男' : record.gender === '2' ? '女' : '未知'}</span></>,
  350. },
  351. {
  352. title: '类型',
  353. dataIndex: 'personType',
  354. key: 'personType',
  355. render: (_, record) => <><span>{record.channelName !== null ? '渠道经纪人' : '独立经纪人'}</span></>,
  356. },
  357. {
  358. title: '所属渠道',
  359. dataIndex: 'channelName',
  360. key: 'channelName',
  361. },
  362. {
  363. title: '操作',
  364. dataIndex: 'customerId',
  365. key: 'customerId',
  366. render: (_, record) => (
  367. <>
  368. {
  369. <>
  370. {/* <span style={{ color: 'rgba(239,39,58,1)' }}>查看详细</span> */}
  371. <AuthButton name="admin.channel.InviteClientsList.get" noRight={null}>
  372. <a style={{ color: 'rgba(239,39,58,1)' }} onClick={() => Invite(record)}>邀请经纪人</a>
  373. </AuthButton>
  374. &nbsp;&nbsp;&nbsp;&nbsp;
  375. <AuthButton name="admin.customer.recommend.id.get" noRight={null}>
  376. <a style={{ color: 'rgba(239,39,58,1)' }} onClick={() => gM(record)}>推荐客户</a>
  377. </AuthButton>
  378. </>
  379. }
  380. </>
  381. ),
  382. },
  383. ]
  384. return (
  385. <>
  386. <Form layout="inline" onSubmit={e => handleSubmit(e, props)} style={{ display: 'flex', alignItems: 'center' }}>
  387. <Form.Item>
  388. {getFieldDecorator('name')(
  389. <Input
  390. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  391. placeholder="姓名"
  392. />,
  393. )}
  394. </Form.Item>
  395. <Form.Item>
  396. {getFieldDecorator('tel')(
  397. <Input
  398. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  399. placeholder="电话"
  400. />,
  401. )}
  402. </Form.Item>
  403. <Form.Item style={{ position: 'absolute', right: '38px' }} >
  404. <Button type="primary" htmlType="submit" >
  405. 搜索
  406. </Button>
  407. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  408. 重置
  409. </Button>
  410. </Form.Item>
  411. </Form>
  412. <Button type="primary" onClick={() => exportIndependen()} style={{ float: 'right', margin: '20px 0', zIndex: 1 }}>
  413. 导出
  414. </Button>
  415. <Table rowKey="independentIndex" dataSource={dataSource.records} columns={columns} pagination={{ total: dataSource.total, onChange }} />
  416. {/* 调整归属 */}
  417. <ModalTable visibleData={gVisibleData} />
  418. <InviteTable visibleData={gInviteData} />
  419. </>
  420. );
  421. }
  422. const WrappedBody = Form.create({ name: 'body' })(body);
  423. export default WrappedBody