lineHeader.vue 1.79 KB
<template>
  <div class="header">
    <div>{{ title }}趋势</div>
    <div class="times">
      <div
        :class="{
          time: true,
          active: index === activeIndex
        }"
        v-for="(item, index) in timeopts"
        :key="index"
        @click="handleClick(index)"
      >
        {{ item.label }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeIndex: 0,
      timeopts: [
        { label: "近7日", value: 1 },
        { label: "本月", value: 2 },
        { label: "上月", value: 3 },
        { label: "近30日", value: 4 }
      ]
    }
  },
  props: {
    title: {
      type: String,
      default: "评估量趋势"
    }
  },
  methods: {
    handleClick(index) {
      if (this.activeIndex != index) {
        this.activeIndex = index
        let data = this.timeopts[index]
        this.$emit("handleClick", data, this.activeIndex, index)
      }
    }
  }
}
</script>

<style scoped lang="scss">
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  .times {
    display: flex;
    align-items: center;
    border: 1px solid #dbdbdb;
    border-radius: 2px;
    box-sizing: border-box;
    .time {
      padding: 7.5px 18px;
      line-height: 17px;
      cursor: pointer;
      color: #1d1d1d;
      font-size: 12px;
      font-weight: 400;
      border-right: 1px solid #dbdbdb;
      box-sizing: border-box;
    }
    .active {
      color: #ffffff;
      background: #2a58ad;
      &:first-child {
        border-top-left-radius: 2px;
        border-bottom-left-radius: 2px;
      }

      &:last-child {
        border-right: none;
        border-top-right-radius: 2px;
        border-bottom-right-radius: 2px;
      }
    }
    .time:last-child {
      border-right: none;
    }
  }
}
</style>