CardAdvThreeImageComponent.ets 2.82 KB
//全标题 "appStyle":"2",
import { CompDTO } from 'wdBean';
import { CommonConstants } from 'wdConstant/Index';
import { ProcessUtils } from 'wdRouter';
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import PageModel from '../../viewmodel/PageModel';
import { CardAdvBottom } from './CardAdvBottom';

const TAG: string = 'Card2Component';

/**
 * @Description: 广告---三图卡
 * @Author:
 * @Email: liyubing@wondertek.com.cn
 * @CreateDate:
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Component
export struct CardAdvThreeImageComponent {
  @State compDTO: CompDTO = {} as CompDTO
  @State loadImg: boolean = false;
  pageModel: PageModel = new PageModel();

  async aboutToAppear(): Promise<void> {
    this.loadImg = await onlyWifiLoadImg();
  }

  aboutToDisappear(): void {

  }

  build() {
    Column() {
      //body
      Column() {
        //新闻标题
        Text(this.compDTO.matInfo.advTitle)
          .fontSize($r('app.float.font_size_18'))
          .fontColor($r('app.color.color_222222'))
          .maxLines(3)
          .textOverflow({ overflow: TextOverflow.Ellipsis }) // 超出的部分显示省略号。
        //三图
        Row() {
          GridRow({ gutter: 2 }) {
            ForEach(this.compDTO.matInfo.matImageUrl, (url: string, index: number) => {
              if (index < 3) {
                GridCol({ span: { xs: 4 } }) {
                  Image(this.loadImg ? url : '')
                    .backgroundColor(this.loadImg ? $r('app.color.color_B0B0B0') : 0xf5f5f5)
                    .width('100%')
                    .aspectRatio(113 / 75)
                    .borderRadius({
                      topLeft: index === 0 ? $r('app.float.image_border_radius') : 0,
                      topRight: index === 2 ? $r('app.float.image_border_radius') : 0,
                      bottomLeft: index === 0 ? $r('app.float.image_border_radius') : 0,
                      bottomRight: index === 2 ? $r('app.float.image_border_radius') : 0,
                    })
                    .borderColor($r('app.color.color_0D000000'))
                }
              }
            })
          }
        }
        .width(CommonConstants.FULL_PARENT)
        .margin({ top: 8 })

        //  广告工具组件
        CardAdvBottom({ pageModel: this.pageModel, compDTO: this.compDTO }).width('100%').margin({ top: 8 })
      }
      .width('100%')
      .justifyContent(FlexAlign.Start)
      .alignItems(HorizontalAlign.Start)
      .onClick((event: ClickEvent) => {
        ProcessUtils.openAdvDetail(this.compDTO.matInfo)
      })

    }
    .width(CommonConstants.FULL_WIDTH)
    .padding({
      left: 10,
      right: 10,
      top: $r('app.float.card_comp_pagePadding_tb'),
      bottom: $r('app.float.card_comp_pagePadding_tb')
    })
  }
}

@Extend(Text)
function bottomTextStyle() {
  .fontSize(12)
  .fontColor('#B0B0B0')
}