Commit baceacea authored by Junling Bu's avatar Junling Bu
Browse files

fix: 小商城的订单列表支持分页

parent 5b04fa44
...@@ -69,7 +69,7 @@ public class LitemallOrderService { ...@@ -69,7 +69,7 @@ public class LitemallOrderService {
return orderSn; return orderSn;
} }
public List<LitemallOrder> queryByOrderStatus(Integer userId, List<Short> orderStatus) { public List<LitemallOrder> queryByOrderStatus(Integer userId, List<Short> orderStatus, Integer page, Integer size) {
LitemallOrderExample example = new LitemallOrderExample(); LitemallOrderExample example = new LitemallOrderExample();
example.setOrderByClause(LitemallOrder.Column.addTime.desc()); example.setOrderByClause(LitemallOrder.Column.addTime.desc());
LitemallOrderExample.Criteria criteria = example.or(); LitemallOrderExample.Criteria criteria = example.or();
...@@ -78,20 +78,10 @@ public class LitemallOrderService { ...@@ -78,20 +78,10 @@ public class LitemallOrderService {
criteria.andOrderStatusIn(orderStatus); criteria.andOrderStatusIn(orderStatus);
} }
criteria.andDeletedEqualTo(false); criteria.andDeletedEqualTo(false);
PageHelper.startPage(page, size);
return litemallOrderMapper.selectByExample(example); return litemallOrderMapper.selectByExample(example);
} }
public int countByOrderStatus(Integer userId, List<Short> 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<LitemallOrder> querySelective(Integer userId, String orderSn, List<Short> orderStatusArray, Integer page, Integer size, String sort, String order) { public List<LitemallOrder> querySelective(Integer userId, String orderSn, List<Short> orderStatusArray, Integer page, Integer size, String sort, String order) {
LitemallOrderExample example = new LitemallOrderExample(); LitemallOrderExample example = new LitemallOrderExample();
LitemallOrderExample.Criteria criteria = example.createCriteria(); LitemallOrderExample.Criteria criteria = example.createCriteria();
......
...@@ -7,6 +7,7 @@ import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; ...@@ -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.bean.result.BaseWxPayResult;
import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.WxPayService; import com.github.binarywang.wxpay.service.WxPayService;
import com.github.pagehelper.PageInfo;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
...@@ -135,8 +136,9 @@ public class WxOrderService { ...@@ -135,8 +136,9 @@ public class WxOrderService {
} }
List<Short> orderStatus = OrderUtil.orderStatus(showType); List<Short> orderStatus = OrderUtil.orderStatus(showType);
List<LitemallOrder> orderList = orderService.queryByOrderStatus(userId, orderStatus); List<LitemallOrder> orderList = orderService.queryByOrderStatus(userId, orderStatus, page, size);
int count = orderService.countByOrderStatus(userId, orderStatus); long count = PageInfo.of(orderList).getTotal();
int totalPages = (int) Math.ceil((double) count / size);
List<Map<String, Object>> orderVoList = new ArrayList<>(orderList.size()); List<Map<String, Object>> orderVoList = new ArrayList<>(orderList.size());
for (LitemallOrder order : orderList) { for (LitemallOrder order : orderList) {
...@@ -172,6 +174,7 @@ public class WxOrderService { ...@@ -172,6 +174,7 @@ public class WxOrderService {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
result.put("count", count); result.put("count", count);
result.put("data", orderVoList); result.put("data", orderVoList);
result.put("totalPages", totalPages);
return ResponseUtil.ok(result); return ResponseUtil.ok(result);
} }
......
...@@ -4,7 +4,10 @@ var api = require('../../../config/api.js'); ...@@ -4,7 +4,10 @@ var api = require('../../../config/api.js');
Page({ Page({
data: { data: {
orderList: [], orderList: [],
showType: 0 showType: 0,
page: 1,
size: 10,
totalPages: 1
}, },
onLoad: function(options) { onLoad: function(options) {
// 页面初始化 options为页面跳转所带来的参数 // 页面初始化 options为页面跳转所带来的参数
...@@ -29,20 +32,42 @@ Page({ ...@@ -29,20 +32,42 @@ Page({
getOrderList() { getOrderList() {
let that = this; let that = this;
util.request(api.OrderList, { util.request(api.OrderList, {
showType: that.data.showType showType: that.data.showType,
page: that.data.page,
size: that.data.size
}).then(function(res) { }).then(function(res) {
if (res.errno === 0) { if (res.errno === 0) {
console.log(res.data); console.log(res.data);
that.setData({ 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) { switchTab: function(event) {
let showType = event.currentTarget.dataset.index; let showType = event.currentTarget.dataset.index;
this.setData({ this.setData({
showType: showType orderList: [],
showType: showType,
page: 1,
size: 10,
totalPages: 1
}); });
this.getOrderList(); this.getOrderList();
}, },
......
...@@ -4,7 +4,10 @@ var api = require('../../../config/api.js'); ...@@ -4,7 +4,10 @@ var api = require('../../../config/api.js');
Page({ Page({
data: { data: {
orderList: [], orderList: [],
showType: 0 showType: 0,
page: 1,
size: 10,
totalPages: 1
}, },
onLoad: function(options) { onLoad: function(options) {
// 页面初始化 options为页面跳转所带来的参数 // 页面初始化 options为页面跳转所带来的参数
...@@ -28,20 +31,42 @@ Page({ ...@@ -28,20 +31,42 @@ Page({
let that = this; let that = this;
util.request(api.OrderList, { util.request(api.OrderList, {
showType: that.data.showType showType: that.data.showType,
page: that.data.page,
size: that.data.size
}).then(function(res) { }).then(function(res) {
if (res.errno === 0) { if (res.errno === 0) {
that.setData({ that.setData({
orderList: res.data.data orderList: that.data.orderList.concat(res.data.data),
totalPages: res.data.totalPages
}); });
wx.hideLoading(); 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) { switchTab: function(event) {
let showType = event.currentTarget.dataset.index; let showType = event.currentTarget.dataset.index;
this.setData({ this.setData({
showType: showType orderList: [],
showType: showType,
page: 1,
size: 10,
totalPages: 1
}); });
this.getOrderList(); this.getOrderList();
}, },
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment