yuminge-app/yun-min-program-plugin-master/packageA/member/order/cpsOrder/cpsOrder.js

93 lines
1.8 KiB
JavaScript

// packageA/member/order/cpsOrder/cpsOrder.js
const app = getApp();
Page({
data: {
activeName: 0,
isCoupon: false,
page: 1,
finished: false,
orderList: [],
},
onLoad: function (options) {
if(options.status) {
this.setData({
activeName: Number(options.status)
});
}
this.getData();
},
onShow: function () {
},
switchTab (event) {
this.initGetData();
this.setData({
activeName: event.detail.name
});
this.getData();
},
getData () {
if (this.data.finished) return;
let baseUrl = app.getNetAddresss("plugin.aggregation-cps.api.order.index");
app._getNetWork({
url: baseUrl,
data: {
status: this.data.activeName,
page: this.data.page
},
success: (respone) => {
if (respone.data.result !== 1) {
wx.showToast({
title: respone.data.msg,
});
return false;
}
let res = respone.data.data;
let finished = false;
let orderList = [];
if (this.data.page >= res.last_page || (!res.data) || res.data.length < res.per_page) {
finished = true;
}
if (this.data.page > 1) {
orderList = this.data.orderList.concat(res.data);
} else {
orderList = res.data;
}
this.setData({
finished,
orderList,
page: ++this.data.page
});
}
});
},
initGetData () {
this.setData({
page: 1,
finished: false,
});
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.initGetData();
this.getData();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
if (this.data.finished) return;
this.getData();
},
});