<template>
  <div>
    <div class="level-title">
      <h1>临时用电作业许可证</h1>
    </div>
    <table class="table-ui">
      <tr>
        <td class="bbg-transparent">用电单位</td>
        <td>{{ info.ELECTRICITY_UNIT }}</td>
        <td class="bbg-transparent">作业证编号</td>
        <td>{{ info.CHECK_NO }}</td>
      </tr>

      <tr>
        <td class="bbg-transparent">用电原因</td>
        <td>{{ info.WORK_CONTENT }}</td>
        <td class="bbg-transparent">作业地点</td>
        <td>{{ info.WORK_PLACE }}</td>
      </tr>

      <tr>
        <td class="bbg-transparent">电源接入点</td>
        <td>{{ info.ACCESS_POINT }}</td>
        <td class="bbg-transparent">用电设备及功率</td>
        <td>{{ info.EQUIPMENT_POWER }}</td>
      </tr>

      <tr>
        <td class="bbg-transparent">危险性分析</td>
        <td>{{ info.RISK_ANALYSIS }}</td>
        <td class="bbg-transparent">作业实施时间</td>
        <td>
          {{ formatDate(info.WORK_START_DATE,'YYYY年MM月DD日HH时mm分') }} 至 {{ formatDate(info.WORK_END_DATE,'YYYY年MM月DD日HH时mm分') }}
        </td>
      </tr>
      <tr>
        <td class="bbg-transparent">安全交底人</td>
        <td>{{ info.SECURITY_CONFIDANT }}</td>
        <td class="bbg-transparent">作业人员</td>
        <td>
          <div v-for="(item, index) in info.WORK_OPERATOR_NAME" :key="index+Math.random()">
            {{ index + 1 }}. <span style="margin: 0 15px 0 5px">{{ info.WORK_OPERATOR_NAME[index] }}</span> 作业证号：{{ info.WORK_OPERATOR_NUMBER[index] }}
          </div>
        </td>
      </tr>
      <tr v-for="item in gasList" :key="item.ELECTRICITYGAS_ID">
        <td colspan="4" style="padding: 0;">
          <table class="table-vi">
            <tr>
              <td class="bbg-transparent">分析时间</td>
              <td>{{ item.ANALYZE_TIME }}</td>
              <td class="bbg-transparent">分析点</td>
              <td>{{ item.ANALYZE_PLACE }}</td>
            </tr>
            <tr>
              <td class="bbg-transparent">分析结果</td>
              <td>{{ item.ANALYZE_RESULT }}</td>
              <td class="bbg-transparent">分析人</td>
              <td>{{ item.ANALYZE_USER }}</td>
            </tr>
          </table>
        </td>
      </tr>

      <tr>
        <td colspan="4" style="padding: 0;">
          <table class="table-vi">
            <tr class="bbg-transparent">
              <td>序号</td>
              <td>主要安全措施</td>
              <td class="ccenter select">是否合格</td>
            </tr>
            <tr v-for="(item,index) in measuresList" :key="item.BUS_ELECTRICITY_MEASURES_ID">
              <td style="text-align: center">{{ index + 1 }}</td>
              <td>
                {{ item.PROTECTIVE_MEASURES }}
              </td>
              <td style="text-align: center">
                <span v-if="item.STATUS=='1'">合格</span>
                <span v-if="item.STATUS=='-1'">不合格</span>
                <span v-if="item.STATUS=='2'">不涉及</span>
              </td>
            </tr>
          </table>
        </td>
      </tr>

      <tr v-if="otherProtectiveMeasures.length > 0">
        <td colspan="4" style="padding: 0;">
          <table class="table-vi">
            <tr class="bbg-transparent">
              <td colspan="2">补充措施</td>
            </tr>
            <tr v-for="(item,i) in otherProtectiveMeasures" :key="item">
              <td v-if="item" class="bbg-transparent">
                <span v-if="i==0">作业单位</span>
                <span v-else-if="i==1">配送电单位</span>
                <span v-else-if="i==2">审批人</span>
              </td>
              <td v-if="item">{{ item }}</td>
            </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td colspan="2">
          <div><span>安全措施确认人：</span>
            <span/>
          </div>
          <div style="text-align: right">
            <span class="print-approval-img">
              <img v-if="info.CONFIRM_USER_SIGNER_PATH" :src="config.fileUrl+info.CONFIRM_USER_SIGNER_PATH">
            </span>
            <span v-if="info.CONFIRM_USER_SIGNER_TIME">{{ formatDate(info.CONFIRM_USER_SIGNER_TIME,'YYYY年MM月DD日HH时mm分') }}</span>
          </div>
        </td>
        <td colspan="2">
          <div><span>作业单位：</span>
            <span/>
          </div>
          <div style="text-align: right">
            <span class="print-approval-img">
              <img v-if="info.WORK_USER_SIGNER_PATH" :src="config.fileUrl+info.WORK_USER_SIGNER_PATH">
            </span>
            <span v-if="info.WORK_USER_SIGNER_TIME">{{ formatDate(info.WORK_USER_SIGNER_TIME,'YYYY年MM月DD日HH时mm分') }}</span>
          </div>
        </td>
      </tr>
      <tr>
        <td colspan="2">
          <div><span>运维保障部门：</span>
            <span/>
          </div>
          <div style="text-align: right">
            <span class="print-approval-img">
              <img v-if="info.ASSURE_USER_SIGNER_PATH" :src="config.fileUrl+info.ASSURE_USER_SIGNER_PATH">
            </span>
            <span v-if="info.ASSURE_USER_SIGNER_TIME">{{ formatDate(info.ASSURE_USER_SIGNER_TIME,'YYYY年MM月DD日HH时mm分') }}</span>
          </div>
        </td>
        <td colspan="2">
          <div><span>临时用电审批：</span>
            <span/>
          </div>
          <div style="text-align: right">
            <span class="print-approval-img">
              <img v-if="info.APPROVE_USER_SIGNER_PATH" :src="config.fileUrl+info.APPROVE_USER_SIGNER_PATH">
            </span>
            <span v-if="info.APPROVE_USER_SIGNER_TIME">{{ formatDate(info.APPROVE_USER_SIGNER_TIME,'YYYY年MM月DD日HH时mm分') }}</span>
          </div>
        </td>
      </tr>
      <tr v-if="info.CHECK_STATUS==='1' || info.CHECK_STATUS==='3'">
        <td colspan="4" style="padding: 0;">
          <table class="table-vi">
            <tr>
              <td class="bbg-transparent">验收部门：</td>
              <td>{{ info.ACCEPT_DEPARTMENT_NAME }}</td>
              <td class="bbg-transparent">验收人：</td>
              <td>{{ info.ACCEPT_USER_NAME }}</td>
              <td class="bbg-transparent">验收意见：</td>
              <td>{{ info.ACCEPT_RESULT_NAME }}</td>
              <td class="bbg-transparent">验收时间：</td>
              <td>{{ info.ACCEPT_TIME }}</td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
