import React from 'react';
import PropTypes from 'prop-types';
import { VtxPageLayout, VtxSearch, VtxDatagrid } from '@vtx/components';
import { Form } from 'antd';
import { useAntdTable } from 'ahooks';
import { getSiteList } from './api';
import VtxGasSupplyStationModal from '../vtx-gas-supply-station-modal';
import ParamConfigSelect from '../param-config-select';
const { TableLayout } = VtxPageLayout;

const SupplyStationInfo = ({ id }) => {
    const [form] = Form.useForm();
    const columns = [
        {
            title: '供应站名称',
            dataIndex: 'name',
            render: (text, record) => {
                const { id, name } = record;
                return <VtxGasSupplyStationModal id={id} label={name} />;
            },
        },
        {
            title: '站长',
            dataIndex: 'chargePerson',
            render: (text, record) => {
                return record?.dataJson?.chargePerson;
            },
        },
        {
            title: '联系方式',
            dataIndex: 'chargePersonTel',
            render: (text, record) => {
                return record?.dataJson?.chargePersonTel;
            },
        },
        {
            title: '地址',
            dataIndex: 'address',
        },
        {
            title: '营业状态',
            dataIndex: 'businessStatusName',
            render: (text, record) => {
                return record?.dataJson?.businessStatusName;
            },
        },
    ];
    const { refresh, search, tableProps } = useAntdTable(getSiteList(id), {
        defaultPageSize: 10,
        form,
        refreshDeps: [id],
    });
    const { submit, reset } = search;
    const { current, pageSize } = tableProps?.pagination;
    const datagridProps = {
        ...tableProps,
        columns,
        toolbarTilte: '查询结果',
        startIndex: (current - 1) * pageSize + 1,
        onRefresh: refresh,
        toolbar: false,
    };

    return (
        <TableLayout.Page>
            <TableLayout.Search>
                <Form form={form}>
                    <VtxSearch
                        titles={['营业状态']}
                        gridWeight={[1]}
                        onConfirm={submit}
                        onClear={reset}
                    >
                        <Form.Item name="businessStatusId">
                            <ParamConfigSelect code="businessStatus" />
                        </Form.Item>
                    </VtxSearch>
                </Form>
            </TableLayout.Search>
            <TableLayout.Content>
                <TableLayout.Table>
                    <VtxDatagrid {...datagridProps} />
                </TableLayout.Table>
            </TableLayout.Content>
        </TableLayout.Page>
    );
};

SupplyStationInfo.propTypes = {
    id: PropTypes.string,
};

export default SupplyStationInfo;
