<template>
  <div class="sameAnalysis">
    <div class="sameContent1">
      <div style="display: flex">
        <el-select
          v-model="store.state.siteId"
          @change="siteChange"
          placeholder="选择站点"
        >
          <el-option
            v-for="item in store.state.siteList"
            :key="item.id"
            :label="item.siteName"
            :value="item.id"
          ></el-option>
        </el-select>
      </div>

      <div class="sameSwitch">
        <el-tree
          ref="tree"
          :data="store.state.deviceList"
          show-checkbox
          node-key="id"
          accordion
          :check-strictly="true"
          :props="defaultProps"
          @check="currentChecked"
        />
      </div>
    </div>
    <div class="sameContent2">
      <div class="sameDivOne">
        <div class="sameDivTwo">
          <div class="block">
            <span class="demonstration">选择时间范围：</span>
            <el-date-picker
              v-model="value1"
              type="datetimerange"
              range-separator="➥"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
            ></el-date-picker>
          </div>
        </div>
        <el-radio-group
          v-model="listTabPosition"
          @change="listTabsChange(listTabPosition)"
          style="display: flex"
        >
          <el-radio-button label="allValue">所有值</el-radio-button>
          <el-radio-button label="dailyValue">每日值</el-radio-button>
          <el-radio-button label="monthValue">每月值</el-radio-button>

          <div style="margin-left: 10px">
            <el-button
              icon="el-icon-search"
              type="primary"
              style="padding: 7px 12px"
              @click="select()"
            >
              查询
            </el-button>
          </div>
        </el-radio-group>
      </div>
      <div class="sameEcharts">
        <echarts></echarts>
      </div>
    </div>
  </div>
</template>
<script>
import { useStore } from 'vuex'
import { defineComponent, ref, reactive, toRefs } from 'vue'
import echarts from './ehcarts/index.vue'
import { ElNotification } from 'element-plus'

export default defineComponent({
  name: 'sameAnalysis',
  components: { echarts },
  props: {},
  setup() {
    const store = useStore()
    const listTabPosition = ref('allValue') //tabs切换
    const treeCheckedList = ref([])
    const treeData = ref([])
    const tree = ref(null)

    const listTabsChange = (value) => {
      console.log(value)
      select()
    }

    const currentChecked = (nodeObj, SelectedObj) => {
      console.log(nodeObj, SelectedObj)
      if (treeCheckedList.value.length <= 0) {
        treeCheckedList.value = SelectedObj.checkedNodes[0]
      } else {
        console.log('')
      }
      // 'userXM' in data
      tree.value.getCurrentNode(SelectedObj.checkedNodes[0])
      treeCheckedList.value = SelectedObj.checkedKeys
    }

    function select() {
      console.log(treeCheckedList.value)
      if (treeCheckedList.value.length > 0) {
        console.log('', store.state.deviceList)
      } else {
        console.log('', 1)
        ElNotification({
          title: '提示',
          message: '请选择测点',
          type: 'warning',
        })
      }
    }

    //通过站点切换下拉框 change事件改变 tree树中的数据
    const siteChange = () => {
      store.commit('publicDeviceList')
    }
    const state = reactive({
      value1: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
    })
    return {
      store,
      ...toRefs(state),
      listTabPosition,
      tree,
      treeData,
      defaultProps: {
        children: 'children',
        label: 'deviceName',
        deviceCode: 'deviceCode',
        id: 'id',
      },

      select,
      currentChecked,
      siteChange,
      listTabsChange,
    }
  },
})
</script>

<style lang="scss" scoped>
.sameAnalysis {
  display: flex;
  height: calc(100vh - 130px);
  // padding: 30px;
  // margin-top: 50px;
  .sameContent1 {
    background-color: #fff;
    width: 15%;
    height: 100%;
    margin-right: 25px;
    padding: 20px;
    min-width: 200px;
    .sameSwitch {
      margin-top: 20px;
      width: 100%;
      height: 20px;
      cursor: pointer;
      .sameSwitchOne {
        display: flex;
        border: 0.5px solid silver;
        padding: 8px;
        font-size: 13px;
        div:nth-child(1) {
          width: 100%;
        }
      }
      .sameSwitchOne:hover {
        background-color: #409eff;
      }
      .sameSwitchOne:focus {
        background-color: #409eff;
      }
    }
  }
  .sameContent2 {
    background-color: #fff;
    width: 85%;
    min-width: 845px;
    height: 100%;
    .sameDivOne {
      display: flex;
      margin: 15px 0px 15px 15px;
      .sameDivTwo {
        font-weight: 600;
        color: #9d9d9d;
        margin-right: 20px;
      }
    }
  }
}
</style>

<style lang="less">
.sameSwitch {
  .el-tree-node__content .el-checkbox__input {
    display: none;
  }
  .el-tree-node
    .el-tree-node__children
    .el-tree-node__content
    .el-checkbox__input {
    display: block;
  }
}
</style>