$scope.searchMap={'keywords':'','category':'','brand':'','spec':{},'price':'' };//搜索条件封装对象
//添加搜索项
$scope.addSearchItem=function(key,value){
if(key=='category' || key=='brand' || key=='price'){//如果点击的是分类或品牌
$scope.searchMap[key]=value;
}else{//如果是规格
$scope.searchMap.spec[key]=value;
}
$scope.search();
}
//移除复合搜索条件
$scope.removeSearchItem=function(key){
if(key=="category" || key=="brand" || key=='price'){//如果是分类或品牌
$scope.searchMap[key]="";
}else{//否则是规格
delete $scope.searchMap.spec[key];//移除此属性
}
$scope.search();
}
<ul class="type-list" ng-if="searchMap.price==''">
<li>
<a ng-click="addSearchItem('price','0-500')">0-500 元</a>
</li>
<li>
<a ng-click="addSearchItem('price','500-1000')">500-1000 元</a>
</li>
<li>
<a ng-click="addSearchItem('price','1000-1500')">1000-1500 元</a>
</li>
<li>
<a ng-click="addSearchItem('price','1500-2000')">1500-2000 元</a>
</li>
<li>
<a ng-click="addSearchItem('price','2000-3000')">2000-3000 元 </a>
</li>
<li>
<a ng-click="addSearchItem('price','3000-*')">3000 元以上</a>
</li>
</ul>
< li class="tag" ng-if="searchMap.price!=''" ng-click="removeSearchItem('price')">价格:
/**
* 根据关键字搜索列表
*@param keywords
*@return
*/
private Map searchList(Map searchMap){
......
//1.1 关键字查询.....
//1.2 按分类筛选.....
//1.3 按品牌筛选.....
//1.4 过滤规格......
//1.5 按价格筛选.....
if(!"".equals(searchMap.get("price"))){
String[] price = ((String) searchMap.get("price")).split("-");
if(!price[0].equals("0")){//如果区间起点不等于 0 Criteria filterCriteria=new
Criteria("item_price").greaterThanEqual(price[0]);
FilterQuery filterQuery=new SimpleFilterQuery(filterCriteria); query.addFilterQuery(filterQuery);
}
if(!price[1].equals("*")){//如果区间终点不等于* Criteria filterCriteria=new
Criteria("item_price").lessThanEqual(price[1]);
FilterQuery filterQuery=new SimpleFilterQuery(filterCriteria); query.addFilterQuery(filterQuery);
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |