Listbox+time picker

本文展示了如何在小程序中将Listbox与Timepicker组件结合使用,实现选择时间和筛选功能。通过XFL-SELECT组件和Picker组件,用户可以选择‘全部’、‘近一周’等预设选项,或者自定义开始和结束日期。当选择‘自定义’时,会弹出Timepicker以输入具体日期。代码示例详细解释了组件的配置和事件处理方法。
摘要由CSDN通过智能技术生成

本文主要讲述listbox与 time picker的混合使用

	<template>
		<view>
			<view class="body"> 
				 <view class="select-view">
						<xfl-select 
						:list="list" :showItemNum="5" 
						:clearable="false" :style_Container="listBoxStyle" 
						:initValue="'全部'" :selectHideType="'independent'"
						@change="xfl_select_change">
						</xfl-select> 
				</view>
				<div  v-show="cus_timepicker_show"  style="width: 100px; margin: 10rpx 10rpx;">
					<view class="uni-list-select">
						<view class="uni-list-cell-select">
							<view class="uni-list-cell-db">
								<picker style="width: 100px;" mode="date" :value="date_start" :start="startDate" :end="endDate" @change="bindDateChange">
									<view class="uni-input">{{date_start}}</view>
								</picker>
							</view>
						</view>
					</view>
				</div>	
				<div  v-show="cus_timepicker_show"  style="width: 100px; margin: 10rpx 10rpx;">
					<view class="uni-list-select">
						<view class="uni-list-cell-select">
							<view class="uni-list-cell-db">
								<picker style="width: 100px;" mode="date" :value="date_end" :start="startDate" :end="endDate" @change="endDateChange">
									<view class="uni-input">{{date_end}}</view>
								</picker>
							</view>
						</view>
					</view>
				</div>	
			</view> 

					
				
		</view>
	</template>
	<script>
		import uniPopup from '@/components/uni-popup/uni-popup.vue'
		import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue'
		import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
		import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue'
		import uniCombox from "@/components/uni-combox/uni-combox"
		import xflSelect from '@/components/xfl-select/xfl-select.vue'
	  
	    function getDate(type) {
	    	const date = new Date();
	    
	    	let year = date.getFullYear();
	    	let month = date.getMonth() + 1;
	    	let day = date.getDate();
	    
	    	if (type === 'start') {
	    		year = year - 60;
	    	} else if (type === 'end') {
	    		year = year + 2;
	    	}
	    	month = month > 9 ? month : '0' + month;;
	    	day = day > 9 ? day : '0' + day;
	    
	    	return `${year}-${month}-${day}`;
	    }
	
		export default {
			components: {
				uniPopup,
				uniPopupMessage,
				uniPopupDialog,
				uniSearchBar,
				uniCombox,
				xflSelect
			},
	
			data() {
				return {
					date_start: '开始时间',
					date_end: '结束时间',
					startDate:getDate('start'),
					endDate:getDate('end'),
					
					listBoxStyle: `height: 40px; font-size: 16px;`,
					
					list: ['全部', '近一周', '近一月', '近一年', '自定义'],
					
					// list: ['全部',  '自定义'],
					tabIndex : '0', //选中标签栏的序列
					cus_timepicker_show:false,
	
				}
			},
	
			
			methods: {
		
			tabTap(index) {
				console.log(index)
				this.tabIndex = index;
			
			},
			tabChange(e) {
				console.log(e.detail)
				const index = e.detail.current
				this.tabIndex = index;
			},
			bindDateChange(e) {
				this.date_start = e.detail.value
			},
			endDateChange(e) {
				this.date_end = e.detail.value
			},
			confirmDialog() {
				this.$refs.dialogInput.open()
			},
			dialogInputConfirm(done, val) {
				done()
			},
			xfl_select_change(val){
					if(val.newVal=="自定义"){
						// console.log("弹出时间框");
						this.cus_timepicker_show = true;
					}else{
						if(this.cus_timepicker_show){
							this.cus_timepicker_show=false;
						}
					}
				}
			},
			}
	</script>
	
	
	<style>
	
		
			
	</style>
	

结果展示:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值