<template>
  <el-dialog
    :visible="visible"
    :append-to-body="false"
    :close-on-press-escape="true"
    :show-close="false"
    destroy-on-close
    width="100%"
    custom-class="data-modal"
    @close="closeModal"
  >
    <div style="display: flex;height: 100%;overflow: hidden;padding: 8px">
      <div style="height: 100%;display: flex;flex-direction: column;width: 514px;">
        <data-box type="workshop" :title-name="$store.state.company.workshop" style="flex: 1;">
          <realtime-table ref="realtimeTable"/>
        </data-box>
        <data-box type="warn" title-name="报警信息" style="margin-top: 8px;height: 370px;">
          <data-modal-warn ref="dataModalWarn"/>
        </data-box>
      </div>
      <div style="flex: 1;margin-left: 8px;">
        <data-box type="realtime" title-name="实时数据">
          <realtime-line v-if="visible" ref="realtimeLine"/>
        </data-box>
      </div>
      <div style="width: 350px;margin-left: 8px;">
        <data-box type="analysis" title-name="设备运行分析">
          <device-analysis ref="deviceAnalysis"/>
        </data-box>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import DataBox from '@/components/DataModal/common/DataBox'
import JgChart from '@/components/JgChart'
import RealtimeTable from '@/components/DataModal/common/RealtimeTable'
import RealtimeLine from '@/components/DataModal/common/RealtimeLine'
import DeviceAnalysis from '@/components/DataModal/common/DeviceAnalysis'
import DataModalWarn from '@/components/DataModal/common/DataModalWarn'

export default {
  name: 'DataModal',
  components: { DataModalWarn, DeviceAnalysis, RealtimeTable, JgChart, DataBox, RealtimeLine },
  data() {
    return {
      visible: false,
    }
  },
  methods: {
    showModal() {
      this.visible = true
      this.fetchData()
    },
    closeModal() {
      this.visible = false
      this.$emit('closeModal')
    },
    fetchData() {
      this.$nextTick(() => {
        this.$refs.realtimeTable.getTableData()
        this.$refs.realtimeLine.initData()
        this.$refs.deviceAnalysis.getCollectEntity()
      })
    },
  },
}
</script>

<style lang="less" scoped>
  /deep/ .data-modal {
    height: 100%;
    background: #ebebeb !important;
    display: flex;
    flex-direction: column;

    .el-dialog__header {
      background-color: #04091f;
      user-select: none;
      padding: 0;
    }

    .el-dialog__body {
      flex: 1;
      padding: 0;
      color: #fff;
      font-size: 14px;
      word-break: break-all;
      background-color: #04091f;
      display: flex;
      flex-direction: column;
    }
  }

</style>
