<template>
  <div style="height: 100%; width: 100%">
    <index-e-chats ref="indexChart" v-if="ltdShow" :jhProp="jh" @goZjy="goZjy" :zjy="zjy" :serchTime="serchTime" />
    <index-e-chats-jwss ref="indexChartJwss" v-else-if="jwssShow" :jhProp="jh" @goZjy="goZjy" :zjy="zjy" />

    <zjy-echarts ref="zjyChart" v-else :jhProp="jh" @goLtd="goLtd" :ltd="ltd" :serchTime="serchTime" />
  </div>
</template>
<script>
import storage from 'store'
import zjyEcharts from '@/views/part1/zjyEcharts'
import IndexEChats from '@/views/part1/IndexEChats2'
import IndexEChatsJwss from '@/views/part1/IndexEChatsJwss'
import events from '@/views/top/events'
import { TOP_WELL_CHOOSEN } from '@/store/mutation-types'
export default {
  name: 'index',
  components: {
    zjyEcharts,
    IndexEChats,
    IndexEChatsJwss
  },
  data() {
    return {
      ltd: 1,
      zjy: 0,
      jh: '车古271',
      ltdShow: false,
      jwssShow: false,
      serchTime: ''
    }
  },
  created() {
    const record = storage.get(TOP_WELL_CHOOSEN)
    if (record) {
      this.jh = record.JH
      this.ltd = record.ltd
      this.zjy = record.zjy
      if (record.ltd == 1) {
        if (process.env.VUE_APP_JWSS === 'TRUE') {
          this.jwssShow = true
        } else {
          this.ltdShow = true
        }

      } else if (record.zjy == 1) {
        this.ltdShow = false
        this.jwssShow = false
      }
    }
  },
  mounted() {
    let query = this.$route.query
    if (query.jh) {
      this.jh = query.jh;
    }
    if (query.serchTime && query.jh) {
      this.jh = query.jh + ',' + query.serchTime
      this.serchTime = query.serchTime
    }
    if (query.gcyj) {
      this.jh = this.jh + ',' + "gcyj"
    }
    console.log(this.jh);

    events.$on('jhSelected', (val) => {
      console.log('工程预警数据', val)
      if (val.serchTime) {
        this.jh = val.jh + ',' + val.serchTime
      } else {
        this.jh = val.jh
      }

      if (val.gcyj === 1 && val.serchTime) {
        this.jh = this.jh + ',' + "gcyj"
      }

      this.ltd = val.record.ltd
      this.zjy = val.record.zjy
      this.serchTime = val.serchTime
      if (val.record.ltd == 1) {
        if (process.env.VUE_APP_JWSS === 'TRUE') {
          this.jwssShow = true
        } else {
          this.ltdShow = true
        }
      } else if (val.record.zjy == 1) {
        this.ltdShow = false
        this.jwssShow = false
      } else {
        this.ltdShow = true
      }
    })
  },
  methods: {
    chartResize() {
      if (this.ltdShow) {
        this.$refs.indexChart.chartResize()
      } else if (this.jwssShow) {
        this.$refs.indexChartJwss.chartResize()
      }
      else {
        this.$refs.zjyChart.chartResize()
      }
    },
    goLtd() {
      this.fromZjy = 'Y'
      if (this.ltd == 1) {
        if (process.env.VUE_APP_JWSS === 'TRUE') {
          this.jwssShow = true
        } else {
          this.ltdShow = true
        }
      } else {
        this.$message.warning('没有录井仪数据!')
      }
    },
    goZjy() {
      if (this.zjy == 1) {
        this.ltdShow = false
        this.jwssShow = false
      } else {
        this.$message.warning('没有钻井液数据!')
      }
    }
  }
}
</script>
