ソースを参照

添加小程序搜索支持商品名,修复搜索页面排序参数问题

Menethil 7 年 前
コミット
40081d1b9c

+ 4 - 0
litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallGoodsService.java

@@ -76,6 +76,10 @@ public class LitemallGoodsService {
         }
         if(!StringUtils.isEmpty(keyword)){
             criteria.andKeywordsLike("%" + keyword + "%");
+
+            LitemallGoodsExample.Criteria criteria2 = example.createCriteria();
+            criteria2.andNameLike("%" + keyword + "%");
+            example.or(criteria2);
         }
         criteria.andDeletedEqualTo(false);
 

+ 22 - 7
litemall-wx/pages/search/search.js

@@ -10,6 +10,7 @@ Page({
     helpKeyword: [],
     historyKeyword: [],
     categoryFilter: false,
+    currentSort: 'name',
     currentSortType: 'default',
     currentSortOrder: 'desc',
     filterCategory: [],
@@ -57,7 +58,9 @@ Page({
   },
   getHelpKeyword: function () {
     let that = this;
-    util.request(api.SearchHelper, { keyword: that.data.keyword }).then(function (res) {
+    util.request(api.SearchHelper, {
+      keyword: that.data.keyword
+    }).then(function(res) {
       if (res.errno === 0) {
         that.setData({
           helpKeyword: res.data
@@ -87,7 +90,14 @@ Page({
   },
   getGoodsList: function () {
     let that = this;
-    util.request(api.GoodsList, { keyword: that.data.keyword, page: that.data.page, size: that.data.size, sort: that.data.currentSortType, order: that.data.currentSortOrder, categoryId: that.data.categoryId }).then(function (res) {
+    util.request(api.GoodsList, {
+      keyword: that.data.keyword,
+      page: that.data.page,
+      size: that.data.size,
+      sort: that.data.currentSort,
+      order: that.data.currentSortOrder,
+      categoryId: that.data.categoryId
+    }).then(function(res) {
       if (res.errno === 0) {
         that.setData({
           searchStatus: true,
@@ -107,7 +117,7 @@ Page({
 
   },
   getSearchResult(keyword) {
-    if(keyword === ''){
+    if (keyword === '') {
       keyword = this.data.defaultKeyword.keyword;
     }
     this.setData({
@@ -119,13 +129,15 @@ Page({
 
     this.getGoodsList();
   },
-  openSortFilter: function (event) {
+  openSortFilter: function(event) {
     let currentId = event.currentTarget.id;
     switch (currentId) {
       case 'categoryFilter':
         this.setData({
           categoryFilter: !this.data.categoryFilter,
-          currentSortOrder: 'asc'
+          currentSortType: 'category',
+          currentSort: 'add_time',
+          currentSortOrder: 'desc'
         });
         break;
       case 'priceSort':
@@ -135,6 +147,7 @@ Page({
         }
         this.setData({
           currentSortType: 'price',
+          currentSort: 'retail_price',
           currentSortOrder: tmpSortOrder,
           categoryFilter: false
         });
@@ -145,13 +158,15 @@ Page({
         //综合排序
         this.setData({
           currentSortType: 'default',
+          currentSort: 'name',
           currentSortOrder: 'desc',
-          categoryFilter: false
+          categoryFilter: false,
+          categoryId: 0,
         });
         this.getGoodsList();
     }
   },
-  selectCategory: function (event) {
+  selectCategory: function(event) {
     let currentIndex = event.target.dataset.categoryIndex;
     let filterCategory = this.data.filterCategory;
     let currentCategory = null;

+ 2 - 2
litemall-wx/pages/search/search.wxml

@@ -39,7 +39,7 @@
       <view class="item by-price {{currentSortType == 'price' ? 'active' : ''}} {{currentSortOrder == 'asc'  ? 'asc' : 'desc'}}" bindtap="openSortFilter" id="priceSort">
         <text class="txt">价格</text>
       </view>
-      <view class="item {{currentSortType == 'category' ? 'active' : ''}}" bindtap="openSortFilter" id="categoryFilter">
+      <view class="item {{currentSortType == 'category' ? 'active' : ''}}" id="categoryFilter">
         <text class="txt">分类</text>
       </view>
     </view>
@@ -50,7 +50,7 @@
   <view class="cate-item">
     <view class="b">
       <navigator class="item {{(iindex + 1) % 2 == 0 ? 'item-b' : ''}}" url="/pages/goods/goods?id={{iitem.id}}" wx:for="{{goodsList}}" wx:key="id" wx:for-item="iitem" wx:for-index="iindex">
-        <image class="img" src="{{iitem.listPicUrl}}" background-size="cover"></image>
+        <image class="img" src="{{iitem.picUrl}}" background-size="cover"></image>
         <text class="name">{{iitem.name}}</text>
         <text class="price">¥{{iitem.retailPrice}}</text>
       </navigator>