element UI选择,季度,半年

<template>
  <div>
    <div>
      <el-button type="primary" size="small" plain @click="quarterTime">季度</el-button>
      <el-button type="primary" size="small" plain @click="halfYear">半年</el-button>
    </div>
    <span @click="showDoubleMonth">
      <el-input
        v-model="choseQuarter"
        prefix-icon="el-icon-date"
        placeholder="请选择"
      />
    </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>
  export default {
    data() {
      return {
        value: '',
        showTime2: false,
        showTime1a: false,
        year: new Date().getFullYear(),
        fullMonth: ['第一季度', '第二季度', '第三季度', '第四季度'],
        choseQuarter: ''
      }
    },
    methods: {
      // 点击季度按钮
      quarterTime() {
        this.showTime2 = true
        this.choseQuarter = ''
        this.fullMonth = ['第一季度', '第二季度', '第三季度', '第四季度']
      },
      // 点击半年按钮
      halfYear() {
        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.choseQuarter = this.year + '-' + 'Q1'
          break
        case '第二季度':
          this.choseQuarter = this.year + '-' + 'Q2'
          break
        case '第三季度':
          this.choseQuarter = this.year + '-' + 'Q3'
          break
        case '第四季度':
          this.choseQuarter = this.year + '-' + 'Q4'
          break
        case '上半年':
          this.choseQuarter = this.year + '-' + 'H1'
          break
        case '下半年':
          this.choseQuarter = this.year + '-' + 'H2'
          break
        }
        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;
  }
  .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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值