1
0

index.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. import React, { useEffect, useState } from 'react';
  2. import { Button, Card, Form, Input, message, Modal, Space, Table } from 'antd';
  3. import { PlusCircleOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons';
  4. import { PageContainer } from '@ant-design/pro-components';
  5. import type { ColumnsType } from 'antd/es/table';
  6. import Edit from './edit';
  7. import {
  8. queryReportHome,
  9. queryReportHomeDetail,
  10. reportHomeAbandon,
  11. reportHomeSuccess,
  12. } from '@/services/reportHome';
  13. import Check from './check';
  14. interface DataType {
  15. name: string;
  16. address: string;
  17. created_name: string;
  18. record_id: string;
  19. status: number;
  20. }
  21. const CommunityManagement: React.FC = () => {
  22. const [form] = Form.useForm();
  23. const [loading, setLoading] = useState(false);
  24. const [dataList, setDataList] = useState([]);
  25. const [searchData, setSearchData] = useState<object | null>({});
  26. const [pagination, setPagination] = useState({ total: 0, current: 1, pageSize: 10 });
  27. const [editData, setEditData] = useState(null);
  28. const [visible, setVisible] = useState(false);
  29. const [checkVisible, setCheckVisible] = useState(false);
  30. const [checkData, setCheckData] = useState<object | null>({});
  31. const getList = () => {
  32. const params = {
  33. q: 'page',
  34. current: pagination.current,
  35. pageSize: pagination.pageSize,
  36. ...searchData,
  37. };
  38. queryReportHome(params).then((res) => {
  39. if (res && res.code === 0) {
  40. setDataList(res.data.list || []);
  41. setLoading(false);
  42. }
  43. });
  44. };
  45. useEffect(() => {
  46. setLoading(true);
  47. getList();
  48. }, []);
  49. const onFinish = () => {
  50. form.validateFields().then((data) => {
  51. setLoading(true);
  52. setSearchData(data);
  53. });
  54. };
  55. const onReset = () => {
  56. form.resetFields();
  57. setLoading(true);
  58. setSearchData(null);
  59. };
  60. useEffect(() => {
  61. getList();
  62. }, [searchData]);
  63. // 分页切换
  64. const tableChange = () => {
  65. setLoading(true);
  66. const params = {
  67. q: 'page',
  68. current: pagination.current,
  69. pageSize: pagination.pageSize,
  70. ...searchData,
  71. };
  72. queryReportHome(params).then((res) => {
  73. if (res?.code === 0) {
  74. setDataList(res?.data?.list || []);
  75. setPagination(res.data.pagination);
  76. setLoading(false);
  77. }
  78. });
  79. };
  80. // 新增弹框
  81. const onAdd = () => {
  82. setEditData(null);
  83. setVisible(true);
  84. };
  85. const toEdit = (record: any) => {
  86. setEditData(record);
  87. setVisible(true);
  88. };
  89. // 编辑回调
  90. const onEditCallback = () => {
  91. setVisible(false);
  92. getList();
  93. };
  94. // 查看弹框回调
  95. const checkCallback = () => {
  96. setCheckVisible(false);
  97. };
  98. // 成交
  99. const toDeal = (record: any) => {
  100. Modal.confirm({
  101. title: '成交',
  102. content: '是否确认成交?',
  103. onOk: () => {
  104. reportHomeSuccess(record.record_id)
  105. .then((res) => {
  106. if (res.code === 0) {
  107. message.success('成交成功');
  108. } else {
  109. message.error('成交失败');
  110. }
  111. getList();
  112. })
  113. .catch((e) => {
  114. message.error(e?.message);
  115. });
  116. },
  117. });
  118. };
  119. // 放弃
  120. const toDisable = (record: any) => {
  121. Modal.confirm({
  122. title: '放弃',
  123. content: '是否确认放弃?',
  124. onOk: () => {
  125. reportHomeAbandon(record.record_id)
  126. .then((res) => {
  127. if (res.code === 0) {
  128. message.success('放弃成功');
  129. } else {
  130. message.error('放弃失败');
  131. }
  132. getList();
  133. })
  134. .catch((e) => {
  135. message.error(e?.message);
  136. });
  137. },
  138. });
  139. };
  140. // 查看弹框
  141. const toCheck = (record: any) => {
  142. queryReportHomeDetail(record.record_id).then((res) => {
  143. if (res?.code === 0) {
  144. setCheckData(record);
  145. setCheckVisible(true);
  146. }
  147. });
  148. };
  149. const columns: ColumnsType<DataType> = [
  150. {
  151. title: '序号',
  152. align: 'center',
  153. key: 'index',
  154. render: (_: any, _row: any, index: number) => index + 1,
  155. },
  156. {
  157. title: '小区名称',
  158. dataIndex: 'community_name',
  159. key: 'community_name',
  160. },
  161. {
  162. title: '门牌号',
  163. dataIndex: 'doorplate',
  164. key: 'doorplate',
  165. },
  166. {
  167. title: '详细地址',
  168. dataIndex: 'address',
  169. key: 'address',
  170. },
  171. {
  172. title: '空调类型',
  173. dataIndex: 'air_conditioner_type',
  174. key: 'air_conditioner_type',
  175. },
  176. {
  177. title: '业主姓名',
  178. dataIndex: 'proprietor_name',
  179. key: 'proprietor_name',
  180. },
  181. {
  182. title: '成功几率',
  183. dataIndex: 'success_probability',
  184. key: 'success_probability',
  185. },
  186. {
  187. title: '状态',
  188. dataIndex: 'status',
  189. key: 'status',
  190. render: (v) =>
  191. v && <span>{{ 1: '审核未通过', 2: '审核通过', 3: '成交', 4: '放弃', 5: '丢单' }[v]}</span>,
  192. },
  193. {
  194. title: '跟进人',
  195. dataIndex: 'follow_people',
  196. key: 'follow_people',
  197. },
  198. {
  199. title: '操作',
  200. key: 'action',
  201. render: (_, record) => (
  202. <Space size="middle">
  203. <a
  204. onClick={() => {
  205. toEdit(record);
  206. }}
  207. >
  208. 编辑
  209. </a>
  210. <a
  211. onClick={() => {
  212. toCheck(record);
  213. }}
  214. >
  215. 查看
  216. </a>
  217. {record?.status === 2 && (
  218. <a
  219. style={{ color: 'green' }}
  220. onClick={() => {
  221. toDeal(record);
  222. }}
  223. >
  224. 成交
  225. </a>
  226. )}
  227. {record?.status === 2 && (
  228. <a
  229. style={{ color: 'red' }}
  230. onClick={() => {
  231. toDisable(record);
  232. }}
  233. >
  234. 放弃
  235. </a>
  236. )}
  237. </Space>
  238. ),
  239. },
  240. ];
  241. return (
  242. <PageContainer>
  243. <div>
  244. <Card>
  245. <Form form={form} layout="inline" onFinish={onFinish}>
  246. <Form.Item name="like_name" label="小区名称">
  247. <Input placeholder="请输入小区名称" />
  248. </Form.Item>
  249. <Form.Item style={{ marginBottom: '10px' }}>
  250. <Space>
  251. <Button type="primary" htmlType="submit">
  252. <SearchOutlined />
  253. 查询
  254. </Button>
  255. <Button htmlType="button" onClick={onReset}>
  256. <ReloadOutlined />
  257. 重置
  258. </Button>
  259. </Space>
  260. </Form.Item>
  261. </Form>
  262. <Button htmlType="button" type="primary" style={{ margin: '20px 0' }} onClick={onAdd}>
  263. <PlusCircleOutlined />
  264. 新增报备
  265. </Button>
  266. <Table
  267. columns={columns}
  268. dataSource={dataList}
  269. rowKey={(record) => record.record_id}
  270. pagination={pagination}
  271. loading={loading}
  272. onChange={tableChange}
  273. />
  274. {visible && <Edit editCallback={onEditCallback} params={editData} visible={visible} />}
  275. {checkVisible && (
  276. <Check visible={checkVisible} data={checkData} checkCallback={checkCallback} />
  277. )}
  278. </Card>
  279. </div>
  280. </PageContainer>
  281. );
  282. };
  283. export default CommunityManagement;