elementUI 季度选择组件

代码组件:

<template>
  <div>
    <div
      class="mask-wrapper"
      v-show="showSeason"
      @click.stop="showSeason = false"
    ></div>
    <el-popover placement="bottom" popper-class="quarter-popover-custom" trigger="manual" v-model="showSeason">
      
      <div class="season-picker-box">
        <div class="el-date-picker__header el-date-picker__header--bordered">
          <i
            aria-label="前一年"
            class="el-picker-panel__icon-btn el-date-picker__prev-btn el-icon-d-arrow-left"
            @click="prev"
          />
          <span role="button" class="el-date-picker__header-label" >{{ year }}年</span>
          <i
            aria-label="后一年"
            @click="next"
            class="el-picker-panel__icon-btn el-date-picker__next-btn el-icon-d-arrow-right"
          />
        </div>

        <div class="el-picker-panel__content">
          <table class="el-month-table">
            <tr>
              <td :class="{'today': current === 1}">
                <div>
                  <a class="cell" @click="selectSeason(1)">一季度</a>
                </div>
              </td>
              <td :class="{'today': current === 2}">
                <div>
                  <a class="cell" @click="selectSeason(2)">二季度</a>
                </div>
              </td>
            </tr>
            <tr>
              <td :class="{'today': current === 3}">
                <div>
                  <a class="cell" @click="selectSeason(3)">三季度</a>
                </div>
              </td>
              <td :class="{'today': current === 4}">
                <div>
                  <a class="cell" @click="selectSeason(4)">四季度</a>
                </div>
              </td>
            </tr>
          </table>
        </div>
      </div>

      <el-input
        slot="reference"
        placeholder="请选择季度"
        v-model="strValue"
        style="width: 2.75rem"
        prefix-icon="el-icon-date"
        @focus="showSeason = true"
      />
    </el-popover>
  </div>
</template>

<script>
export default {
  model: {
    prop: 'quarterValue',
    event: 'quarterChange'
  },
  props: {
    quarterValue: ''
  },

  data() {
    return {
      showSeason: false,
      year: new Date().getFullYear(),
      strValue: '',
      current: ''
    };
  },

  watch: {
    showSeason(val) {
      if (val) {
        this.current = this.quarterValue ? Number(this.quarterValue.split('-')[1]) : ''
      }
    }
  },

  methods: {

    prev() {
      this.year = this.year * 1 - 1;
    },

    next() {
      this.year = this.year * 1 + 1;
    },

    selectSeason(i) {
      this.season = `${this.year}-${i}`;
      console.log(this.season, 'season')
      this.$emit('quarterChange', this.season)
      this.showSeason = false;
      const cnNum = ['一', '二', '三', '四']
      this.strValue = `${this.year}年${cnNum[i-1]}季度`;
    }
  },
};
</script>

<style lang="scss">
.quarter-popover-custom {
  padding: 0;
  width: 3rem !important;
}
</style>

<style lang="scss" scoped>
@import '~@/styles/variables.scss';

.mask-wrapper {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0);
  z-index: 999;
}

.season-picker-box {
  margin-bottom: 0;
  border-bottom: 1px solid #ebeef5;
  .el-month-table {
    width: 100%;
  }
  .el-month-table td .cell {
    width: 80px;
  }
}

.box-card {
  width: 240px;
  padding: 0 3px;
  margin-top: 10px;
  position: fixed;
  z-index: 9999;

  .item {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .el-button {
      width: 80px;
      margin: 5px;
      color: #606266;
      &:hover {
        color: $themeColor;
      }
    }
  }
}
</style>

运用:

 <quarter-picker v-model="quarterValueStart" />

 结果:

说明:

运用父子组件双向绑定的写法,input内显示和value不同,可根据自己业务场景进行修改

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值