ViewControl.vue 5.02 KB
<template>
  <div class="control">
    <div class="left flex user-select pointer">
      <template v-for="(i,index) in tab">
        <div
          :class="['item flex',index == 0?'text-center':'brand',{'active':tabIndex == index}]"
          :key="index"
          @click="change(index)"
        >
          {{i}}
        </div>
      </template>
      <div
        class="options-box"
        :key="brandsKey"
        ref="brands"
      >
        <template v-for="(i,index) in brands">
          <div
            :class="['options-item flex',{'active':i.active}]"
            :key="index"
            @click="chooseBrand({i,index})"
          >{{i.name}}</div>
        </template>
      </div>
    </div>
    <div class="right y-center flex user-select pointer">
      <template v-for="(i,index) in options">
        <div
          :key="index"
          @click="reportChange(index)"
          :class="['item text-center',{'active':reportIndex == index}]"
        >
          {{i}}
        </div>
      </template>
      <div :class="['line',`line-${reportIndex}`]"></div>
    </div>
  </div>
</template>

<script type='text/ecmascript-6'>
let test = [{ name: '东风本田' },
{ name: '别克' },
{ name: '凯迪拉克' },
{ name: 'MINI' },
{ name: '荣威' },
{ name: '上海大众' },
{ name: '沃尔沃' },
{ name: '一汽丰田' },
{ name: '平行进口' },
{ name: '奥迪' },
{ name: '广汽本田' },
{ name: '比亚迪' },
{ name: '奔驰' },]
export default {
  name: 'ViewControl',
  data () {
    return {
      tab: ['广汇集团', '品牌概览'],
      tabIndex: 0,
      options: ['日表', '月表'],
      reportIndex: 1,
      brands: [],
      brandsKey: Date.now()
    }
  },
  mounted () {
    test.map(e => e.active = false)
    this.brands = test
    console.log(this.$store)
  },
  methods: {
    change (index, item) {
      let { tabIndex } = this
      if (index == 0) {
        if (tabIndex == index) return
        this.tab = ['广汇集团', '品牌概览']
      } else {
        if (!item) return
        this.tab[1] = item.name
      }
      this.tabIndex = index
      this.emit()
    },
    reportChange (index) {
      let { reportIndex } = this
      if (reportIndex == index) return
      this.reportIndex = index
      this.emit()
    },
    emit () {
      let { reportIndex, tabIndex, brands } = this
      let params = {
        reportType: reportIndex
      }
      if (tabIndex == 1) brands.map(e => {
        if (e.active) params.brand = e
      })
      this.$store.state.app.reportParams = params
    },
    chooseBrand ({ i, index }) {
      let { brands } = this
      brands.map(e => e.active = false)
      brands[index].active = true
      this.brandsKey = Date.now()
      this.$refs.brands.style.display = 'none'
      this.change(1, i)
    },
  }
}
</script>

<style scoped lang='scss'>
.control {
  position: relative;
  .left {
    width: 280px;
    height: 3.9vh;
    background: #383737;
    border-radius: 4px;
    position: relative;
    .item {
      font-size: 14px;
      color: #eb6001;
      font-weight: 600;
      border-radius: 4px 0px 0px 4px;
    }
    .brand {
      padding-left: 16px;
      border-radius: 0 4px 4px 0;
      &:hover ~ .options-box {
        display: block;
      }
    }
    .active {
      color: #fff;
      background: #eb6001;
    }
    .options-box {
      display: none;
      position: absolute;
      top: 4.1vh;
      right: 0;
      width: 50%;
      height: 30vh;
      background: #383737;
      border: 1px solid rgba(96, 98, 102, 1);
      box-shadow: 0px 3px 2px 1px rgba(0, 0, 0, 0.5);
      border-radius: 4px;
      box-sizing: border-box;
      z-index: 2;
      overflow-y: scroll;
      &:hover {
        display: block;
      }
      .options-item {
        height: 2.9vh;
        font-size: 12px;
        color: #ffffff;
        padding-left: 19px;
        position: relative;
      }
      .active,
      .options-item:hover {
        background: #1e1e1e;
        color: #eb6001;
        &::after {
          position: absolute;
          left: 0;
          top: 0;
          width: 4px;
          height: 100%;
          content: '';
          background-color: #eb6001;
        }
      }
    }
    ::-webkit-scrollbar {
      background-color: #383737;
      width: 6px;
      position: absolute;
    }
    ::-webkit-scrollbar-thumb {
      background: #464646;
      border-radius: 3px;
    }
  }
  .right {
    width: 120px;
    height: 3.4vh;
    background: #383737;
    border-radius: 2px;
    right: -144px;
    .item {
      font-size: 12px;
      color: #e8e8e8;
    }
    .active {
      font-weight: 500;
      font-size: 14px;
      color: #eb6001;
    }
    .line {
      border-radius: 2px;
      background: #eb6001;
      width: 32px;
      height: 0.4vh;
      position: absolute;
      bottom: 0;
      transform: translateX(-50%);
      transition: all 0.25s;
    }
    .line-0 {
      left: 26%;
    }
    .line-1 {
      left: 76%;
    }
  }
  .item {
    width: 50%;
    height: 100%;
    box-sizing: border-box;
    transition: all 0.25s;
    &:hover {
      opacity: 0.9;
    }
  }
}
</style>