import { Permission } from "@cqsjjb/jjb-common-decorator/permission";
import { Connect } from "@cqsjjb/jjb-dva-runtime";
import { Button, Space } from "antd";
import Page from "zy-react-library/components/Page";
import Search from "zy-react-library/components/Search";
import Table from "zy-react-library/components/Table";
import useTable from "zy-react-library/hooks/useTable";
import { NS_BRANCH_PERSONNEL_AND_VEHICLES } from "~/enumerate/namespace";

function List(props) {
  const [form] = Search.useForm();
  const { tableProps, getData } = useTable(props["branchPersonnelAndVehiclesList"], {
    form,
    params: { corpType: 1 },
  });

  return (
    <Page isShowAllAction={false}>
      <Search
        form={form}
        labelCol={{ span: 4 }}
        onFinish={getData}
        options={[
          { name: "corpName", label: "企业名称" },
        ]}
      />
      <Table
        columns={[
          { title: "企业名称", dataIndex: "corpName" },
          { title: "人员数", dataIndex: "userCount" },
          { title: "人员车辆数", dataIndex: "priCarCount" },
          { title: "单位车辆数", dataIndex: "pubCarCount" },
          {
            title: "操作",
            fixed: "right",
            width: 200,
            render: (_, record) => (
              <Space>
                {props.permission("jgd-io-branch-pv-personinfo") && (
                  <Button
                    type="link"
                    onClick={() => {
                      props.history.push(`./personnelAndVehicle/list?id=${record.corpId}`);
                    }}
                  >
                    人员及车辆详情
                  </Button>
                )}
                {props.permission("jgd-io-branch-pv-pubinfo") && (
                  <Button
                    type="link"
                    onClick={() => {
                      props.history.push(`./unitVehicle/list?id=${record.corpId}`);
                    }}
                  >
                    单位车辆详情
                  </Button>
                )}
              </Space>
            ),
          },
        ]}
        {...tableProps}
      />
    </Page>
  );
}

export default Connect([NS_BRANCH_PERSONNEL_AND_VEHICLES], true)(Permission(List));
