<template>
  <view class="content">
    <view class="card">
      <view class="view-title">
        <u--text text="隐患信息" bold></u--text>
      </view>
      <u-cell-group :border="false">
        <u-cell>
          <view slot="title" class="title">隐患来源</view>
          <view slot="value">
            <template v-if="form.SOURCE=='1'">
              隐患快报
            </template>
            <template v-else-if="form.SOURCE=='2'">
              清单排查
            </template>
            <template v-else-if="form.SOURCE=='3'">
              清单排查
            </template>
            <template v-else-if="form.SOURCE=='4'">
              安全环保检查(监管端)
            </template>
            <template v-else-if="form.SOURCE=='5'">
              安全环保检查(企业端)
            </template>
            <template v-else-if="form.SOURCE=='6'">
              消防检查
            </template>
            <template v-else-if="form.SOURCE=='8'">
              点检隐患
            </template>
          </view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">隐患描述</view>
          <view slot="label" class="mt-10 u-line-5">{{ form.HIDDENDESCR }}</view>
        </u-cell>
        <template v-if="form.SOURCE=='2'">
          <u-cell>
            <view slot="title" class="title">风险点（单元）</view>
            <view slot="value">{{ form.RISK_UNIT }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">辨识部位</view>
            <view slot="value">{{ form.IDENTIFICATION }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">存在风险</view>
            <view slot="value">{{ form.RISK_DESCR }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">风险分级</view>
            <view slot="value">{{ form.LEVEL }}</view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title">检查内容</view>
            <view slot="value">{{ form.CHECK_CONTENT }}</view>
          </u-cell>
        </template>
        <u-cell>
          <view slot="title" class="title">隐患级别</view>
          <view slot="value">{{ form.editLevelName || form.HIDDENLEVELNAME }}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">隐患类型</view>
          <view slot="value">{{ form.HIDDENTYPENAME }}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">隐患部位</view>
          <view slot="value">{{ form.hregionName?form.hregionName:form.HIDDENPART }}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">隐患上报位置</view>
          <view slot="label" class="mt-10">
            <view>经度:{{ form.LONGITUDE }}</view>
            <view>纬度:{{ form.LATITUDE }}</view>
          </view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">隐患位置描述</view>
          <view slot="label" class="mt-10">{{ form.POSITIONDESC }}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">隐患图片</view>
          <view slot="label" class="mt-10">
            <view style="display: flex;flex-wrap: wrap">
              <view v-for="(item,index) in hImgs" :key="index" class="ml-10 mt-10">
                <u--image :showLoading="true" :src="item" width="80px" height="80px"
                          @click="previewImage(hImgs, item)"></u--image>
              </view>
            </view>
          </view>
        </u-cell>
        <u-cell v-if="videoUrl">
          <view slot="title" class="title">隐患视频</view>
          <view slot="value">
            <u-icon name="play-circle-fill" size="30" @click="modalShow = true"></u-icon>
          </view>
        </u-cell>
        <u-modal :show="modalShow" title="视频播放" confirmText="关闭" @confirm="modalShow = false">
          <view>
            <video v-if="modalShow" :src="videoUrl" :autoplay="true"></video>
          </view>
        </u-modal>
        <u-cell v-for="(item,index) in hiddenFindPeople" :key="index">
          <view slot="title" class="title">隐患发现人</view>
          <view slot="value">{{ item.NAME }}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">隐患发现时间</view>
          <view slot="value">{{ form.DISCOVERYTIME }}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">整改负责人</view>
          <view slot="value">{{ form.oldUserName || form.RECTIFICATIONORNAME }}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">整改完成期限</view>
          <view slot="value">{{ form.oldRectificationDeadline || form.RECTIFICATIONDEADLINE }}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">是否相关方</view>
          <view slot="value">{{ form.ISRELEVANT == '1' ? '是' : '否' }}</view>
        </u-cell>
      </u-cell-group>
    </view>
    <view class="card">
      <view class="view-title">
        <u--text text="确认信息" bold></u--text>
      </view>
      <u-cell-group :border="false">
        <u-cell>
          <view slot="title" class="title">隐患级别</view>
          <view slot="value">{{form.HIDDENLEVELNAME}}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">整改负责人</view>
          <view slot="value">{{form.RECTIFICATIONORNAME}}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">整改完成期限</view>
          <view slot="value">{{form.RECTIFICATIONDEADLINE}}</view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">隐患确认人</view>
          <view slot="value">{{form.conUserName}}</view>
        </u-cell>
        <u-cell v-if="form.STATE != '-2'">
          <view slot="title" class="title">隐患确认时间</view>
          <view slot="value">{{form.CONFIRM_TIME}}</view>
        </u-cell>
      </u-cell-group>
    </view>
  </view>
</template>

<script>
import {getHiddenGoEdit} from "../../../api";

export default {
  data() {
    return {
      HIDDEN_ID: '',
      form: {},
      hImgs: [],
      videoUrl: '',
      modalShow: false,
      hiddenFindPeople: [],
    }
  },
  onLoad(event) {
    this.HIDDEN_ID = event.HIDDEN_ID;
    this.getData()
  },
  methods: {
    async getData() {
      let resData = await getHiddenGoEdit({HIDDEN_ID: this.HIDDEN_ID});
      this.form = resData.pd;
      this.hiddenFindPeople = resData.hiddenFindPeople;
      for (let i = 0; i < resData.hImgs.length; i++) {
        this.hImgs.push(this.$store.state.filePath + resData.hImgs[i].FILEPATH)
      }
      if (resData.hiddenVideo.length > 0) this.videoUrl = this.$store.state.filePath + resData.hiddenVideo[0].FILEPATH
      resData.hiddenExa && resData.hiddenExa.forEach(item => {
        if (item.TYPE == 4) {
          this.form.oldUserName = item.editUserName
          this.form.oldDeptName = item.editDeptName
          this.form.oldLevelName = item.editLevelName
          this.form.oldRectificationDeadline = item.spare3
        }
      })
    },
    previewImage(list, current) {
      uni.previewImage({
        urls: list,
        current
      });
    },
  },
}
</script>

<style scoped>
.title {
  min-width: 150rpx;
}
</style>
