<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>
    
    <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 } 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{
          fUploadTypeLable: "",
          fUploadTimeLabel: "",
          enterprises: [],
          countyInfo: [],
          detailInfo: {},
          enterpriseName:"",
          detailOpen: false,
          fUploadType: "",
          fUploadTime: null
        }
    },
    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;
          }
        })
      },
      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>
