Browse Source

商品服务,上拉浏览更多(分页)

nnkwrik 6 years ago
parent
commit
a5236d3c58
32 changed files with 312 additions and 133 deletions
  1. 7 5
      goods-service/src/main/java/io/github/nnkwrik/goodsservice/controller/GoodsController.java
  2. 22 2
      goods-service/src/main/java/io/github/nnkwrik/goodsservice/controller/IndexController.java
  3. 1 1
      goods-service/src/main/java/io/github/nnkwrik/goodsservice/controller/SearchController.java
  4. 22 12
      goods-service/src/main/java/io/github/nnkwrik/goodsservice/controller/UserController.java
  5. 4 7
      goods-service/src/main/java/io/github/nnkwrik/goodsservice/dao/GoodsMapper.java
  6. 1 1
      goods-service/src/main/java/io/github/nnkwrik/goodsservice/dao/OtherMapper.java
  7. 1 1
      goods-service/src/main/java/io/github/nnkwrik/goodsservice/dao/SearchMapper.java
  8. 5 5
      goods-service/src/main/java/io/github/nnkwrik/goodsservice/dao/UserMapper.java
  9. 1 1
      goods-service/src/main/java/io/github/nnkwrik/goodsservice/service/GoodsService.java
  10. 5 1
      goods-service/src/main/java/io/github/nnkwrik/goodsservice/service/IndexService.java
  11. 4 4
      goods-service/src/main/java/io/github/nnkwrik/goodsservice/service/UserService.java
  12. 3 5
      goods-service/src/main/java/io/github/nnkwrik/goodsservice/service/impl/GoodsServiceImpl.java
  13. 8 5
      goods-service/src/main/java/io/github/nnkwrik/goodsservice/service/impl/IndexServiceImpl.java
  14. 9 4
      goods-service/src/main/java/io/github/nnkwrik/goodsservice/service/impl/UserServiceImpl.java
  15. 1 1
      wx-front/app.json
  16. 35 16
      wx-front/pages/category/category.js
  17. 3 1
      wx-front/pages/category/category.json
  18. 14 2
      wx-front/pages/goods/goods.js
  19. 44 10
      wx-front/pages/index/index.js
  20. 3 1
      wx-front/pages/index/index.json
  21. 43 21
      wx-front/pages/search/search.js
  22. 2 1
      wx-front/pages/search/search.json
  23. 1 1
      wx-front/pages/search/search.wxss
  24. 1 1
      wx-front/pages/ucenter/about/about.wxml
  25. 23 11
      wx-front/pages/ucenter/bought/bought.js
  26. 1 1
      wx-front/pages/ucenter/bought/bought.wxml
  27. 15 3
      wx-front/pages/ucenter/collect/collect.js
  28. 1 1
      wx-front/pages/ucenter/collect/collect.wxml
  29. 15 3
      wx-front/pages/ucenter/posted/posted.js
  30. 1 1
      wx-front/pages/ucenter/posted/posted.wxml
  31. 15 3
      wx-front/pages/ucenter/sold/sold.js
  32. 1 1
      wx-front/pages/ucenter/sold/sold.wxml

+ 7 - 5
goods-service/src/main/java/io/github/nnkwrik/goodsservice/controller/GoodsController.java

