123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- import React, { useEffect, useState } from 'react';
- import { Button, Card, Form, Input, message, Modal, Space, Table } from 'antd';
- import { PlusCircleOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons';
- import { PageContainer } from '@ant-design/pro-components';
- import type { ColumnsType } from 'antd/es/table';
- import Edit from './edit';
- import {
- queryReportHome,
- queryReportHomeDetail,
- reportHomeAbandon,
- reportHomeSuccess,
- } from '@/services/reportHome';
- import Check from './check';
- interface DataType {
- name: string;
- address: string;
- created_name: string;
- record_id: string;
- status: number;
- }
- const CommunityManagement: React.FC = () => {
- const [form] = Form.useForm();
- const [loading, setLoading] = useState(false);
- const [dataList, setDataList] = useState([]);
- const [searchData, setSearchData] = useState<object | null>({});
- const [pagination, setPagination] = useState({ total: 0, current: 1, pageSize: 10 });
- const [editData, setEditData] = useState(null);
- const [visible, setVisible] = useState(false);
- const [checkVisible, setCheckVisible] = useState(false);
- const [checkData, setCheckData] = useState<object | null>({});
- const getList = () => {
- const params = {
- q: 'page',
- current: pagination.current,
- pageSize: pagination.pageSize,
- ...searchData,
- };
- queryReportHome(params).then((res) => {
- if (res && res.code === 0) {
- setDataList(res.data.list || []);
- setLoading(false);
- }
- });
- };
- useEffect(() => {
- setLoading(true);
- getList();
- }, []);
- const onFinish = () => {
- form.validateFields().then((data) => {
- setLoading(true);
- setSearchData(data);
- });
- };
- const onReset = () => {
- form.resetFields();
- setLoading(true);
- setSearchData(null);
- };
- useEffect(() => {
- getList();
- }, [searchData]);
- // 分页切换
- const tableChange = () => {
- setLoading(true);
- const params = {
- q: 'page',
- current: pagination.current,
- pageSize: pagination.pageSize,
- ...searchData,
- };
- queryReportHome(params).then((res) => {
- if (res?.code === 0) {
- setDataList(res?.data?.list || []);
- setPagination(res.data.pagination);
- setLoading(false);
- }
- });
- };
- // 新增弹框
- const onAdd = () => {
- setEditData(null);
- setVisible(true);
- };
- const toEdit = (record: any) => {
- setEditData(record);
- setVisible(true);
- };
- // 编辑回调
- const onEditCallback = () => {
- setVisible(false);
- getList();
- };
- // 查看弹框回调
- const checkCallback = () => {
- setCheckVisible(false);
- };
- // 成交
- const toDeal = (record: any) => {
- Modal.confirm({
- title: '成交',
- content: '是否确认成交?',
- onOk: () => {
- reportHomeSuccess(record.record_id)
- .then((res) => {
- if (res.code === 0) {
- message.success('成交成功');
- } else {
- message.error('成交失败');
- }
- getList();
- })
- .catch((e) => {
- message.error(e?.message);
- });
- },
- });
- };
- // 放弃
- const toDisable = (record: any) => {
- Modal.confirm({
- title: '放弃',
- content: '是否确认放弃?',
- onOk: () => {
- reportHomeAbandon(record.record_id)
- .then((res) => {
- if (res.code === 0) {
- message.success('放弃成功');
- } else {
- message.error('放弃失败');
- }
- getList();
- })
- .catch((e) => {
- message.error(e?.message);
- });
- },
- });
- };
- // 查看弹框
- const toCheck = (record: any) => {
- queryReportHomeDetail(record.record_id).then((res) => {
- if (res?.code === 0) {
- setCheckData(record);
- setCheckVisible(true);
- }
- });
- };
- const columns: ColumnsType<DataType> = [
- {
- title: '序号',
- align: 'center',
- key: 'index',
- render: (_: any, _row: any, index: number) => index + 1,
- },
- {
- title: '小区名称',
- dataIndex: 'community_name',
- key: 'community_name',
- },
- {
- title: '门牌号',
- dataIndex: 'doorplate',
- key: 'doorplate',
- },
- {
- title: '详细地址',
- dataIndex: 'address',
- key: 'address',
- },
- {
- title: '空调类型',
- dataIndex: 'air_conditioner_type',
- key: 'air_conditioner_type',
- },
- {
- title: '业主姓名',
- dataIndex: 'proprietor_name',
- key: 'proprietor_name',
- },
- {
- title: '成功几率',
- dataIndex: 'success_probability',
- key: 'success_probability',
- },
- {
- title: '状态',
- dataIndex: 'status',
- key: 'status',
- render: (v) =>
- v && <span>{{ 1: '审核未通过', 2: '审核通过', 3: '成交', 4: '放弃', 5: '丢单' }[v]}</span>,
- },
- {
- title: '跟进人',
- dataIndex: 'follow_people',
- key: 'follow_people',
- },
- {
- title: '操作',
- key: 'action',
- render: (_, record) => (
- <Space size="middle">
- <a
- onClick={() => {
- toEdit(record);
- }}
- >
- 编辑
- </a>
- <a
- onClick={() => {
- toCheck(record);
- }}
- >
- 查看
- </a>
- {record?.status === 2 && (
- <a
- style={{ color: 'green' }}
- onClick={() => {
- toDeal(record);
- }}
- >
- 成交
- </a>
- )}
- {record?.status === 2 && (
- <a
- style={{ color: 'red' }}
- onClick={() => {
- toDisable(record);
- }}
- >
- 放弃
- </a>
- )}
- </Space>
- ),
- },
- ];
- return (
- <PageContainer>
- <div>
- <Card>
- <Form form={form} layout="inline" onFinish={onFinish}>
- <Form.Item name="like_name" label="小区名称">
- <Input placeholder="请输入小区名称" />
- </Form.Item>
- <Form.Item style={{ marginBottom: '10px' }}>
- <Space>
- <Button type="primary" htmlType="submit">
- <SearchOutlined />
- 查询
- </Button>
- <Button htmlType="button" onClick={onReset}>
- <ReloadOutlined />
- 重置
- </Button>
- </Space>
- </Form.Item>
- </Form>
- <Button htmlType="button" type="primary" style={{ margin: '20px 0' }} onClick={onAdd}>
- <PlusCircleOutlined />
- 新增报备
- </Button>
- <Table
- columns={columns}
- dataSource={dataList}
- rowKey={(record) => record.record_id}
- pagination={pagination}
- loading={loading}
- onChange={tableChange}
- />
- {visible && <Edit editCallback={onEditCallback} params={editData} visible={visible} />}
- {checkVisible && (
- <Check visible={checkVisible} data={checkData} checkCallback={checkCallback} />
- )}
- </Card>
- </div>
- </PageContainer>
- );
- };
- export default CommunityManagement;
|