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 } from "~/enumerate/constant";
import { NS_ENCLOSED_AREA_PERSONNEL_APPLY } from "~/enumerate/namespace";

function List(props) {
  const [form] = Search.useForm();

  const { tableProps, getData } = useTable(props["enclosedAreaPersonnelApplyList"], {
    form,
    params: { processOrRecord: 1, personBelongType: 4 },
  });

  return (
    <Page isShowAllAction={false}>
      <Search
        options={[
          { name: "applyPersonUserName", label: "人员姓名" },
        ]}
        form={form}
        onFinish={getData}
      />
      <Table
        columns={[
          { title: "姓名", dataIndex: "applyPersonUserName" },
          { title: "手机号", dataIndex: "userPhone" },
          {
            title: "身份证号",
            dataIndex: "userCard",
            render: (_, record) => record.userCard ? atob(record.userCard) : "",
          },
          { title: "申请区域", dataIndex: "closedAreaName" },
          { title: "申请口门名称", dataIndex: "levelTwoMkmjName" },
          {
            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: 100,
            fixed: "right",
            render: (_, record) => (
              <Space>
                {(record.currentUserCanAudit === 1 && props.permission("jgd-ent-temp-personnel-review-review")) && (
                  <Button
                    type="link"
                    onClick={() => {
                      props.history.push(`./review?id=${record.id}`);
                    }}
                  >
                    审核
                  </Button>
                )}
              </Space>
            ),
          },
        ]}
        {...tableProps}
      />
    </Page>
  );
}

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