filter-popup.vue 3.92 KB
<template>
	<u-popup @close="$emit('close')" closeable bgColor="#fff" :show="show" mode="bottom" :round="20"
		@touchmove.stop.prevent="disabledScroll">
		<view class="filter" @touchmove.stop.prevent="disabledScroll">
			<view class="filter-title"><text>{{ $t('common.filterCriteria') }}</text></view>
			<view class="query-item" v-for="(item, index) in filterList">
				<view class="query-title">
					<text>{{ item.title }}</text>
				</view>
				<view class="query-list">
					<view v-for="(itemChild, indexChild) in item.typeList" :key="indexChild" @click="handleClickTag(indexChild, item.typeList)"
						:class="['tag-item', { checked: itemChild.checked, 'mr-30': (indexChild + 1) % 3 !== 0 }]">
						{{ $t(itemChild.name) }}
					</view>
				</view>
				<view class="select-date" v-if="item.isDate">
					<view class="datetime-picker">	
						<uni-datetime-picker return-type="string" v-model="item.range" type="datetimerange"
							:rangeSeparator="$t('common.toText')" />
					</view>
				</view>
			</view>
			<view class="button-group">
				<view>
					<u-button :customStyle="{ color: '#333' }" color="#e3e3e5" shape="circle" :text="$t('common.resetting')"
						@click="resetFilter"></u-button>
				</view>
				<view>
					<u-button color="#3388ff" shape="circle" :text="$t('common.confirm')" @click="confirmFilter"></u-button>
				</view>
			</view>
		</view>
	</u-popup>
</template>

<script>
	export default {
		components: {
			
		},
		props: {
			show: Boolean,
			filterList: {
				type: Array,
				default: () => []
			},
			filterName:Object
		},
		data() {
			return {
			
				
				
			}
		},
		
		methods: {
			disabledScroll() {
				return;
			},
			//点击选中的标签
			handleClickTag(currentIndex, list) {
				list.map((item, index) => {
					item.checked = index === currentIndex;
				});
			},
			//重置
			resetFilter() {
				this.filterList.forEach((item)=>{
					
					if(item.isDate){
						item.range = []
					}else{
						item.typeList.forEach((item1)=>{
							if(item1.name === '全部'){
								item1.checked = true
							}else{
								item1.checked = false
							}
						})
					}
				})
				
			},
			//确定
			confirmFilter() {
				let checkedList = this.filterName
				this.filterList.forEach((item)=>{
					
					if(item.isDate){
						if (Array.isArray(item.range)) {
							checkedList[item.startDate] = item.range[0] ? item.range[0] : ''
							checkedList[item.endDate] = item.range[1] ? item.range[1] : ''
						}
					}else{
						item.typeList.forEach((item1)=>{
							if(item1.checked){
								checkedList[item.titleCode] = item1.code
							}
						})
					}
					
				})
				this.$emit('queryCondition', checkedList)
			},
			
			change(e) {
							// this.single = e;
							// console.log("-change事件:", e);
						},
		}
	}
</script>

<style lang="scss" scoped>
	.filter {
		padding: 0 30rpx;

		.filter-title {
			text-align: center;
			margin-top: 14px;
			font-size: 16px;
			font-weight: 700;
		}

		.button-group {
			display: flex;
			margin-top: 40rpx;
			justify-content: space-between;

			view {
				width: 330rpx;
			}
		}
		.select-date {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
		}
		
		.datetime-picker {
			width: 640rpx;
			margin-left: 5rpx;
			margin-right: 70rpx;
			margin-top: 35rpx;
		}
		.query-item {
			margin-top: 40rpx;
		
			.query-title {
				color: #333;
				font-size: 14px;
				font-weight: 700;
			}
		
			.query-list {
				display: flex;
				flex-wrap: wrap;
		
				.tag-item {
					margin-top: 30rpx;
					min-width: 198rpx;
					padding: 0 12rpx;
					height: 68rpx;
					border-radius: 32rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					color: #333;
					font-size: 13px;
					border: 1px solid #fff;
					background-color: #f6f6f6;
				}
		
				.checked {
					border: 1px solid #377dff4d;
					background-color: #377dff0d;
					color: #377dffff;
				}
		
				.mr-30 {
					margin-right: 30rpx;
				}
			}
		}
	    
	}
</style>