element UI选择年,月,季度,双月

element ui 选择年,半年,季度,月

效果图
在这里插入图片描述
在这里插入图片描述

源码


<template>
	<div class="block">
		<div>
			<el-button @click="years"></el-button>
			<el-button @click="halfyear">半年</el-button>
			<el-button @click="quarter">季度</el-button>
			<el-button @click="month"></el-button>
			<!-- 半年 -->
			<div v-show="showTime6">
				<span @click="showsixMonth">
					<el-input prefix-icon="el-icon-date" v-model="halfYearMonth" placeholder="请选择" style="width: 13.75rem;"></el-input>
				</span>
				<li class="show6" v-show="showTimehalfYear">
					<p class="show6P"> <span>
							<button type="button" aria-label="前一年" class="el-picker-panel__icon-btn el-date-picker__prev-btn el-icon-d-arrow-left"
							 @click="prev"></button>
						</span>
						<span role="button" class="span-year">{{year}}</span>
						<span>
							<button type="button" aria-label="后一年" @click="next" class="el-picker-panel__icon-btn el-date-picker__next-btn el-icon-d-arrow-right"></button>
						</span>
					</p>
					<div class="selectMonth">
						<p v-for="(item,index) in fullMonth" @click="choseHalfYear(item)">{{item}}</p>
					</div>
				</li>

			</div>
		</div>
		<el-date-picker v-model="time" v-show="showNomaldata" :type=dataType placeholder="请选择">
		</el-date-picker>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				time: '',
				dataType: 'year',
				showNomaldata: true,
				year: new Date().getFullYear(),
				fullMonth: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
				status: '',
				//半年
				halfYearMonth: "",
				showTimehalfYear: false,
				showTime6: false
			}
		},
		
		methods: {
			prev() {
				this.year = this.year * 1 - 1
			},
			next() {
				this.year = this.year * 1 + 1
			},
			years() {
				this.dataType = 'year'
				this.showNomaldata = true
				this.showTime6 = false
			},
			//半年
			halfyear() {
				this.showNomaldata = false
				this.showTime6 = true
				this.showTimehalfYear = true
				this.halfYearMonth = ''
				this.status = 'halfyear'
			},
			showsixMonth() {
				this.showTimehalfYear = !this.showTimehalfYear
			},
			choseHalfYear(v) {
				console.log(this.status)
				if (this.status == "halfyear") {
					if (v <= 6) {
						this.halfYearMonth = this.year + "上半年"
					} else {
						this.halfYearMonth = this.year + "下半年"
					}
				}else if(this.status == "quarter"){
					if ( v>0 && v<4) {
						this.halfYearMonth = this.year + "第一季度"
					} else if ( v>3 && v<7){
						this.halfYearMonth = this.year + "第二季度"
					}else if ( v>6 && v<10){
						this.halfYearMonth = this.year + "第三季度"
					}else{
						this.halfYearMonth = this.year + "第四季度"
					}
				}
			},
			quarter() {
				this.showNomaldata = false
				this.showTime6 = true
				this.showTimehalfYear = true
				this.halfYearMonth = ''
				this.status = 'quarter'
			},
			month() {
				this.dataType = 'month'
				this.showNomaldata = true
				this.showTime6 = false
			},
		}
	}
</script>

<style>
	.show6 {
		width: 322px;
		margin-top: 5px;
		position: absolute;
		z-index: 2;
		height: 272px;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
		background: #fff;
		padding: 10px;
		box-sizing: border-box;
	}

	.show6P {
		width: 100%;
		height: 43px;
		line-height: 43px;
		border-bottom: 1px solid #f5f5f5;

	}


	.show6:nth-child(1) span {
		display: inline-block;
		height: 100%;
		line-height: 43px;
		float: left;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.selectMonth {
		width: 100%;
		height: 14.3125rem;
		display: flex;
		flex-flow: wrap;
	}

	.selectMonth p {
		width: 25%;
		height: 25%;
		text-align: center;
		line-height: 4rem;
	}

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

	.span-year {
		width: 90%;
		margin: 0 auto;
		display: inline-block;
		float: left;
		text-align: center;
		line-height: 40px;

	}

	.el-input {
		width: 215px;
		height: 38px;
		display: inline-block;
	}
</style>

待优化

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值