ViewControl.vue 5.97 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)"
        >
          <div class="text text-hide">
            {{i}}
          </div>
          <template v-if="index == 1">
            <div class="arrow"></div>
          </template>
        </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})"
          >
            <div class="text-hide">{{i.brandName}}</div>
          </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'>
export default {
  name: 'ViewControl',
  data () {
    return {
      tab: ['广汇集团', '品牌概览'],
      tabIndex: 0,
      options: ['日表', '月表'],
      reportIndex: 1,
      brands: [],
      brandsKey: Date.now()
    }
  },
  mounted () {
    this.api.common.getBrandList().then(({ code, data }) => {
      let brands = []
      if (code == 0) {
        data.dataList.map(e => {
          brands.push({
            brandName: e,
            active: false
          })
        })
      }
      this.brands = brands
    })
  },
  methods: {
    change (index, item) {
      let { tabIndex } = this
      if (index == 0) {
        if (tabIndex == index) return
        this.tab = ['广汇集团', '品牌概览']
        this.brands.map(e => e.active = false)
      } else {
        if (!item) return
        this.tab[1] = item.brandName
      }
      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 == 0 ? 1 : 0 //月表0,日表1
      }
      if (tabIndex == 1) brands.map(e => {
        if (e.active) params.brand = {
          name: e.brandName
        }
      })
      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: 0 16px;
      border-radius: 0 4px 4px 0;
      .text {
        width: calc(100% - 20px);
      }
      &:hover ~ .options-box {
        display: block;
      }
      .arrow {
        position: relative;
        top: 4.5px;
        border-top: 4.5px solid #eb6001;
        border-right: 4.5px solid transparent;
        border-bottom: 4.5px solid transparent;
        border-left: 4.5px solid transparent;
        margin-left: auto;
        transition: all 0.25s;
      }
      &:hover {
        .arrow {
          transform: rotate(-180deg);
          top: 0;
        }
      }
    }
    .active {
      color: #fff;
      background: #eb6001;
      .arrow {
        border-top-color: #fff;
        transform: rotate(-180deg);
        top: 0;
      }
    }
    .options-box {
      display: none;
      position: absolute;
      top: 4.1vh;
      right: 0;
      width: 50%;
      max-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;
      }
      &:hover .brand {
        background-color: #096;
      }
      .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;
        }
      }
      .active{
        position: sticky;
        top: 0;
        z-index: 2;
        left: 0;
      }
    }
    ::-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.75;
    }
  }
}
</style>