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 { getLabelName } from "zy-react-library/utils";
import { ENCLOSED_AREA_AUDIT_STATUS_ENUM, ENCLOSED_AREA_BELONGING_END_ENUM } from "~/enumerate/constant";
import { NS_ENCLOSED_AREA_VEHICLE_APPLY } from "~/enumerate/namespace";

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

  return (
    <Page isShowAllAction={false}>
      <Search
        options={[
          { name: "applyPersonUserName", label: "人员姓名" },
          { name: "licenceNo", label: "车牌号" },
        ]}
        form={form}
        onFinish={getData}
      />
      <Table
        columns={[
          {
            title: "申请来源",
            dataIndex: "carBelongType",
            render: (_, record) => getLabelName({ list: ENCLOSED_AREA_BELONGING_END_ENUM, status: record.carBelongType }),
          },
          { title: "车辆类型", dataIndex: "vehicleTypeName" },
          { title: "车牌号", dataIndex: "licenceNo" },
          { title: "申请人姓名", dataIndex: "applyPersonUserName" },
          { title: "手机号", dataIndex: "userPhone" },
          { title: "部门", dataIndex: "applyPersonDepartmentName" },
          { title: "申请区域", dataIndex: "closedAreaName" },
          {
            title: "申请时间范围",
            dataIndex: "visitStartTime",
            render: (_, record) => `${record.visitStartTime} - ${record.visitEndTime}`,
          },
          {
            title: "审核状态",
            dataIndex: "auditFlag",
            render: (_, record) => getLabelName({ list: ENCLOSED_AREA_AUDIT_STATUS_ENUM, status: record.auditFlag }),
          },
          {
            title: "操作",
            width: 80,
            fixed: "right",
            render: (_, record) => (
              <Space>
                {(record.currentUserCanAudit === 1 && props.permission("jgd-ent-long-vehicle-review-review")) && (
                  <Button
                    type="link"
                    onClick={() => {
                      const entrance = ENCLOSED_AREA_BELONGING_END_ENUM.find(item => +item.bianma === record.carBelongType).bianma;
                      props.history.push(`./review?id=${record.id}&entrance=${entrance}`);
                    }}
                  >
                    审核
                  </Button>
                )}
              </Space>
            ),
          },
        ]}
        {...tableProps}
      />
    </Page>
  );
}

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