<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>
          <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-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="fUploadTimeLable" >
                <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.entRepTime }}</span>
            </el-form-item>
          </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,
          fUploadType: "",
          fUploadTime: null,
          fUploadTimeLable: "",
          fUploadTypeLable: "",
          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:{
      //根据不同角色显示不同字段
      showUploadType() {
        let roleId = this.$store.state.user.roleId;
        if (roleId == 3) {
          this.fUploadType =  this.detailInfo.fGovUploadStatus
          this.fUploadTypeLable = "上报省厅状态"
        }
        if (roleId == 5) {
          this.fUploadType =  this.detailInfo.fRepStatus
          this.fUploadTypeLable = "上报状态"
        }

        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.fGovUploadTime
          this.fUploadTimeLable = "上报省厅时间"
        }
        if (roleId == 5) {
          this.fUploadTime =  this.detailInfo.entRepTime
          this.fUploadTimeLable = "上报时间"
        }
      },
      getDetailInfo(id){
        this.queryParams.fGasStopId = id;
        getSup(id).then(res =>{
          if(res.code == 200 && res.data){
            this.detailInfo = res.data;
            this.showUploadType();
            this.showUploadTime();
            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>