@@ -46,8 +46,8 @@ public class GoodsController {
     @GetMapping("/category/{categoryId}")
 
     public Response<CategoryPageVo> getCategoryPage(@PathVariable("categoryId") int categoryId,
-                                                @RequestParam(value = "page", defaultValue = "1") int page,
-                                                @RequestParam(value = "limit", defaultValue = "10") int size) {
+                                                    @RequestParam(value = "page", defaultValue = "1") int page,
+                                                    @RequestParam(value = "size", defaultValue = "10") int size) {
 
 
         CategoryPageVo vo = goodsService.getGoodsAndBrotherCateById(categoryId, page, size);
@@ -67,7 +67,7 @@ public class GoodsController {
     @GetMapping("/list/{categoryId}")
     public Response<Goods> getGoodsByCategory(@PathVariable("categoryId") int categoryId,
                                               @RequestParam(value = "page", defaultValue = "1") int page,
-                                              @RequestParam(value = "limit", defaultValue = "10") int size) {
+                                              @RequestParam(value = "size", defaultValue = "10") int size) {
 
         List<Goods> goodsList = goodsService.getGoodsByCateId(categoryId, page, size);
         log.info("通过分类浏览商品 : 分类id = {},展示{}个商品", categoryId, goodsList.size());
@@ -119,8 +119,10 @@ public class GoodsController {
      * @return
      */
     @GetMapping("/related/{goodsId}")
-    public Response<List<Goods>> getGoodsRelated(@PathVariable("goodsId") int goodsId) {
-        List<Goods> goodsList = goodsService.getGoodsRelated(goodsId);
+    public Response<List<Goods>> getGoodsRelated(@PathVariable("goodsId") int goodsId,
+                                                 @RequestParam(value = "page", defaultValue = "1") int page,
+                                                 @RequestParam(value = "size", defaultValue = "10") int size) {
+        List<Goods> goodsList = goodsService.getGoodsRelated(goodsId,page,size);
         log.info("获取与 goodsId=[{}] 相关的商品 : 展示{}个商品", goodsId, goodsList.size());
 
         return Response.ok(goodsList);

+ 22 - 2
goods-service/src/main/java/io/github/nnkwrik/goodsservice/controller/IndexController.java

@@ -4,6 +4,7 @@ import io.github.nnkwrik.common.dto.JWTUser;
 import io.github.nnkwrik.common.dto.Response;
 import io.github.nnkwrik.common.token.injection.JWT;
 import io.github.nnkwrik.goodsservice.model.po.Category;
+import io.github.nnkwrik.goodsservice.model.po.Goods;
 import io.github.nnkwrik.goodsservice.model.po.GoodsComment;
 import io.github.nnkwrik.goodsservice.model.po.Region;
 import io.github.nnkwrik.goodsservice.model.vo.CatalogPageVo;
@@ -33,14 +34,29 @@ public class IndexController {
      * @return
      */
     @GetMapping("/index/index")
-    public Response<IndexPageVO> index() {
+    public Response<IndexPageVO> index(@RequestParam(value = "page", defaultValue = "1") int page,
+                                       @RequestParam(value = "size", defaultValue = "10") int size) {
 
-        IndexPageVO vo = indexService.getIndex();
+        IndexPageVO vo = indexService.getIndex(page, size);
         log.info("浏览首页 : 展示{}个广告, {}个分类, {}个商品", vo.getBanner().size(), vo.getChannel().size(), vo.getIndexGoodsList().size());
 
         return Response.ok(vo);
     }
 
+    /**
+     * 首页展示更多推荐商品
+     * @param page
+     * @param size
+     * @return
+     */
+    @GetMapping("/index/more")
+    public Response<List<Goods>> indexMore(@RequestParam(value = "page", defaultValue = "1") int page,
+                                           @RequestParam(value = "size", defaultValue = "10") int size) {
+        List<Goods> goodsList = indexService.getIndexMore(page, size);
+        log.info("首页获取更多推荐商品 : 返回{}个商品", goodsList.size());
+        return Response.ok(goodsList);
+    }
+
     /**
      * 分类页,展示:所有主分类,排名第一的主分类包含的子分类
      *
@@ -57,6 +73,7 @@ public class IndexController {
 
     /**
      * 分类页, 获取选定主分类下的子分类
+     *
      * @param id
      * @return
      */
@@ -71,6 +88,7 @@ public class IndexController {
 
     /**
      * 发表评论
+     *
      * @param goodsId
      * @param comment
      * @param user
@@ -98,6 +116,7 @@ public class IndexController {
 
     /**
      * 获取发布商品时需要填选的发货地区
+     *
      * @param regionId
      * @return
      */
@@ -111,6 +130,7 @@ public class IndexController {
 
     /**
      * 获取发布商品时需要填选的分类
+     *
      * @param cateId
      * @return
      */

+ 1 - 1
goods-service/src/main/java/io/github/nnkwrik/goodsservice/controller/SearchController.java

@@ -79,7 +79,7 @@ public class SearchController {
     @GetMapping("/result/{keyword}")
     public Response<List<Goods>> searchGoods(@PathVariable("keyword") String keyword,
                                              @RequestParam(value = "page", defaultValue = "1") int page,
-                                             @RequestParam(value = "limit", defaultValue = "10") int size,
+                                             @RequestParam(value = "size", defaultValue = "10") int size,
                                              @JWT JWTUser jwtUser) {
         List<String> keywordList = Arrays.asList(StringUtils.split(keyword));
         List<Goods> goodsListVo = searchService.searchByKeyword(keywordList, page, size);

+ 22 - 12
goods-service/src/main/java/io/github/nnkwrik/goodsservice/controller/UserController.java

@@ -7,10 +7,7 @@ import io.github.nnkwrik.goodsservice.model.po.Goods;
 import io.github.nnkwrik.goodsservice.service.UserService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -27,6 +24,7 @@ public class UserController {
 
     /**
      * 收藏或取消收藏某个商品
+     *
      * @param goodsId
      * @param hasCollect
      * @param user
@@ -45,48 +43,60 @@ public class UserController {
 
     /**
      * 获取用户收藏的商品列表
+     *
      * @param user
      * @return
      */
     @GetMapping("/collect/list")
-    public Response<List<Goods>> getCollectList(@JWT(required = true) JWTUser user) {
-        List<Goods> vo = userService.getUserCollectList(user.getOpenId());
+    public Response<List<Goods>> getCollectList(@JWT(required = true) JWTUser user,
+                                                @RequestParam(value = "page", defaultValue = "1") int page,
+                                                @RequestParam(value = "size", defaultValue = "10") int size) {
+        List<Goods> vo = userService.getUserCollectList(user.getOpenId(), page, size);
         log.info("用户【{}】查询收藏的商品,总数:{}", user.getNickName(), vo.size());
         return Response.ok(vo);
     }
 
     /**
      * 获取用户买过的商品列表
+     *
      * @param user
      * @return
      */
     @GetMapping("goods/bought")
-    public Response<List<Goods>> getUserBought(@JWT(required = true) JWTUser user) {
-        List<Goods> vo = userService.getUserBought(user.getOpenId());
+    public Response<List<Goods>> getUserBought(@JWT(required = true) JWTUser user,
+                                               @RequestParam(value = "page", defaultValue = "1") int page,
+                                               @RequestParam(value = "size", defaultValue = "10") int size) {
+        List<Goods> vo = userService.getUserBought(user.getOpenId(), page, size);
         log.info("用户【{}】查询买过的商品,总数:{}", user.getNickName(), vo.size());
         return Response.ok(vo);
     }
 
     /**
      * 获取用户卖出的商品列表
+     *
      * @param user
      * @return
      */
     @GetMapping("goods/sold")
-    public Response<List<Goods>> getUserSold(@JWT(required = true) JWTUser user) {
-        List<Goods> vo = userService.getUserSold(user.getOpenId());
+    public Response<List<Goods>> getUserSold(@JWT(required = true) JWTUser user,
+                                             @RequestParam(value = "page", defaultValue = "1") int page,
+                                             @RequestParam(value = "size", defaultValue = "10") int size) {
+        List<Goods> vo = userService.getUserSold(user.getOpenId(), page, size);
         log.info("用户【{}】查询卖出的商品,总数:{}", user.getNickName(), vo.size());
         return Response.ok(vo);
     }
 
     /**
      * 获取用户发布但还没卖出的商品列表
+     *
      * @param user
      * @return
      */
     @GetMapping("goods/posted")
-    public Response getUserPosted(@JWT(required = true) JWTUser user) {
-        List<Goods> vo = userService.getUserPosted(user.getOpenId());
+    public Response getUserPosted(@JWT(required = true) JWTUser user,
+                                  @RequestParam(value = "page", defaultValue = "1") int page,
+                                  @RequestParam(value = "size", defaultValue = "10") int size) {
+        List<Goods> vo = userService.getUserPosted(user.getOpenId(), page, size);
         log.info("用户【{}】查询发布的商品,总数:{}", user.getNickName(), vo.size());
         return Response.ok(vo);
     }

+ 4 - 7
goods-service/src/main/java/io/github/nnkwrik/goodsservice/dao/GoodsMapper.java

@@ -3,10 +3,7 @@ package io.github.nnkwrik.goodsservice.dao;
 import io.github.nnkwrik.goodsservice.model.po.Goods;
 import io.github.nnkwrik.goodsservice.model.po.GoodsComment;
 import io.github.nnkwrik.goodsservice.model.po.GoodsGallery;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.annotations.Select;
-import org.apache.ibatis.annotations.Update;
+import org.apache.ibatis.annotations.*;
 
 import java.util.List;
 
@@ -144,7 +141,7 @@ public interface GoodsMapper {
     List<GoodsComment> findReplyComment(@Param("reply_comment_id") int commentId);
 
 
-    @Select("insert into goods (category_id,\n" +
+    @Insert("insert into goods (category_id,\n" +
             "                   seller_id,\n" +
             "                   name,\n" +
             "                   price,\n" +
@@ -161,13 +158,13 @@ public interface GoodsMapper {
             "#{marketPrice},#{postage}," +
 //            "#{primaryPicUrl}," +
             "#{desc}," +
-            "#{regionId},#{region},#{ableExpress},#{ableMeet},#{ableSelfTake});")
+            "#{regionId},#{region},#{ableExpress},#{ableMeet},#{ableSelfTake})")
     void addGoods(Goods goods);
 
     @Select("select COUNT(*)\n" +
             "from goods\n" +
             "where seller_id = #{seller_id}\n" +
             "  and is_selling = false\n" +
-            "  and is_delete = false;")
+            "  and is_delete = false")
     Integer getSellerHistory(@Param("seller_id") String sellerId);
 }

+ 1 - 1
goods-service/src/main/java/io/github/nnkwrik/goodsservice/dao/OtherMapper.java

@@ -27,7 +27,7 @@ public interface OtherMapper {
 
 
     @Insert("insert into goods_comment (goods_id, user_id, reply_comment_id, reply_user_id, content)\n" +
-            "values (#{goods_id}, #{user_id}, #{reply_comment_id}, #{reply_user_id}, #{content});")
+            "values (#{goods_id}, #{user_id}, #{reply_comment_id}, #{reply_user_id}, #{content})")
     void addComment(@Param("goods_id") int goodsId,
                     @Param("user_id") String userId,
                     @Param("reply_comment_id") int replyCommentId,

+ 1 - 1
goods-service/src/main/java/io/github/nnkwrik/goodsservice/dao/SearchMapper.java

@@ -60,7 +60,7 @@ public interface SearchMapper {
 
     @Update("update search_history\n" +
             "set search_time = now()\n" +
-            "where user_id = #{user_id} and keyword = #{keyword};")
+            "where user_id = #{user_id} and keyword = #{keyword}")
     void updateSearchTime(@Param("user_id") String userId, @Param("keyword") String keyword);
 
 

+ 5 - 5
goods-service/src/main/java/io/github/nnkwrik/goodsservice/dao/UserMapper.java

@@ -24,7 +24,7 @@ public interface UserMapper {
             "from user_preference\n" +
             "where goods_id = #{goods_id}\n" +
             "  and user_id = #{user_id}\n" +
-            "  and type = 1;")
+            "  and type = 1")
     void deleteUserCollect(@Param("user_id") String userId, @Param("goods_id") int goodsId);
 
 
@@ -39,7 +39,7 @@ public interface UserMapper {
             "from user_preference\n" +
             "where goods_id = #{goods_id}\n" +
             "  and user_id = #{user_id}\n" +
-            "  and type = 2;")
+            "  and type = 2")
     void deleteUserWant(@Param("user_id") String userId, @Param("goods_id") int goodsId);
 
 
@@ -47,7 +47,7 @@ public interface UserMapper {
             "from goods\n" +
             "       inner join user_preference as u \n" +
             "         on goods.id = u.goods_id and u.user_id = #{user_id} and u.type = 1 and is_delete = false\n" +
-            "order by u.create_time desc;")
+            "order by u.create_time desc")
     List<Goods> getUserCollect(@Param("user_id") String userId);
 
     @Select("select id, name, primary_pic_url, price, sold_time\n" +
@@ -61,7 +61,7 @@ public interface UserMapper {
             "from goods\n" +
             "where seller_id = #{seller_id}\n" +
             "  and is_selling = 0\n" +
-            "order by sold_time desc;")
+            "order by sold_time desc")
     List<Goods> getUserSold(@Param("seller_id") String sellerId);
 
     @Select("select id, name, primary_pic_url, price, last_edit\n" +
@@ -69,6 +69,6 @@ public interface UserMapper {
             "where seller_id = #{seller_id}\n" +
             "  and is_selling = 1\n" +
             "  and is_delete = 0\n" +
-            "order by last_edit desc;")
+            "order by last_edit desc")
     List<Goods> getUserPosted(@Param("seller_id") String sellerId);
 }

+ 1 - 1
goods-service/src/main/java/io/github/nnkwrik/goodsservice/service/GoodsService.java

@@ -26,7 +26,7 @@ public interface GoodsService {
 
     List<GoodsGallery> getGoodsGallery(int goodsId);
 
-    List<Goods> getGoodsRelated(int goodsId);
+    List<Goods> getGoodsRelated(int goodsId, int page, int size);
 
     List<CommentVo> getGoodsComment(int goodsId);
 

+ 5 - 1
goods-service/src/main/java/io/github/nnkwrik/goodsservice/service/IndexService.java

@@ -1,6 +1,7 @@
 package io.github.nnkwrik.goodsservice.service;
 
 import io.github.nnkwrik.goodsservice.model.po.Category;
+import io.github.nnkwrik.goodsservice.model.po.Goods;
 import io.github.nnkwrik.goodsservice.model.po.Region;
 import io.github.nnkwrik.goodsservice.model.vo.CatalogPageVo;
 import io.github.nnkwrik.goodsservice.model.vo.IndexPageVO;
@@ -13,7 +14,9 @@ import java.util.List;
  */
 public interface IndexService {
 
-    IndexPageVO getIndex();
+    IndexPageVO getIndex(int page, int size);
+
+    List<Goods> getIndexMore(int page, int size);
 
     CatalogPageVo getCatalogIndex();
 
@@ -25,4 +28,5 @@ public interface IndexService {
     List<Region> getRegionList(int regionId);
 
     List<Category> getPostCateList(int cateId);
+
 }

+ 4 - 4
goods-service/src/main/java/io/github/nnkwrik/goodsservice/service/UserService.java

@@ -14,11 +14,11 @@ public interface UserService {
 
     void collectAddOrDelete(int goodsId, String userId, boolean hasCollect);
 
-    List<Goods> getUserCollectList(String userId);
+    List<Goods> getUserCollectList(String userId, int page, int size);
 
-    List<Goods> getUserBought(String buyerId);
+    List<Goods> getUserBought(String buyerId, int page, int size);
 
-    List<Goods> getUserSold(String sellerId);
+    List<Goods> getUserSold(String sellerId, int page, int size);
 
-    List<Goods> getUserPosted(String userId);
+    List<Goods> getUserPosted(String userId, int page, int size);
 }

+ 3 - 5
goods-service/src/main/java/io/github/nnkwrik/goodsservice/service/impl/GoodsServiceImpl.java

@@ -84,16 +84,14 @@ public class GoodsServiceImpl implements GoodsService {
     }
 
     @Override
-    public List<Goods> getGoodsRelated(int goodsId) {
+    public List<Goods> getGoodsRelated(int goodsId, int page, int size) {
         //获取同一子分类下
-        int pageNum = 1;
-        int pageSize = 10;
-        PageHelper.startPage(pageNum, pageSize);
+        PageHelper.startPage(page, size);
         List<Goods> simpleGoods = goodsMapper.findSimpleGoodsInSameCate(goodsId);
 
         //统一子分类下的数量少于10, 查找同一父分类下
         if (simpleGoods.size() < 10) {
-            PageHelper.startPage(pageNum, pageSize);
+            PageHelper.startPage(page, size);
             simpleGoods = goodsMapper.findSimpleGoodsInSameParentCate(goodsId);
         }
 

+ 8 - 5
goods-service/src/main/java/io/github/nnkwrik/goodsservice/service/impl/IndexServiceImpl.java

@@ -27,7 +27,7 @@ public class IndexServiceImpl implements IndexService {
     private GoodsMapper goodsMapper;
 
     @Override
-    public IndexPageVO getIndex() {
+    public IndexPageVO getIndex(int page, int size) {
         //广告
         List<Ad> adList = otherMapper.findAd();
 
@@ -35,14 +35,17 @@ public class IndexServiceImpl implements IndexService {
         List<Channel> channelList = otherMapper.findChannel();
 
         //推荐商品
-        int pageNum = 1;
-        int pageSize = 10;
-        PageHelper.startPage(pageNum, pageSize);
-        List<Goods> goodsList = goodsMapper.findSimpleGoods();
+        List<Goods> goodsList = getIndexMore(page,size);
 
         return new IndexPageVO(goodsList, adList, channelList);
     }
 
+    @Override
+    public List<Goods> getIndexMore(int page, int size) {
+        PageHelper.startPage(page, size);
+        return goodsMapper.findSimpleGoods();
+    }
+
     @Override
     public CatalogPageVo getCatalogIndex() {
         List<Category> allCategory = categoryMapper.findMainCategory();

+ 9 - 4
goods-service/src/main/java/io/github/nnkwrik/goodsservice/service/impl/UserServiceImpl.java

@@ -1,5 +1,6 @@
 package io.github.nnkwrik.goodsservice.service.impl;
 
+import com.github.pagehelper.PageHelper;
 import io.github.nnkwrik.goodsservice.dao.UserMapper;
 import io.github.nnkwrik.goodsservice.model.po.Goods;
 import io.github.nnkwrik.goodsservice.service.UserService;
@@ -33,23 +34,27 @@ public class UserServiceImpl implements UserService {
     }
 
     @Override
-    public List<Goods> getUserCollectList(String userId) {
+    public List<Goods> getUserCollectList(String userId, int page, int size) {
+        PageHelper.startPage(page, size);
         return userMapper.getUserCollect(userId);
     }
 
     @Override
-    public List<Goods> getUserBought(String buyerId) {
+    public List<Goods> getUserBought(String buyerId, int page, int size) {
+        PageHelper.startPage(page, size);
         return userMapper.getUserBought(buyerId);
     }
 
     @Override
-    public List<Goods> getUserSold(String sellerId) {
+    public List<Goods> getUserSold(String sellerId, int page, int size) {
+        PageHelper.startPage(page, size);
         return userMapper.getUserSold(sellerId);
 
     }
 
     @Override
-    public List<Goods> getUserPosted(String userId) {
+    public List<Goods> getUserPosted(String userId, int page, int size) {
+        PageHelper.startPage(page, size);
         return userMapper.getUserPosted(userId);
     }
 

+ 1 - 1
wx-front/app.json

@@ -44,7 +44,7 @@
     "navigationBarBackgroundColor": "#fff",
     "navigationBarTitleText": "仿闲鱼交易平台",
     "navigationBarTextStyle": "black",
-    "enablePullDownRefresh": true
+    "enablePullDownRefresh": false
   },
   "tabBar": {
     "backgroundColor": "#fafafa",

+ 35 - 16
wx-front/pages/category/category.js

@@ -12,9 +12,9 @@ Page({
     scrollTop: 0,
     scrollHeight: 0,
     page: 1,
-    size: 10000
+    size: 10
   },
-  onLoad: function (options) {
+  onLoad: function(options) {
     // 页面初始化 options为页面跳转所带来的参数
     var that = this;
     if (options.id) {
@@ -24,7 +24,7 @@ Page({
     }
 
     wx.getSystemInfo({
-      success: function (res) {
+      success: function(res) {
         that.setData({
           scrollHeight: res.windowHeight
         });
@@ -35,10 +35,10 @@ Page({
     this.getCategoryInfo();
 
   },
-  getCategoryInfo: function () {
+  getCategoryInfo: function() {
     let that = this;
     util.request(api.GoodsCategory + "/" + this.data.id)
-      .then(function (res) {
+      .then(function(res) {
 
         if (res.errno == 0) {
           that.setData({
@@ -65,33 +65,36 @@ Page({
         } else {
           //显示错误信息
         }
-        
+
       });
   },
-  onReady: function () {
+  onReady: function() {
     // 页面渲染完成
   },
-  onShow: function () {
+  onShow: function() {
     // 页面显示
     console.log(1);
   },
-  onHide: function () {
+  onHide: function() {
     // 页面隐藏
   },
-  getGoodsList: function () {
+  getGoodsList: function() {
     var that = this;
 
-    util.request(api.GoodsList + "/" + that.data.id, { page: that.data.page, size: that.data.size})
-      .then(function (res) {
+    util.request(api.GoodsList + "/" + that.data.id, {
+        page: that.data.page,
+        size: that.data.size
+      })
+      .then(function(res) {
         that.setData({
-          goodsList: res.data,
+          goodsList: that.data.goodsList.concat(res.data),
         });
       });
   },
-  onUnload: function () {
+  onUnload: function() {
     // 页面关闭
   },
-  switchCate: function (event) {
+  switchCate: function(event) {
     if (this.data.id == event.currentTarget.dataset.id) {
       return false;
     }
@@ -112,5 +115,21 @@ Page({
     });
 
     this.getGoodsList();
-  }
+  },
+  onPullDownRefresh: function() {
+    console.log("上拉刷新")
+    this.onLoad()
+    setTimeout(function callback() {
+      wx.stopPullDownRefresh()
+    }, 500)
+
+
+  },
+  onReachBottom: function() {
+    console.log("拉到底")
+    this.setData({
+      page: this.data.page + 1
+    })
+    this.getGoodsList()
+  },
 })

+ 3 - 1
wx-front/pages/category/category.json

@@ -1 +1,3 @@
-{}
+{
+  "enablePullDownRefresh": true
+}

+ 14 - 2
wx-front/pages/goods/goods.js

@@ -28,6 +28,8 @@ Page({
     replyId: '',
     replyUserId: '',
     replyUserName: '',
+    page: 1,
+    size: 10,
     commentContent: '',
     onLoadOption: {},
     noCollectImage: "/static/images/detail_star.png",
@@ -77,10 +79,13 @@ Page({
   },
   getGoodsRelated: function() {
     let that = this;
-    util.request(api.GoodsRelated + '/' + that.data.id, ).then(function(res) {
+    util.request(api.GoodsRelated + '/' + that.data.id, {
+      page: this.data.page,
+      size: this.data.size
+    }).then(function(res) {
       if (res.errno === 0) {
         that.setData({
-          relatedGoods: res.data,
+          relatedGoods: that.data.relatedGoods.concat(res.data)
         });
       }
     });
@@ -405,4 +410,11 @@ Page({
   //     number: this.data.number + 1
   //   });
   // }
+  onReachBottom: function() {
+    console.log("拉到底")
+    this.setData({
+      page: this.data.page + 1
+    })
+    this.getGoodsRelated()
+  },
 })

+ 44 - 10
wx-front/pages/index/index.js

@@ -8,7 +8,9 @@ Page({
   data: {
     banner: [],
     channel: [],
-    indexGoods: []
+    indexGoods: [],
+    page: 1,
+    size: 10,
     // newGoods: [],
     // hotGoods: [],
     // topics: [],
@@ -17,7 +19,7 @@ Page({
     // banner: [],
     // channel: []
   },
-  onShareAppMessage: function () {
+  onShareAppMessage: function() {
     return {
       title: '古早交易平台',
       desc: '一款开源仿闲鱼交易平台!',
@@ -25,9 +27,9 @@ Page({
     }
   },
 
-  getIndexData: function () {
+  getIndexData: function() {
     let that = this;
-    util.request(api.IndexUrl).then(function (res) {
+    util.request(api.IndexUrl).then(function(res) {
       console.log(res.data)
       // console.log(res.data.hotGoodsList)
       // console.log(res.data.categoryList)
@@ -45,19 +47,51 @@ Page({
       }
     });
   },
-  onLoad: function (options) {
+  getIndexMore: function() {
+    let that = this;
+    util.request(api.IndexMore, {
+      page: this.data.page,
+      size: this.data.size
+    }).then(function(res) {
+      console.log(res.data)
+      if (res.errno === 0) {
+        that.setData({
+          indexGoods: that.data.indexGoods.concat(res.data),
+        });
+      }
+    });
+  },
+  onLoad: function(options) {
     this.getIndexData();
+
   },
-  onReady: function () {
+  onReady: function() {
     // 页面渲染完成
   },
-  onShow: function () {
+  onShow: function() {
     // 页面显示
   },
-  onHide: function () {
+  onHide: function() {
     // 页面隐藏
   },
-  onUnload: function () {
+  onUnload: function() {
     // 页面关闭
   },
-})
+
+  onPullDownRefresh: function() {
+    console.log("上拉刷新")
+    this.onLoad()
+    setTimeout(function callback() {
+      wx.stopPullDownRefresh()
+    }, 500)
+
+
+  },
+  onReachBottom: function() {
+    console.log("拉到底")
+    this.setData({
+      page: this.data.page + 1
+    })
+    this.getIndexMore()
+  },
+})

+ 3 - 1
wx-front/pages/index/index.json

@@ -1 +1,3 @@
-{}
+{
+  "enablePullDownRefresh": true
+}

+ 43 - 21
wx-front/pages/search/search.js

@@ -16,28 +16,28 @@ Page({
     defaultKeyword: '输入关键字',
     hotKeyword: [],
     page: 1,
-    size: 20,
+    size: 10,
     // currentSortType: 'id',
     // currentSortOrder: 'desc',
     // categoryId: 0
   },
   //事件处理函数
-  closeSearch: function () {
+  closeSearch: function() {
     wx.navigateBack()
   },
-  clearKeyword: function () {
+  clearKeyword: function() {
     this.setData({
       keyword: '',
       searchStatus: false
     });
   },
-  onLoad: function () {
+  onLoad: function() {
     this.getSearchKeyword();
   },
 
   getSearchKeyword() {
     let that = this;
-    util.request(api.SearchIndex).then(function (res) {
+    util.request(api.SearchIndex).then(function(res) {
       if (res.errno === 0) {
         that.setData({
           historyKeyword: res.data.historyKeywordList,
@@ -47,7 +47,7 @@ Page({
     });
   },
 
-  inputChange: function (e) {
+  inputChange: function(e) {
 
     this.setData({
       keyword: e.detail.value,
@@ -55,18 +55,21 @@ Page({
     });
     this.getHelpKeyword();
   },
-  getHelpKeyword: function () {
+  getHelpKeyword: function() {
     let that = this;
     // 'https://suggest.taobao.com/sug?code=utf-8&q=a'
-    util.request('https://suggest.taobao.com/sug', { code: 'utf-8', q: that.data.keyword }).then(function (res) {
-      
-        that.setData({
-          helpKeyword: res.result
-        });
-      
+    util.request('https://suggest.taobao.com/sug', {
+      code: 'utf-8',
+      q: that.data.keyword
+    }).then(function(res) {
+
+      that.setData({
+        helpKeyword: res.result
+      });
+
     });
   },
-  inputFocus: function () {
+  inputFocus: function() {
     this.setData({
       searchStatus: false,
       goodsList: []
@@ -76,25 +79,28 @@ Page({
       this.getHelpKeyword();
     }
   },
-  clearHistory: function () {
+  clearHistory: function() {
     let that = this;
     this.setData({
       historyKeyword: []
     })
 
     util.request(api.SearchClearHistory)
-      .then(function (res) {
+      .then(function(res) {
         console.log('清除成功');
       });
   },
-  getGoodsList: function () {
+  getGoodsList: function() {
     let that = this;
-    util.request(api.SearchResult + '/' + that.data.keyword).then(function (res) {
+    util.request(api.SearchResult + '/' + that.data.keyword, {
+      page: this.data.page,
+      size: this.data.size
+    }).then(function(res) {
       if (res.errno === 0) {
         that.setData({
           searchStatus: true,
           categoryFilter: false,
-          goodsList: res.data,
+          goodsList: that.data.goodsList.concat(res.data),
           // page: res.data.currentPage,
           // size: res.data.numsPerPage
         });
@@ -104,7 +110,7 @@ Page({
       that.getSearchKeyword();
     });
   },
-  onKeywordTap: function (event) {
+  onKeywordTap: function(event) {
 
     this.getSearchResult(event.target.dataset.keyword);
 
@@ -174,5 +180,21 @@ Page({
   // },
   onKeywordConfirm(event) {
     this.getSearchResult(event.detail.value);
-  }
+  },
+  onPullDownRefresh: function() {
+    console.log("上拉刷新")
+    this.onLoad()
+    setTimeout(function callback() {
+      wx.stopPullDownRefresh()
+    }, 500)
+
+
+  },
+  onReachBottom: function() {
+    console.log("拉到底")
+    this.setData({
+      page: this.data.page + 1
+    })
+    this.getGoodsList()
+  },
 })

+ 2 - 1
wx-front/pages/search/search.json

@@ -1,3 +1,4 @@
 {
-  "navigationBarTitleText": "商品搜索"
+  "navigationBarTitleText": "商品搜索",
+  "enablePullDownRefresh": true
 }

+ 1 - 1
wx-front/pages/search/search.wxss

@@ -229,7 +229,7 @@ page{
 }
 
 .cate-item{
-    margin-top: 175rpx;
+    margin-top: 100rpx;
     height: auto;
     overflow: hidden;
 }

+ 1 - 1
wx-front/pages/ucenter/about/about.wxml

@@ -9,7 +9,7 @@
 </text>
   <image class="i" src="../../../static/images/qr.jpg" mode="aspectFit"></image>
   <text class='txt'>
-另外,我还写过很多好玩有趣的项目托管在Github上。
+另外,我还写过很多有趣的项目托管在Github上。
 今后打算专注写框架和中间件之类的,也会把平时学到的一些原理知识推到Github和博客,如果能给个Follow,我会非常开心。
 
 </text>

+ 23 - 11
wx-front/pages/ucenter/bought/bought.js

@@ -5,41 +5,53 @@ var app = getApp();
 
 Page({
   data: {
-    boughtList: []
+    boughtList: [],
+    page: 1,
+    size: 10
   },
   getBoughtList() {
     let that = this;
-    util.request(api.BoughtList).then(function (res) {
+    util.request(api.BoughtList, {
+      page: this.data.page,
+      size: this.data.size
+    }).then(function(res) {
       if (res.errno === 0) {
         console.log(res.data);
         that.setData({
-          boughtList: res.data
+          boughtList: that.data.boughtList.concat(res.data),
         });
       }
     });
   },
-  onLoad: function (options) {
+  onLoad: function(options) {
     this.getBoughtList();
   },
-  onReady: function () {
+  onReady: function() {
 
   },
-  onShow: function () {
+  onShow: function() {
 
   },
-  onHide: function () {
+  onHide: function() {
     // 页面隐藏
 
   },
-  onUnload: function () {
+  onUnload: function() {
     // 页面关闭
   },
   openGoods(event) {
     let goodsId = this.data.boughtList[event.currentTarget.dataset.index].id;
 
-      wx.navigateTo({
-        url: '/pages/goods/goods?id=' + goodsId,
-      });
+    wx.navigateTo({
+      url: '/pages/goods/goods?id=' + goodsId,
+    });
+  },
+  onReachBottom: function() {
+    console.log("拉到底")
+    this.setData({
+      page: this.data.page + 1
+    })
+    this.getBoughtList()
   },
 
 })

+ 1 - 1
wx-front/pages/ucenter/bought/bought.wxml

@@ -1,7 +1,7 @@
 <view class="container">
   <view class="collect-list" wx:if='{{boughtList.length}}'>
     <view class="item" bindtap="openGoods" wx:for="{{boughtList}}" wx:key="{{item.id}}" data-index="{{index}}">
-      <image class="img" src="{{item.primaryPicUrl}}"></image>
+      <image class="img" src="{{item.primaryPicUrl}}" mode='aspectFill'></image>
       <view class="info">
         <view class="name">{{item.name}}</view>
         <view class="flex">

+ 15 - 3
wx-front/pages/ucenter/collect/collect.js

@@ -5,15 +5,20 @@ var app = getApp();
 
 Page({
   data: {
-    collectList: []
+    collectList: [],
+    page: 1,
+    size: 10
   },
   getCollectList() {
     let that = this;
-    util.request(api.CollectList).then(function (res) {
+    util.request(api.CollectList, {
+      page: this.data.page,
+      size: this.data.size
+    }).then(function (res) {
       if (res.errno === 0) {
         console.log(res.data);
         that.setData({
-          collectList: res.data
+          collectList: that.data.collectList.concat(res.data),
         });
       }
     });
@@ -88,4 +93,11 @@ Page({
     })
     console.log(e.timeStamp + '- touch-end')
   }, 
+  onReachBottom: function () {
+    console.log("拉到底")
+    this.setData({
+      page: this.data.page + 1
+    })
+    this.getCollectList()
+  },
 })

+ 1 - 1
wx-front/pages/ucenter/collect/collect.wxml

@@ -1,7 +1,7 @@
 <view class="container">
   <view class="collect-list" wx:if='{{collectList.length}}'>
     <view class="item" bindtap="openGoods" bindtouchstart="touchStart" bindtouchend="touchEnd" wx:for="{{collectList}}" wx:key="{{item.id}}" data-index="{{index}}">
-      <image class="img" src="{{item.primaryPicUrl}}"></image>
+      <image class="img" src="{{item.primaryPicUrl}}" mode='aspectFill'></image>
       <view class="info">
         <view class="name">{{item.name}}</view>
         <view class="flex">

+ 15 - 3
wx-front/pages/ucenter/posted/posted.js

@@ -5,15 +5,20 @@ var app = getApp();
 
 Page({
   data: {
-    postedList: []
+    postedList: [],
+    page: 1,
+    size: 10
   },
   getPostedList() {
     let that = this;
-    util.request(api.PostedList).then(function (res) {
+    util.request(api.PostedList, {
+      page: this.data.page,
+      size: this.data.size
+    }).then(function (res) {
       if (res.errno === 0) {
         console.log(res.data);
         that.setData({
-          postedList: res.data
+          postedList: that.data.postedList.concat(res.data),
         });
       }
     });
@@ -41,5 +46,12 @@ Page({
       url: '/pages/goods/goods?id=' + goodsId,
     });
   },
+  onReachBottom: function () {
+    console.log("拉到底")
+    this.setData({
+      page: this.data.page + 1
+    })
+    this.getPostedList()
+  },
 
 })

+ 1 - 1
wx-front/pages/ucenter/posted/posted.wxml

@@ -1,7 +1,7 @@
 <view class="container">
   <view class="collect-list" wx:if='{{postedList.length}}'>
     <view class="item" bindtap="openGoods" wx:for="{{postedList}}" wx:key="{{item.id}}" data-index="{{index}}">
-      <image class="img" src="{{item.primaryPicUrl}}"></image>
+      <image class="img" src="{{item.primaryPicUrl}}" mode='aspectFill'></image>
       <view class="info">
         <view class="name">{{item.name}}</view>
         <view class="flex">

+ 15 - 3
wx-front/pages/ucenter/sold/sold.js

@@ -5,15 +5,20 @@ var app = getApp();
 
 Page({
   data: {
-    soldList: []
+    soldList: [],
+    page: 1,
+    size: 10
   },
   getSoldList() {
     let that = this;
-    util.request(api.SoldList).then(function (res) {
+    util.request(api.SoldList, {
+      page: this.data.page,
+      size: this.data.size
+    }).then(function (res) {
       if (res.errno === 0) {
         console.log(res.data);
         that.setData({
-          soldList: res.data
+          soldList: that.data.soldList.concat(res.data),
         });
       }
     });
@@ -41,5 +46,12 @@ Page({
       url: '/pages/goods/goods?id=' + goodsId,
     });
   },
+  onReachBottom: function () {
+    console.log("拉到底")
+    this.setData({
+      page: this.data.page + 1
+    })
+    this.getSoldList()
+  },
 
 })

+ 1 - 1
wx-front/pages/ucenter/sold/sold.wxml

@@ -1,7 +1,7 @@
 <view class="container">
   <view class="collect-list" wx:if='{{soldList.length}}'>
     <view class="item" bindtap="openGoods" wx:for="{{soldList}}" wx:key="{{item.id}}" data-index="{{index}}">
-      <image class="img" src="{{item.primaryPicUrl}}"></image>
+      <image class="img" src="{{item.primaryPicUrl}}" mode='aspectFill'></image>
       <view class="info">
         <view class="name">{{item.name}}</view>
         <view class="flex">