<template>
  <page-meta :page-style="'overflow:'+(visible?'hidden':'visible')"></page-meta>
  <uni-popup ref="popup" type="center" :mask-click="false">
      <scroll-view scroll-y style="width: 100vw;height: 100vh;">
        <view :style="{padding: this.CustomBar + 15 + 'px 15px 15px 15px'}">
          <view>
            <view v-for="(item,index) in list" :key="item.HIDDEN_LIBRARY_ID" class="item" @click="determine(item)">
              <view style="padding-left: 10upx;">隐患部位:{{ item.HIDDEN_PART }}</view>
              <view style="padding-left: 10upx;">隐患描述:{{ item.INSPECTION_BASIS }}</view>
              <view style="padding-left: 10upx;">整改建议:{{ item.RECTIFYDESCR }}</view>
            </view>
          </view>
        </view>
        <view class="cu-bar btn-group" style="margin-top: 50upx;">
          <button class="cu-btn bg-grey margin-tb-sm lg" @click="close">关闭</button>
        </view>
      </scroll-view>
  </uni-popup>
</template>

<script>
import uniPopup from '@/components/more-select/uni-popup/uni-popup.vue';
import {basePath, loginUser,corpinfoId} from "@/common/tool";
export default {
  components: {
    uniPopup,
  },
  props: {
    visible: {
      type: Boolean,
      required: true,
      default: false
    },
    value:{
      type: String,
      required: true,
      default: ''
    },
    name:{
      type: String,
      required: true,
      default: ''
    },
  },
  data() {
    return {
      list: [],
      selectValue:[],
    }
  },
  watch:{
    visible:{
      handler(newValue) {
        if (newValue) this.getData()
      },
      immediate:true
    }
  },
  methods: {
    getData() {
      uni.showLoading({
        title: '请稍候'
      })
      uni.request({
        url: basePath + 'app/hiddenLibrary/list',
        method: 'POST',
        header: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          RISK_UNIT_NAME: this.name,
          HIDDEN_PART: this.value,
          CORPINFO_ID: corpinfoId
        },
        success: (res) => {
          if ("success" === res.data.result) {
            this.list = res.data.varList
            this.$refs.popup.open()
            uni.hideLoading();
          } else if ("exception" === res.data.result) {
            uni.showToast({
              title: '错误',
              duration: 2000
            });
          }
        }
      });
    },
    close(){
      this.$emit('update:visible',false)
      this.$refs.popup.close()
    },
    determine(item){
      let info = {
        INSPECTION_BASIS:item.INSPECTION_BASIS,
        RECTIFYDESCR:item.RECTIFYDESCR,
        HIDDEN_PART: item.HIDDEN_PART,
        HIDDENTYPE: [],
        HIDDEN_TYPE_ONE_NAME:item.HIDDEN_TYPE_ONE_NAME,
        HIDDEN_TYPE_TWO_NAME:item.HIDDEN_TYPE_TWO_NAME,
        HIDDEN_TYPE_THREE_NAME:item.HIDDEN_TYPE_THREE_NAME
      }
      if (item.HIDDEN_TYPE_ONE) info.HIDDENTYPE.push(item.HIDDEN_TYPE_ONE)
      if (item.HIDDEN_TYPE_TWO) info.HIDDENTYPE.push(item.HIDDEN_TYPE_TWO)
      if (item.HIDDEN_TYPE_THREE) info.HIDDENTYPE.push(item.HIDDEN_TYPE_THREE)
      this.$emit('confirm',info)
      this.close()
    }
  },
}
</script>

<style scoped>
.item{
  margin-top: 15upx;
  background-color: #f5f5f5;
  border-radius: 20upx;
  padding: 20upx;
}
</style>