<template>
  <layout-print-table-package :entrance="entrance">
    <table>
      <thead>
        <tr>
          <td colspan="10" style="border: none">
            <el-divider content-position="left"> 动火安全作业票 </el-divider>
            <div class="tr">编号:{{ data.info.CHECK_NO }}</div>
          </td>
        </tr>
      </thead>
      <tr>
        <td class="title">作业申请单位</td>
        <td>{{ data.info.APPLY_DEPARTMENT_NAME }}</td>
        <td class="title">作业申请时间</td>
        <td>{{ data.info.CREATTIME }}</td>
      </tr>
      <tr>
        <td class="title">作业内容</td>
        <td>{{ data.info.WORK_CONTENT }}</td>
        <td class="title">动火地点及动火部位</td>
        <td>{{ data.info.WORK_PLACE }}</td>
      </tr>
      <tr>
        <td class="title">动火作业级别</td>
        <td>{{ data.info.WORK_LEVEL }}</td>
        <td class="title">动火方式</td>
        <td>{{ data.info.WORK_FUNCTION }}</td>
      </tr>
      <tr>
        <td class="title">动火人及证书编号</td>
        <td colspan="3">{{ data.info.WORK_USER }}</td>
      </tr>
      <tr>
        <td class="title">作业单位</td>
        <td>{{ data.info.CONFIRM_DEPARTMENT_NAME }}</td>
        <td class="title">作业负责人</td>
        <td>{{ data.info.CONFIRM_USER_NAME }}</td>
      </tr>
      <template v-for="(item, index) in data.gasList" :key="index">
        <tr>
          <td class="title">气体取样分析时间</td>
          <td>{{ item.ANALYZE_TIME }}</td>
          <td class="title">代表性气体</td>
          <td>{{ item.ANALYZE_PLACE }}</td>
        </tr>
        <tr>
          <td class="title">分析结果/%</td>
          <td>{{ item.ANALYZE_RESULT }}</td>
          <td class="title">分析人</td>
          <td>{{ item.ANALYZE_USER }}</td>
        </tr>
      </template>
      <tr>
        <td class="title">关联的其他特殊作业及安全作业票编号</td>
        <td colspan="3">{{ data.info.SPECIAL_WORK }}</td>
      </tr>
      <tr>
        <td class="title">风险辨识结果</td>
        <td colspan="3">{{ data.info.RISK_IDENTIFICATION }}</td>
      </tr>
      <tr>
        <td class="title">动火作业实施时间</td>
        <td colspan="3">
          {{ data.info.WORK_START_DATE }}至{{ data.info.WORK_END_DATE }}止
        </td>
      </tr>
      <tr>
        <td colspan="4">
          <table class="table-ui">
            <tr>
              <td style="width: 80px">序号</td>
              <td>安全措施</td>
              <td style="width: 100px">是否涉及</td>
              <td style="width: 100px">确认人</td>
            </tr>
            <tr v-for="(item, index) in data.measuresList" :key="index">
              <td>{{ index + 1 }}</td>
              <td>
                {{ item.PROTECTIVE_MEASURES }}
              </td>
              <td>
                <span v-if="item.STATUS === '1'">
                  <input type="radio" disabled checked />涉&nbsp;&nbsp;&nbsp;及
                </span>
                <span v-if="item.STATUS === '-1'">
                  <input type="radio" disabled checked />不涉及
                </span>
              </td>
              <td>
                {{ item.CONFIRM_NAME }}
              </td>
            </tr>
            <tr
              v-if="
                data.info.CONFIRM_USER_MEASURES ||
                data.info.LEADER_USER_MEASURES ||
                data.info.AUDIT_USER_MEASURES ||
                data.info.APPROVE_USER_MEASURES ||
                data.info.MONITOR_USER_MEASURES
              "
            >
              <td>{{ data.measuresList.length + 1 }}</td>
              <td colspan="3">
                <div
                  v-if="data.info.CONFIRM_USER_MEASURES"
                  style="display: flex; justify-content: space-between"
                >
                  <span>
                    其他安全措施：{{ data.info.CONFIRM_USER_MEASURES }}
                  </span>
                  <span>编制人：{{ data.info.CONFIRM_USER_NAME }}</span>
                </div>
                <div
                  v-if="data.info.LEADER_USER_MEASURES"
                  style="
                    display: flex;
                    justify-content: space-between;
                    margin-top: 10px;
                  "
                >
                  <span>
                    其他安全措施：{{ data.info.LEADER_USER_MEASURES }}
                  </span>
                  <span>编制人：{{ data.info.LEADER_USER_NAME }}</span>
                </div>
                <div
                  v-if="data.info.AUDIT_USER_MEASURES"
                  style="
                    display: flex;
                    justify-content: space-between;
                    margin-top: 10px;
                  "
                >
                  <span>其他安全措施：{{ data.info.AUDIT_USER_MEASURES }}</span>
                  <span>编制人：{{ data.info.AUDIT_USER_NAME }}</span>
                </div>
                <div
                  v-if="data.info.APPROVE_USER_MEASURES"
                  style="
                    display: flex;
                    justify-content: space-between;
                    margin-top: 10px;
                  "
                >
                  <span>
                    其他安全措施：{{ data.info.APPROVE_USER_MEASURES }}
                  </span>
                  <span>编制人：{{ data.info.APPROVE_USER_NAME }}</span>
                </div>
                <div
                  v-if="data.info.MONITOR_USER_MEASURES"
                  style="
                    display: flex;
                    justify-content: space-between;
                    margin-top: 10px;
                  "
                >
                  <span>
                    其他安全措施：{{ data.info.MONITOR_USER_MEASURES }}
                  </span>
                  <span>编制人：{{ data.info.MONITOR_USER_NAME }}</span>
                </div>
              </td>
            </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td class="title">安全交底人</td>
        <td colspan="10">
          <div v-if="data.info.CONFESS_USER_SIGNER_PATH" class="tr">
            <span>签字：</span>
            <img
              v-viewer
              :src="VITE_FILE_URL + data.info.CONFESS_USER_SIGNER_PATH"
              alt=""
              width="100"
              height="100"
            />
            <span>{{ data.info.CONFESS_USER_SIGNER_TIME }}</span>
          </div>
        </td>
      </tr>
      <tr>
        <td class="title">接受交底人</td>
        <td colspan="10">
          <div
            v-for="item in data.imgList"
            :key="item.ACCEPT_CONFESS_ID"
            class="tr"
          >
            <span>签字：</span>
            <img
              v-viewer
              :src="VITE_FILE_URL + item.ACCEPT_CONFESS_USER_SIGNER_PATH"
              alt=""
              width="100"
              height="100"
            />
            <span>{{ item.ACCEPT_CONFESS_USER_SIGNER_TIME }}</span>
          </div>
        </td>
      </tr>
      <tr>
        <td class="title">监护人</td>
        <td colspan="3">
          <div v-if="data.info.GUARDIAN_USER_SIGNER_PATH" class="tr">
            <span>签字：</span>
            <img
              v-viewer
              :src="VITE_FILE_URL + data.info.GUARDIAN_USER_SIGNER_PATH"
              alt=""
              width="100"
              height="100"
            />
            <span>{{ data.info.GUARDIAN_USER_SIGNER_TIME }}</span>
          </div>
        </td>
      </tr>
      <tr v-if="data.info.CONFIRM_USER_SIGNER_PATH">
        <td colspan="6">
          <div>作业负责人意见：{{ data.info.CONFIRM_CONTENT }}</div>
          <div class="tr">
            <span>签字：</span>
            <img
              v-viewer
              :src="VITE_FILE_URL + data.info.CONFIRM_USER_SIGNER_PATH"
              alt=""
              width="100"
              height="100"
            />
            <span>{{ data.info.CONFIRM_USER_SIGNER_TIME }}</span>
          </div>
        </td>
      </tr>
      <tr v-if="data.info.LEADER_USER_SIGNER_PATH">
        <td colspan="6">
          <div>所在单位意见：{{ data.info.LEADER_CONTENT }}</div>
          <div class="tr">
            <span>签字：</span>
            <img
              v-viewer
              :src="VITE_FILE_URL + data.info.LEADER_USER_SIGNER_PATH"
              alt=""
              width="100"
              height="100"
            />
            <span>{{ data.info.LEADER_USER_SIGNER_TIME }}</span>
          </div>
        </td>
      </tr>
      <tr v-if="data.info.AUDIT_USER_SIGNER_PATH">
        <td colspan="6">
          <div>安全管理部门意见：{{ data.info.AUDIT_CONTENT }}</div>
          <div class="tr">
            <span>签字：</span>
            <img
              v-viewer
              :src="VITE_FILE_URL + data.info.AUDIT_USER_SIGNER_PATH"
              alt=""
              width="100"
              height="100"
            />
            <span>{{ data.info.AUDIT_USER_SIGNER_TIME }}</span>
          </div>
        </td>
      </tr>
      <tr v-if="data.info.APPROVE_USER_SIGNER_PATH">
        <td colspan="6">
          <div>动火审批人意见：{{ data.info.APPROVE_CONTENT }}</div>
          <div class="tr">
            <span>签字：</span>
            <img
              v-viewer
              :src="VITE_FILE_URL + data.info.APPROVE_USER_SIGNER_PATH"
              alt=""
              width="100"
              height="100"
            />
            <span>{{ data.info.APPROVE_USER_SIGNER_TIME }}</span>
          </div>
        </td>
      </tr>
      <tr v-if="data.info.MONITOR_USER_SIGNER_PATH">
        <td colspan="6">
          <div>
            动火前，岗位当班班长验票情况：{{ data.info.MONITOR_CONTENT }}
          </div>
          <div class="tr">
            <span>签字：</span>
            <img
              v-viewer
              :src="VITE_FILE_URL + data.info.MONITOR_USER_SIGNER_PATH"
              alt=""
              width="100"
              height="100"
            />
            <span>{{ data.info.MONITOR_USER_SIGNER_TIME }}</span>
          </div>
        </td>
      </tr>
      <tr v-if="data.imgList1.length > 0">
        <td colspan="10">
          <div>完工验收：{{ data.info.ACCEPT_CONTENT }}</div>
          <div
            v-for="item in data.imgList1"
            :key="item.ACCEPT_CONFESS_ID"
            class="tr"
          >
            <span>签字：</span>
            <img
              v-viewer
              :src="VITE_FILE_URL + item.ACCEPT_USER_SIGNER_PATH"
              alt=""
              width="100"
              height="100"
            />
            <span>{{ item.ACCEPT_USER_SIGNER_TIME }}</span>
          </div>
        </td>
      </tr>
    </table>
  </layout-print-table-package>
