<template>
  <view class="content">
    <view class="card">
      <u-cell-group :border="false">
        <u-cell>
          <view slot="title" class="title required">检查题目：</view>
          <view slot="value">
            <u-radio-group v-model="form.INSPECTION_SUBJECT" placement="row" disabled>
              <u-radio label="安全" name="安全"></u-radio>
              <u-radio label="环保" name="环保" class="ml-10"></u-radio>
              <u-radio label="综合" name="综合" class="ml-10"></u-radio>
            </u-radio-group>
          </view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title required">被检查单位：</view>
          <view slot="value">
            <text>{{ form.INSPECTED_CORPINFO_ID_NAME }}</text>
          </view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title required">被检查单位现场负责人：</view>
          <view slot="value">
            <text>{{ form.INSPECTED_SITEUSER_NAME }}</text>
          </view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title required">检查场所：</view>
          <view slot="value">
            <u--input v-model="form.INSPECTION_PLACE" border="none" placeholder="请输入检查场所" inputAlign="right"
                      disabled></u--input>
          </view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title required">检查类型：</view>
          <view slot="value">
            <text>{{ form.INSPECTION_TYPE_NAME }}</text>
          </view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title required">检查开始时间：</view>
          <view slot="value">
            <text>{{ form.INSPECTION_TIME_START }}</text>
          </view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title required">检查结束时间：</view>
          <view slot="value">
            <text>{{ form.INSPECTION_TIME_END }}</text>
          </view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title required">记录填写时间：</view>
          <view slot="value">
            <text>{{ form.CREATTIME }}</text>
          </view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">检查情况：</view>
        </u-cell>
        <u-cell>
          <view slot="label textarea-box">
            <view class="pr mt-10" v-for="(item,index) in form.situationList" :key="item.id">
              <u--textarea v-model="item.SITUATION" placeholder="请输入检查情况" disabled></u--textarea>
            </view>
          </view>
        </u-cell>
        <u-cell>
          <view slot="title" class="title">检查人员：</view>
        </u-cell>
        <view class="title-none">
          <u-cell>
            <view slot="value" style="width: 100%">
              <view class="pr mt-10" v-for="(item,index) in form.inspectorList" :key="item.id">
                <u-cell-group :border="false" class="border">
                  <view class="title-show">
                    <u-cell>
                      <view slot="title">{{ index + 1 }}.检查人员单位</view>
                      <view slot="value">
                        <text>{{ item.INSPECTION_DEPARTMENT_NAME }}</text>
                      </view>
                    </u-cell>
                  </view>
                  <view class="title-show">
                    <u-cell :border="false">
                      <view slot="title">{{ index + 1 }}.检查人员</view>
                      <view slot="value">
                        <text>{{ item.INSPECTION_USER_NAME }}</text>
                      </view>
                    </u-cell>
                  </view>
                </u-cell-group>
              </view>
            </view>
          </u-cell>
        </view>
        <u-cell>
          <view slot="title" class="title">发现问题：</view>
        </u-cell>
        <view class="title-none">
          <u-cell>
            <view slot="label" style="width: 100%">
              <uni-table border stripe emptyText="暂无更多数据">
                <uni-tr>
                  <uni-th align="center">序号</uni-th>
                  <uni-th align="center">隐患部位</uni-th>
                  <uni-th align="center">隐患描述</uni-th>
                  <uni-th align="center">操作</uni-th>
                </uni-tr>
                <uni-tr v-for="(item,index) in form.hiddenList" :key="item.id">
                  <uni-td>{{ index + 1 }}</uni-td>
                  <uni-td>{{ item.HIDDENPART_NAME }}</uni-td>
                  <uni-td>{{ item.HIDDENDESCR }}</uni-td>
                  <uni-td>
                    <view class="flex-between">
                      <u-icon name="eye-fill" @tap="showHidden(item, index)"></u-icon>
                    </view>
                  </uni-td>
                </uni-tr>
              </uni-table>
            </view>
          </u-cell>
        </view>
        <template v-for="item in form.inspectorVerifyList">
          <u-cell v-show="item.INSPECTION_USER_OPINION">
            <view slot="title" class="title">检查人意见：</view>
            <view slot="label" class="mt-10 textarea-box">
              <u--textarea v-model="item.INSPECTION_USER_OPINION" disabled placeholder="请输入检查人意见"></u--textarea>
            </view>
          </u-cell>
          <u-cell v-show="item.INSPECTION_USER_SIGN_IMG">
            <view slot="title" class="title">签字：</view>
            <view slot="label" class="mt-10">
              <u--image :showLoading="true" :src="$store.state.filePath + item.INSPECTION_USER_SIGN_IMG"
                        width="100%" height="80px" mode="scaleToFill"
                        @click="previewImage($store.state.filePath + item.INSPECTION_USER_SIGN_IMG)"></u--image>
            </view>
          </u-cell>
        </template>
      </u-cell-group>
    </view>
    <u-popup :show="popupShow" @close="popupShow = false" mode="right" :closeOnClickOverlay="false"
             :customStyle="{width:'85vw',overflowY:'auto'}">
      <view class="card">
        <u-cell-group :border="false">
          <u-cell>
            <view slot="title" class="title required">隐患照片：</view>
            <view slot="label" class="mt-10">
              <u-upload
                  disabled
                  deletable
                  uploadIcon="plus"
                  :fileList="hiddenForm.hiddenImgs"
                  multiple
                  :maxCount="4"
              ></u-upload>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title flex-between">
              隐患视频：
              <u-icon v-if="hiddenForm.hiddenVideos.length !== 0 && hiddenForm.hiddenVideos[0].url"
                      name="play-circle-fill" size="30" @click="previewVideo(hiddenForm.hiddenVideos[0].url)"></u-icon>
            </view>
            <view slot="label" class="mt-10">
              <u-upload
                  disabled
                  deletable
                  accept="video"
                  uploadIcon="plus"
                  :fileList="hiddenForm.hiddenVideos"
                  multiple
                  :maxCount="1"
              ></u-upload>
              <u-modal :show="modalShow" title="视频播放" confirmText="关闭" @confirm="modalShow = false">
                <view>
                  <video v-if="modalShow" :src="videoUrl" :autoplay="true"></video>
                </view>
              </u-modal>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title required">隐患描述：</view>
            <view slot="label" class="mt-10 textarea-box">
              <u--textarea v-model="hiddenForm.HIDDENDESCR" placeholder="请输入隐患描述" disabled></u--textarea>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title required">隐患部位：</view>
            <view slot="value">
              <text>{{ hiddenForm.HIDDENPART_NAME ? hiddenForm.HIDDENPART_NAME : hiddenForm.HIDDENPART }}</text>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title required">隐患级别：</view>
            <view slot="value">
              <text>{{ hiddenForm.HIDDENLEVEL_NAME }}</text>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title required">隐患类型：</view>
            <view slot="value">
              <text>{{ hiddenForm.HIDDENTYPE_NAME }}</text>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title required">是否是相关方：</view>
            <view slot="value">
              <text>{{ hiddenForm.ISRELEVANT === '1' ? '是' : '否' }}</text>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title required">隐患发现时间：</view>
            <view slot="value">
              <text>{{ hiddenForm.DISCOVERYTIME }}</text>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title required">隐患上报位置：</view>
            <view slot="label" class="mt-10">
              <view>经度:{{ hiddenForm.LONGITUDE }}</view>
              <view>纬度:{{ hiddenForm.LATITUDE }}</view>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title required">隐患位置描述：</view>
            <view slot="label" class="mt-10 textarea-box">
              <u--textarea v-model="hiddenForm.POSITIONDESC" placeholder="请输入隐患位置描述" disabled></u--textarea>
            </view>
          </u-cell>
          <u-cell>
            <view slot="title" class="title required">隐患发现人：</view>
            <view slot="value">
              <text>{{ hiddenForm.CREATOR_NAME }}</text>
            </view>
          </u-cell>
          <u-cell :border="false">
            <view slot="label" class="flex-between">
              <u-button type="info" text="取消" @click="popupClose"></u-button>
            </view>
          </u-cell>
        </u-cell-group>
      </view>
    </u-popup>
  </view>
