<template>
  <div>
    <div id="printTest" class="app-container" style="padding-bottom: 100px">
      <el-page-header content="隐患详情" class="no-print" @back="back"/>
      <div class="level-title mt-20">
        <h1>隐患信息</h1>
      </div>
      <div class="mb-20 print-break" >
        <table class="table-ui">
          <tr>
            <td class="tbg">隐患来源</td>
            <template v-if="pd.SOURCE=='1'">
              <td>隐患快报</td>
            </template>
            <template v-else-if="pd.SOURCE=='2'">
              <td>隐患排查</td>
            </template>
            <template v-else-if="pd.SOURCE=='3'">
              <td>隐患排查</td>
            </template>
          </tr>
          <tr v-if="pd.SOURCE=='2'">
            <td class="tbg">风险点（单元）</td>
            <td>{{ pd.RISK_UNIT }}</td>
          </tr>
          <tr v-if="pd.SOURCE=='2'">
            <td class="tbg">辨识部位</td>
            <td>{{ pd.IDENTIFICATION }}</td>
          </tr>
          <tr v-if="pd.SOURCE=='2'">
            <td class="tbg">存在风险</td>
            <td>{{ pd.RISK_DESCR }}</td>
          </tr>
          <tr v-if="pd.SOURCE=='2'">
            <td class="tbg">风险分级</td>
            <td>{{ pd.LEVEL }}</td>
          </tr>
          <tr v-if="pd.SOURCE=='2'">
            <td class="tbg">检查内容</td>
            <td>{{ pd.CHECK_CONTENT }}</td>
          </tr>
          <tr>
            <td class="tbg">隐患级别</td>
            <td>{{ pd.HIDDENLEVELNAME }}</td>
          </tr>
          <tr>
            <td class="tbg">隐患类型</td>
            <td>{{ (pd.HIDDENTYPE1_NAME?pd.HIDDENTYPE1_NAME:'') + '/' + (pd.HIDDENTYPE2_NAME?pd.HIDDENTYPE2_NAME:'') +'/'+ (pd.HIDDENTYPE3_NAME?pd.HIDDENTYPE3_NAME:'') }}</td>
          </tr>
          <tr>
            <td class="tbg">隐患状态</td>
            <td>
              <template v-if="pd.STATE=='1'">
                未整改
              </template>
              <template v-else-if="pd.STATE=='3'">
                已整改
              </template>
              <template v-else-if="pd.STATE=='4'">
                已验收
              </template>
              <template v-else-if="pd.STATE=='-1'">
                已超期
              </template>
            </td>
          </tr>
          <tr>
            <td class="tbg">隐患描述</td>
            <td>{{ pd.HIDDENDESCR }}</td>
          </tr>
          <tr>
            <td class="tbg">隐患部位</td>
            <td>{{ pd.HIDDENPART }}</td>
          </tr>
          <tr>
            <td class="tbg">隐患发现部门</td>
            <td>{{ pd.HIDDENFINDDEPTNAME }}</td>
          </tr>
          <tr>
            <td class="tbg">发现人</td>
            <td>{{ pd.CREATORNAME }}</td>
          </tr>
          <tr>
            <td class="tbg">发现时间</td>
            <td>{{ pd.CREATTIME }}</td>
          </tr>
          <tr>
            <td class="tbg">整改类型</td>
            <td>
              <template v-if="pd.RECTIFICATIONTYPE=='1'">
                立即整改
              </template>
              <template v-else-if="pd.RECTIFICATIONTYPE=='2'">
                限期整改
              </template>
            </td>
          </tr>
          <tr v-if="pd.RECTIFICATIONTYPE=='2'">
            <td class="tbg">整改期限</td>
            <td>{{ pd.RECTIFICATIONDEADLINE }}</td>
          </tr>
          <tr v-if="pd.HIDDEN_CATEGORY">
            <td class="tbg">隐患类别</td>
            <td>{{ pd.HIDDEN_CATEGORY_NAME }}</td>
          </tr>
          <tr>
            <td class="tbg">隐患图片</td>
            <td class="img-select">
              <viewer :images="hImgs">
                <img v-for="item in hImgs" :src="config.fileUrl + item.FILEPATH" :key="item.IMGFILES_ID" width="100" height="100">
              </viewer>
            </td>
          </tr>
          <tr v-if="playerOptions.sources[0].src">
            <td class="tbg">隐患视频</td>
            <td class="img-select">
              <i class="el-icon-video-play" style="font-size: 30px" @click="dialogVisibleVideo = true"/>
            </td>
            <el-dialog :visible.sync="dialogVisibleVideo" :append-to-body="true">
              <video-player ref="videoPlayer" :playsinline="true" :options="playerOptions" class="video-player vjs-custom-skin" />
            </el-dialog>
          </tr>
        </table>
      </div>

      <div v-show="pd.STATE>=2" class="print-break">
        <div class="level-title">
          <h1>整改信息</h1>
        </div>
        <table class="table-ui mb-20">
          <thead/>
          <tbody>
            <tr>
              <td class="tbg">整改描述</td>
              <td>{{ pd.RECTIFYDESCR }}</td>
            </tr>

            <tr>
              <td class="tbg">整改部门</td>
              <td>{{ pd.RECTIFICATIONDEPTNAME }}</td>
            </tr>
            <tr>
              <td class="tbg">整改人</td>
              <td>{{ pd.RECTIFICATIONORNAME }}</td>
            </tr>
            <tr>
              <td class="tbg">整改时间</td>
              <td>{{ pd.RECTIFICATIONTIME }}</td>
            </tr>
            <tr>
              <td class="tbg">整改后图片</td>
              <td class="img-select">
                <viewer :images="rImgs">
                  <img v-for="item in rImgs" :src="config.fileUrl + item.FILEPATH" :key="item.IMGFILES_ID" width="100" height="100">
                </viewer>
              </td>
            </tr>
            <tr v-if="pd.RECTIFICATIONTYPE!=='1'">
              <td class="tbg">整改方案</td>
              <td v-if="pd.HAVESCHEME==0">无</td>
              <td v-else-if="pd.HAVESCHEME==1">有</td>
              <td v-else/>
            </tr>
            <tr v-if="hs && pd.HAVESCHEME==1">
              <td class="tbg">排查日期</td>
              <td>{{ hs.SCREENINGDATE }}</td>
            </tr>
            <tr v-if="hs && pd.HAVESCHEME==1">
              <td class="tbg">隐患清单</td>
              <td>{{ hs.LISTNAME }}</td>
            </tr>
            <tr v-if="hs && pd.HAVESCHEME==1">
              <td class="tbg">治理标准要求</td>
              <td>{{ hs.GOVERNSTANDARDS }}</td>
            </tr>
            <tr v-if="hs && pd.HAVESCHEME==1">
              <td class="tbg">治理方法</td>
              <td>{{ hs.GOVERNMETHOD }}</td>
            </tr>
            <tr v-if="hs && pd.HAVESCHEME==1">
              <td class="tbg">经费和物资的落实</td>
              <td>{{ hs.EXPENDITURE }}</td>
            </tr>
            <tr v-if="hs && pd.HAVESCHEME==1">
              <td class="tbg">负责治理人员</td>
              <td>{{ hs.PRINCIPAL }}</td>
            </tr>
            <tr v-if="hs && pd.HAVESCHEME==1">
              <td class="tbg">工时安排</td>
              <td>{{ hs.PROGRAMMING }}</td>
            </tr>
            <tr v-if="hs && pd.HAVESCHEME==1">
              <td class="tbg">时限要求</td>
              <td>{{ hs.TIMELIMITFOR }}</td>
            </tr>
            <tr v-if="hs && pd.HAVESCHEME==1">
              <td class="tbg">工作要求</td>
              <td>{{ hs.JOBREQUIREMENT }}</td>
            </tr>
            <tr v-if="hs && pd.HAVESCHEME==1">
              <td class="tbg">其他事项</td>
              <td>{{ hs.OTHERBUSINESS }}</td>
            </tr>
            <tr v-if="hs && pd.HAVESCHEME==1">
              <td class="tbg">方案图片</td>
              <td class="img-select">
                <viewer :images="sImgs">
                  <img v-for="item in sImgs" :src="config.fileUrl + item.FILEPATH" :key="item.IMGFILES_ID" width="100" height="100">
                </viewer>
              </td>
            </tr>

            <tr v-if="pd.RECTIFICATIONTYPE!=='1'">
              <td class="tbg">整改计划</td>
              <td v-if="pd.HAVEPLAN==0">无</td>
              <td v-else-if="pd.HAVEPLAN==1">有</td>
              <td v-else/>
            </tr>
            <tr v-if="pd.HAVEPLAN==1">
              <td class="tbg">计划图片</td>
              <td class="img-select">
                <viewer :images="pImgs">
                  <img v-for="item in pImgs" :src="config.fileUrl + item.FILEPATH" :key="item.IMGFILES_ID" width="100" height="100">
                </viewer>
              </td>
            </tr>
          </tbody>
        </table>
      </div>

      <div v-show="pd.STATE>=4" v-if="pd.RECTIFICATIONTYPE!=='1'" class="print-break">
        <div class="level-title">
          <h1>验收信息</h1>
        </div>
        <template>
          <table v-for="(data) in checkList" :key="data.value" class="table-ui">
            <thead/>
            <tbody>
              <tr>
                <td class="tbg">验收描述</td>
                <td>{{ data.CHECKDESCR }}</td>
              </tr>
              <tr>
                <td class="tbg">是否合格</td>
                <td>
                  <template v-if="data.STATUS=='1'">
                    是
                  </template>
                  <template v-else-if="data.STATUS=='0'">
                    否
                  </template>
                </td>
              </tr>
              <tr>
                <td class="tbg">验收部门</td>
                <td>{{ data.CHECKDEPTNAME }}</td>
              </tr>
              <tr>
                <td class="tbg">验收人</td>
                <td>{{ data.CHECKORNAME }}</td>
              </tr>

              <tr>
                <td class="tbg">验收时间</td>
                <td>{{ data.CHECK_TIME }}</td>
              </tr>
              <tr>
                <td class="tbg">验收图片</td>
                <td class="img-select">
                  <viewer :images="data.cImgs">
                    <img v-for="item in data.cImgs" :src="config.fileUrl + item.FILEPATH" :key="item.IMGFILES_ID" width="100" height="100">
                  </viewer>
                </td>
              </tr>
            </tbody>
          </table>
        </template>
      </div>
    </div>

    <!--    <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="back">返 回</el-button>
    </div>
    <div v-html="styleText"/>
  </div>

