<template>
  <el-container class="content-height-fit">
    <inner-sidebar>
      <project-section-device-tree device-type="1" @node-click="handleTreeClick" />
    </inner-sidebar>
    <list v-if="showDataList" ref="list" :query="listQuery" @viewData="viewData" />
    <gride-work-info v-else ref="grideWorkInfo" :query="query" />
  </el-container>
</template>

<script>
import ProjectSectionDeviceTree from '@/views/projects/components/ProjectSectionDeviceTree'
import list from './list.vue'
import grideWorkInfo from '../gride-work-info/index.vue'
import InnerSidebar from '@/components/InnerSidebar'

export default {
  name: 'ProjectMeasureMng',
  components: { ProjectSectionDeviceTree, list, grideWorkInfo, InnerSidebar },
  data() {
    return {
      list: [],
      listQuery: {
        deviceType: 1,
        projectId: undefined,
        projectName: '',
        sectionId: undefined,
        sectionName: '',
        deviceId: undefined,
        skipCount: 0,
        maxResultCount: 20,
        isOnline: undefined
      },
      query: {
        deviceId: undefined,
        sectionName: undefined
      },
      showDataList: true
    }
  },
  computed: {
  },
  watch: {
  },
  mounted() {
    //  this.$refs.dataList.queryDataList()  父组件调用子组件的方法
  },
  created() {

  },
  methods: {
    viewData(val) {
      if (val) {
        this.query.deviceId = val.id
        this.query.sectionName = this.listQuery.sectionName
        this.showDataList = false
      }
    },
    // 点击项目
    handleTreeClick(data, node) {
      var that = this
      if (data.isProject) {
        that.listQuery.projectId = data.id
        that.listQuery.projectName = data.name
        that.listQuery.sectionId = undefined
        that.showDataList = true
      }
      if (data.isSection) {
        that.listQuery.projectId = data.projectId
        that.listQuery.projectName = data.projectName
        that.listQuery.sectionId = data.id
        that.listQuery.sectionName = data.name
        that.showDataList = true

        that.query.sectionName = data.name
      }
      if (data.isDevice) {
        that.showDataList = false
        that.listQuery.projectId = data.projectId
        that.listQuery.projectName = node.parent.data.projectName
        that.listQuery.sectionId = data.sectionId
        that.listQuery.sectionName = node.parent.data.name
        that.listQuery.deviceId = data.id

        that.query.deviceId = data.id
        that.query.sectionName = node.parent.data.name
      }
    }
  }
}
</script>

<style scoped>
</style>
