吸顶式的多条件筛选、排序等功能,常用于商城列表顶部。 已经完成基础布局及逻辑,请根据项目需求自行改进;
| H5 | APP | 小程序 | NVUE |
| ✔ | ✔ | ✔ | ✔ |
<template>
<gui-page>
<!-- 吸顶 view -->
<view class="fixed-top-view gui-bg-gray gui-flex gui-rows gui-nowrap gui-space-between gui-align-items-center"
slot="gFixedTop" id="fixed-top-view">
<!-- 排序 -->
<view class="graceSelectMenuItem">
<gui-select-menu :titleColor="orderIndex == 0 ? activeColor : defColor"
:items="selectMenu1"
@select="select1"></gui-select-menu>
</view>
<view class="graceSelectMenuItem" @tap="orderBySellNumber">
<text class="gui-block-text gui-text gui-text-center"
:style="{color:orderIndex == 1 ? activeColor : defColor}">销量</text>
</view>
<view class="graceSelectMenuItem">
<gui-order @change="priceOrder"
:orderBy="orderByIndex" :limit="[1,2]">
<text class="gui-text gui-block-text"
:style="{color:orderIndex == 2 ? activeColor : defColor}">价格</text>
</gui-order>
</view>
<view class="graceSelectMenuItem"
@tap="showScreening">
<text class="gui-text gui-block-text gui-text-center gui-icons">筛选 </text>
</view>
</view>
<!-- 页面主体 加一个与吸顶元素等高的 margin-top 或 padding-top -->
<view slot="gBody" class="gui-margin"
style="margin-top:100rpx;">
<text class="gui-block-text gui-text gui-text-center gui-color-gray"
style="margin-top:200rpx;">...页面主体开始,请滚动页面测试...</text>
<view style="height:2000px;"></view>
<!-- 右侧弹出筛选 -->
<gui-popup
ref="guipopupright" position="right"
width="580rpx" :top="rightAraeTop">
<view class="gui-bg-white right-area gui-box-shadow">
<scroll-view :scroll-y="true" :style="{height:rightAraeHeight+'px'}">
<view style="padding-left:25rpx; padding-right:25rpx;">
<view class="gui-margin-top">
<text class="gui-text gui-color-gray">尺寸筛选</text>
</view>
<view style="margin-top:15rpx;">
<gui-stags :tags="sizes" :padding="30" :lineHeight="2.5"
@change="sedSize" type="checkbox"></gui-stags>
</view>
<view class="gui-margin-top">
<text class="gui-text gui-color-gray">价格区间</text>
</view>
<view style="margin-top:15rpx;"
class="gui-flex gui-rows gui-nowrap gui-align-items-center">
<input type="text" class="price-input gui-border-box" v-model="price1" />
<text class="gui-block-text gui-color-gray" style="margin:20rpx;"> - </text>
<input type="text" class="price-input gui-border-box" v-model="price2" />
</view>
<view class="gui-margin-top">
<text class="gui-text gui-color-gray">其他条件</text>
</view>
<view style="margin-top:15rpx;">
<text class="gui-text gui-color-gray">请跟据项目需要自行完善</text>
</view>
</view>
</scroll-view>
<view class="right-area-footer gui-flex gui-rows gui-nowrap">
<view class="right-area-footer-btn" hover-class="gui-tap"
@tap="screeningReset">
<text class="right-area-footer-btn gui-block-text gui-color-gray">重置</text>
</view>
<view class="right-area-footer-btn gui-bg-red" hover-class="gui-tap"
@tap="screeningSubmit">
<text class="right-area-footer-btn gui-block-text gui-color-white">提交</text>
</view>
</view>
</view>
</gui-popup>
</view>
</gui-page>
</template>
<script>
var graceJS = require('@/GraceUI5/js/grace.js');
export default {
data(){
return {
// 第 1 排序选择
selectMenu1 : ['综合', '信用'],
// 默认颜色
defColor : '#2B2E3D',
// 选中颜色
activeColor : '#FF0036',
// 排序索引
orderIndex : 0,
// 价格排序索引
orderByIndex : 0,
// 尺寸标签
sizes : [
{id:0,text:"30 cm",checked:false},
{id:1,text:"50 cm",checked:false},
{id:2,text:"60 cm",checked:false},
{id:3,text:"70 cm",checked:false},
{id:4,text:"80 cm",checked:false},
{id:4,text:"90 cm",checked:false}
],
sizeSed : null,
price1 : 100,
price2 : 999,
// 右侧区高度
rightAraeHeight : 200,
// 右侧弹出层 top 值
rightAraeTop : 0
}
},
onLoad : function () {
var systemInfo = graceJS.system();
console.log(systemInfo);
// #ifdef H5
this.rightAraeHeight = systemInfo.windowHeight + 44 - uni.upx2px(100);
// #endif
// #ifndef H5
this.rightAraeHeight = systemInfo.windowHeight - uni.upx2px(100);
// #endif
},
onReady:function(){
// 此处计算吸顶元素高度作为右侧弹出层的top值
graceJS.select('#fixed-top-view', (res)=>{
console.log(res);
this.rightAraeTop = res.height;
// #ifdef H5
this.rightAraeTop += 44;
// #endif
});
},
methods:{
// 第一个排序
showMenu1 : function () {this.show1 = true;},
closeMenu1 : function () {this.show1 = false;},
select1 : function (index, val) {
// 获得选择项目后按照数据继续排序即可
console.log("选择了 " + val);
this.orderIndex = 0;
this.orderByIndex = 0;
},
// 销量排序
orderBySellNumber : function(){
// 排序逻辑自己来实现
this.orderIndex = 1;
this.orderByIndex = 0;
},
// 价格排序
priceOrder : function(e){
console.log(e);
// 1 2 为价格排序 0 为默认排序
if(e != 0){
this.orderIndex = 2;
}
this.orderByIndex = e;
},
// 展示筛选界面
showScreening : function () {
this.$refs.guipopupright.open();
},
// 选择尺寸
sedSize : function(e){
this.sizeSed = e;
},
// 筛选提交
screeningSubmit : function () {
uni.showToast({ icon:"none", title:"请观察控制台" });
// 尺寸
console.log(this.sizeSed);
// 价格
console.log(this.price1, this.price2);
this.$refs.guipopupright.close();
},
// 重置筛选
screeningReset : function () {
this.sizes = [
{id:0,text:"30 cm",checked:false},
{id:1,text:"50 cm",checked:false},
{id:2,text:"60 cm",checked:false},
{id:3,text:"70 cm",checked:false},
{id:4,text:"80 cm",checked:false},
{id:4,text:"90 cm",checked:false}
];
this.price1 = 100;
this.price2 = 999;
}
}
}
</script>
<style>
/* 自定义吸顶元素样式 */
.fixed-top-view{height:100rpx;}
.graceSelectMenuItem{width:180rpx;}
.right-area{flex:1; height:800rpx;}
.colorTags{width:120rpx; height:60rpx; line-height:60rpx; text-align:center; font-size:26rpx; color:#FFFFFF; border-radius:5rpx;}
.price-input{width:120rpx; padding:15rpx; line-height:50rpx; height:80rpx; font-size:26rpx; text-align:center; background-color:#F5F6F8; border-radius:5rpx;}
.right-area-footer{width:580rpx; height:100rpx; background-color:#F7F8FA;}
.right-area-footer-btn{width:290rpx; height:100rpx; line-height:100rpx; font-size:28rpx; text-align:center;}
</style>