index.jsx 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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.customerId,
  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. <AuthButton name="customer.detail">
  158. <Button type="link" onClick={() => publicCustomerDetail(record)}>
  159. 查看详情
  160. </Button>
  161. </AuthButton>,
  162. <AuthButton name="customer.consultant.dispatch" noRight={null}>
  163. <Button type="link" onClick={() => handShowModel(record, actionList.assistConsultant)}>
  164. 分配置业顾问
  165. </Button>
  166. </AuthButton>,
  167. ]),
  168. },
  169. ];
  170. }, []);
  171. const searchFields = useMemo(getSearchFields, []);
  172. //操作成功请求数据
  173. const handleCancel = () => {
  174. SetShowModel({});
  175. ref.current.reload();
  176. };
  177. const actionRender = () => {
  178. return (
  179. <>
  180. <Button type="primary" loading={exportLoding} onClick={() => exportCustomer()}>
  181. 导出
  182. </Button>
  183. {/* <AuthButton name="admin.customer.import" noRight={null}>
  184. <Button
  185. type="primary"
  186. onClick={() => batchAssistConsultant()}
  187. style={{ marginLeft: '20px' }}
  188. >
  189. 批量分配置业顾问
  190. </Button>
  191. </AuthButton> */}
  192. </>
  193. );
  194. };
  195. const rowSelection = {
  196. selectedRowKeys,
  197. onChange: (selectedRowKeys, selectedRows) => {
  198. console.log('selectedRowKeys:', selectedRowKeys, 'selectedRows: ', selectedRows);
  199. setSelectedRowKeys(selectedRowKeys)
  200. const newSelectedRows = personInfo.filter(x => !selectedRows.some(y => x.customerId === y.customerId)) // 去重
  201. .concat(selectedRows) // 新增选择
  202. .filter(x => selectedRowKeys.some(y => y === x.customerId)) // 去掉未选的数据
  203. setPersonInfo(newSelectedRows)
  204. },
  205. };
  206. return (
  207. <>
  208. <QueryTable
  209. ref={ref}
  210. // rowSelection={rowSelection}
  211. rowKey="customerId"
  212. api={apis.customer.customerRecommend}
  213. searchFields={searchFields}
  214. params={{
  215. customerType: 'public',
  216. }}
  217. columns={columns}
  218. actionRender={actionRender}
  219. />
  220. <IntegralRecord
  221. modelProps={showModel[actionList.integralRecord]}
  222. handleCancel={handleCancel}
  223. onCancel={() => SetShowModel({})}
  224. />
  225. <Recommend
  226. modelProps={showModel[actionList.recommend]}
  227. handleCancel={handleCancel}
  228. onCancel={() => SetShowModel({})}
  229. />
  230. <AssistConsultant
  231. modelProps={showModel[actionList.assistConsultant]}
  232. handleCancel={handleCancel}
  233. onCancel={() => SetShowModel({})}
  234. />
  235. </>
  236. );
  237. };
  238. export default PublicCustomer;