TabCustomer.vue 2.17 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', `${tabIndex == index ? 'active-' + index : ''}`]" :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', `${tabIndex == index ? 'active' : ''}`]" :key="index + 'i'">{{ i }}</div>
      </template>
    </div>
    <slot></slot>
  </div>
</template>

<script>
export default {
  name: 'TabCustomer',
  props: {
    index: {
      type: Number,
      default: 0
    },
    list: {
      type: Array,
      default: () => {
        return []
      }
    }
  },

  data() {
    return {
      data: this.list,
      tabIndex: this.index
    }
  },

  watch: {
    index(n) {
      this.tabIndex = n
    },
    list: {
      handler(n) {
        this.data = n
      },
      immediate: true,
      deep:true
    }
  },
  mounted() {},
  methods: {
    click(index) {
      this.$emit('change', index)
    }
  }
}
</script>

<style scoped lang='scss'>
.tab {
  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: #EBEFF5;
    .item {
      width: 50%;
      // transition: all 0.5s;
      font-size: 14px;
    }
    .active-0 {
      height: 0;
      border-bottom: 50px solid #ffffff;
      border-right: 10px solid transparent;
    }
    .active-1 {
      height: 0;
      border-bottom: 50px solid #ffffff;
      border-left: 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>