123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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: 'sharePersonName',
  117. key: 'sharePersonName',
  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. },
  142. },
  143. {
  144. title: '操作',
  145. dataIndex: 'customerId',
  146. key: 'customerId',
  147. align: 'center',
  148. width: '20%',
  149. render: withActions((_, record) => [
  150. <Button type="link" onClick={() => toCustomerDateil(record)}>
  151. 查看详情
  152. </Button>,
  153. // <EditIcon color="#FF4A4A" text="查看详情" onClick={() => toCustomerDateil(record)} />,
  154. <AuthButton name="admin.customer.recommend.edit.id.put" noRight={null}>
  155. <Button
  156. type="link"
  157. onClick={() => handShowModel(record, actionList.changeStatus)}
  158. >
  159. 变更状态
  160. </Button>
  161. </AuthButton>,
  162. <AuthButton name="admin.customer.recommend.belong" noRight={null}>
  163. <Button
  164. type="link"
  165. onClick={() => handShowModel(record, actionList.attribution)}
  166. >
  167. 调整归属
  168. </Button>
  169. </AuthButton>,
  170. ]),
  171. },
  172. ];
  173. }, []);
  174. //导出
  175. function exportCustomer() {
  176. console.log(ref.current, 'ref');
  177. setExportLoding(true);
  178. request({
  179. ...apis.customer.customerRecommendExport,
  180. responseType: 'blob',
  181. params: ref.current.getSearchData,
  182. })
  183. .then(response => {
  184. download(response);
  185. setExportLoding(false);
  186. })
  187. .catch(() => {
  188. message.err('连接超时');
  189. setExportLoding(false);
  190. });
  191. }
  192. function download(data) {
  193. if (!data) {
  194. return;
  195. }
  196. const url = window.URL.createObjectURL(new Blob([data]));
  197. const link = document.createElement('a');
  198. link.style.display = 'none';
  199. link.href = url;
  200. link.setAttribute('download', '客户列表.xlsx');
  201. document.body.append(link);
  202. link.click();
  203. }
  204. const searchFields = useMemo(getSearchFields, []);
  205. //操作成功请求数据
  206. const handleCancel = () => {
  207. SetShowModel({});
  208. ref.current.reload();
  209. };
  210. const actionRender = () => {
  211. return (
  212. <Button type="danger" loading={exportLoding} onClick={() => exportCustomer()}>
  213. 导出
  214. </Button>
  215. );
  216. };
  217. return (
  218. <>
  219. <QueryTable
  220. ref={ref}
  221. rowKey="customerId"
  222. api={apis.customer.customerRecommend}
  223. searchFields={searchFields}
  224. params={{
  225. customerType: 'private',
  226. }}
  227. columns={columns}
  228. actionRender={actionRender}
  229. // onPageChange={(pg) => setPage(pg)}
  230. />
  231. <ChangeStatus
  232. modelProps={showModel[actionList.changeStatus]}
  233. handleCancel={handleCancel}
  234. onCancel={() => SetShowModel({})}
  235. ></ChangeStatus>
  236. <Attribution
  237. modelProps={showModel[actionList.attribution]}
  238. handleCancel={handleCancel}
  239. onCancel={() => SetShowModel({})}
  240. />
  241. <IntegralRecord
  242. modelProps={showModel[actionList.integralRecord]}
  243. handleCancel={handleCancel}
  244. onCancel={() => SetShowModel({})}
  245. />
  246. <Recommend
  247. modelProps={showModel[actionList.recommend]}
  248. handleCancel={handleCancel}
  249. onCancel={() => SetShowModel({})}
  250. />
  251. </>
  252. );
  253. };
  254. export default PrivateCustomer;