<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.fCompanyId">{{ detailInfo.fCompanyId }}</span>
              <span v-else>-</span>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="县级行政区">
              <span v-if="detailInfo.fRegionId">{{ detailInfo.fRegionId }}</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="12">
            <el-form-item label="上传状态" >
              <span>{{fUploadType}}</span> 
            </el-form-item>
          </el-col>

          <el-col :span="12">
              <el-form-item label="上传时间" >
                <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-col :span="24">
            <el-form-item label="经纬度位置"> 
              <div id="risk-map" style="height: 300px"></div>
            </el-form-item>
          </el-col>

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

</template>

<script>
  import { getInfor } from "@/api/risk/info";
  import { EditorMap } from "@/utils/mapClass/getPath.js";
  export default {
    name: "detail-info",
    data(){
        return{
          enterprises: [],
          countyInfo: [],
          detailInfo: {},
          enterpriseName:"",
          detailOpen: false,
          fUploadType: "",
          fUploadTime: null
        }
    },
    watch:{
      detailOpen(newVal){
        if(newVal){
          this.initMap();
        }
      }
    },
    methods:{
      //获取县级
      getCountyInfo(){
        getDefaultCountyList().then(res =>{
          if(res.code == 200 && res.data){
          this.countyInfo =  res.data;
        }
      })
      },
      //所属单位
      getEnterpriseLists(){ 
        queryAllEnterprise().then(response => { 
          this.enterprises = response; 
        }); 
      },
      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.fUploadType =  this.detailInfo.govUploadState
        }
        if (roleId == 5) {
          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
        }
        if (roleId == 5) {
          this.fUploadTime =  this.detailInfo.entUploadTime
        }
      },
      getDetailInfo(id){
        getInfor(id).then(res =>{
          if(res.code == 200 && res.data){
            this.detailInfo = res.data;
            this.showUploadType();
            this.showUploadTime();
            this.detailOpen = true;
          }
        })
      },
      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>
