<template>
  <div>
    <div id="printTest" class="app-container print-work">
      <el-page-header content="审批表详情" class="no-print" @back="goBack"/>
      <table class="table-ui">
        <thead>
          <tr>
            <td colspan="10" style="border: none">
              <div class="level-title mt-20">
                <h1>受限空间安全作业票</h1>
                <div class="level-btns">编号:{{ pd.CHECK_NO }}</div>
              </div>
            </td>
          </tr>
        </thead>
        <tr>
          <td class="bbg">作业申请单位</td>
          <td colspan="5">{{ pd.APPLY_DEPARTMENT_NAME }}</td>
          <td class="bbg">作业申请时间</td>
          <td colspan="3">{{ pd.CREATTIME }}</td>
        </tr>
        <tr>
          <td class="bbg">受限空间名称</td>
          <td colspan="5">{{ pd.LIMITSPACE_NAME }}</td>
          <td class="bbg">受限空间内原有介质名称</td>
          <td colspan="3">{{ pd.MEDIUM_NAME }}</td>
        </tr>
        <tr>
          <td class="bbg">作业内容</td>
          <td colspan="9">{{ pd.WORK_CONTENT }}</td>
        </tr>
        <tr>
          <td class="bbg">作业单位</td>
          <td colspan="5">{{ pd.CONFIRM_DEPARTMENT_NAME }}</td>
          <td class="bbg">作业负责人</td>
          <td colspan="3">{{ pd.CONFIRM_USER_NAME }}</td>
        </tr>
        <tr>
          <td class="bbg">作业人</td>
          <td colspan="5">{{ pd.WORK_USER }}</td>
          <td class="bbg">监护人</td>
          <td colspan="5">
            <div v-if="pd.GUARDIAN_USER_SIGNER_PATH" style="text-align: right">
              <span>签字：</span>
              <img v-viewer :src="config.fileUrl + pd.GUARDIAN_USER_SIGNER_PATH" alt="" width="100" height="100">
              <span>{{ pd.GUARDIAN_USER_SIGNER_TIME }}</span>
            </div>
          </td>
        </tr>
        <tr>
          <td class="bbg">关联的其他特殊作业及安全作业票编号</td>
          <td colspan="9">{{ pd.SPECIAL_WORK }}</td>
        </tr>
        <tr>
          <td class="bbg">风险辨识结果</td>
          <td colspan="9">{{ pd.RISK_IDENTIFICATION }}</td>
        </tr>
        <tr>
          <td :rowspan="3 + gasList.length" class="bbg">气体分析</td>
          <td class="bbg" rowspan="2">分析项目</td>
          <td class="bbg" colspan="2">有毒有害气体名称</td>
          <td class="bbg" colspan="2">可燃气体名称</td>
          <td class="bbg" rowspan="2">氧气含量</td>
          <td class="bbg" rowspan="3">取样分析时间</td>
          <td class="bbg" rowspan="3">分析部位</td>
          <td class="bbg" rowspan="3">分析人</td>
        </tr>
        <tr>
          <td :style="{padding:gas.GAS_NAME1 ? '8px' : '16px'}">{{ gas.GAS_NAME1 }}</td>
          <td :style="{padding:gas.GAS_NAME2 ? '8px' : '16px'}">{{ gas.GAS_NAME2 }}</td>
          <td :style="{padding:gas.GAS_NAME3 ? '8px' : '16px'}">{{ gas.GAS_NAME3 }}</td>
          <td :style="{padding:gas.GAS_NAME4 ? '8px' : '16px'}">{{ gas.GAS_NAME4 }}</td>
        </tr>
        <tr>
          <td class="bbg">合格标准</td>
          <td>{{ gas.GAS_STANDARD1 }}</td>
          <td>{{ gas.GAS_STANDARD2 }}</td>
          <td>{{ gas.GAS_STANDARD3 }}</td>
          <td>{{ gas.GAS_STANDARD4 }}</td>
          <td>19.5% 〜21%（体积分数）</td>
        </tr>
        <tr v-for="(item,index) in gasList" :key="index">
          <td v-if="index === 0" :rowspan="gasList.length" class="bbg">分析数据</td>
          <td><span v-if="gas.GAS_NAME1">{{ item.DATA1 }}</span></td>
          <td><span v-if="gas.GAS_NAME2">{{ item.DATA2 }}</span></td>
          <td><span v-if="gas.GAS_NAME3">{{ item.DATA3 }}</span></td>
          <td><span v-if="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="bbg">作业实施时间</td>
          <td colspan="9">{{ pd.WORK_START_DATE }}至{{ pd.WORK_END_DATE }}止</td>
        </tr>
        <tr>
          <td colspan="10">
            <table class="table-ui">
              <tr>
                <td>序号</td>
                <td>安全措施</td>
                <td style="width: 100px">是否涉及</td>
                <td style="width: 100px">确认人</td>
              </tr>
              <tr v-for="(item,index) in 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;&nbsp;及</span>
                  <span v-if="item.STATUS=='-1'"><input type="radio" disabled checked>不涉及</span>
                </td>
                <td>
                  {{ item.CONFIRM_NAME }}
                </td>
              </tr>
              <tr v-if="pd.CONFIRM_USER_MEASURES || pd.APPROVE_USER_MEASURES" >
                <td >{{ measuresList.length + 1 }}</td>
                <td colspan="3">
                  <div v-if="pd.CONFIRM_USER_MEASURES" style="display: flex;justify-content: space-between;">
                    <span>其他安全措施：{{ pd.CONFIRM_USER_MEASURES }}</span>
                    <span>编制人：{{ pd.CONFIRM_USER_NAME }}</span>
                  </div>
                  <div v-if="pd.APPROVE_USER_MEASURES" style="display: flex;justify-content: space-between;">
                    <span>其他安全措施：{{ pd.APPROVE_USER_MEASURES }}</span>
                    <span>编制人：{{ pd.APPROVE_USER_NAME }}</span>
                  </div>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td class="bbg">安全交底人</td>
          <td colspan="10">
            <div v-if="pd.CONFESS_USER_SIGNER_PATH" style="text-align: right">
              <span>签字：</span>
              <img v-viewer :src="config.fileUrl + pd.CONFESS_USER_SIGNER_PATH" alt="" width="100" height="100">
              <span>{{ pd.CONFESS_USER_SIGNER_TIME }}</span>
            </div>
          </td>
        </tr>
        <tr>
          <td class="bbg">接受交底人</td>
          <td colspan="10">
            <div v-if="pd.ACCEPT_CONFESS_USER_SIGNER_PATH" style="text-align: right">
              <span>签字：</span>
              <img v-viewer :src="config.fileUrl + pd.ACCEPT_CONFESS_USER_SIGNER_PATH" alt="" width="100" height="100">
              <span>{{ pd.ACCEPT_CONFESS_USER_SIGNER_TIME }}</span>
            </div>
          </td>
        </tr>
        <tr v-if="pd.CONFIRM_USER_SIGNER_PATH">
          <td colspan="10">
            <div>作业负责人意见：{{ pd.CONFIRM_CONTENT }}</div>
            <div style="text-align: right">
              <span>签字：</span>
              <img v-viewer :src="config.fileUrl + pd.CONFIRM_USER_SIGNER_PATH" alt="" width="100" height="100">
              <span>{{ pd.CONFIRM_USER_SIGNER_TIME }}</span>
            </div>
          </td>
        </tr>
        <tr v-if="pd.APPROVE_USER_SIGNER_PATH">
          <td colspan="10">
            <div>所在单位意见：{{ pd.APPROVE_CONTENT }}</div>
            <div style="text-align: right">
              <span>签字：</span>
              <img v-viewer :src="config.fileUrl + pd.APPROVE_USER_SIGNER_PATH" alt="" width="100" height="100">
              <span>{{ pd.APPROVE_USER_SIGNER_TIME }}</span>
            </div>
          </td>
        </tr>
        <tr v-if="pd.ACCEPT_USER_SIGNER_PATH">
          <td colspan="10">
            <div>完工验收：{{ pd.ACCEPT_CONTENT }}</div>
            <div style="text-align: right">
              <span>签字：</span>
              <img :src="config.fileUrl + pd.ACCEPT_USER_SIGNER_PATH" alt="" width="100" height="100">
              <span>{{ pd.ACCEPT_USER_SIGNER_TIME }}</span>
            </div>
          </td>
        </tr>
      </table>
    </div>
    <div style="padding-top: 100px"/>
    <!--    <div class="ui-height" />-->
    <div class="ui-foot">
      <el-button v-print="'#printTest'" icon="el-icon-printer" type="primary">打 印</el-button>
      <el-button icon="el-icon-arrow-left" @click="goBack">返 回</el-button>
    </div>
  </div>