</template>

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

export default {
  data() {
    return {
      form: {
        INSPECTION_SUBJECT: '',
        INSPECTED_DEPARTMENT_NAME: '',
        INSPECTED_DEPARTMENT_ID: '',
        INSPECTED_SITEUSER_NAME: '',
        INSPECTED_SITEUSER_ID: '',
        INSPECTION_PLACE: '',
        INSPECTION_TYPE_NAME: '',
        INSPECTION_TIME_START: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM'),
        INSPECTION_TIME_END: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM'),
        CREATTIME: '',
        situationList: [{id: Math.random(), INSPECTION_SITUATION_ID: '', SITUATION: ''}],
        inspectorList: [{
          id: Math.random(),
          inspectionUserShow: false,
          INSPECTION_INSPECTOR_ID: '',
          INSPECTION_DEPARTMENT_ID: '',
          INSPECTION_DEPARTMENT_NAME: '',
          INSPECTION_USER_ID: '',
          INSPECTION_USER_NAME: ''
        }],
        hiddenList: [],
        INSPECTION_USER_OPINION: '',
        INSPECTION_USER_SIGN_IMG: '',
      },
      INSPECTION_ID: '',
      popupShow: false,
      hiddenForm: {
        hiddenImgs: [],
        hiddenVideos: [],
        HIDDENDESCR: '',
        HIDDENPART_NAME: '',
        HIDDENPART: '',
        HIDDENLEVEL_NAME: '',
        HIDDENLEVEL: '',
        HIDDENTYPE_NAME: '',
        HIDDENTYPE: '',
        DISCOVERYTIME: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM'),
        LONGITUDE: '',
        LATITUDE: '',
        CREATOR_NAME: '',
        CREATOR: '',
        ISRELEVANT: ''
      },
      modalShow: false,
      videoUrl: ''
    }
  },
  onLoad(event) {
    this.INSPECTION_ID = event.INSPECTION_ID
    if (this.INSPECTION_ID) {
      this.fnGetSafetyenvironmentalGoEdit()
    }
  },
  methods: {
    async fnGetSafetyenvironmentalGoEdit() {
      let resData = await getSafetyenvironmentalGoEdit({INSPECTION_ID: this.INSPECTION_ID})
      for (let i = 0; i < resData.pd.hiddenList.length; i++) {
        resData.pd.hiddenList[i].id = resData.pd.hiddenList[i].HIDDEN_ID
        for (let j = 0; j < resData.pd.hiddenList[i].hiddenImgs.length; j++) {
          resData.pd.hiddenList[i].hiddenImgs[j].url = this.$store.state.filePath + resData.pd.hiddenList[i].hiddenImgs[j].FILEPATH
        }
        for (let j = 0; j < resData.pd.hiddenList[i].hiddenVideos.length; j++) {
          resData.pd.hiddenList[i].hiddenVideos[j].url = this.$store.state.filePath + resData.pd.hiddenList[i].hiddenVideos[j].FILEPATH
        }
      }
      this.form = resData.pd
    },
    showHidden(item) {
      this.hiddenForm = item
      this.popupShow = true
    },
    popupClose() {
      this.popupShow = false
    },
    previewImage(current) {
      if (false) {
        uni.previewImage({
          urls: [current],
          current
        });
      }
    },
    previewVideo(videoUrl) {
      this.modalShow = true;
      this.videoUrl = videoUrl;
    }
  },
}
</script>

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

.textarea-box {
  width: 100%;
}
</style>
