<template>
  <div>
    <span @click="showDoubleMonth">
      <el-input v-model="choseQuarter" prefix-icon="el-icon-date" :placeholder="defaultHint?yearFullMonth+'年 '+defaultQuarter:'请选择'" />
    </span>
    <div v-show="showTime1a" class="show1">
      <p>
        <button type="button" aria-label="前一年" class="el-picker-panel__icon-btn el-date-picker__prev-btn el-icon-d-arrow-left"
          @click="prev" />
        <span role="button" class="span-year">{{ year }}年</span>
        <button type="button" aria-label="后一年" class="el-picker-panel__icon-btn el-date-picker__next-btn el-icon-d-arrow-right"
          @click="next" />
      </p>
      <div>
        <span v-for="(item,index) in fullMonth" :key="index" class="selectMonth" @click="selectQuarter(item)">
               {{ item }}
        </span>
      </div>
    </div>
  </div>
</template>

<script>
import moment from "moment";
  export default {
    name: 'season',
    data() {
      return {
        defaultQuarter:'',
        quarterFullMonth:moment().format("Q"),//默认
        yearFullMonth:moment().format("YYYY"),//默认
        value: '',
        showTime2: false,
        showTime1a: false,
        year: new Date().getFullYear(),
        fullMonth: ['第一季度', '第二季度', '第三季度', '第四季度'],
        choseQuarter: '',
        choseQuarter1: ''
      }
    },
    props:{
      isActive:{
        type:Boolean,
        default:false
      },
      defaultHint:{
        type:Boolean,
        default:false
      }
    },
    mounted() {
      if(this.defaultHint){
        this.defaultQuarter =this.quarterFullMonth == '1'?
        '第一季度':this.quarterFullMonth == '2'?
        '第二季度':this.quarterFullMonth == '3'?
        '第三季度':this.quarterFullMonth == '4'?
        '第四季度':''
      }
      
      if(!this.isActive){
        var date=new Date().getMonth()+1;
        var arrs=this.fullMonth;
        var str=""
        if(date<=3){
          str=arrs[0]
        }else if(date<=6){
          str=arrs[1]
        }else if(date<=9){
          str=arrs[2]
        }else{
          str=arrs[3]
        }
        this.selectQuarter(str);
      }
     },
    methods: {
      // 点击季度按钮
      quarterTime() {
        this.showTime2 = true
        this.choseQuarter = ''
        this.fullMonth = ['第一季度', '第二季度', '第三季度', '第四季度']
      },
      // 点击input框
      showDoubleMonth() {
        this.showTime1a = true
      },
      // 上一年
      prev() {
        this.year = this.year * 1 - 1
      },
      // 下一年
      next() {
        this.year = this.year * 1 + 1
      },
      // 点击选项事件
      selectQuarter(item) {
        switch (item) {
          case '第一季度':
            this.choseQuarter1 = this.year + '1'
            this.choseQuarter = this.year + '年 第一季度'
            break
          case '第二季度':
            this.choseQuarter1 = this.year + '2'
            this.choseQuarter = this.year + '年 第二季度'
            break
          case '第三季度':
            this.choseQuarter1 = this.year + '3'
            this.choseQuarter = this.year + '年 第三季度'
            break
          case '第四季度':
            this.choseQuarter1 = this.year + '4'
            this.choseQuarter = this.year + '年 第四季度'
            break
        }
        this.$emit('confirm', this.choseQuarter1)
        this.showTime1a = false
      }
    }
  }
</script>
<style scoped>
  * {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .show1 {
    width: 320px;
    margin-top: 5px;
    position: absolute;
    z-index: 2;
    height: auto;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
    background: #fff;
    padding: 5px;
    padding-right: 20px;
  }

  .show1 p:nth-child(1) {
    width: 100%;
    height: 40px;
    border-bottom: 1px solid #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: end;
    padding: 0 10px;
  }

  .show1>div {
    width: 100%;
    height: auto;
  }

  .show1>div span {
    width: 50%;
  }

  .selectMonth {
    display: inline-block;
    float: left;
    width: 78px;
    height: 40px;
    line-height: 40px;
    text-align: center;
  }

  .selectMonth:hover {
    background: rgba(19, 131, 255, 0.052);
  }

  .span-year {
    width: 90%;
    margin: 0 auto;
    display: inline-block;
    text-align: center;
    line-height: 40px;
  }
</style>
