<template>
  <view>
    <u-cell-group>
          <u-cell title="隐患描述" :label="info.HIDDENDESCR"/>
          <u-cell title="隐患来源" :value="HIDDEN_SOURCE[info.SOURCE]"/>
          <block v-if="info.SOURCE === '2'">
            <u-cell title="风险点（单元）" :value="info.RISK_UNIT"/>
            <u-cell title="辨识部位" :value="info.IDENTIFICATION"/>
            <u-cell title="存在风险" :value="info.RISK_DESCR"/>
            <u-cell title="风险分级" :value="info.LEVEL"/>
            <u-cell title="检查内容" :value="info.CHECK_CONTENT"/>
          </block>
          <u-cell title="隐患上报位置（经纬度）">
            <template #label>
              <view v-if="info.LONGITUDE && info.LATITUDE">
                <view>经度:{{ info.LONGITUDE }}</view>
                <view>纬度:{{ info.LATITUDE }}</view>
              </view>
            </template>
          </u-cell>
          <u-cell title="隐患部位" :value="info.hregionName || info.HIDDENPART"/>
          <u-cell title="隐患位置描述" :value="info.POSITIONDESC"/>
          <u-cell title="隐患类型" :value="info.HIDDENTYPENAME"/>
          <u-cell title="隐患级别" :value="info.HIDDENLEVELNAME"/>
          <u-cell title="隐患发现人" :value="hiddenFindPeople.map((item) => item.NAME).join('、')"/>
          <u-cell title="隐患发现时间" :value="info.DISCOVERYTIME"/>
          <block v-if="info.RECTIFICATIONTYPE">
            <u-cell title="整改类型">
              <template #value>
                <text v-if="info.RECTIFICATIONTYPE === '1'">立即整改</text>
                <text v-else-if="info.RECTIFICATIONTYPE === '2'">限期整改</text>
              </template>
            </u-cell>
            <u-cell title="整改负责部门" :value="info.editDeptName"/>
            <u-cell title="整改负责人" :value="info.editUserName"/>
            <block v-if="info.RECTIFICATIONTYPE === '2'">
              <u-cell title="整改期限" :value="info.editRectificationDeadline"/>
            </block>
          </block>
          <u-cell title="是否相关方">
            <template #value>
              <text v-if="info.ISRELEVANT === '1'">是</text>
              <text v-else-if="info.ISRELEVANT === '2'">否</text>
            </template>
          </u-cell>
          <app-preview-image :files="hImgs" label="隐患照片"/>
          <block v-if="hiddenVideo.length > 0">
            <u-cell title="隐患视频">
              <template #value>
                <u-icon
                    name="play-circle-fill"
                    size="24"
                    @click="fnPreviewVideo(hiddenVideo[0].FILEPATH)"
                />
              </template>
            </u-cell>
          </block>
          <view v-for="(item, index) in hiddenExamineList" :key="index">
            <block v-if="item.TYPE === 4">
              <u-divider text-position="left" text="隐患确认"></u-divider>
              <u-cell title="隐患级别" :value="item.editLevelName"/>
              <u-cell title="整改负责人部门" :value="item.editDeptName"/>
              <u-cell title="整改负责人" :value="item.editUserName"/>
              <u-cell title="整改完成期限" :value="item.spare3"/>
              <u-cell title="隐患确认人" :value="info.conUserName"/>
              <u-cell title="隐患确认时间" :value="info.CONFIRM_TIME"/>
            </block>
            <block v-if="item.TYPE === 6 && item.spare5 !== '1'">
              <u-cell title="隐患状态" value="确认打回"/>
              <u-cell title="打回原因" :label="item.REPULSE_CAUSE"/>
              <u-cell title="打回时间" :value="item.CREATTIME"/>
            </block>
            <block v-if="item.TYPE === 2">
              <u-divider text-position="left" text="延期信息"></u-divider>
              <u-cell title="申请延期日期" :value="item.CREATTIME"/>
              <u-cell title="延期日期" :value="formatDate(item.DELAY_TIME)"/>
              <u-cell title="审核人" :value="info.conUserName"/>
              <u-cell title="处置方案" :value="item.DISPOSAL_PLAN"/>
              <block v-if="item.DISPOSAL_FILE">
                <u-cell title="处置方案附件">
                  <template #value>
                    <u-button
                        type="primary"
                        size="mini"
                        shape="circle"
                        :custom-style="{ width: 'auto' }"
                        text="下载"
                        @click="fnPreviewFile(item.DISPOSAL_FILE)"
                    />
                  </template>
                </u-cell>
              </block>
              <u-cell title="延期审核状态">
                <template #value>
                  <text v-if="item.STATE === -1">待审核</text>
                  <text v-if="item.STATE === 1">通过</text>
                  <text v-if="item.STATE === 2">未通过</text>
                </template>
              </u-cell>
              <block v-if="item.STATE !== -1">
                <u-cell title="审核时间" :value="item.OPERATTIME"/>
              </block>
            </block>
            <block v-if="item.TYPE === 1">
              <u-divider text-position="left" text="特殊处理审核信息"></u-divider>
              <u-cell title="无法整改原因" :label="item.EXAMINE"/>
              <u-cell title="特殊处置审核状态">
                <template #value>
                  <!-- 是否通过审核 ,1未通过。2通过 -1（初始）16隐患确认打回 -->
                  <text v-if="item.STATE === -1">待审核</text>
                  <text v-if="item.STATE === 1">不通过</text>
                  <text v-if="item.STATE === 2">通过</text>
                </template>
              </u-cell>
              <block v-if="item.STATE === 1">
                <u-cell title="处置方案" :value="item.DISPOSAL_PLAN"/>
                <block v-if="item.DISPOSAL_FILE">
                  <u-cell title="处置方案附件">
                    <template #value>
                      <u-button
                          type="primary"
                          size="mini"
                          shape="circle"
                          :custom-style="{ width: 'auto' }"
                          text="下载"
                          @click="fnPreviewFile(item.DISPOSAL_FILE)"
                      />
                    </template>
                  </u-cell>
                </block>
              </block>
              <block v-if="item.STATE !== -1">
                <u-cell title="审核时间" :value="item.OPERATTIME"/>
                <u-cell title="审核人" :value="info.conUserName"/>
              </block>
              <block v-if="item.STATE === 2">
                <u-cell title="是否更换整改负责人" :value="item.spare1 === '1' ? '是' : '否'"/>
                <block v-if="item.spare1 === '1'">
                  <u-cell title="整改负责人" :value="item.editUserName"/>
                </block>
              </block>
            </block>
            <block v-if="item.TYPE === 3">
              <u-divider text-position="left" text="验收打回信息"></u-divider>
              <u-cell title="验收打回意见" :label="item.EXAMINE"/>
              <u-cell title="验收人" :value="item.CREATORNAME"/>
              <u-cell title="验收时间" :value="item.CREATTIME"/>
            </block>
          </view>
          <block v-if="info.REJECTREASON">
            <u-divider text-position="left" text="隐患复查"></u-divider>
            <u-cell title="复查驳回原因" :label="info.REJECTREASON"/>
          </block>
          <block v-if="info.STATE === '2' || info.STATE === '4' || (info.STATE === '-2' && info.RECTIFICATIONTYPE === '1') || info.STATE === '10'">
            <u-divider text-position="left" text="整改信息"></u-divider>
            <u-cell title="整改描述" :label="info.RECTIFYDESCR"/>
            <u-cell title="整改部门" :value="info.RECTIFICATIONDEPTNAME"/>
            <u-cell title="整改人" :value="info.RECTIFICATIONORNAME"/>
            <u-cell title="整改时间" :value="info.RECTIFICATIONTIME"/>
            <u-cell title="投入资金" :value="info.INVESTMENT_FUNDS === undefined ? '' : info.INVESTMENT_FUNDS + '元'"/>
            <app-preview-image :files="rImgs" label="整改后图片"/>
            <u-cell title="整改方案">
              <template #value>
                <text v-if="info.HAVESCHEME === '0'">无</text>
                <text v-else-if="info.HAVESCHEME === '1'">有</text>
              </template>
            </u-cell>
            <block v-if="info.HAVESCHEME === '1'">
              <u-cell title="排查日期" :value="rectificationPlanInfo.SCREENINGDATE"/>
              <block v-if="rectificationPlanInfo.LISTNAME">
                <u-cell title="隐患清单" :value="rectificationPlanInfo.LISTNAME"/>
              </block>
              <u-cell title="治理标准要求" :value="rectificationPlanInfo.GOVERNSTANDARDS"/>
              <u-cell title="治理方法" :value="rectificationPlanInfo.GOVERNMETHOD"/>
              <u-cell title="经费和物资的落实" :value="rectificationPlanInfo.EXPENDITURE"/>
              <u-cell title="负责治理人员" :value="rectificationPlanInfo.PRINCIPAL"/>
              <u-cell title="工时安排" :value="rectificationPlanInfo.PROGRAMMING"/>
              <u-cell title="时限要求" :value="rectificationPlanInfo.TIMELIMITFOR"/>
              <u-cell title="工作要求" :value="rectificationPlanInfo.JOBREQUIREMENT"/>
              <u-cell title="其他事项" :value="rectificationPlanInfo.OTHERBUSINESS"/>
              <app-preview-image :files="sImgs" label="方案图片"/>
            </block>
          </block>
          <block v-if="info.STATE === '4'">
            <u-divider text-position="left" text="验收信息"></u-divider>
            <block v-if="info.RECTIFICATIONTYPE === '1'">
              <u-cell title="验收人" :value="info.CHECKORNAME" />
            </block>
            <block v-else>
              <view v-for="(item, index) in checkList" :key="index">
                <u-cell title="验收描述" :label="item.CHECKDESCR" />
                <u-cell title="是否合格" :value="item.STATUS === 1 ? '是' : '否'" />
                <u-cell title="验收部门" :value="item.CHECKDEPTNAME" />
                <u-cell title="验收人" :value="item.CHECKORNAME" />
                <u-cell title="验收时间" :value="item.CHECK_TIME" />
                <app-preview-image :files="item.cImgs" label="验收图片" />
              </view>
            </block>
          </block>
        </u-cell-group>
    <u-modal
        :show="videoDialog.visible"
        title="视频预览"
        :show-confirm-button="false"
        show-cancel-button
        cancel-text="关闭"
        @cancel="fnCloseVideoDialog"
    >
      <video
          v-if="videoDialog.src"
          :src="videoDialog.src"
          style="width: 100%; height: 200px; margin: 10px"
          autoplay
      />
    </u-modal>
  </view>
