<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" v-if="detailInfo.fRepStatus == '1'">
              <el-form-item label="企业上报时间">
                <span v-if="detailInfo.entRepTime">{{ detailInfo.entRepTime }}</span>
                <span v-else>-</span>
              </el-form-item>
            </el-col>

            <el-col :span="12" v-if="-2 == $store.state.user.enterpriseId">
              <el-form-item label="政府端上报时间">
                <span v-if="detailInfo.fGovUploadTime">{{ detailInfo.fGovUploadTime }}</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>
          <div>
            <h3>停气操作记录</h3>
            <div class="stop-record">
              <el-table :data="stopLog">
                <el-table-column label="停气进度" align="center" prop="fStopProgress" :formatter="$parent.fStopProgressFormat"/>
                <el-table-column label="操作停气进度时间" align="center" prop="fOprDate" width="150">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.fOprDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                  </template>
                </el-table-column>
              </el-table>
              <pagination
                v-show="total>0"
                :total="total"
                :pageSizes="[5,10, 20, 30, 50]"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getStopLog"
              />
            </div>
          </div>
        </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";
  import { listLog } from "@/api/supplybalance/stopLog.js";
  export default {
    name: "detail-info",
    data(){
        return{
          detailInfo: {},
          detailOpen: false,
          stopLog: [],
          total: 0,
          queryParams: {
            pageNum: 1,
            pageSize: 5,
            fGasStopId: null,
          },
        }
    },
    watch:{
      detailOpen(newVal){
        if(newVal){
          //if(this.detailInfo.fGasStopArea) this.path = JSON.parse(this.detailInfo.fGasStopArea);
          this.$nextTick(() =>{
            this.initMap();
          });
          this.getStopLog();
        }
      }
    },
    methods:{
      getDetailInfo(id){
        this.queryParams.fGasStopId = 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)
        }
      },
      getStopLog(){
        listLog(this.queryParams).then(res =>{
          if(res.code == 200 && res.rows){
            console.log("fdsfd=======",res)
            this.stopLog = res.rows;
            this.total = res.total;
          }
        })
      }
    }
  }
</script>

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

  .stop-record{
    height: 350px;
    overflow-y: scroll;
    &::-webkit-scrollbar {
      /* 设置滚动条宽度 */
      width: 4px;
      /* 设置滚动条背景色 */
      //background: black;
    }

    //滚动条轨道
    &::-webkit-scrollbar-track {
      background-color:transparent;
      -webkit-border-radius: 2em;
      -moz-border-radius: 2em;
      border-radius:2em;
    }

    //滚动条滑块
    &::-webkit-scrollbar-thumb {
      background-color: rgb(147,147,153,0.5);
      -webkit-border-radius: 2em;
      -moz-border-radius: 2em;
      border-radius:2em;
    }
  }

</style>
