CanvasTab.vue 4.96 KB
<template>
  <div class="tab" v-if="data.length > 0">
    <!-- 样式占位符-->
    <div class="canvas-tab flex">
      <template v-for="(i, index) in data">
        <div @click="click(index)" :class="['item', `${tabType.index == index ? 'active-' + i.location : 'unactive'}`]" :key="index"></div>
      </template>
    </div>
    <div class="canvas-place-tab flex placeholder">
      <template v-for="(i, index) in data">
        <div @click="click(index)" :class="['item', 'text-center', `${tabType.index == index ? 'active' : ''}`]" :key="index + 'i'">{{ i.title }}</div>
      </template>
    </div>
    <slot></slot>
  </div>
</template>

<script type='text/ecmascript-6'>
import { mapState, mapMutations } from 'vuex'
export default {
  name: 'CanvasTab',
  watch: {
    tabIndex: {
      handler() {
        this.initTextData()
      },
      immediate: true
    },
    outputData: {
      handler() {
        this.initTextData()
      },
      deep: true,
      immediate: true
    }
  },
  computed: {
    ...mapState({
      reportData: state => state.report.reportData,
      tabIndex: state => state.report.tabIndex,
      reportType: state => state.report.reportType,
      tabType: state => state.report.tabType,
      userInfo: state => state.report.userInfo,
      outputData: state => state.report.outputData
    })
  },
  data() {
    return {
      data: [],
      text: ''
    }
  },
  mounted() {},
  methods: {
    ...mapMutations({
      SET_TABTYPE_INDEX: 'report/SET_TABTYPE_INDEX'
    }),
    initTextData() {
      let { reportType, outputData } = this
      if (reportType == 0) {
        this.text = '本周'
      } else {
        let time = outputData.reportTimeStart.split('-')
        if (parseInt(time[1]) > 9) {
          this.text = time[1] + '月'
        } else {
          this.text = time[1] && time[1].split('')[1] + '月'
        }
      }
      this.initData()
    },
    initData() {
      let {
        userInfo: { accountLevel },
        reportType,
        text,
        tabIndex
      } = this
      if (accountLevel !== 4 && tabIndex == 0) {
        //集团客户周月报
        if (reportType == 0) {
          this.data = [
            { title: '企微客户占比', location: 'left' },
            { title: '新增企微客户数 ', location: 'right' }
          ]
        } else {
          this.data = [
            { title: '企微客户占比', location: 'left' },
            { title: '新增企微客户数 ', location: 'center' },
            { title: '新增客户趋势', location: 'right' }
          ]
        }
      } else if (accountLevel == 4 && tabIndex == 0) {
        //门店客户周月报
        if (reportType == 1) {
          this.data = [
            { title: '新增客户趋势', location: 'left' },
            { title: '新增客户分布', location: 'right' }
          ]
        } else {
          this.data = []
        }
      } else if (accountLevel !== 4 && tabIndex == 1) {
        //集团产值周月报
        if (reportType == 0) {
          this.data = [
            { title: `${text}门店产值排行`, location: 'left' },
            { title: '新增产值分布', location: 'right' }
          ]
        } else {
          this.data = [
            { title: `${text}门店产值`, location: 'left' },
            { title: '新增产值分布', location: 'center' },
            { title: '新增产值趋势', location: 'right' }
          ]
        }
      } else {
        //门店产值月报
        if (reportType == 1) {
          this.data = [
            { title: '新增产值趋势', location: 'left' },
            { title: '新增产值分布', location: 'right' }
          ]
        } else {
          this.data = []
        }
      }
    },
    click(index) {
  
      this.$emit('change', index)
    }
  }
}
</script>

<style scoped lang='scss'>
.tab {
  margin: 30px 0 80px 0;
  height: auto;
  box-shadow: 0px 3px 10px 0px rgba(223, 228, 234, 0.81);
  border-radius: 4px;
  position: relative;
  background-color: #fff;
  .canvas-tab {
    width: 100%;
    height: 50px;
    box-sizing: border-box;
    background-color: #dfe7f1;
    .item {
      width: 50%;
      // transition: all 0.5s;
      font-size: 14px;
    }
    .active-left {
      height: 0;
      border-bottom: 50px solid #ffffff;
      border-right: 10px solid transparent;
    }
    .active-right {
      height: 0;
      border-bottom: 50px solid #ffffff;
      border-left: 10px solid transparent;
    }
    .active-center {
      height: 0;
      border-bottom: 50px solid #ffffff;
      border-left: 10px solid transparent;
      border-right: 10px solid transparent;
    }
  }
  .canvas-place-tab {
    width: 100%;
    height: 50px;
    box-sizing: border-box;
    font-size: 12px;
    color: #333333;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    z-index: 9;
    .item {
      color: #333333;
      flex: 1;
      // transition: all 0.5s;
      font-size: 14px;
    }
    .active {
      color: #3975c6;
      height: 50px;
    }
  }
}
</style>