yangsunyue_wd

desc:评论列表加载更多

... ... @@ -10,6 +10,7 @@ import { CommentCustomDialog } from './CommentCustomDialog'
import { publishCommentModel } from '../model/PublishCommentModel';
import { ifaa } from '@kit.OnlineAuthenticationKit';
import { HttpUrlUtils } from 'wdNetwork/Index';
import NoMoreLayout from '../../page/NoMoreLayout';
const TAG = 'CommentComponent';
... ... @@ -19,6 +20,8 @@ const testString = '因为读书的人\n是低着头向上看的人\n身处一
@Preview
@Component
export struct CommentComponent {
@State hasMore: boolean = true;
@State currentPage: number = 1;
// @State private browSingModel: commentListModel = new commentListModel()
/*必传*/
@ObjectLink publishCommentModel: publishCommentModel
... ... @@ -167,7 +170,19 @@ export struct CommentComponent {
}
}
}, (item: commentItemModel, index: number) => JSON.stringify(item) + index.toString())
// 加载更多
ListItem() {
if (this.hasMore === false) NoMoreLayout()
}
}
.onReachEnd(()=>{
if (this.hasMore) {
this.getData()
}
})
.enableScrollInteraction(false)
}
... ... @@ -175,10 +190,22 @@ export struct CommentComponent {
//获取数据
async getData() {
commentViewModel.fetchContentCommentList('1', this.publishCommentModel.targetId, this.publishCommentModel.targetType)
commentViewModel.fetchContentCommentList(this.currentPage + '', this.publishCommentModel.targetId, this.publishCommentModel.targetType)
.then(commentListModel => {
this.publishCommentModel.totalCommentNumer = commentListModel.totalCount + ''
this.currentPage++
if (Number.parseInt(commentListModel.totalCommentNum) > Number.parseInt(this.publishCommentModel.totalCommentNumer)) {
this.publishCommentModel.totalCommentNumer = commentListModel.totalCommentNum + ''
}
if (commentListModel.hasNext === 0) {
this.hasMore = false;
} else {
this.hasMore = true;
}
if (commentListModel && commentListModel.list && commentListModel.list.length > 0) {
commentListModel.list.forEach(element => {
element.hasMore = Number.parseInt(element.childCommentNum) ? true : false
let newModel = commentViewModel.deepCopyCommentItemModel(element)
... ... @@ -189,6 +216,8 @@ export struct CommentComponent {
});
}else{
this.hasMore = false
}
})
... ...