CustomerChange.jsx 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import React, { Component, useState, useEffect } from 'react';
  2. import request from '../../../utils/request';
  3. import apis from '../../../services/apis';
  4. import moment from 'moment';
  5. import router from 'umi/router';
  6. import { Table, Select, Row, Col, Menu, Dropdown, Button, Icon, message } from 'antd';
  7. import BatchAssistConsultant from './BatchAssistConsultant'
  8. const CustomerChange = (props) => {
  9. const [data, setData] = useState([])
  10. const [consultantVisible, setConsultantVisible] = useState(false)
  11. const [selectIds, setSelectIds] = useState([])
  12. const rowSelection = {
  13. selectedRowKeys: selectIds,
  14. onChange: (selectedRowKeys, selectedRows) => {
  15. console.log('selectedRowKeys:', selectedRowKeys, 'selectedRows: ', selectedRows);
  16. setSelectIds(selectedRowKeys)
  17. },
  18. };
  19. const batchAssistConsultant = () => {
  20. if (selectIds.length < 1) {
  21. message.info("请至少选择一条数据");
  22. return
  23. }
  24. setConsultantVisible(true)
  25. }
  26. const consulatanChange = (e) => {
  27. if (e) {
  28. data.map(x => {
  29. selectIds.map(y => {
  30. if (x.customerId === y) {
  31. x.realtyConsultant = e.userId
  32. x.moveUserId = e.userId
  33. x.moveUserName = e.userName
  34. }
  35. })
  36. })
  37. }
  38. setConsultantVisible(false)
  39. setSelectIds([])
  40. }
  41. //批量保存
  42. const batchSaveConsultant = () => {
  43. const unMoveData = data.filter(x => !x.moveUserId)
  44. if (unMoveData.length > 0) {
  45. message.info("存在未分配归属客户");
  46. return
  47. }
  48. request({ ...apis.staff.move, data }).then(data => {
  49. message.info('操作成功')
  50. props.onSuccess('success')
  51. })
  52. }
  53. //取消按钮
  54. const cancelConsultant = () => {
  55. props.onSuccess('cancel')
  56. }
  57. const columns = [
  58. {
  59. title: '用户名',
  60. dataIndex: 'name',
  61. key: 'name',
  62. align: 'center',
  63. },
  64. {
  65. title: '手机号',
  66. dataIndex: 'phone',
  67. key: 'phone',
  68. align: 'center',
  69. },
  70. {
  71. title: '客户状态',
  72. dataIndex: 'reportRecommendStatus',
  73. key: 'reportRecommendStatus',
  74. align: 'center',
  75. render: (text, records) => {
  76. if (records.status === 1) { return '报备' }
  77. if (records.status === 2) { return '到访' }
  78. if (records.status === 3) { return '认购' }
  79. if (records.status === 4) { return '签约' }
  80. },
  81. },
  82. {
  83. title: '调整后归属',
  84. dataIndex: 'moveUserName',
  85. key: 'moveUserName',
  86. align: 'center',
  87. }
  88. ];
  89. useEffect(() => {
  90. request({ ...apis.staff.check, params: { userId: props.userId, personId: props.consultantPersonId, buildingId: props.buildingId } }).then(data => {
  91. setData(data)
  92. })
  93. }, [props.userId])
  94. return (
  95. <div>
  96. <Button type="primary" onClick={() => batchAssistConsultant()} style={{ float: 'right', margin: '20px 0', marginLeft: '20px', zIndex: 1 }}>分配置业顾问</Button>
  97. <Table rowSelection={rowSelection} dataSource={data} columns={columns} rowKey="customerId" pagination={false} scroll={{ y: 500 }} />
  98. <BatchAssistConsultant visible={consultantVisible} userId={props.userId} buildingId={props.buildingId} onCancel={consulatanChange} />
  99. <div style={{ textAlign: 'center', marginTop: '16px' }}><Button type="primary" onClick={() => batchSaveConsultant()}>保存</Button>
  100. <Button style={{ marginLeft: '10px' }} onClick={() => cancelConsultant()}>取消</Button></div>
  101. </div>
  102. )
  103. }
  104. export default CustomerChange;