</template>

<script>
import AppPreviewImage from '@/components/preview_image/index.vue'
import dayjs from "dayjs";
import {getHiddenInfo} from "@/api/api";

export default {
  components: {
    AppPreviewImage,
  },
  props: {
    hiddenId: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      HIDDEN_SOURCE: {
        1: "隐患快报",
        2: "清单排查",
        3: "清单排查",
        4: "安全环保检查（监管端）",
        5: "安全环保检查（企业端）",
        6: "消防检查",
      },
      info: {},
      hiddenFindPeople: [],
      hImgs: [],
      hiddenVideo: [],
      hiddenExamineList: [],
      rImgs: [],
      rectificationPlanInfo: {},
      sImgs: [],
      checkList: [],
      videoDialog: {
        visible: false,
        src: ''
      }
    }
  },
  mounted() {
    this.fnGetData()
  },
  methods: {
    async fnGetData(){
      if (!this.hiddenId) return;
      const filePath = this.$filePath
      const resData = await getHiddenInfo({
        HIDDEN_ID: this.hiddenId,
        postMethod: 'application/json',
      });
      for (let i = 0; i < resData.hImgs.length; i++) {
        resData.hImgs[i].FILEPATH = filePath + resData.hImgs[i].FILEPATH;
      }
      for (let i = 0; i < resData.rImgs.length; i++) {
        resData.rImgs[i].FILEPATH = filePath + resData.rImgs[i].FILEPATH;
      }
      for (let i = 0; i < resData.sImgs.length; i++) {
        resData.sImgs[i].FILEPATH = filePath + resData.sImgs[i].FILEPATH;
      }
      for (let i = 0; i < resData.hiddenVideo.length; i++) {
        resData.hiddenVideo[i].FILEPATH =
            filePath + resData.hiddenVideo[i].FILEPATH;
      }
      for (let i = 0; i < resData.checkList.length; i++) {
        for (let j = 0; j < resData.checkList[i].cImgs.length; j++) {
          resData.checkList[i].cImgs[j].FILEPATH =
              filePath + resData.checkList[i].cImgs[j].FILEPATH;
        }
      }
      this.info = resData.pd;
      this.rectificationPlanInfo = resData.hs;
      this.hiddenFindPeople = resData.hiddenFindPeople;
      this.hImgs = resData.hImgs;
      this.rImgs = resData.rImgs;
      this.sImgs = resData.sImgs;
      this.checkList = resData.checkList;
      this.hiddenVideo = resData.hiddenVideo;
      this.hiddenExamineList = resData.hiddenExa;
      this.$emit("throw-basic-info", resData)
    },
    formatDate(date) {
      return dayjs(date).format('YYYY-MM-DD')
    },
    fnPreviewVideo(src) {
      this.videoDialog.visible = true;
      this.videoDialog.src = src;
    },
    fnCloseVideoDialog() {
      this.videoDialog.visible = false;
      this.videoDialog.src = '';
    },
    fnPreviewFile(src) {
      uni.downloadFile({
        url: this.$filePath + src,
        success: (res) => {
          uni.openDocument({
            filePath: res.tempFilePath,
          });
        },
      });
    }
  },
}
</script>

<style scoped lang="scss">
.ml-10:first-child {
  margin-left: 0;
}
</style>
