123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 ChangeStatus from './components/ChangeStatus';
  11. import Attribution from './components/Attribution';
  12. import IntegralRecord from './components/IntegralRecord';
  13. import Recommend from './components/Recommend';
  14. import getSearchFields from './searchFields';
  15. const actionList = {
  16. changeStatus: 'changeStatus', // 变更状态
  17. attribution: 'attribution', //调整归属
  18. integralRecord: 'integralRecord', //积分记录
  19. recommend: 'recommend', //推荐客户
  20. };
  21. const PrivateCustomer = () => {
  22. const ref = useRef();
  23. const [showModel, SetShowModel] = useState({});
  24. const [exportLoding, setExportLoding] = useState(false);
  25. const handShowModel = (record, actionType) => {
  26. SetShowModel({
  27. [actionList[actionType]]: {
  28. visible: true,
  29. data: record,
  30. },
  31. });
  32. };
  33. function toCustomerDateil(record) {
  34. router.push({
  35. pathname: '/customer/customerlist/privateCustomerDetail',
  36. query: {
  37. id: record.customerId,
  38. },
  39. });
  40. }
  41. const columns = useMemo(() => {
  42. return [
  43. {
  44. title: '头像',
  45. dataIndex: 'picture',
  46. key: 'picture',
  47. align: 'center',
  48. width: '10%',
  49. render: (_, record) => (
  50. <Avatar
  51. shape="square"
  52. style={{ color: 'blue' }}
  53. src={record.picture}
  54. size={64}
  55. icon="user"
  56. />
  57. ),
  58. },
  59. {
  60. title: '姓名',
  61. dataIndex: 'name',
  62. key: 'name',
  63. align: 'center',
  64. width: '10%',
  65. // eslint-disable-next-line no-nested-ternary
  66. // render: (_, record) => (
  67. // <>
  68. // <Navigate onClick={() => toCustomerDateil(record)}>{record.name}</Navigate>
  69. // </>
  70. // ),
  71. },
  72. {
  73. title: '电话',
  74. dataIndex: 'phone',
  75. key: 'phone',
  76. align: 'center',
  77. width: '10%',
  78. },
  79. {
  80. title: '性别',
  81. dataIndex: 'sex',
  82. key: 'sex',
  83. align: 'center',
  84. width: '10%',
  85. // eslint-disable-next-line no-nested-ternary
  86. render: (_, record) => (
  87. <>
  88. <span>{record.sex === 1 ? '男' : record.sex === 2 ? '女' : '未知'}</span>
  89. </>
  90. ),
  91. },
  92. {
  93. title: '置业顾问',
  94. dataIndex: 'consultantName',
  95. key: 'consultantName',
  96. align: 'center',
  97. width: '10%',
  98. // eslint-disable-next-line no-nested-ternary
  99. render: (_, record) => (
  100. <>
  101. <span>{record.consultantName}</span>
  102. <br />
  103. <span>{record.consultTel}</span>
  104. </>
  105. ),
  106. },
  107. {
  108. title: '归属项目',
  109. dataIndex: 'buildingName',
  110. key: 'buildingName',
  111. align: 'center',
  112. width: '10%',
  113. },
  114. {
  115. title: '推广人员',
  116. dataIndex: 'recommendName',
  117. key: 'recommendName',
  118. align: 'center',
  119. width: '10%',
  120. },
  121. {
  122. title: '客户状态',
  123. dataIndex: 'reportRecommendStatus',
  124. key: 'reportRecommendStatus',
  125. align: 'center',
  126. width: '10%',
  127. // eslint-disable-next-line no-nested-ternary
  128. render: (_, records) => {
  129. if (records.status === 1) {
  130. return '报备';
  131. }
  132. if (records.status === 2) {
  133. return '到访';
  134. }
  135. if (records.status === 3) {
  136. return '认筹';
  137. }
  138. if (records.status === 4) {
  139. return '签约';
  140. }
  141. if (records.status === 5) {
  142. return '结佣';
  143. }
  144. // if (records.status === 6) {
  145. // return '报废';
  146. // }
  147. },
  148. },
  149. {
  150. title: '操作',
  151. dataIndex: 'customerId',
  152. key: 'customerId',
  153. align: 'center',
  154. width: '20%',
  155. render: withActions((_, record) => [
  156. <AuthButton name="customer.detail">
  157. <Button type="link" onClick={() => toCustomerDateil(record)}>
  158. 查看详情
  159. </Button>
  160. </AuthButton>,
  161. // <EditIcon color="#FF4A4A" text="查看详情" onClick={() => toCustomerDateil(record)} />,
  162. <AuthButton name="customer.status.change" noRight={null}>
  163. <Button
  164. type="link"
  165. onClick={() => {
  166. router.push({
  167. pathname: '/customer/customer/StatusChange',
  168. query: {
  169. id: record.customerId,
  170. buildingId:record.buildingId
  171. },
  172. });
  173. }}
  174. >
  175. 变更状态
  176. </Button>
  177. </AuthButton>,
  178. <AuthButton name="customer.belong.change" noRight={null}>
  179. <Button type="link" onClick={() => handShowModel(record, actionList.attribution)}>
  180. 调整归属
  181. </Button>
  182. </AuthButton>,
  183. ]),
  184. },
  185. ];
  186. }, []);
  187. //导出
  188. function exportCustomer() {
  189. console.log(ref.current, 'ref');
  190. setExportLoding(true);
  191. request({
  192. ...apis.customer.customerRecommendExport,
  193. responseType: 'blob',
  194. params: ref.current.getSearchData,
  195. })
  196. .then(response => {
  197. download(response);
  198. setExportLoding(false);
  199. })
  200. .catch(() => {
  201. message.err('连接超时');
  202. setExportLoding(false);
  203. });
  204. }
  205. function download(data) {
  206. if (!data) {
  207. return;
  208. }
  209. const url = window.URL.createObjectURL(new Blob([data]));
  210. const link = document.createElement('a');
  211. link.style.display = 'none';
  212. link.href = url;
  213. link.setAttribute('download', '客户列表.xlsx');
  214. document.body.append(link);
  215. link.click();
  216. }
  217. const searchFields = useMemo(getSearchFields, []);
  218. //操作成功请求数据
  219. const handleCancel = () => {
  220. SetShowModel({});
  221. ref.current.reload();
  222. };
  223. const actionRender = () => {
  224. return (
  225. <Button type="danger" loading={exportLoding} onClick={() => exportCustomer()}>
  226. 导出
  227. </Button>
  228. );
  229. };
  230. return (
  231. <>
  232. <QueryTable
  233. ref={ref}
  234. rowKey="customerId"
  235. api={apis.customer.customerRecommend}
  236. searchFields={searchFields}
  237. params={{
  238. customerType: 'private',
  239. }}
  240. columns={columns}
  241. actionRender={actionRender}
  242. // onPageChange={(pg) => setPage(pg)}
  243. />
  244. <ChangeStatus
  245. modelProps={showModel[actionList.changeStatus]}
  246. handleCancel={handleCancel}
  247. onCancel={() => SetShowModel({})}
  248. ></ChangeStatus>
  249. <Attribution
  250. modelProps={showModel[actionList.attribution]}
  251. handleCancel={handleCancel}
  252. onCancel={() => SetShowModel({})}
  253. />
  254. <IntegralRecord
  255. modelProps={showModel[actionList.integralRecord]}
  256. handleCancel={handleCancel}
  257. onCancel={() => SetShowModel({})}
  258. />
  259. <Recommend
  260. modelProps={showModel[actionList.recommend]}
  261. handleCancel={handleCancel}
  262. onCancel={() => SetShowModel({})}
  263. />
  264. </>
  265. );
  266. };
  267. export default PrivateCustomer;