<template>
  <el-dialog title="详情" :visible.sync="detailOpen" width="1200px" append-to-body destroy-on-close :close-on-click-modal="false">

    <el-form label-width="120px">
      <el-row>
        <el-col :span="12">
          <el-row class="el-row-table">
            <el-col :span="12">
              <el-form-item label="停气开始日期">
                <span v-if="detailInfo.fStartDate">{{ detailInfo.fStartDate }}</span>
                <span v-else>-</span>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="停气结束日期">
                <span v-if="detailInfo.fEndDate">{{ detailInfo.fEndDate }}</span>
                <span v-else>-</span>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="停气类型">
                <span v-if="detailInfo.fStopType">{{ $parent.fStopTypeFormat(detailInfo) }}</span>
                <span v-else>-</span>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="停气进度">
                <span v-if="detailInfo.fStopType">{{ $parent.fStopProgressFormat(detailInfo) }}</span>
                <span v-else>-</span>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="影响用户">
                <span v-if="detailInfo.fInfluenceCus">{{ detailInfo.fInfluenceCus }}</span>
                <span v-else>-</span>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="停气原因">
                <span v-if="detailInfo.fStopReason">{{ detailInfo.fStopReason }}</span>
                <span v-else>-</span>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="停气范围">
                <span v-if="detailInfo.fStopRange">{{ detailInfo.fStopRange }}</span>
                <span v-else>-</span>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="创建时间">
                <span v-if="detailInfo.createTime">{{ detailInfo.createTime }}</span>
                <span v-else>-</span>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="更新时间">
                <span v-if="detailInfo.updateTime">{{ detailInfo.updateTime }}</span>
                <span v-else>-</span>
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>

        <el-col :span="12" style="padding-left: 10px">
          <div style="font-size: 14px;color: #606266;margin-bottom: 10px;font-weight: 700">停气区域</div>
          <div id="areaInfo"></div>
        </el-col>
      </el-row>

    </el-form>

  </el-dialog>

</template>

<script>
  import { getSup } from "@/api/supplybalance/stop";
  import { EditorMap } from "@/utils/mapClass/getPath.js";
  export default {
    name: "detail-info",
    data(){
        return{
          detailInfo: {},
          detailOpen: false,
        }
    },
    watch:{
      detailOpen(newVal){
        if(newVal){
          //if(this.detailInfo.fGasStopArea) this.path = JSON.parse(this.detailInfo.fGasStopArea);
          this.$nextTick(() =>{
            this.initMap();
          })
        }
      }
    },
    methods:{
      getDetailInfo(id){
        getSup(id).then(res =>{
          if(res.code == 200 && res.data){
            this.detailInfo = res.data;
            this.detailOpen = true;
          }
        })
      },
      initMap(){
        const path = eval(this.$store.state.user.systemSetting.map_center);
        const gaoMap = new EditorMap("areaInfo", {center:path}, this);
        if(this.detailInfo.fGasStopArea){
          if (this.detailInfo.fGasStopArea.includes("#")){
            let areas = this.detailInfo.fGasStopArea.split("#");
            for (let i = 0; i < areas.length;i++) { 
                let areasItem = areas[i]; 
                if (areasItem != null && areasItem != "") {   
                    new AMap.Polygon({
                      map: gaoMap.map,
                      path: JSON.parse(areasItem),
                      fillColor:'#00b0ff',
                      strokeColor:'#80d8ff'
                    }); 
                }
            }

          } else {
            new AMap.Polygon({
            map: gaoMap.map,
            path: JSON.parse(this.detailInfo.fGasStopArea),
            fillColor:'#00b0ff',
            strokeColor:'#80d8ff'
          });
          gaoMap.setCenter(JSON.parse(this.detailInfo.fGasStopArea)[0]);
          }
          gaoMap.map.setZoom(12)
        }
      }
    }
  }
</script>

<style scoped lang="scss">
  #areaInfo{
    width: 100%;
    height: 500px;
  }

</style>
