1.HTML
<view class="content_box1" v-for="(item,index) in historyData" :key="item.id">
<view class="line">
</view>
<u-cell-group>
<u-cell :title="item.userName" :value="item.status == 0?'未审核':'已审核'"></u-cell>
<u-cell title="品类" :value="item.goodsTypeName"></u-cell>
<u-cell title="净重(kg)" :value="item.weight"></u-cell>
<u-cell title="单价(元/kg)" :value="item.unitPrice"></u-cell>
<u-cell title="总价(元)" :value="item.finalPrice"></u-cell>
<u-cell title="交易状态" :value="item.pay == 0?'未支付':'已支付'"></u-cell>
<u-cell title="交易时间" :value="item.createTime | formatDate"></u-cell>
</u-cell-group>
</view>
<u-loadmore :status="status" :iconSize="17" v-if="historyData.length" />
2.data数据
data() {
return {
//需要加载的数据必须要触碰到每一页的底部才会加载数据
status: 'loadmore',
page: 1,
limit: 5,
userId: '',
dataType: 'day',
userInfo: '',
dayData: '',
monthData: '',
historyData: '',
suo: true
}
},
3.此处有两个方法,一个是第一次请求数据,第二个是上拉加载请求数据
// 历史,第一次请求全部列表
orderHistoryData() {
let that = this
that.dataType = 'history'
uni.showLoading({
title: '加载中...',
mask: true
});
uni.request({
url: `http://wx.cunkou.co/api/wx/orderList`,
method: 'GET',
data: {
page: that.page,
limit: that.limit,
userId: that.userId,
dataType: that.dataType
},
success: res => {
uni.hideLoading();
if (res.data.code == 0) {
that.historyData = res.data.data.list
if (res.data.data.list.length == '') {
this.status = 'nomore';
this.suo = false
} else if (res.data.data.list.length < 5) {
this.status = 'nomore';
this.suo = false
} else if (res.data.data.list.length = 5) {
this.status = 'loadmore';
this.suo = true
}
} else {
uni.showToast({
title: res.data.message,
icon: 'none',
duration: 2000
})
}
}
})
},
// 历史,上拉
orderHistoryDataCon() {
let that = this
that.dataType = 'history'
uni.showLoading({
title: '加载中...',
mask: true
});
uni.request({
url: `http://wx.cunkou.co/api/wx/orderList`,
method: 'GET',
data: {
page: that.page,
limit: that.limit,
userId: that.userId,
dataType: that.dataType
},
success: res => {
uni.hideLoading();
if (res.data.code == 0) {
this.historyData = this.historyData.concat(res.data.data.list)
if (res.data.data.list.length == '') {
this.status = 'nomore';
this.suo = false
} else if (res.data.data.list.length < 5) {
this.status = 'nomore';
this.suo = false
} else if (res.data.data.list.length = 5) {
this.status = 'loadmore';
this.suo = true
}
} else {
uni.showToast({
title: res.data.message,
icon: 'none',
duration: 2000
})
}
}
})
},
4.定义个小锁,当没有数据时锁住
onReachBottom() {
if (this.suo) { //定义个小锁,当没有数据时锁住suo
this.status = 'loading';
this.page = ++this.page;
if (this.isActive == 1) {
setTimeout(() => {
this.orderDayDataCon()
}, 1000)
}
if (this.isActive == 2) {
setTimeout(() => {
this.orderMonthDataCon()
}, 1000)
}
if (this.isActive == 3) {
setTimeout(() => {
this.orderHistoryDataCon()
}, 1000)
}
}
}