ENewspaperListDialog.ets 3.78 KB
import { NewspaperListBean, NewspaperListItemBean, NewspaperPositionItemBean } from 'wdBean'

@CustomDialog
export struct ENewspaperListDialog {
  @State currentPageNum: string = '01'
  controller: CustomDialogController
  newspaperListBean: NewspaperListBean = {} as NewspaperListBean

  build() {
    Column() {
      Row() {
        Text(this.currentPageNum)
          .fontSize($r('app.float.font_size_36'))
          .fontColor($r('app.color.color_222222'))
        Text('版')
          .fontSize($r('app.float.font_size_16'))
          .fontColor($r('app.color.color_222222'))
          .margin({ bottom: 6 })

        Image($r('app.media.icon_triangle_black'))
          .width($r('app.float.border_radius_6'))
          .height($r('app.float.border_radius_6'))
          .margin({ left: 2, bottom: 6 })
      }
      .alignItems(VerticalAlign.Bottom)
      .margin({ top: 25, left: 15 })
      .alignSelf(ItemAlign.Start)

      Image($r('app.media.line'))
        .width('100%')
        .height(6)
        .margin({ top: 20, left: 16, right: 16 })
        .objectFit(ImageFit.Contain)

      List() {
        ForEach(this.newspaperListBean?.list, (item: NewspaperListItemBean, index: number) => {
          ForEach(item.items, (positionItem: NewspaperPositionItemBean, itemIndex: number) => {
            ListItem() {
              Column(){
                if (itemIndex == 0) {
                  Text(item.pageNum + item.pageName)
                    .fontSize($r('app.float.font_size_14'))
                    .fontColor($r('app.color.color_ED2800'))
                    .margin({ top: 16 })
                    .maxLines(1)
                }

                if (positionItem.shortTitle) {
                  Text(positionItem.shortTitle)
                    .fontSize($r('app.float.font_size_14'))
                    .fontColor($r('app.color.color_222222'))
                    .margin({ top: 16 })
                    .maxLines(2)
                }

                if (positionItem.title) {
                  Text(positionItem.title)
                    .fontSize($r('app.float.font_size_17'))
                    .fontColor($r('app.color.color_222222'))
                    .margin({ top: 16 })
                    .maxLines(2)
                }

                if (positionItem.downTitle) {
                  Text(positionItem.downTitle)
                    .fontSize($r('app.float.font_size_14'))
                    .fontColor($r('app.color.color_222222'))
                    .margin({ top: 16 })
                    .maxLines(2)
                }

                if (positionItem.newsTxt) {
                  Text(positionItem.newsTxt)
                    .fontSize($r('app.float.font_size_14'))
                    .fontColor($r('app.color.color_999999'))
                    .margin({ top: 16, bottom: 16 })
                    .maxLines(5)
                }
              }
              .alignItems(HorizontalAlign.Start)
            }

          })

        })

      }
      .width('100%')
      .margin({ top: 16, left: 16, right: 16 })
      .scrollBar(BarState.Off)
      .divider({
        strokeWidth: 1,
        color: '#EDEDED'
      })
      .onScrollIndex((firstIndex: number) => {
        this.updateCurrentPageNum(firstIndex)
      })

    }
    .width('100%')
    .height(674)
    .backgroundColor(Color.White)

  }

  updateCurrentPageNum(firstIndex: number): void {
    if (this.newspaperListBean.list && this.newspaperListBean.list.length > 0) {
      let index = 0;
      for (let itemBean of this.newspaperListBean.list) {
        if (itemBean.items && itemBean.items.length > 0){
          for (let item of itemBean.items){
            index++
            if (index == firstIndex){
              this.currentPageNum = itemBean.pageNum
              return
            }

          }
        }
      }
    }

   }
}