yangsunyue_wd

desc:评论列表界面、评论弹窗

... ... @@ -8,6 +8,10 @@ import { MyCommentDataSource } from '../model/MyCommentDataSource'
import { HttpUtils } from 'wdNetwork/src/main/ets/utils/HttpUtils'
import { HttpUrlUtils } from 'wdNetwork/Index'
import PageModel from '../../../viewmodel/PageModel'
import { ErrorComponent } from '../../view/ErrorComponent'
import { EmptyComponent , WDViewDefaultType} from '../../view/EmptyComponent'
import { CustomPullToRefresh } from '../../reusable/CustomPullToRefresh'
import NoMoreLayout from '../../page/NoMoreLayout'
const TAG = 'QualityCommentsComponent';
... ... @@ -16,8 +20,13 @@ const TAG = 'QualityCommentsComponent';
@Component
export struct QualityCommentsComponent {
@State private browSingModel: PageModel = new PageModel()
isloading : boolean = false
//刷新
@State viewType:number = ViewType.LOADING;
@State hasMore: boolean = true;
@State currentPage: number = 1;
private scroller: Scroller = new Scroller();
@State tileOpacity: number = 0;
firstPositionY: number = 0;
... ... @@ -25,7 +34,7 @@ export struct QualityCommentsComponent {
topSafeHeight: number = AppStorage.get<number>('topSafeHeight') as number;
lastWindowColor: string = '#ffffff'
currentWindowColor: string = '#FF4202'
@State allDatas: MyCommentDataSource = new MyCommentDataSource();
@State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource();
aboutToDisappear(): void {
... ... @@ -40,14 +49,31 @@ export struct QualityCommentsComponent {
aboutToAppear(): void {
this.fullScreen();
this.getData();
}
getData(resolve?: (value: string | PromiseLike<string>) => void){
commentViewModel.fetchQualityCommentList(this.currentPage + '').then((commentListModel) => {
if(resolve) resolve('刷新成功')
commentViewModel.fetchQualityCommentList('1').then((commentListModel) => {
if (commentListModel && commentListModel.list && commentListModel.list.length > 0) {
if (this.currentPage === 1) {
this.allDatas.clear()
}
commentListModel.list.forEach(element => {
this.allDatas.pushData(commentViewModel.deepCopyCommentItemModel(element))
this.allDatas.push(commentViewModel.deepCopyCommentItemModel(element))
});
} else {
if (commentListModel.hasNext === 0) {
this.hasMore = false;
} else {
this.hasMore = true;
}
} else {
if (this.currentPage === 1) {
this.viewType = ViewType.EMPTY;
}
}
})
}
... ... @@ -151,36 +177,46 @@ export struct QualityCommentsComponent {
build() {
Column() {
Stack({ alignContent: Alignment.Top }) {
Scroll() {
Column() {
Stack() {
this.titleHeader()
this.listLayout()
// if(this.viewType == ViewType.ERROR){
// ErrorComponent()
// }else if(this.viewType == ViewType.EMPTY){
// EmptyComponent({emptyType:WDViewDefaultType.WDViewDefaultType_NoComment})
// }else {
// CustomPullToRefresh({
// alldata:[],
// scroller:this.scroller,
// customList:()=>{
// // this.listLayout()
// this.testLayout()
// },
// onRefresh:(resolve)=>{
// this.currentPage = 1
// this.getData(resolve)
// },
// onLoadMore:(resolve)=> {
// if (this.hasMore === false) {
// if(resolve) resolve('')
// return
// }
// this.currentPage++
// this.getData(resolve)
// }
// })
// }
List({ space: 12 }) {
// ListItemGroup({ header: this.titleHeader() })
LazyForEach(this.allDatas, (item: commentItemModel, index: number) => {
ListItem() {
QualityCommentItem({ item: item, index: index }).margin({ left: 12, right: 12 })
}
})
ListItem() {
}.height(this.bottomSafeHeight)
}
.margin({ top: 196 })
.height("100%")
.width("100%")
.edgeEffect(EdgeEffect.Spring)
.nestedScroll({
scrollForward: NestedScrollMode.PARENT_FIRST,
scrollBackward: NestedScrollMode.SELF_FIRST
})
// .margin({ bottom: this.bottomSafeHeight })
// .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM])
}.alignContent(Alignment.Top)
}.backgroundColor(this.currentWindowColor).width('100%')
}
... ... @@ -193,15 +229,57 @@ export struct QualityCommentsComponent {
this.TabbarTransparent()
this.TabbarNormal()
}
}
}
@Builder
listLayout(){
List({ space: 12, scroller:this.scroller }) {
// ListItemGroup({ header: this.titleHeader() })
LazyForEach(this.allDatas, (item: commentItemModel, index: number) => {
ListItem() {
QualityCommentItem({ item: item, index: index }).margin({ left: 12, right: 12 })
}
})
// 加载更多
ListItem() {
if (this.hasMore === false) NoMoreLayout()
}
ListItem() {
}.height(this.bottomSafeHeight)
}
.margin({ top: 196 })
.height("100%")
.width("100%")
.edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
// .edgeEffect(EdgeEffect.Spring)
.nestedScroll({
scrollForward: NestedScrollMode.PARENT_FIRST,
scrollBackward: NestedScrollMode.SELF_FIRST
})
}
@Builder
testLayout(){
List({ space: 12, scroller:this.scroller }){
LazyForEach(this.allDatas, (item: commentItemModel, index: number) => {
ListItem() {
// QualityCommentItem({ item: item, index: index }).margin({ left: 12, right: 12 })
}
})
}
}
}
@Component
struct QualityCommentItem {
@ObjectLink item: commentItemModel
... ... @@ -316,10 +394,10 @@ struct QualityCommentItem {
.margin({ left: 3 })
}
}.onClick(() => {
commentViewModel.commnetLikeChange(this.item)
commentLikeChange(this.item)
commentViewModel.commentLike(this.item).then(() => {
}).catch(() => {
commentViewModel.commnetLikeChange(this.item)
commentLikeChange(this.item)
})
})
}
... ... @@ -331,5 +409,24 @@ struct QualityCommentItem {
}
}
function commentLikeChange(item: commentItemModel) {
item.api_status = !item.api_status
//点赞
if (item.api_status) {
if (item.likeNum.length > 0) {
item.likeNum = (Number.parseInt(item.likeNum) + 1) + ''
} else {
item.likeNum = '1'
}
}
//取消点赞
if (!item.api_status) {
item.likeNum = (Number.parseInt(item.likeNum) - 1) + ''
if (Number.parseInt(item.likeNum) <= 0) {
item.likeNum = ''
}
}
}
... ...