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: 2 },
  });

  return (
    <Page isShowAllAction={false}>
      <Search
        options={[
          { name: "corpName", label: "驻港单位名称" },
        ]}
        form={form}
        onFinish={getData}
      />
      <Table
        columns={[
          { title: "驻港单位名称", dataIndex: "corpName" },
          { title: "人员进出数", dataIndex: "userCount" },
          { title: "人员车辆进出数", dataIndex: "priCarCount" },
          {
            title: "操作",
            width: 150,
            fixed: "right",
            render: (_, record) => (
              <Space>
                {props.permission("jgd-io-port-unit-pv-show") && (
                  <Button
                    type="link"
                    onClick={() => {
                      props.history.push(`./personnelAndVehicle/list?id=${record.corpId}`);
                    }}
                  >
                    人员及车辆详情
                  </Button>
                )}
              </Space>
            ),
          },
        ]}
        {...tableProps}
      />
    </Page>
  );
}

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