import { Connect } from "@cqsjjb/jjb-dva-runtime";
import { Descriptions, Divider, Spin } from "antd";
import { useEffect, useState } from "react";
import Page from "zy-react-library/components/Page";
import PreviewImg from "zy-react-library/components/PreviewImg";
import { UPLOAD_FILE_TYPE_ENUM } from "zy-react-library/enum/uploadFile/gwj";
import useGetFile from "zy-react-library/hooks/useGetFile";
import useGetUrlQuery from "zy-react-library/hooks/useGetUrlQuery";
import { getLabelName } from "zy-react-library/utils";
import { NS_TEMPORARY_PERSONNEL } from "~/enumerate/namespace";

const VEHICLE_APPROVAL_STATUS_ENUM = [
  { bianma: 1, name: "审批中" },
  { bianma: 2, name: "通过" },
  { bianma: 3, name: "已驳回" },
];
function View(props) {
  const query = useGetUrlQuery();
  const { loading: getFileLoading, getFile } = useGetFile();

  const [info, setInfo] = useState({});

  const getData = async () => {
    const { data } = await props["temporaryPersonnelInfo"]({ id: query.id });
    const informSignFile = await getFile({ eqType: UPLOAD_FILE_TYPE_ENUM[611], eqForeignKey: data.informSignId });
    setInfo({
      ...data,
      informSignFile,
    });
  };

  useEffect(() => {
    getData();
  }, []);

  return (
    <Page headerTitle="查看" contentPadding="0 20px 20px 20px">
      <Spin spinning={props.temporaryPersonnel.temporaryPersonnelLoading || getFileLoading}>
        <Divider orientation="left">申请信息</Divider>
        <Descriptions
          column={2}
          bordered
          styles={{ label: { width: 200 } }}
          items={[
            { label: "访问人姓名", children: info.personApplyList?.[0].employeePersonUserName, span: 2 },
            { label: "手机号", children: info.personApplyList?.[0].userPhone },
            { label: "身份证号", children: info.personApplyList?.[0].userCard },
            { label: "访问开始时间", children: info.visitStartTime },
            { label: "访问结束时间", children: info.visitEndTime },
            { label: "访问港区", children: info.gateLevelAuthArea && JSON.parse(info.gateLevelAuthArea).area.map(item => item.value).join("、") },
            { label: "访问口门名称", children: info.mkmjName },
            { label: "来访事由", children: info.reasonVisit, span: 2 },
            { label: "人脸照片", children: (<PreviewImg files={[info.personApplyList?.[0].userFaceUrl]} />), span: 2 },
            { label: "申请人安全告知签字", children: (<PreviewImg files={info.informSignFile} />) },
          ]}
        />
        <Divider orientation="left">审批信息</Divider>
        <Descriptions
          column={2}
          bordered
          styles={{ label: { width: 200 } }}
          items={[
            { label: "审批企业", children: info.auditCorpName },
            { label: "审批部门", children: info.auditDeptName },
            { label: "审批人", children: info.auditUserName },
            { label: "审批状态", children: getLabelName({ list: VEHICLE_APPROVAL_STATUS_ENUM, status: info.auditFlag }) },
            ...(info.auditFlag === 1 ? [] : [{ label: "审批时间", children: info.auditTime }, { label: "驳回原因", children: info.reasonsRefusal }]),
          ]}
        />
      </Spin>
    </Page>
  );
}

export default Connect([NS_TEMPORARY_PERSONNEL], true)(View);
