import { Connect } from "@cqsjjb/jjb-dva-runtime";
import { Divider, Image } from "antd";
import { useEffect, useState } from "react";
import { getFileUrl } from "zy-react-library/utils";
import { NS_BI_MARK_INFO } from "~/enumerate/namespace";
import DisclaimerSign from "../eightWordPubilc/DisclaimerSign";
import OpinionSign from "../eightWordPubilc/OpinionSign";
import SafetyMeasures from "../eightWordPubilc/SafetyMeasures";
import "../eightWordPubilc/index.less";

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

  const getData = async () => {
    const { data: basicInfo } = await props.eightWorkInfo({ id: props.id });
    setInfo(basicInfo);
  };

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

  const blindboardWorkParams = Array.isArray(info?.info?.blindboardWorkParams)
    && info.info.blindboardWorkParams.length > 0
    ? info.info.blindboardWorkParams
    : [{}];

  return (
    <div className="work_ticket_details">
      <table>
        <thead>
          <tr>
            <td colSpan={7} style={{ border: "none" }}>
              <Divider orientation="left">盲板抽堵安全作业票</Divider>
            </td>
          </tr>
          <tr>
            <td colSpan={7} style={{ border: "none" }}>
              <span>编号：</span>
              <span>{info.checkNo}</span>
            </td>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td className="title">申请单位</td>
            <td colSpan={3}>{info?.info?.applyUnit}</td>
            <td className="title">作业单位</td>
            <td colSpan={2}>{info?.info?.step_21?.actUserDepartmentName}</td>
          </tr>
          <tr>
            <td className="title">作业人</td>
            <td colSpan={3}>{info?.info?.workUserName}</td>
            <td className="title">作业类型</td>
            <td colSpan={2}>{info?.info?.operationTypeName}</td>
          </tr>
          <tr>
            <td className="title center" rowSpan={2}>设备管道名称</td>
            <td className="title center" colSpan={3}>管道参数</td>
            <td className="title center" colSpan={3}>盲板参数</td>
          </tr>
          <tr>
            <td className="title center">介质</td>
            <td className="title center">温度</td>
            <td className="title center">压力</td>
            <td className="title center">材质</td>
            <td className="title center">规格</td>
            <td className="title center">编号</td>
          </tr>
          {blindboardWorkParams.map((item, index) => (
            <tr key={item.id || index}>
              {index === 0 && (
                <>
                  <td className="center" rowSpan={blindboardWorkParams.length}>{info?.info?.devicePipelineName}</td>
                  <td className="center" rowSpan={blindboardWorkParams.length}>{info?.info?.mediumName}</td>
                  <td className="center" rowSpan={blindboardWorkParams.length}>{info?.info?.temperature}</td>
                  <td className="center" rowSpan={blindboardWorkParams.length}>{info?.info?.pressure}</td>
                </>
              )}
              <td className="center">{item?.matertal}</td>
              <td className="center">{item?.specification}</td>
              <td className="center">{item?.number}</td>
            </tr>
          ))}
          <tr>
            <td className="title">作业类别</td>
            <td colSpan={6}>
              {
                { blindboardWorkType001: "抽盲板", blindboardWorkType002: "堵盲板" }[info?.info?.blindboardWorkType]
              }
            </td>
          </tr>
          <tr>
            <td className="title">盲板抽堵位置图</td>
            <td colSpan={3}>
              {info?.info?.workScopeAndMethodImage
                && <Image src={getFileUrl() + info?.info?.workScopeAndMethodImage} width={50} height={50} />}
            </td>
            <td className="title">作业单位</td>
            <td colSpan={2}>{info?.info?.step_21?.actUserDepartmentName}</td>
          </tr>
          <tr>
            <td className="title">监护人</td>
            <td colSpan={3}>
              {info?.info?.step_20?.signPath
                && <Image src={getFileUrl() + info?.info?.step_20?.signPath} width={50} height={50} />}
            </td>
            <td className="title">作业负责人</td>
            <td colSpan={2}>
              {info?.info?.step_21?.signPath
                && <Image src={getFileUrl() + info?.info?.step_21?.signPath} width={50} height={50} />}
            </td>
          </tr>
          <tr>
            <td className="title">关联的其他特殊作业及安全作业票编号</td>
            <td colSpan={6}>{info?.info?.linkSpecialWorks}</td>
          </tr>
          <tr>
            <td className="title">风险辨识结果</td>
            <td colSpan={6}>{info?.info?.riskResults}</td>
          </tr>
          <tr>
            <td className="title">实际作业开始时间</td>
            <td colSpan={6}>{info?.info?.workStartTime}</td>
          </tr>
          <SafetyMeasures colSpan={7} workId={props.workId} />
          <DisclaimerSign
            firstColSpan={4}
            lastColSpan={3}
            safetyRemarks={info?.info?.step_18?.remarks}
            safetySignPath={info?.info?.step_18?.signPath}
            safetySignTime={info?.info?.step_18?.status !== 0 && info?.info?.step_18?.signTime}
            AcceptRemarks={info?.info?.step_19?.remarks}
            AcceptSignPath={info?.info?.step_19?.signPath}
            AcceptSignTime={info?.info?.step_19?.status !== 0 && info?.info?.step_19?.signTime}
          />
          <OpinionSign
            title="作业负责人意见"
            colSpan={7}
            remarks={info?.info?.step_21?.remarks}
            signPath={info?.info?.step_21?.signPath}
            signTime={info?.info?.step_21?.status !== 0 && info?.info?.step_21?.signTime}
          />
          <OpinionSign
            title="所在单位意见"
            colSpan={7}
            remarks={info?.info?.step_22?.remarks}
            signPath={info?.info?.step_22?.signPath}
            signTime={info?.info?.step_22?.status !== 0 && info?.info?.step_22?.signTime}
          />
          <OpinionSign
            title="审核部门意见"
            colSpan={7}
            remarks={info?.info?.step_23?.remarks}
            signPath={info?.info?.step_23?.signPath}
            signTime={info?.info?.step_23?.status !== 0 && info?.info?.step_23?.signTime}
          />
          <OpinionSign
            title="审批部门意见"
            colSpan={7}
            remarks={info?.info?.step_24?.remarks}
            signPath={info?.info?.step_24?.signPath}
            signTime={info?.info?.step_24?.status !== 0 && info?.info?.step_24?.signTime}
          />
          <OpinionSign
            title="完工验收"
            colSpan={7}
            remarks={info?.info?.step_25?.remarks}
            signPath={info?.info?.step_25?.signPath}
            signTime={info?.info?.step_25?.status !== 0 && info?.info?.step_25?.signTime}
          />
        </tbody>
      </table>
    </div>
  );
}

export default Connect([NS_BI_MARK_INFO], true)(BlindBoardWork);
