Commit 7fbc07bf by 姜雷

添加反馈数据切片

parent 5138e9e0
......@@ -15,6 +15,8 @@ Page({
list1: [],
list2: [],
areaList: [],
list: [],
pageNum: [null, 0, 0],
},
initData() {
this.fetchList(1);
......@@ -23,10 +25,9 @@ Page({
toggleList(e) {
const { tabindex } = e.currentTarget.dataset;
if (tabindex !== this.data.tabIndex) {
this.setData!({
tabIndex: tabindex,
this.setData!({ tabIndex: tabindex }, () => {
this.fetchList(tabindex);
});
this.fetchList(tabindex);
}
},
fetchList(state?: number) {
......@@ -44,8 +45,15 @@ Page({
.then(res => {
wx.hideLoading();
const list = res.data;
let viewList = list.slice(0, 10);
if (state === this.data.tabIndex) {
this.setData!({
list: viewList,
});
}
this.setData!({
['list' + state]: list,
[`pageNum[${state}]`]: 0,
});
})
.catch(err => {
......@@ -90,4 +98,24 @@ Page({
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 @@
<text class="feedback-tabCount">{{list2.length}}</text>
</view>
</view>
<view wx:if="{{tabIndex===1}}" class="feedback-list">
<feedback-item wx:for="{{list1}}" wx:key="{{item.id}}" feedback-data="{{item}}" bind:refresh="refreshHandle" />
</view>
<view wx:elif="{{tabIndex===2}}" class="feedback-list">
<feedback-item wx:for="{{list2}}" wx:key="{{item.id}}" feedback-data="{{item}}" bind:refresh="refreshHandle" />
</view>
<scroll-view wx:if="{{tabIndex===1}}" class="feedback-list" scroll-y bindscrolltolower="getMoreListItem">
<feedback-item wx:for="{{list}}" wx:key="{{item.id}}" feedback-data="{{item}}" bind:refresh="refreshHandle" />
</scroll-view>
<scroll-view wx:elif="{{tabIndex===2}}" class="feedback-list" scroll-y bindscrolltolower="getMoreListItem">
<feedback-item wx:for="{{list}}" wx:key="{{item.id}}" feedback-data="{{item}}" bind:refresh="refreshHandle" />
</scroll-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