知与行后台管理端

index.jsx 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. function toAudit(cuurentId) {
  295. router.push({
  296. pathname: '/customer/recommendCustomer/audit',
  297. query: {
  298. id: cuurentId,
  299. },
  300. })
  301. }
  302. function exportIndependen() {
  303. request({ ...apis.customer.customerRecommendAgentsExport, responseType: 'blob' })
  304. .then(response => {
  305. download(response)
  306. }).catch(error => {
  307. })
  308. }
  309. function download(data) {
  310. if (!data) {
  311. return
  312. }
  313. const url = window.URL.createObjectURL(new Blob([data]))
  314. const link = document.createElement('a')
  315. link.style.display = 'none'
  316. link.href = url
  317. link.setAttribute('download', '经纪人.xlsx')
  318. document.body.append(link)
  319. link.click()
  320. }
  321. const columns = [
  322. {
  323. title: '头像',
  324. dataIndex: 'avatarurl',
  325. key: 'avatarurl',
  326. render: (_, record) => <Avatar shape="square" src={record.avatarurl} size={64} icon="user" />,
  327. },
  328. {
  329. title: '姓名',
  330. dataIndex: 'nickname',
  331. key: 'nickname',
  332. },
  333. {
  334. title: '电话',
  335. dataIndex: 'phone',
  336. key: 'phone',
  337. },
  338. {
  339. title: '性别',
  340. dataIndex: 'gender',
  341. key: 'gender',
  342. // eslint-disable-next-line no-nested-ternary
  343. render: (_, record) => <><span>{ record.gender === '1' ? '男' : record.gender === '2' ? '女' : '未知' }</span></>,
  344. },
  345. {
  346. title: '类型',
  347. dataIndex: 'personType',
  348. key: 'personType',
  349. render: (_, record) => <><span>{ record.channelName !== null ? '渠道经纪人' : '独立经纪人' }</span></>,
  350. },
  351. {
  352. title: '所属渠道',
  353. dataIndex: 'channelName',
  354. key: 'channelName',
  355. },
  356. {
  357. title: '操作',
  358. dataIndex: 'customerId',
  359. key: 'customerId',
  360. render: (_, record) => (
  361. <>
  362. {
  363. <>
  364. {/* <span style={{ color: 'rgba(239,39,58,1)' }}>查看详细</span> */}
  365. <AuthButton name="admin.channel.InviteClientsList.get" noRight={null}>
  366. <a style={{ color: 'rgba(239,39,58,1)' }} onClick={() => Invite(record)}>邀请经纪人</a>
  367. </AuthButton>
  368. &nbsp;&nbsp;&nbsp;&nbsp;
  369. <AuthButton name="admin.customer.recommend.id.get" noRight={null}>
  370. <a style={{ color: 'rgba(239,39,58,1)' }} onClick={() => gM(record)}>推荐客户</a>
  371. </AuthButton>
  372. </>
  373. }
  374. </>
  375. ),
  376. },
  377. ]
  378. return (
  379. <>
  380. <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
  381. <Form.Item>
  382. {getFieldDecorator('name')(
  383. <Input
  384. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  385. placeholder="姓名"
  386. />,
  387. )}
  388. </Form.Item>
  389. <Form.Item>
  390. {getFieldDecorator('tel')(
  391. <Input
  392. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  393. placeholder="电话"
  394. />,
  395. )}
  396. </Form.Item>
  397. <Form.Item>
  398. <Button type="primary" htmlType="submit" className={Styles.SubmitButton}>
  399. 搜索
  400. </Button>
  401. </Form.Item>
  402. </Form>
  403. <Button type="primary" onClick={() => exportIndependen()} className={Styles.SubmitButton} style={{ marginTop: '5px', marginBottom: '5px' }}>
  404. 导出数据
  405. </Button>
  406. <Table rowKey="independentIndex" dataSource={dataSource.records} columns={columns} pagination={{ total: dataSource.total, onChange }} />
  407. {/* 调整归属 */}
  408. <ModalTable visibleData={gVisibleData} />
  409. <InviteTable visibleData={gInviteData} />
  410. </>
  411. );
  412. }
  413. const WrappedBody = Form.create({ name: 'body' })(body);
  414. export default WrappedBody