</template>

<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import { videoPlayer } from 'vue-video-player'
import 'video.js/dist/video-js.css'
export default {
  components: { Pagination, videoPlayer },
  data() {
    return {
      styleText: '<style type="text/css" media="print">\n' + '  @page { margin-top: 20px }\n' + '</style>',
      HIDDEN_ID: '',	// 主键ID
      pd: [],						// 存放字段参数
      hs: [],
      checkList: [],
      msg: 'add',
      pageType: '',
      config: config,
      hImgs: [],
      rImgs: [],
      sImgs: [],
      pImgs: [],
      dialogVisibleVideo: false,
      playerOptions: {
        playbackRates: [0.5, 1.0, 1.5, 2.0], // 可选的播放速度
        autoplay: false, // 如果为true,浏览器准备好时开始回放。
        muted: false, // 默认情况下将会消除任何音频。
        loop: false, // 是否视频一结束就重新开始。
        preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
        language: 'zh-CN',
        aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        sources: [{
          type: 'video/mp4', // 类型
          src: '' // url地址
        }],
        poster: '', // 封面地址
        notSupportedMessage: '此视频暂无法播放，请稍后再试', // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
        controlBar: {
          timeDivider: true, // 当前时间和持续时间的分隔符
          durationDisplay: true, // 显示持续时间
          remainingTimeDisplay: true, // 是否显示剩余时间功能
          fullscreenToggle: true // 是否显示全屏按钮
        }
      }
    }
  },
  created() {
    if (this.$parent.HIDDEN_ID) {
      this.getData(this.$parent.HIDDEN_ID)
    }
  },
  methods: {
    getData(hiddenId) {
      this.listLoading = true
      requestFN(
        '/hiddenLibrary/hiddenGoEdit',
        {
          HIDDEN_ID: hiddenId,
          tm: new Date().getTime()
        }
      ).then((data) => {
        var vm = this
        vm.pd = data.pd							// 参数map
        vm.hs = data.hs							// 参数map
        vm.checkList = data.checkList
        for (let i = 0; i < data.hImgs.length; i++) {
          if (data.hImgs[i].FILEPATH.substring(data.hImgs[i].FILEPATH.lastIndexOf('.') + 1) === 'mp4') {
            this.playerOptions.sources[0].src = config.fileUrl + data.hImgs[i].FILEPATH
          } else {
            this.hImgs.push(data.hImgs[i])
          }
        }
        this.rImgs = data.rImgs
        this.sImgs = data.sImgs
        this.pImgs = data.pImgs
      }).catch((e) => {
        this.listLoading = false
      })
    },
    back() {
      this.$parent.activeName = 'List'
    }
  }
}
</script>

<style lang="sass" scoped>
  .table-ui
    .tbg
      width: 150px
    .img-flex
      display: flex
      .img-ui
        width: 240px
        height: 240px
        margin-right: 20px
        & img
          width: 100%
          height: 100%
</style>
