<template>
  <div class="title">
    <div class="text">
      <div class="big-title">
        <slot name="h1"></slot>
      </div>
      <div class="small-text">
        <slot name="span"></slot>
      </div>
    </div>
    <div class="year" v-if="isShow">
      <span>{{ showYear }}</span>
      <div class="btn">
        <span
          :class="index == item.id ? 'active' : ''"
          v-for="item in data"
          :key="item.id"
          @click="handleYearClick(item)"
        >
          {{ item.name }}
        </span>
      </div>
    </div>
    <div class="year" v-else-if="isShowYear_">
      <span>2021</span>
      <div class="btn">
        <span class="active">
          年
        </span>
      </div>
    </div>
    <!-- <div class="line"></div> -->
  </div>
</template>
<script>
export default {
  props: {
    show: Boolean,
    value: String,
    isShowYear: Boolean,
    year: String,
    yearMouth: String,
  },
  data() {
    return {
      data: [
        {
          id: 1,
          name: '月'
        },
        {
          id: 2,
          name: '年'
        }
      ],
      index: 2,
      isShow: this.show,
      isShowYear_: this.isShowYear,
      showYear:''
    }
  },
  watch: {
    value(newValue) {
      this.value = newValue
    },
    yearMouth(newValue) {
      this.showYear = newValue;
      // console.log(newValue, 'rrrrrrrrrrrrrrrrrr')
    }
  },
  created() {
    this.showYear = new Date().getFullYear(); //获取完整的年份(4位)
  },
  methods: {
    handleYearClick(data) {
      this.index = data.id
      if (data.id == 2) {
        this.showYear = this.yearMouth.slice(0,4);
      }else{
        this.showYear = this.yearMouth
      }
      console.log(this.showYear, "this.showYear");
      // 模块，时间，年/年月
      this.$emit('BizChange', this.value, this.showYear, data.id)
    }
  }
}
</script>
<style lang="scss" scoped>
.title {
  width: 100%;
  height: 4vh;
  pointer-events: auto;
  image-rendering: -webkit-optimize-contrast;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  // background-image: url('../images/backgroundColor.png');
  background: linear-gradient(90deg,#3a596e,#002352);
  border-radius: 0px;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  // border-radius: 6px;
  .text {
    overflow: unset;
    text-overflow: unset;
    white-space: unset;
    color: rgb(255, 255, 255);
    background-image: none;
    background-clip: unset;
    display: flex;
    align-items: center;
    .big-title {
      margin-left: 1rem;
      div {
        font-weight: normal;
        font-family: 'Microsoft Yahei', Arial, sans-serif;
        font-size: 1.5vh;
        writing-mode: horizontal-tb;
        letter-spacing: 0px;
      }
    }
    .small-text {
      margin-left: 10px;
      div {
        color: rgba(255, 255, 255, 0.6);
        font-size: 10px;
        font-weight: normal;
        font-family: 'Microsoft Yahei', Arial, sans-serif;
        writing-mode: horizontal-tb;
        letter-spacing: 0px;
      }
    }
  }
  .year {
    margin-right: 30px;
    display: flex;
    align-content: center;
    z-index: 999;
    span {
      font-weight: normal;
      font-family: 'Microsoft Yahei', Arial, sans-serif;
      font-size: 0.8vh;
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .btn {
      margin-left: 10px;
      display: flex;
      align-items: center;
      border: 1px solid #086383;
      .active {
        background: #009bff;
      }
      span {
        width: 3vh;
        height: 3vh;
        padding: 0 5px;
        display: flex;
        align-items: center;
        justify-content: center;
        &:hover {
          background: #02629c;
        }
      }
    }
  }
  .line {
    width: 100%;
    height: 100%;
    opacity: 1;
    background-image: url('../images/lineAnamiton.gif');
    background-size: 100%;
    background-repeat: no-repeat;
    background-position: center center;
    position: absolute;
    top: 17px;
    left: -46px;
  }
}
</style>
