From baceaceac6a55edd7171a212268d48752cd85aee Mon Sep 17 00:00:00 2001 From: Junling Bu Date: Thu, 7 Mar 2019 21:20:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=8F=E5=95=86=E5=9F=8E=E7=9A=84?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=88=97=E8=A1=A8=E6=94=AF=E6=8C=81=E5=88=86?= =?UTF-8?q?=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db/service/LitemallOrderService.java | 14 ++------ .../litemall/wx/service/WxOrderService.java | 7 ++-- litemall-wx/pages/ucenter/order/order.js | 33 ++++++++++++++++--- renard-wx/pages/ucenter/order/order.js | 33 ++++++++++++++++--- 4 files changed, 65 insertions(+), 22 deletions(-) diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderService.java index 100826eb..34b70b41 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallOrderService.java @@ -69,7 +69,7 @@ public class LitemallOrderService { return orderSn; } - public List queryByOrderStatus(Integer userId, List orderStatus) { + public List queryByOrderStatus(Integer userId, List orderStatus, Integer page, Integer size) { LitemallOrderExample example = new LitemallOrderExample(); example.setOrderByClause(LitemallOrder.Column.addTime.desc()); LitemallOrderExample.Criteria criteria = example.or(); @@ -78,20 +78,10 @@ public class LitemallOrderService { criteria.andOrderStatusIn(orderStatus); } criteria.andDeletedEqualTo(false); + PageHelper.startPage(page, size); return litemallOrderMapper.selectByExample(example); } - public int countByOrderStatus(Integer userId, List orderStatus) { - LitemallOrderExample example = new LitemallOrderExample(); - LitemallOrderExample.Criteria criteria = example.or(); - criteria.andUserIdEqualTo(userId); - if (orderStatus != null) { - criteria.andOrderStatusIn(orderStatus); - } - criteria.andDeletedEqualTo(false); - return (int) litemallOrderMapper.countByExample(example); - } - public List querySelective(Integer userId, String orderSn, List orderStatusArray, Integer page, Integer size, String sort, String order) { LitemallOrderExample example = new LitemallOrderExample(); LitemallOrderExample.Criteria criteria = example.createCriteria(); diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/WxOrderService.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/WxOrderService.java index 60260440..18406917 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/WxOrderService.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/service/WxOrderService.java @@ -7,6 +7,7 @@ import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; +import com.github.pagehelper.PageInfo; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -135,8 +136,9 @@ public class WxOrderService { } List orderStatus = OrderUtil.orderStatus(showType); - List orderList = orderService.queryByOrderStatus(userId, orderStatus); - int count = orderService.countByOrderStatus(userId, orderStatus); + List orderList = orderService.queryByOrderStatus(userId, orderStatus, page, size); + long count = PageInfo.of(orderList).getTotal(); + int totalPages = (int) Math.ceil((double) count / size); List> orderVoList = new ArrayList<>(orderList.size()); for (LitemallOrder order : orderList) { @@ -172,6 +174,7 @@ public class WxOrderService { Map result = new HashMap<>(); result.put("count", count); result.put("data", orderVoList); + result.put("totalPages", totalPages); return ResponseUtil.ok(result); } diff --git a/litemall-wx/pages/ucenter/order/order.js b/litemall-wx/pages/ucenter/order/order.js index 8351766b..e5b3481c 100644 --- a/litemall-wx/pages/ucenter/order/order.js +++ b/litemall-wx/pages/ucenter/order/order.js @@ -4,7 +4,10 @@ var api = require('../../../config/api.js'); Page({ data: { orderList: [], - showType: 0 + showType: 0, + page: 1, + size: 10, + totalPages: 1 }, onLoad: function(options) { // 页面初始化 options为页面跳转所带来的参数 @@ -29,20 +32,42 @@ Page({ getOrderList() { let that = this; util.request(api.OrderList, { - showType: that.data.showType + showType: that.data.showType, + page: that.data.page, + size: that.data.size }).then(function(res) { if (res.errno === 0) { console.log(res.data); that.setData({ - orderList: res.data.data + orderList: that.data.orderList.concat(res.data.data), + totalPages: res.data.totalPages }); } }); }, + onReachBottom() { + if (this.data.totalPages > this.data.page) { + this.setData({ + page: this.data.page + 1 + }); + this.getOrderList(); + } else { + wx.showToast({ + title: '没有更多订单了', + icon: 'none', + duration: 2000 + }); + return false; + } + }, switchTab: function(event) { let showType = event.currentTarget.dataset.index; this.setData({ - showType: showType + orderList: [], + showType: showType, + page: 1, + size: 10, + totalPages: 1 }); this.getOrderList(); }, diff --git a/renard-wx/pages/ucenter/order/order.js b/renard-wx/pages/ucenter/order/order.js index 014dc22d..1b693554 100644 --- a/renard-wx/pages/ucenter/order/order.js +++ b/renard-wx/pages/ucenter/order/order.js @@ -4,7 +4,10 @@ var api = require('../../../config/api.js'); Page({ data: { orderList: [], - showType: 0 + showType: 0, + page: 1, + size: 10, + totalPages: 1 }, onLoad: function(options) { // 页面初始化 options为页面跳转所带来的参数 @@ -28,20 +31,42 @@ Page({ let that = this; util.request(api.OrderList, { - showType: that.data.showType + showType: that.data.showType, + page: that.data.page, + size: that.data.size }).then(function(res) { if (res.errno === 0) { that.setData({ - orderList: res.data.data + orderList: that.data.orderList.concat(res.data.data), + totalPages: res.data.totalPages }); wx.hideLoading(); } }); }, + onReachBottom() { + if (this.data.totalPages > this.data.page) { + this.setData({ + page: this.data.page + 1 + }); + this.getOrderList(); + } else { + wx.showToast({ + title: '没有更多订单了', + icon: 'none', + duration: 2000 + }); + return false; + } + }, switchTab: function(event) { let showType = event.currentTarget.dataset.index; this.setData({ - showType: showType + orderList: [], + showType: showType, + page: 1, + size: 10, + totalPages: 1 }); this.getOrderList(); },