Commit 7fbc07bf by 姜雷

添加反馈数据切片

parent 5138e9e0
...@@ -15,6 +15,8 @@ Page({ ...@@ -15,6 +15,8 @@ Page({
list1: [], list1: [],
list2: [], list2: [],
areaList: [], areaList: [],
list: [],
pageNum: [null, 0, 0],
}, },
initData() { initData() {
this.fetchList(1); this.fetchList(1);
...@@ -23,10 +25,9 @@ Page({ ...@@ -23,10 +25,9 @@ Page({
toggleList(e) { toggleList(e) {
const { tabindex } = e.currentTarget.dataset; const { tabindex } = e.currentTarget.dataset;
if (tabindex !== this.data.tabIndex) { if (tabindex !== this.data.tabIndex) {
this.setData!({ this.setData!({ tabIndex: tabindex }, () => {
tabIndex: tabindex,
});
this.fetchList(tabindex); this.fetchList(tabindex);
});
} }
}, },
fetchList(state?: number) { fetchList(state?: number) {
...@@ -44,8 +45,15 @@ Page({ ...@@ -44,8 +45,15 @@ Page({
.then(res => { .then(res => {
wx.hideLoading(); wx.hideLoading();
const list = res.data; const list = res.data;
let viewList = list.slice(0, 10);
if (state === this.data.tabIndex) {
this.setData!({
list: viewList,
});
}
this.setData!({ this.setData!({
['list' + state]: list, ['list' + state]: list,
[`pageNum[${state}]`]: 0,
}); });
}) })
.catch(err => { .catch(err => {
...@@ -90,4 +98,24 @@ Page({ ...@@ -90,4 +98,24 @@ Page({
console.log(err); console.log(err);
}); });
}, },
getMoreListItem() {
let state = this.data.tabIndex;
let index = this.data.pageNum[state] + 1;
let max = Math.ceil(this.data['list' + state].length / 10);
console.log('in getMoreListItem', index, max);
if (index >= max) {
wx.showToast({
title: '没有更多数据',
icon: 'none',
});
} else {
this.setData({
[`pageNum[${state}]`]: index,
list: [
...this.data.list,
...this.data['list' + state].slice(index * 10, (index + 1) * 10),
],
});
}
},
}); });
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
<text class="feedback-tabCount">{{list2.length}}</text> <text class="feedback-tabCount">{{list2.length}}</text>
</view> </view>
</view> </view>
<view wx:if="{{tabIndex===1}}" class="feedback-list"> <scroll-view wx:if="{{tabIndex===1}}" class="feedback-list" scroll-y bindscrolltolower="getMoreListItem">
<feedback-item wx:for="{{list1}}" wx:key="{{item.id}}" feedback-data="{{item}}" bind:refresh="refreshHandle" /> <feedback-item wx:for="{{list}}" wx:key="{{item.id}}" feedback-data="{{item}}" bind:refresh="refreshHandle" />
</view> </scroll-view>
<view wx:elif="{{tabIndex===2}}" class="feedback-list"> <scroll-view wx:elif="{{tabIndex===2}}" class="feedback-list" scroll-y bindscrolltolower="getMoreListItem">
<feedback-item wx:for="{{list2}}" wx:key="{{item.id}}" feedback-data="{{item}}" bind:refresh="refreshHandle" /> <feedback-item wx:for="{{list}}" wx:key="{{item.id}}" feedback-data="{{item}}" bind:refresh="refreshHandle" />
</view> </scroll-view>
</view> </view>
\ No newline at end of file
Markdown is supported
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