uniapp 实现下拉筛选框 二次开发定制

前言

最近又收到了一个需求,需要在uniapp 小程序上做一个下拉筛选框,然后找了一下插件市场,确实有找到,但不过他不支持搜索,于是乎,我就自动动手,进行了二开定制,站在巨人的肩膀上,哈哈哈哈!具体的效果如下:

视频效果: 链接


一、核心代码

javascript 复制代码
<view class="filter-wrapper"
		:style="{  top: top,'border-top':border?'1rpx solid #f2f2f2':'none', }"
		@touchmove.stop.prevent="discard">
		<view class="inner-wrapper">
			<view class="mask" :class="showMask ? 'show' : 'hide'" @tap="tapMask"></view>
			<view class="navs" :style='{backgroundColor:bgColor}'>
				<view class="c-flex-align" :class="{ 'c-flex-center': index > 0, actNav: index === actNav }"
					v-for="(item, index) in navData" :key="index" @click="navClick(index,item)">
					<view v-for="(child, childx) in item" :key="childx" v-if="child.select"
						:class='[child.text.length>4?"navTextClass":""]'>
						{{ child.text.indexOf('全部')!==-1?child.text.split('全部')[1]:child.text }}
					</view>
					<image src="http://s08dznyms.hd-bkt.clouddn.com/wechat/up.png" mode="" class="icon-triangle"
						v-if="index === actNav ">
					</image>
					<image src="http://s08dznyms.hd-bkt.clouddn.com/wechat/down.png" mode="" class="icon-triangle"
						v-if="index !== actNav ">
					</image>
				</view>
			</view>
			<scroll-view scroll-y="true" class="popup" :class="popupShow ? 'popupShow' : ''">
				<view v-if='!changeType'>
					<!-- 自定义搜索 -->
					<view class='inputClass'>
						<view style='width:75%'>
							<u-input :placeholder="placeHolderName" prefixIcon="search"
								prefixIconStyle="font-size: 22px;color: #909399;color:rgba(36, 107, 183, 1);"
								shape='circle' @change='change' v-model="searchValue">
							</u-input>
						</view>
						<view class='totalClass'>共<text style='color:rgb(33, 107, 228)'>{{totalNum}}</text>条</view>
					</view>
					<view v-if='navData[actNav].length>0 ' class="item-opt c-flex-align1"
						:class="item.select ? 'actOpt' : ''" v-for="(item, index) in navData[actNav]" :key="index"
						@click="handleOpt(index,item)">
						{{ item.text }}
					</view>
					<view v-if='result.length===0' class='noDataClass'> 暂无数据 </view>
				</view>
				
			</scroll-view>
		</view>
	</view>

二、js 部分部分

复制代码
changeData(index, data) {
				this.$set(this.navData, index, data)
				console.log(this.navData)
				this.selIndex = this.defaultIndex;
				this.keepStatus('init');
			},
			change(e) {
				console.log(this.copyNavData[this.actNav][0].text)
				this.result = this.copyNavData[this.actNav].filter(item => item.text.indexOf(e) !== -1)
				this.$set(this.navData, this.actNav, this.result)
				setTimeout(() => {
					this.totalNum = this.navData[this.actNav].length
				}, 200)
			},
			keepStatus(type) {
				if (type === 'init') {
					this.navData.forEach(itemnavData => {
						itemnavData.map(child => {
							child.select = false;
						});
						return itemnavData;
					});
					for (let i = 0; i < this.selIndex.length; i++) {
						let selindex = this.selIndex[i];
						this.navData[i][selindex].select = true;
					}
					this.copyNavData = JSON.parse(JSON.stringify(this.navData));
				} else {
					this.copyNavData.forEach(itemnavData => {
						itemnavData.map(child => {
							child.select = false;
						});
						return itemnavData;
					});
					for (let i = 0; i < this.selIndex.length; i++) {
						let selindex = this.selIndex[i];
						this.copyNavData[i][selindex].select = true;
					}
				}
				console.log(this.copyNavData)
			},

总结

总体来说,进行二次开发的难度不大,关键是需要看的懂代码,然后进行二次开发就不难了!!!

javascript 复制代码
如果需要完整的demo 代码,请联系1015095073@qq.com
相关推荐
时光足迹10 小时前
uni-app 视频通话实战:康复师与患者视频问诊的 6 个致命 Bug 与解决方案
android·ios·uni-app
时光足迹11 小时前
腾讯云 TRTC UniApp SDK 从入门到上线
前端·vue.js·uni-app
时光足迹11 小时前
uni-app 里把加密视频嵌入页面播放?我分析了 4 种方案,只有 1 种接近完美
前端·vue.js·uni-app
时光足迹11 小时前
JPush UniApp UTS 插件完全参考手册:API、事件与厂商通道一网打尽
vue.js·ios·uni-app
时光足迹11 小时前
极光推送全攻略(下):uni-app 代码实现与 iOS 排查实战
vue.js·ios·uni-app
时光足迹11 小时前
极光推送全攻略(上):被iOS证书折磨了三天,我写了一份前端也能看懂的避坑指南
前端·ios·uni-app
spmcor2 天前
身份证读卡“无感登录”方案实践:从手动点击到自动检测
uni-app
PedroQue993 天前
uni-router v1.8.0新增冷启动守卫补执行
前端·uni-app
PedroQue994 天前
uni-router v1.7.0重磅更新:守卫重定向自由掌控
前端·uni-app
一份执念5 天前
uni-app项目 (vue+vite + uni-UI)中引入umd格式JS文件,微信小程序中导入报错处理方案
前端·uni-app·echarts