</template>

<script setup>
import LayoutPrintTablePackage from "@/components/print_table_package/index.vue";
import { reactive } from "vue";
import { useRoute } from "vue-router";
import { getHotWorkView } from "@/request/hot_work.js";
import { findCharIndex } from "@/assets/js/utils.js";

const VITE_FILE_URL = import.meta.env.VITE_FILE_URL;
const route = useRoute();
const { HOTWORK_ID, entrance } = route.query;
const data = reactive({
  info: {},
  imgList: [],
  imgList1: [],
  measuresList: [],
  gasList: [],
});
const fnGetData = async () => {
  const resData = await getHotWorkView({ HOTWORK_ID });
  data.info = resData.pd;
  data.imgList = resData.imgList;
  data.imgList1 = resData.imgList1;
  for (let i = 0; i < resData.measuresList.length; i++) {
    const PROTECTIVE_MEASURES =
      resData.measuresList[i].PROTECTIVE_MEASURES.split("");
    for (let j = 1; j <= 3; j++) {
      if (findCharIndex(PROTECTIVE_MEASURES, "（", j) !== -1) {
        PROTECTIVE_MEASURES.splice(
          findCharIndex(PROTECTIVE_MEASURES, "（", j) + 1,
          0,
          resData.measuresList[i]["ANSWER" + j]
        );
      }
    }
    resData.measuresList[i].PROTECTIVE_MEASURES = PROTECTIVE_MEASURES.join("");
  }
  data.measuresList = resData.measuresList;
  data.gasList = resData.gasList;
  data.info.CONFIRM_USER_MEASURES =
    data.info.OTHER_PROTECTIVE_MEASURES.split(";_;")[0];
  data.info.LEADER_USER_MEASURES =
    data.info.OTHER_PROTECTIVE_MEASURES.split(";_;")[1];
  data.info.AUDIT_USER_MEASURES =
    data.info.OTHER_PROTECTIVE_MEASURES.split(";_;")[2];
  data.info.APPROVE_USER_MEASURES =
    data.info.OTHER_PROTECTIVE_MEASURES.split(";_;")[3];
  data.info.MONITOR_USER_MEASURES =
    data.info.OTHER_PROTECTIVE_MEASURES.split(";_;")[4];
};
fnGetData();
</script>

<style scoped lang="scss"></style>
