index.tsx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. import { PageContainer } from '@ant-design/pro-components';
  2. import { Button, Card, DatePicker, Form, Input, message, Modal, Select, Space, Table } from 'antd';
  3. import React, { useEffect, useState } from 'react';
  4. import { PlusCircleOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons';
  5. import type { ColumnsType } from 'antd/es/table';
  6. import {
  7. infoQuery,
  8. reportingAbandon,
  9. reportingDetailQuery,
  10. reportingQuery,
  11. reportingSuccess,
  12. salesQuery,
  13. } from '@/services/ReportingManagement';
  14. import Edit from './edit';
  15. import Check from './check';
  16. import moment from 'moment';
  17. const { RangePicker } = DatePicker;
  18. interface DataType {
  19. community_name: string;
  20. record_id: string;
  21. status: number;
  22. }
  23. /**
  24. * 报备管理
  25. * @constructor
  26. */
  27. const ReportingManagement: React.FC = () => {
  28. const [form] = Form.useForm();
  29. const [pagination, setPagination] = useState({ total: 0, current: 1, pageSize: 10 });
  30. const [detailData, setDetailData] = useState<object | null>({});
  31. const [loading, setLoading] = useState(false);
  32. const [dataList, setDataList] = useState([]);
  33. const [searchData, setSearchData] = useState<object | null>({});
  34. const [visible, setVisible] = useState(false);
  35. const [salesmanList, setSalesmanList] = useState([]);
  36. const [checkVisible, setCheckVisible] = useState(false);
  37. const [checkData, setCheckData] = useState<object | null>({});
  38. const getList = () => {
  39. const params = {
  40. q: 'page',
  41. current: pagination.current,
  42. pageSize: pagination.pageSize,
  43. ...searchData,
  44. };
  45. reportingQuery(params).then((res) => {
  46. if (res?.code === 0) {
  47. setDataList(res?.data?.list || []);
  48. setPagination(res.data.pagination);
  49. setLoading(false);
  50. }
  51. });
  52. };
  53. const getSalesList = (id: string) => {
  54. const params = {
  55. q: 'list',
  56. status: 1,
  57. parent_id: id,
  58. };
  59. salesQuery(params).then((res) => {
  60. if (res?.code === 0) {
  61. setSalesmanList(res?.data || []);
  62. }
  63. });
  64. };
  65. const getUserInfo = () => {
  66. infoQuery().then((res) => {
  67. if (res?.code === 0) {
  68. getSalesList(res.data.record_id);
  69. }
  70. });
  71. };
  72. useEffect(() => {
  73. getList();
  74. getUserInfo();
  75. }, []);
  76. // 搜索
  77. const onFinish = () => {
  78. form.validateFields().then((data) => {
  79. const params: any = {};
  80. if (data.project_name) {
  81. params.project_name = data.project_name;
  82. }
  83. if (data.status) {
  84. params.status = data.status;
  85. }
  86. if (data.user_id) {
  87. params.user_id = data.user_id;
  88. }
  89. if (data.time) {
  90. params.time_start = moment(data.time[0]).format('YYYY-MM-DD');
  91. params.time_end = moment(data.time[1]).format('YYYY-MM-DD');
  92. }
  93. setLoading(true);
  94. setSearchData(params);
  95. });
  96. };
  97. const onReset = () => {
  98. form.resetFields();
  99. setLoading(true);
  100. setSearchData(null);
  101. };
  102. useEffect(() => {
  103. getList();
  104. }, [searchData]);
  105. // 分页切换
  106. const tableChange = () => {
  107. setLoading(true);
  108. const params = {
  109. q: 'page',
  110. current: pagination.current,
  111. pageSize: pagination.pageSize,
  112. ...searchData,
  113. };
  114. reportingQuery(params).then((res) => {
  115. if (res?.code === 0) {
  116. setDataList(res?.data?.list || []);
  117. setPagination(res.data.pagination);
  118. setLoading(false);
  119. }
  120. });
  121. };
  122. // 新增
  123. const onAdd = () => {
  124. setVisible(true);
  125. setDetailData(null);
  126. };
  127. // 编辑弹框
  128. const toEdit = (record: any) => {
  129. reportingDetailQuery(record.record_id).then((res) => {
  130. if (res?.code === 0) {
  131. setDetailData(record || null);
  132. setVisible(true);
  133. }
  134. });
  135. };
  136. // 编辑弹框回调
  137. const onEditCallback = () => {
  138. setVisible(false);
  139. getList();
  140. };
  141. // 查看弹框
  142. const toCheck = (record: any) => {
  143. reportingDetailQuery(record.record_id).then((res) => {
  144. if (res?.code === 0) {
  145. setCheckData(record);
  146. setCheckVisible(true);
  147. }
  148. });
  149. };
  150. // 查看弹框回调
  151. const checkCallback = () => {
  152. setCheckVisible(false);
  153. };
  154. // 成交
  155. const toDeal = (record: any) => {
  156. Modal.confirm({
  157. title: '成交',
  158. content: '是否确认成交?',
  159. onOk: () => {
  160. reportingSuccess(record.record_id)
  161. .then((res) => {
  162. if (res.code === 0) {
  163. message.success('成交成功');
  164. } else {
  165. message.error('成交失败');
  166. }
  167. getList();
  168. })
  169. .catch((e) => {
  170. message.error(e?.message);
  171. });
  172. },
  173. });
  174. };
  175. // 放弃
  176. const toDisable = (record: any) => {
  177. Modal.confirm({
  178. title: '放弃',
  179. content: '是否确认放弃?',
  180. onOk: () => {
  181. reportingAbandon(record.record_id)
  182. .then((res) => {
  183. if (res.code === 0) {
  184. message.success('放弃成功');
  185. } else {
  186. message.error('放弃失败');
  187. }
  188. getList();
  189. })
  190. .catch((e) => {
  191. message.error(e?.message);
  192. });
  193. },
  194. });
  195. };
  196. const columns: ColumnsType<DataType> = [
  197. {
  198. title: '序号',
  199. align: 'center',
  200. key: 'index',
  201. render: (_: any, row: any, index: number) => index + 1,
  202. },
  203. {
  204. title: '项目名称',
  205. dataIndex: 'project_name',
  206. key: 'project_name',
  207. },
  208. {
  209. title: '城市',
  210. dataIndex: 'city',
  211. key: 'city',
  212. render: (_, data: any) => (
  213. <span>{`${data.province}` + ' ' + `${data.city}` + ' ' + `${data.district}`}</span>
  214. ),
  215. },
  216. {
  217. title: '甲方联系人',
  218. dataIndex: 'contact_person',
  219. key: 'contact_person',
  220. },
  221. {
  222. title: '联系方式',
  223. dataIndex: 'phone',
  224. key: 'phone',
  225. },
  226. {
  227. title: '跟进人',
  228. dataIndex: 'follow_people',
  229. key: 'follow_people',
  230. },
  231. {
  232. title: '状态',
  233. dataIndex: 'status',
  234. key: 'status',
  235. render: (v) =>
  236. v && <span>{{ 1: '审核未通过', 2: '审核通过', 3: '成交', 4: '放弃', 5: '丢单' }[v]}</span>,
  237. },
  238. {
  239. title: '操作',
  240. key: 'action',
  241. render: (_, record) => (
  242. <Space size="middle">
  243. <a
  244. onClick={() => {
  245. toEdit(record);
  246. }}
  247. >
  248. 编辑
  249. </a>
  250. <a
  251. onClick={() => {
  252. toCheck(record);
  253. }}
  254. >
  255. 查看
  256. </a>
  257. {record?.status === 2 && (
  258. <a
  259. style={{ color: 'green' }}
  260. onClick={() => {
  261. toDeal(record);
  262. }}
  263. >
  264. 成交
  265. </a>
  266. )}
  267. {record?.status === 2 && (
  268. <a
  269. style={{ color: 'red' }}
  270. onClick={() => {
  271. toDisable(record);
  272. }}
  273. >
  274. 放弃
  275. </a>
  276. )}
  277. </Space>
  278. ),
  279. },
  280. ];
  281. const paginationProps = {
  282. showSizeChanger: true,
  283. showQuickJumper: true,
  284. showTotal: (total: number) => {
  285. return <span> 共 {total}条 </span>;
  286. },
  287. ...pagination,
  288. };
  289. return (
  290. <PageContainer>
  291. <Card>
  292. <Form form={form} layout="inline" onFinish={onFinish}>
  293. <Form.Item name="project_name" label="工程名称">
  294. <Input placeholder="请输入工程名称" />
  295. </Form.Item>
  296. <Form.Item name="status" label="状态">
  297. <Select style={{ width: '175px' }} placeholder="请选择状态">
  298. <Select.Option key={2} value={2}>
  299. 审核通过
  300. </Select.Option>
  301. <Select.Option key={3} value={3}>
  302. 成交
  303. </Select.Option>
  304. <Select.Option key={4} value={4}>
  305. 放弃
  306. </Select.Option>
  307. <Select.Option key={5} value={5}>
  308. 丢单
  309. </Select.Option>
  310. </Select>
  311. </Form.Item>
  312. <Form.Item name="user_id" label="业务员">
  313. <Select style={{ width: '175px' }} placeholder="请选择业务员">
  314. {salesmanList && salesmanList.length
  315. ? salesmanList.map((res: any) => {
  316. return (
  317. <Select.Option key={res?.record_id} value={res?.record_id}>
  318. {res?.user_name}
  319. </Select.Option>
  320. );
  321. })
  322. : null}
  323. </Select>
  324. </Form.Item>
  325. <Form.Item name="time" label="时间">
  326. <RangePicker />
  327. </Form.Item>
  328. <Form.Item style={{ marginBottom: '10px' }}>
  329. <Space>
  330. <Button type="primary" htmlType="submit">
  331. <SearchOutlined />
  332. 查询
  333. </Button>
  334. <Button htmlType="button" onClick={onReset}>
  335. <ReloadOutlined />
  336. 重置
  337. </Button>
  338. </Space>
  339. </Form.Item>
  340. </Form>
  341. <Button htmlType="button" type="primary" style={{ margin: '20px 0' }} onClick={onAdd}>
  342. <PlusCircleOutlined />
  343. 新增报备
  344. </Button>
  345. <Table
  346. columns={columns}
  347. dataSource={dataList}
  348. rowKey={(record) => record.record_id}
  349. pagination={paginationProps}
  350. loading={loading}
  351. onChange={tableChange}
  352. />
  353. </Card>
  354. {visible && <Edit detailData={detailData} editCallback={onEditCallback} visible={visible} />}
  355. {checkVisible && (
  356. <Check visible={checkVisible} data={checkData} checkCallback={checkCallback} />
  357. )}
  358. </PageContainer>
  359. );
  360. };
  361. export default ReportingManagement;