<template>
  <layout-print-table-package :print="entrance === 'archive'">
    <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 colspan="5">{{ data.info.APPLY_DEPARTMENT_NAME }}</td>
        <td class="title">作业申请时间</td>
        <td colspan="3">{{ data.info.CREATTIME }}</td>
      </tr>
      <tr>
        <td class="title">受限空间名称</td>
        <td colspan="5">{{ data.info.LIMITSPACE_NAME }}</td>
        <td class="title">受限空间内原有介质名称</td>
        <td colspan="3">{{ data.info.MEDIUM_NAME }}</td>
      </tr>
      <tr>
        <td class="title">作业内容</td>
        <td colspan="9">{{ data.info.WORK_CONTENT }}</td>
      </tr>
      <tr>
        <td class="title">作业单位</td>
        <td colspan="5">{{ data.info.CONFIRM_DEPARTMENT_NAME }}</td>
        <td class="title">作业负责人</td>
        <td colspan="3">{{ data.info.CONFIRM_USER_NAME }}</td>
      </tr>

      <tr>
        <td class="title">关联的其他特殊作业及安全作业票编号</td>
        <td colspan="9">{{ data.info.SPECIAL_WORK }}</td>
      </tr>
      <tr>
        <td class="title">风险辨识结果</td>
        <td colspan="9">{{ data.info.RISK_IDENTIFICATION }}</td>
      </tr>
      <tr>
        <td :rowspan="3 + data.gasList.length" class="title">气体分析</td>
        <td class="title" rowspan="2">分析项目</td>
        <td class="title" colspan="2">有毒有害气体名称</td>
        <td class="title" colspan="2">可燃气体名称</td>
        <td class="title" rowspan="2">氧气含量</td>
        <td class="title" rowspan="3">取样分析时间</td>
        <td class="title" rowspan="3">分析部位</td>
        <td class="title" rowspan="3">分析人</td>
      </tr>
      <tr>
        <td :style="{ padding: data.gas.GAS_NAME1 ? '8px' : '16px' }">
          {{ data.gas.GAS_NAME1 }}
        </td>
        <td :style="{ padding: data.gas.GAS_NAME2 ? '8px' : '16px' }">
          {{ data.gas.GAS_NAME2 }}
        </td>
        <td :style="{ padding: data.gas.GAS_NAME3 ? '8px' : '16px' }">
          {{ data.gas.GAS_NAME3 }}
        </td>
        <td :style="{ padding: data.gas.GAS_NAME4 ? '8px' : '16px' }">
          {{ data.gas.GAS_NAME4 }}
        </td>
      </tr>
      <tr>
        <td class="title">合格标准</td>
        <td>{{ data.gas.GAS_STANDARD1 }}</td>
        <td>{{ data.gas.GAS_STANDARD2 }}</td>
        <td>{{ data.gas.GAS_STANDARD3 }}</td>
        <td>{{ data.gas.GAS_STANDARD4 }}</td>
        <td>19.5% 〜21%（体积分数）</td>
      </tr>
      <tr v-for="(item, index) in data.gasList" :key="index">
        <td v-if="index === 0" :rowspan="data.gasList.length" class="title">
          分析数据
        </td>
        <td>
          <span v-if="data.gas.GAS_NAME1">{{ item.DATA1 }}</span>
        </td>
        <td>
          <span v-if="data.gas.GAS_NAME2">{{ item.DATA2 }}</span>
        </td>
        <td>
          <span v-if="data.gas.GAS_NAME3">{{ item.DATA3 }}</span>
        </td>
        <td>
          <span v-if="data.gas.GAS_NAME4">{{ item.DATA4 }}</span>
        </td>
        <td>{{ item.OXYGEN_CONTENT }}</td>
        <td>{{ item.ANALYZE_TIME }}</td>
        <td>{{ item.ANALYZE_PLACE }}</td>
        <td>{{ item.ANALYZE_USER }}</td>
      </tr>
      <tr>
        <td class="title">作业实施时间</td>
        <td colspan="9">
          {{ data.info.WORK_START_DATE }}至{{ data.info.WORK_END_DATE }}止
        </td>
      </tr>
      <tr>
        <td colspan="10">
          <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 }}
                <div v-if="item.IMG_PATH">
                  <template v-for="img in item.IMG_PATH.split(',')" :key="img">
                    <img
                      v-viewer
                      :src="VITE_FILE_URL + img"
                      alt=""
                      width="100"
                      height="100"
                    />
                  </template>
                </div>
              </td>
              <td>
                <span v-if="item.STATUS === '1'"> 涉&nbsp;&nbsp;&nbsp;及 </span>
                <span v-if="item.STATUS === '-1'"> 不涉及 </span>
              </td>
              <td>
                <img
                  v-if="item.SIGN_PATH"
                  v-viewer
                  :src="VITE_FILE_URL + item.SIGN_PATH"
                  alt=""
                  width="100"
                  height="100"
                />
              </td>
            </tr>
            <template v-if="data.signs.MEASURES_CONFIRM">
              <tr
                v-for="(item, index) in data.signs.MEASURES_CONFIRM"
                :key="item.BUS_CONFINEDSPACE_MEASURES_ID"
              >
                <td>{{ data.measuresList.length + 1 + index }}</td>
                <td colspan="2">
                  <div style="display: flex; justify-content: space-between">
                    <span> 其他安全措施： {{ item.DESCR }} </span>
                  </div>
                </td>
                <td>
                  <img
                    v-if="item.SIGN_PATH[0]"
                    v-viewer
                    :src="VITE_FILE_URL + item.SIGN_PATH[0]"
                    alt=""
                    width="100"
                    height="100"
                  />
                </td>
              </tr>
            </template>
          </table>
        </td>
      </tr>
      <tr v-if="data.signs.GUARDIAN">
        <td colspan="10">
          <div>监护人：</div>
          <div
            v-for="(item, index) in data.signs.GUARDIAN[0].SIGN_TIME"
            :key="index"
            class="tr"
          >
            <span>签字：</span>
            <img
              v-viewer
              :src="VITE_FILE_URL + data.signs.GUARDIAN[0].SIGN_PATH[index]"
              alt=""
              width="100"
              height="100"
            />
            <span>{{ data.signs.GUARDIAN[0].SIGN_TIME[index] }}</span>
          </div>
        </td>
      </tr>
      <tr v-if="data.signs.CONFESS">
        <td colspan="10">
          <div>
            安全交底人：
            <div v-if="data.signs.CONFESS[0].IMG_PATH">
              <template
                v-for="img in data.signs.CONFESS[0].IMG_PATH"
                :key="img"
              >
                <img
                  v-viewer
                  :src="VITE_FILE_URL + img"
                  alt=""
                  width="100"
                  height="100"
                />
              </template>
            </div>
          </div>
          <div
            v-for="(item, index) in data.signs.CONFESS[0].SIGN_TIME"
            :key="index"
            class="tr"
          >
            <span>签字：</span>
            <img
              v-viewer
              :src="VITE_FILE_URL + data.signs.CONFESS[0].SIGN_PATH[index]"
              alt=""
              width="100"
              height="100"
            />
            <span>{{ data.signs.CONFESS[0].SIGN_TIME[index] }}</span>
          </div>
        </td>
      </tr>
      <tr v-if="data.signs.ACCEPT_CONFESS">
        <td colspan="10">
          <div>接受交底人：</div>
          <div
            v-for="(item, index) in data.signs.ACCEPT_CONFESS[0].SIGN_TIME"
            :key="index"
            class="tr"
          >
            <span>签字：</span>
            <img
              v-viewer
              :src="
                VITE_FILE_URL + data.signs.ACCEPT_CONFESS[0].SIGN_PATH[index]
              "
              alt=""
              width="100"
              height="100"
            />
            <span>{{ data.signs.ACCEPT_CONFESS[0].SIGN_TIME[index] }}</span>
          </div>
        </td>
      </tr>
      <tr v-if="data.signs.CONFIRM">
        <td colspan="10">
          <div>作业负责人意见：{{ data.signs.CONFIRM[0].DESCR }}</div>
          <div
            v-for="(item, index) in data.signs.CONFIRM[0].SIGN_TIME"
            :key="index"
            class="tr"
          >
            <span>签字：</span>
            <img
              v-viewer
              :src="VITE_FILE_URL + data.signs.CONFIRM[0].SIGN_PATH[index]"
              alt=""
              width="100"
              height="100"
            />
            <span>{{ data.signs.CONFIRM[0].SIGN_TIME[index] }}</span>
          </div>
        </td>
      </tr>
      <tr v-if="data.signs.WORK_USER">
        <td colspan="10">
          <div>作业人：</div>
          <div
            v-for="(item, index) in data.signs.WORK_USER[0].SIGN_TIME"
            :key="index"
            class="tr"
          >
            <span>签字：</span>
            <img
              v-viewer
              :src="VITE_FILE_URL + data.signs.WORK_USER[0].SIGN_PATH[index]"
              alt=""
              width="100"
              height="100"
            />
            <span>{{ data.signs.WORK_USER[0].SIGN_TIME[index] }}</span>
          </div>
        </td>
      </tr>

      <tr v-if="data.signs.LEADER">
        <td colspan="10">
          <div>所在单位意见：{{ data.signs.LEADER[0].DESCR }}</div>
          <div
            v-for="(item, index) in data.signs.LEADER[0].SIGN_TIME"
            :key="index"
            class="tr"
          >
            <span>签字：</span>
            <img
              v-viewer
              :src="VITE_FILE_URL + data.signs.LEADER[0].SIGN_PATH[index]"
              alt=""
              width="100"
              height="100"
            />
            <span>{{ data.signs.LEADER[0].SIGN_TIME[index] }}</span>
          </div>
        </td>
      </tr>

      <tr v-if="data.signs.ACCEPT">
        <td colspan="10">
          <div>完工验收：{{ data.signs.ACCEPT[0].DESCR }}</div>
          <div
            v-for="(item, index) in data.signs.ACCEPT[0].SIGN_TIME"
            :key="index"
            class="tr"
          >
            <span>签字：</span>
            <img
              v-viewer
              :src="VITE_FILE_URL + data.signs.ACCEPT[0].SIGN_PATH[index]"
              alt=""
              width="100"
              height="100"
            />
            <span>{{ data.signs.ACCEPT[0].SIGN_TIME[index] }}</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 { findCharIndex } from "@/assets/js/utils.js";
import { getConfinedSpaceView } from "@/request/eight_work.js";

const VITE_FILE_URL = import.meta.env.VITE_FILE_URL;
const route = useRoute();
const { CONFINEDSPACE_ID, entrance } = route.query;
const data = reactive({
  info: {},
  gasList: [],
  gas: {},
  measuresList: [],
  signs: [],
});
const fnGetData = async () => {
  const resData = await getConfinedSpaceView({ CONFINEDSPACE_ID });
  data.info = resData.pd;
  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.gas = resData.gas || {};
  data.signs = resData.signs;
};
fnGetData();
</script>

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