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_STAKEHOLDER_PERSONNEL_AND_VEHICLES } from "~/enumerate/namespace";

function List(props) {
  const [form] = Search.useForm();
  const { tableProps, getData } = useTable(props["stakeholderPersonnelAndVehiclesList"], {
    form,
  });

  return (
    <Page isShowAllAction={false}>
      <Search
        labelCol={{ span: 4 }}
        options={[
          { name: "name", label: "相关方名称" },
        ]}
        onFinish={getData}
        form={form}
      />
      <Table
        columns={[
          { title: "相关方名称", dataIndex: "applyCorpName" },
          { title: "项目数", dataIndex: "projectCount" },
          {
            title: "操作",
            width: 200,
            fixed: "right",
            render: (_, record) => (
              <Space>
                {props.permission(props.personnelListBtn || "jgd-io-stk-pv-personlist") && (
                  <Button
                    type="link"
                    onClick={() => {
                      props.history.push(`./personnel/list?id=${record.applyCorpId}`);
                    }}
                  >
                    人员列表
                  </Button>
                )}
                {props.permission(props.vehicleListBtn || "jgd-io-stk-pv-carlist") && (
                  <Button
                    type="link"
                    onClick={() => {
                      props.history.push(`./vehicle/list?id=${record.applyCorpId}`);
                    }}
                  >
                    车辆列表
                  </Button>
                )}
              </Space>
            ),
          },
        ]}
        {...tableProps}
      />
    </Page>
  );
}

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