<template>
  <el-dialog title="详情" :visible.sync="detailOpen" width="900px" append-to-body destroy-on-close :close-on-click-modal="false">
    <el-form label-width="140px">
      <el-row class="el-row-table">
          <el-col :span="12">
            <el-form-item label="重要风险点名称">
              <span v-if="detailInfo.fRiskName">{{ detailInfo.fRiskName }}</span>
              <span v-else>-</span>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="重要风险点编码">
              <span v-if="detailInfo.fRiskCode">{{ detailInfo.fRiskCode }}</span>
              <span v-else>-</span>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="燃气企业">
              <span v-if="detailInfo.companyName">{{ detailInfo.companyName }}</span>
              <span v-else>-</span>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="县级行政区">
              <span v-if="detailInfo.regionName">{{ detailInfo.regionName }}</span>
              <span v-else>-</span>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="重要风险点类型">
              <span v-if="detailInfo.fRiskType">{{ $parent.fRiskTypeFormat(detailInfo) }}</span>
              <span v-else>-</span>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="所在位置地址描述">
              <span v-if="detailInfo.fRiskPlaceDetail">{{ detailInfo.fRiskPlaceDetail }}</span>
              <span v-else>-</span>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="风险构成">
              <span v-if="detailInfo.fRiskStructure">{{ detailInfo.fRiskStructure }}</span>
              <span v-else>-</span>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="风险管控措施">
              <span v-if="detailInfo.fRiskControlMeasures">{{ detailInfo.fRiskControlMeasures }}</span>
              <span v-else>-</span>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="备注">
              <span v-if="detailInfo.fRemark">{{ detailInfo.fRemark }}</span>
              <span v-else>-</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="经纬度位置">
              <div id="risk-map" style="height: 300px"></div>
            </el-form-item>
          </el-col>

      </el-row>
    </el-form>

    <div class="tableTitle">
      <img :src="relationImg" style="width: 24px; height: 25px;position: relative; left: -339px; top: -12px;"/>
      <span class="midText">关联设备</span>
    </div>
    <el-table v-loading="loadings" :data="DetailInfoList" tooltip-effect="dark" style="width: 100%" max-height="250">
      <el-table-column label="设备名称" align="center" prop="deviceName" />
      <el-table-column label="设备型号" align="center" prop="deviceModel" />
      <el-table-column label="设备类型" align="center" prop="deviceType" />
      <el-table-column label="物联网编号" align="center" prop="iotNo" />
      <el-table-column label="备注" align="center" prop="remarksn" />
    </el-table>

    <el-divider content-position="left">上报时态</el-divider>
    <el-form label-width="170px">
      <el-row class="el-row-table">
          <el-col :span="12">
                <el-form-item :label="fUploadTypeLable" >
                  <span>{{fUploadType}}</span>
                </el-form-item>
          </el-col>

          <el-col :span="12">
              <el-form-item :label="fUploadTimeLabel" >
                <span>{{ fUploadTime }}</span>
              </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item  v-if="this.$store.state.user.roleId == 3" label="企业端上报时间" >
              <span>{{ detailInfo.entUploadTime }}</span>
            </el-form-item>
          </el-col>
      </el-row>
    </el-form>

  </el-dialog>

</template>

<script>
  import { getInforForDetail,selectDetailInfoList } from "@/api/risk/info";
  import { EditorMap } from "@/utils/mapClass/getPath.js";
  import { getDefaultCountyList } from "@/api/area/county";
  import { enterpriseLists } from "@/api/regulation/info";
  export default {
    name: "detail-info",
    data(){
        return{
          relationImg: require('@/assets/project/relation.png'),
          fUploadTypeLable: "",
          fUploadTimeLabel: "",
          enterprises: [],
          countyInfo: [],
          detailInfo: {},
          enterpriseName:"",
          detailOpen: false,
          fUploadType: "",
          fUploadTime: null,
          DetailInfoList: [],
          loadings: true
        }
    },
    watch:{
      detailOpen(newVal){
        if(newVal){
          this.initMap();
        }
      }
    },
    created(){
    },
    methods:{
      //获取县级
      getCountyInfo(){
        getDefaultCountyList().then(res =>{
          if(res.code == 200 && res.data){
          this.countyInfo =  res.data;
        }
      })
      },
      //所属单位
      getEnterpriseLists(){
        const param = {};
          enterpriseLists(param).then(response => {
            this.enterprises = response.rows;
        });
      },
      beyondCountyFormat(row){
        let info = this.countyInfo.find(item => item.fId == row.fRegionId);
        return info?info.fName:"-";
      },
      beyondCompanyFormat(row){
        let info = this.enterprises.find(item => item.enterpriseId == row.fCompanyId);
        return info?info.enterpriseName:"-";
      },
      //根据不同角色显示不同字段
      showUploadType() {
        let roleId = this.$store.state.user.roleId;
        console.log("roleId == 3" + (roleId == 3))
        if (roleId == 3) {
          this.fUploadTypeLable = "上报省厅状态"
          this.fUploadType =  this.detailInfo.govUploadState
        }
        if (roleId == 5) {
          this.fUploadTypeLable = "上报状态"
          this.fUploadType =  this.detailInfo.entUploadState
        }

        if (this.fUploadType == '0') {
          this.fUploadType = "未上传"
        }
        if (this.fUploadType == '1') {
          this.fUploadType = "已上传"
        }
      },
      showUploadTime() {

        let roleId = this.$store.state.user.roleId;
        if (roleId == 3) {
          this.fUploadTime =  this.detailInfo.govUploadTime
          this.fUploadTimeLabel = "上报省厅时间"
        }
        if (roleId == 5) {
          this.fUploadTime =  this.detailInfo.entUploadTime
          this.fUploadTimeLabel = "上报时间"
        }
      },
      getDetailInfo(id){
        getInforForDetail(id).then(res =>{
          if(res.code == 200 && res.data){
            this.detailInfo = res.data;
            this.showUploadType();
            this.showUploadTime();
            this.detailOpen = true;

            // 查询关联设备信息
            var tRiskInfo = {
              id: id,
              relationDeviceType: '4'
            }
            selectDetailInfoList(JSON.stringify(tRiskInfo)).then(response => {
              this.DetailInfoList = response.rows;
              this.loadings = false;
            });
          }
        })
      },
      initMap(){
        this.$nextTick(() => {
          const path = eval(this.$store.state.user.systemSetting.map_center);
          this.gaoMap = new EditorMap("risk-map", {center:path}, this);
          new AMap.Marker({
            map: this.gaoMap.map,
            position: path,
          });
          this.gaoMap.map.setCenter(path)
        })
      },
      destroyed(){
        this.gaoMap.map.destroy();
      },
    }
  }
</script>

<style scoped lang="scss">
  .dbtn {
    display: inline-block;
    line-height: normal;
    padding-left: 2px;
    padding-right: 2px;
    cursor: pointer;
    border-radius: 3px;
    border-style: solid;
    border-width: 0;
    color: rgb(48, 180, 107);
  }
</style>
