index.jsx 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. import React, { useState, useMemo, useRef } from 'react';
  2. import { Avatar, Button,message } from 'antd';
  3. import router from 'umi/router';
  4. import QueryTable from '@/components/QueryTable';
  5. import apis from '@/services/apis';
  6. import request from '@/utils/request';
  7. import withActions from '@/components/ActionList';
  8. import AuthButton from '@/components/AuthButton';
  9. import Styles from '../style.less';
  10. import IntegralRecord from './components/IntegralRecord';
  11. import Recommend from './components/Recommend';
  12. import AssistConsultant from './components/assistConsultant';
  13. import getSearchFields from './searchFields';
  14. const actionList = {
  15. integralRecord: 'integralRecord', //积分记录
  16. recommend: 'recommend', //推荐客户
  17. assistConsultant: 'assistConsultant', //分配置业顾问
  18. };
  19. const PublicCustomer = () => {
  20. const ref = useRef();
  21. const [showModel, SetShowModel] = useState({
  22. // changeStatus: { visible: true, data: {} },
  23. });
  24. const [exportLoding, setExportLoding] = useState(false);
  25. // 选中的公客信息
  26. const [personInfo, setPersonInfo] = useState([])
  27. const [selectedRowKeys, setSelectedRowKeys] = useState([])
  28. const handShowModel = (record, actionType) => {
  29. SetShowModel({
  30. [actionList[actionType]]: {
  31. visible: true,
  32. data: record,
  33. },
  34. });
  35. };
  36. function batchAssistConsultant() {
  37. console.log(personInfo, 'personInfo')
  38. console.log(personInfo.length)
  39. if (personInfo.length <= 0) {
  40. return message.info('请至少选择一条数据');
  41. }
  42. const compareSet = new Set();
  43. personInfo.filter(record => {
  44. compareSet.add(record.buildingName)
  45. })
  46. if (compareSet.size != 1) {
  47. return message.info('选中的公客存在于不同项目中,请分开进行分配置业顾问操作');
  48. }
  49. handShowModel({
  50. customerId: personInfo, buildingId: personInfo[0].buildingId
  51. }, actionList.assistConsultant)
  52. // SetShowModel({
  53. // [actionList[actionType]]: {
  54. // visible: true,
  55. // data: record,
  56. // },
  57. // });
  58. // };
  59. // setBatchAssistVisibleData({ visible: true, customerId: personInfo, buildingId: personInfo[0].buildingId })
  60. }
  61. function publicCustomerDetail(record) {
  62. router.push({
  63. pathname: '/customer/customerlist/publicCustomerDetail',
  64. query: {
  65. id: record.personId,
  66. },
  67. });
  68. }
  69. //导出
  70. function exportCustomer() {
  71. console.log(ref.current, 'ref');
  72. setExportLoding(true);
  73. request({
  74. ...apis.customer.customerRecommendExport,
  75. responseType: 'blob',
  76. params: ref.current.getSearchData,
  77. })
  78. .then(response => {
  79. download(response);
  80. setExportLoding(false);
  81. })
  82. .catch(() => {
  83. message.err('连接超时');
  84. setExportLoding(false);
  85. });
  86. }
  87. function download(data) {
  88. if (!data) {
  89. return;
  90. }
  91. const url = window.URL.createObjectURL(new Blob([data]));
  92. const link = document.createElement('a');
  93. link.style.display = 'none';
  94. link.href = url;
  95. link.setAttribute('download', '客户列表.xlsx');
  96. document.body.append(link);
  97. link.click();
  98. }
  99. const columns = useMemo(() => {
  100. return [
  101. {
  102. title: '头像',
  103. dataIndex: 'picture',
  104. key: 'picture',
  105. align: 'center',
  106. width: '10%',
  107. render: (_, record) => (
  108. <Avatar
  109. shape="square"
  110. style={{ color: 'blue' }}
  111. src={record.picture}
  112. size={64}
  113. icon="user"
  114. />
  115. ),
  116. },
  117. {
  118. title: '姓名',
  119. dataIndex: 'name',
  120. key: 'name',
  121. align: 'center',
  122. width: '20%',
  123. },
  124. {
  125. title: '电话',
  126. dataIndex: 'phone',
  127. key: 'phone',
  128. align: 'center',
  129. width: '20%',
  130. },
  131. {
  132. title: '性别',
  133. dataIndex: 'sex',
  134. key: 'sex',
  135. align: 'center',
  136. width: '10%',
  137. // eslint-disable-next-line no-nested-ternary
  138. render: (_, record) => (
  139. <>
  140. <span>{record.sex === 1 ? '男' : record.sex === 2 ? '女' : '未知'}</span>
  141. </>
  142. ),
  143. },
  144. {
  145. title: '推广人员',
  146. dataIndex: 'sharePersonName',
  147. key: 'sharePersonName',
  148. align: 'center',
  149. width: '20%',
  150. },
  151. {
  152. title: '操作',
  153. dataIndex: 'customerId',
  154. key: 'customerId',
  155. align: 'center',
  156. render: withActions((_, record) => [
  157. <Button type="link" onClick={() => publicCustomerDetail(record)}>
  158. 查看详情
  159. </Button>,
  160. <AuthButton name="admin.customer.assign" noRight={null}>
  161. <Button
  162. type="link"
  163. onClick={() => handShowModel(record, actionList.assistConsultant)}
  164. >
  165. 分配置业顾问
  166. </Button>
  167. </AuthButton>,
  168. ]),
  169. },
  170. ];
  171. }, []);
  172. const searchFields = useMemo(getSearchFields, []);
  173. //操作成功请求数据
  174. const handleCancel = () => {
  175. SetShowModel({});
  176. ref.current.reload();
  177. };
  178. const actionRender = () => {
  179. return (
  180. <>
  181. <Button type="danger" loading={exportLoding} onClick={() => exportCustomer()}>
  182. 导出
  183. </Button>
  184. <AuthButton name="admin.customer.import" noRight={null}>
  185. <Button
  186. type="primary"
  187. onClick={() => batchAssistConsultant()}
  188. style={{ marginLeft: '20px' }}
  189. >
  190. 批量分配置业顾问
  191. </Button>
  192. </AuthButton>
  193. </>
  194. );
  195. };
  196. const rowSelection = {
  197. selectedRowKeys,
  198. onChange: (selectedRowKeys, selectedRows) => {
  199. console.log('selectedRowKeys:', selectedRowKeys, 'selectedRows: ', selectedRows);
  200. setSelectedRowKeys(selectedRowKeys)
  201. const newSelectedRows = personInfo.filter(x => !selectedRows.some(y => x.customerId === y.customerId)) // 去重
  202. .concat(selectedRows) // 新增选择
  203. .filter(x => selectedRowKeys.some(y => y === x.customerId)) // 去掉未选的数据
  204. setPersonInfo(newSelectedRows)
  205. },
  206. };
  207. return (
  208. <>
  209. <QueryTable
  210. ref={ref}
  211. rowSelection={rowSelection}
  212. rowKey="customerId"
  213. api={apis.customer.customerRecommend}
  214. searchFields={searchFields}
  215. params={{
  216. customerType: 'public',
  217. }}
  218. columns={columns}
  219. actionRender={actionRender}
  220. />
  221. <IntegralRecord
  222. modelProps={showModel[actionList.integralRecord]}
  223. handleCancel={handleCancel}
  224. onCancel={() => SetShowModel({})}
  225. />
  226. <Recommend
  227. modelProps={showModel[actionList.recommend]}
  228. handleCancel={handleCancel}
  229. onCancel={() => SetShowModel({})}
  230. />
  231. <AssistConsultant
  232. modelProps={showModel[actionList.assistConsultant]}
  233. handleCancel={handleCancel}
  234. onCancel={() => SetShowModel({})}
  235. />
  236. </>
  237. );
  238. };
  239. export default PublicCustomer;