yangsunyue_wd

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

@@ -8,6 +8,10 @@ import { MyCommentDataSource } from '../model/MyCommentDataSource' @@ -8,6 +8,10 @@ import { MyCommentDataSource } from '../model/MyCommentDataSource'
8 import { HttpUtils } from 'wdNetwork/src/main/ets/utils/HttpUtils' 8 import { HttpUtils } from 'wdNetwork/src/main/ets/utils/HttpUtils'
9 import { HttpUrlUtils } from 'wdNetwork/Index' 9 import { HttpUrlUtils } from 'wdNetwork/Index'
10 import PageModel from '../../../viewmodel/PageModel' 10 import PageModel from '../../../viewmodel/PageModel'
  11 +import { ErrorComponent } from '../../view/ErrorComponent'
  12 +import { EmptyComponent , WDViewDefaultType} from '../../view/EmptyComponent'
  13 +import { CustomPullToRefresh } from '../../reusable/CustomPullToRefresh'
  14 +import NoMoreLayout from '../../page/NoMoreLayout'
11 15
12 const TAG = 'QualityCommentsComponent'; 16 const TAG = 'QualityCommentsComponent';
13 17
@@ -16,8 +20,13 @@ const TAG = 'QualityCommentsComponent'; @@ -16,8 +20,13 @@ const TAG = 'QualityCommentsComponent';
16 @Component 20 @Component
17 export struct QualityCommentsComponent { 21 export struct QualityCommentsComponent {
18 22
19 - @State private browSingModel: PageModel = new PageModel()  
20 - isloading : boolean = false 23 + //刷新
  24 + @State viewType:number = ViewType.LOADING;
  25 + @State hasMore: boolean = true;
  26 + @State currentPage: number = 1;
  27 + private scroller: Scroller = new Scroller();
  28 +
  29 +
21 30
22 @State tileOpacity: number = 0; 31 @State tileOpacity: number = 0;
23 firstPositionY: number = 0; 32 firstPositionY: number = 0;
@@ -25,7 +34,7 @@ export struct QualityCommentsComponent { @@ -25,7 +34,7 @@ export struct QualityCommentsComponent {
25 topSafeHeight: number = AppStorage.get<number>('topSafeHeight') as number; 34 topSafeHeight: number = AppStorage.get<number>('topSafeHeight') as number;
26 lastWindowColor: string = '#ffffff' 35 lastWindowColor: string = '#ffffff'
27 currentWindowColor: string = '#FF4202' 36 currentWindowColor: string = '#FF4202'
28 - @State allDatas: MyCommentDataSource = new MyCommentDataSource(); 37 + @State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource();
29 38
30 aboutToDisappear(): void { 39 aboutToDisappear(): void {
31 40
@@ -40,14 +49,31 @@ export struct QualityCommentsComponent { @@ -40,14 +49,31 @@ export struct QualityCommentsComponent {
40 aboutToAppear(): void { 49 aboutToAppear(): void {
41 50
42 this.fullScreen(); 51 this.fullScreen();
  52 + this.getData();
  53 +
  54 + }
  55 +
  56 + getData(resolve?: (value: string | PromiseLike<string>) => void){
  57 + commentViewModel.fetchQualityCommentList(this.currentPage + '').then((commentListModel) => {
  58 + if(resolve) resolve('刷新成功')
43 59
44 - commentViewModel.fetchQualityCommentList('1').then((commentListModel) => {  
45 if (commentListModel && commentListModel.list && commentListModel.list.length > 0) { 60 if (commentListModel && commentListModel.list && commentListModel.list.length > 0) {
  61 + if (this.currentPage === 1) {
  62 + this.allDatas.clear()
  63 + }
46 commentListModel.list.forEach(element => { 64 commentListModel.list.forEach(element => {
47 - this.allDatas.pushData(commentViewModel.deepCopyCommentItemModel(element)) 65 + this.allDatas.push(commentViewModel.deepCopyCommentItemModel(element))
48 }); 66 });
49 - } else {  
50 67
  68 + if (commentListModel.hasNext === 0) {
  69 + this.hasMore = false;
  70 + } else {
  71 + this.hasMore = true;
  72 + }
  73 + } else {
  74 + if (this.currentPage === 1) {
  75 + this.viewType = ViewType.EMPTY;
  76 + }
51 } 77 }
52 }) 78 })
53 } 79 }
@@ -151,20 +177,77 @@ export struct QualityCommentsComponent { @@ -151,20 +177,77 @@ export struct QualityCommentsComponent {
151 177
152 build() { 178 build() {
153 Column() { 179 Column() {
  180 +
  181 +
154 Stack({ alignContent: Alignment.Top }) { 182 Stack({ alignContent: Alignment.Top }) {
155 183
156 Scroll() { 184 Scroll() {
157 Column() { 185 Column() {
158 Stack() { 186 Stack() {
159 this.titleHeader() 187 this.titleHeader()
  188 + this.listLayout()
  189 +
  190 + // if(this.viewType == ViewType.ERROR){
  191 + // ErrorComponent()
  192 + // }else if(this.viewType == ViewType.EMPTY){
  193 + // EmptyComponent({emptyType:WDViewDefaultType.WDViewDefaultType_NoComment})
  194 + // }else {
  195 + // CustomPullToRefresh({
  196 + // alldata:[],
  197 + // scroller:this.scroller,
  198 + // customList:()=>{
  199 + // // this.listLayout()
  200 + // this.testLayout()
  201 + // },
  202 + // onRefresh:(resolve)=>{
  203 + // this.currentPage = 1
  204 + // this.getData(resolve)
  205 + // },
  206 + // onLoadMore:(resolve)=> {
  207 + // if (this.hasMore === false) {
  208 + // if(resolve) resolve('')
  209 + // return
  210 + // }
  211 + // this.currentPage++
  212 + // this.getData(resolve)
  213 + // }
  214 + // })
  215 + // }
160 216
161 - List({ space: 12 }) { 217 +
  218 +
  219 +
  220 + }.alignContent(Alignment.Top)
  221 + }.backgroundColor(this.currentWindowColor).width('100%')
  222 + }
  223 + .friction(0.6)
  224 + .scrollBar(BarState.Off)
  225 + .edgeEffect(EdgeEffect.None)
  226 + .width('100%')
  227 + .height('100%')
  228 +
  229 + this.TabbarTransparent()
  230 + this.TabbarNormal()
  231 +
  232 + }
  233 +
  234 + }
  235 +
  236 + }
  237 +
  238 + @Builder
  239 + listLayout(){
  240 + List({ space: 12, scroller:this.scroller }) {
162 // ListItemGroup({ header: this.titleHeader() }) 241 // ListItemGroup({ header: this.titleHeader() })
163 LazyForEach(this.allDatas, (item: commentItemModel, index: number) => { 242 LazyForEach(this.allDatas, (item: commentItemModel, index: number) => {
164 ListItem() { 243 ListItem() {
165 QualityCommentItem({ item: item, index: index }).margin({ left: 12, right: 12 }) 244 QualityCommentItem({ item: item, index: index }).margin({ left: 12, right: 12 })
166 } 245 }
167 }) 246 })
  247 + // 加载更多
  248 + ListItem() {
  249 + if (this.hasMore === false) NoMoreLayout()
  250 + }
168 ListItem() { 251 ListItem() {
169 252
170 }.height(this.bottomSafeHeight) 253 }.height(this.bottomSafeHeight)
@@ -172,36 +255,31 @@ export struct QualityCommentsComponent { @@ -172,36 +255,31 @@ export struct QualityCommentsComponent {
172 .margin({ top: 196 }) 255 .margin({ top: 196 })
173 .height("100%") 256 .height("100%")
174 .width("100%") 257 .width("100%")
175 - .edgeEffect(EdgeEffect.Spring) 258 + .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
  259 + // .edgeEffect(EdgeEffect.Spring)
176 .nestedScroll({ 260 .nestedScroll({
177 scrollForward: NestedScrollMode.PARENT_FIRST, 261 scrollForward: NestedScrollMode.PARENT_FIRST,
178 scrollBackward: NestedScrollMode.SELF_FIRST 262 scrollBackward: NestedScrollMode.SELF_FIRST
179 }) 263 })
180 -  
181 - // .margin({ bottom: this.bottomSafeHeight })  
182 -  
183 - // .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM])  
184 - }.alignContent(Alignment.Top)  
185 - }.backgroundColor(this.currentWindowColor).width('100%')  
186 } 264 }
187 - .friction(0.6)  
188 - .scrollBar(BarState.Off)  
189 - .edgeEffect(EdgeEffect.None)  
190 - .width('100%')  
191 - .height('100%')  
192 -  
193 - this.TabbarTransparent()  
194 - this.TabbarNormal()  
195 265
196 266
  267 + @Builder
  268 + testLayout(){
  269 + List({ space: 12, scroller:this.scroller }){
  270 + LazyForEach(this.allDatas, (item: commentItemModel, index: number) => {
  271 + ListItem() {
  272 + // QualityCommentItem({ item: item, index: index }).margin({ left: 12, right: 12 })
197 } 273 }
198 - 274 + })
199 } 275 }
200 -  
201 } 276 }
  277 +
202 } 278 }
203 279
204 280
  281 +
  282 +
205 @Component 283 @Component
206 struct QualityCommentItem { 284 struct QualityCommentItem {
207 @ObjectLink item: commentItemModel 285 @ObjectLink item: commentItemModel
@@ -316,10 +394,10 @@ struct QualityCommentItem { @@ -316,10 +394,10 @@ struct QualityCommentItem {
316 .margin({ left: 3 }) 394 .margin({ left: 3 })
317 } 395 }
318 }.onClick(() => { 396 }.onClick(() => {
319 - commentViewModel.commnetLikeChange(this.item) 397 + commentLikeChange(this.item)
320 commentViewModel.commentLike(this.item).then(() => { 398 commentViewModel.commentLike(this.item).then(() => {
321 }).catch(() => { 399 }).catch(() => {
322 - commentViewModel.commnetLikeChange(this.item) 400 + commentLikeChange(this.item)
323 }) 401 })
324 }) 402 })
325 } 403 }
@@ -331,5 +409,24 @@ struct QualityCommentItem { @@ -331,5 +409,24 @@ struct QualityCommentItem {
331 } 409 }
332 } 410 }
333 411
  412 +function commentLikeChange(item: commentItemModel) {
  413 + item.api_status = !item.api_status
  414 + //点赞
  415 + if (item.api_status) {
  416 + if (item.likeNum.length > 0) {
  417 + item.likeNum = (Number.parseInt(item.likeNum) + 1) + ''
  418 + } else {
  419 + item.likeNum = '1'
  420 + }
  421 + }
  422 + //取消点赞
  423 + if (!item.api_status) {
  424 + item.likeNum = (Number.parseInt(item.likeNum) - 1) + ''
  425 + if (Number.parseInt(item.likeNum) <= 0) {
  426 + item.likeNum = ''
  427 + }
  428 + }
  429 +}
  430 +
334 431
335 432