<template>
  <div class="energyReport">
    <div class="energContent1">
      <div style="display: flex">
        <el-select v-model="siteValue" placeholder="选择站点">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </div>

      <div class="energSwitch">
        <el-tree
          :data="data"
          show-checkbox
          node-key="id"
          :default-expanded-keys="[2, 3]"
          :props="defaultProps"
        />
      </div>
    </div>
    <div class="energContent2">
      <div class="energDivOne">
        <div class="energHaeder">
          <el-radio-group
            v-model="listTabPosition"
            @change="listTabsChange(listTabPosition)"
            style="display: flex"
          >
            <el-radio-button label="dayValue">日报表</el-radio-button>
            <el-radio-button label="monthValue">月报表</el-radio-button>
            <el-radio-button label="yearValue">年报表</el-radio-button>
          </el-radio-group>
          <div class="energDivTwo">
            <div class="block">
              <span>日期：</span>
              <el-date-picker
                style="width: 150px"
                v-model="value1"
                :type="dateType"
              ></el-date-picker>
            </div>
          </div>
          <div style="margin: 0 15px">
            <el-button
              icon="el-icon-search"
              type="primary"
              style="padding: 7px 12px"
            >
              查询
            </el-button>
          </div>
          <el-radio-group
            v-model="electricTabs"
            @change="listTabsChange(electricTabs)"
            style="display: flex"
          >
            <el-radio-button label="electriQuan">电量</el-radio-button>
            <el-radio-button label="electriFees">电费</el-radio-button>
          </el-radio-group>
        </div>

        <div style="width: 30%">
          <div style="display: flex; float: right; margin-right: 15px">
            <el-checkbox
              v-model="checked"
              label="显示抄表"
              style="margin-right: 20px"
            ></el-checkbox>
            <el-radio-group
              v-model="rightTabs"
              @change="listTabsChange(rightTabs)"
              style="display: flex"
            >
              <el-radio-button label="tables">表格</el-radio-button>
              <el-radio-button label="echarts">图表</el-radio-button>
            </el-radio-group>
          </div>
        </div>
      </div>
      <div class="energEcharts">
        <echarts v-if="rightTabsBool" :Height="Height"></echarts>
        <tables v-if="!rightTabsBool" :Height="Height"></tables>
      </div>
    </div>
  </div>
</template>
<script>
import { defineComponent, ref, reactive, toRefs } from 'vue'
import echarts from './ehcarts/index.vue'
import tables from './tables/index.vue'

export default defineComponent({
  name: 'energyReport',
  components: { echarts, tables },
  props: {},
  setup() {
    let dateType = ref('date')
    let rightTabsBool = ref(true)

    const listTabsChange = (value) => {
      if (
        value == 'dayValue' ||
        value == 'monthValue' ||
        value == 'yearValue'
      ) {
        value == 'dayValue'
          ? (dateType.value = 'date')
          : value == 'monthValue'
          ? (dateType.value = 'month')
          : (dateType.value = 'year')
      } else if (value == 'electriQuan' || value == 'electriFees') {
        console.log()
      } else if (value == 'tables' || value == 'echarts') {
        value == 'echarts'
          ? (rightTabsBool.value = true)
          : (rightTabsBool.value = false)
      }

      console.log(dateType)
    }

    const state = reactive({
      value1: '2021-10-16',
    })

    const Height = ref(0)
    Height.value = window.innerHeight - 210 + 'px'
    window.addEventListener('resize', () => {
      Height.value = window.innerHeight - 210 + 'px'
    })
    return {
      Height,
      ...toRefs(state),
      dateType, //tabs切换时间选择器类型
      listTabPosition: ref('dayValue'), //日月年报表tabs v-model
      electricTabs: ref('electriQuan'), //电量电费tabs v-model
      rightTabs: ref('echarts'), //表格图表tabs v-model
      rightTabsBool, //表格图表 显示隐藏
      siteValue: ref(''), //站点下拉列表v-model
      checked: ref(false),
      data: [
        {
          id: 1,
          label: '设备1',
          children: [
            {
              id: 4,
              label: '母线停电次数',
            },
            {
              id: 4,
              label: '功率因数',
            },
            {
              id: 4,
              label: 'A相功率因数',
            },
          ],
        },
      ],
      options: ref([
        {
          value: 'Option1',
          label: 'Option1',
        },
        {
          value: 'Option2',
          label: 'Option2',
        },
        {
          value: 'Option3',
          label: 'Option3',
        },
        {
          value: 'Option4',
          label: 'Option4',
        },
        {
          value: 'Option5',
          label: 'Option5',
        },
      ]),
      defaultProps: {
        children: 'children',
        label: 'label',
      },

      listTabsChange,
    }
  },
})
</script>

<style lang="scss" scoped>
.energyReport {
  display: flex;
  height: calc(100vh - 130px);
  // padding: 30px;
  // margin-top: 50px;
  .energContent1 {
    background-color: #fff;
    width: 15%;
    height: 100%;
    margin-right: 25px;
    padding: 20px;
    min-width: 200px;
    .energSwitch {
      margin-top: 20px;
      width: 100%;
      height: 20px;
      cursor: pointer;
      .energSwitchOne {
        display: flex;
        border: 0.5px solid silver;
        padding: 8px;
        font-size: 13px;
        div:nth-child(1) {
          width: 100%;
        }
      }
      .energSwitchOne:hover {
        background-color: #409eff;
      }
      .energSwitchOne:focus {
        background-color: #409eff;
      }
    }
  }
  .energContent2 {
    background-color: #fff;
    width: 85%;
    min-width: 845px;
    height: 100%;
    .energDivOne {
      display: flex;
      margin: 15px 0px 15px 15px;
      .energHaeder {
        width: 70%;
        display: flex;
        .energDivTwo {
          font-weight: 600;
          color: #9d9d9d;
          width: 195px;
          margin-left: 20px;
          .block {
            white-space: nowrap;
          }
        }
      }
    }
  }
}

// tab重置样式
.tabsSizeColor > .el-tabs__header .el-tabs__item {
  line-height: 50px;
  height: 50px;
  font-size: 16px;
}

.tabsSizeColor > .el-tabs__header .el-tabs__item.is-active {
  border-bottom: 2px solid #409eff;
  color: #409eff;
}
.el-tabs__header {
  margin-bottom: 0;
}
.el-tabs--card > .el-tabs__header .el-tabs__item,
.el-tabs--card > .el-tabs__header .el-tabs__nav {
  border: none;
}
</style>