import { requestFN } from '@/utils/request'
import moment from 'moment/moment'

export default {
  props: {
    id: {
      type: String,
      default() {
        return ''
      }
    },
    type: {
      type: String,
      default() {
        return ''
      }
    },
    gangkou: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      config: config,
      info: {
        WORK_OPERATOR_ID: [],
        WORK_OPERATOR_NAME: [],
        WORK_OPERATOR_NUMBER: []
      },
      measuresList: [],
      gasList: [],
      otherProtectiveMeasures: []
    }
  },
  created() {
    this.getData()
  },
  methods: {
    formatDate(date, format) {
      if (date) {
        return moment(date).format(format)
      } else {
        return ''
      }
    },
    getData() {
      requestFN(
        '/map/Eight/getById',
        {
          id: this.id,
          TYPE: this.type,
          GANGKOU: this.gangkou
        }
      ).then(data => {
        this.info = data.pd
        this.measuresList = data.measuresList
        this.gasList = data.gasList
        this.otherProtectiveMeasures = this.validStr(this.info.OTHER_PROTECTIVE_MEASURES.replace(/;_;/g, '')) ? this.info.OTHER_PROTECTIVE_MEASURES.split(';_;') : []
        console.info(this.otherProtectiveMeasures)
        if (!this.info.WORK_OPERATOR_ID) {
          this.$set(this.info, 'WORK_OPERATOR_ID', [])
        } else {
          this.info.WORK_OPERATOR_ID = this.info.WORK_OPERATOR_ID.split(',')
        }
        if (!this.info.WORK_OPERATOR_NAME) {
          this.$set(this.info, 'WORK_OPERATOR_NAME', [])
        } else {
          this.info.WORK_OPERATOR_NAME = this.info.WORK_OPERATOR_NAME.split(',')
        }
        if (!this.info.WORK_OPERATOR_NUMBER) {
          this.$set(this.info, 'WORK_OPERATOR_NUMBER', [])
        } else {
          this.info.WORK_OPERATOR_NUMBER = this.info.WORK_OPERATOR_NUMBER.split(',')
        }
      })
    }
  }
}
</script>

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