</template>

<script>
import { requestFN } from '@/utils/request'
import dateformat from '@/utils/dateformat'
export default {
  data() {
    return {
      config: config,
      CONFINEDSPACE_ID: this.$parent.CONFINEDSPACE_ID, // 主键ID
      pd: [], // 存放字段参数
      measuresList: [],
      gasList: [],
      gas: {},
      otherProtectiveMeasures: []
    }
  },
  created() {
    this.getData()
  },
  methods: {
    validStr(str) {
      if (str != null && str != '' && typeof (str) != 'undefined' && str != 0) { return true }
      return false
    },
    formatTime(date, column) {
      if (date) {
        return dateformat(date, 'YYYY年MM月DD日HH时mm分')
      } else {
        return ''
      }
    },
    formatDate(date, column) {
      if (date) {
        return dateformat(date, 'YYYY-MM-DD')
      } else {
        return ''
      }
    },
    getRowKey(row) {
      return row.CONFINEDSPACE_ID
    },
    getData() {
      this.listLoading = true
      requestFN(
        '/gfConfinedSpace/goEdit',
        {
          CONFINEDSPACE_ID: this.CONFINEDSPACE_ID
        }
      ).then((data) => {
        this.listLoading = false
        this.pd = data.pd // 参数map
        for (let i = 0; i < data.measuresList.length; i++) {
          // 将字符串转成数组
          const PROTECTIVE_MEASURES = data.measuresList[i].PROTECTIVE_MEASURES.split('')
          for (let j = 1; j <= 3; j++) {
            // 判断字符串是否存在
            if (this.findCharIndex(PROTECTIVE_MEASURES, '（', j) !== -1) {
              // 给字符串后面添加上需要的数据
              PROTECTIVE_MEASURES.splice(
                this.findCharIndex(PROTECTIVE_MEASURES, '（', j) + 1,
                0,
                data.measuresList[i]['ANSWER' + j]
              )
            }
          }
          // 将数组转回字符串
          data.measuresList[i].PROTECTIVE_MEASURES = PROTECTIVE_MEASURES.join('')
        }
        this.measuresList = data.measuresList // 参数map
        this.gasList = data.gasList // 参数map
        this.gas = data.gas || {} // 参数map
        this.pd.CONFIRM_USER_MEASURES = this.pd.OTHER_PROTECTIVE_MEASURES.split(';_;')[0]
        this.pd.APPROVE_USER_MEASURES = this.pd.OTHER_PROTECTIVE_MEASURES.split(';_;')[1]
      }).catch((e) => {
        this.listLoading = false
      })
    },
    // 查找字符串第几次出现的位置
    findCharIndex(str, char, num) {
      let index = str.indexOf(char)
      for (let i = 0; i < num - 1; i++) {
        index = str.indexOf(char, index + 1)
      }
      return index
    },
    goBack() {
      this.$parent.activeName = 'List'
    }

  }
}
</script>

<style lang="sass" scoped>
  .print-approval-p10
    padding: 20px 0
    span
      vertical-align: middle

  .print-approval-img
    width: 200px
    height: 97px
    display: inline-block
    img
      width: 100%
      height: 100%
</style>
