ZhSingleRow06.ets 7.54 KB
import { commentInfo, CompDTO, ContentDTO, Params } from 'wdBean';
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import { HttpUtils } from 'wdNetwork/Index';
import { postInteractAccentionOperateParams } from 'wdBean';
import { PageRepository } from '../../repository/PageRepository';
import { DateTimeUtils } from 'wdKit/Index';
import { ProcessUtils } from 'wdRouter';

/**
 * 精选评论卡
 * Zh_Single_Row-06
 */
const TAG = 'Zh_Single_Row-06'

// interface commentInfo {
//   commentTitle: string,
//   newsTitle: string,
//   userName: string,
//   userHeaderUrl: string,
//   publishTime: number
// }
// interface operDataListItem {
//   commentInfo: commentInfo
// }
// interface CommentData{
//   operDataList: Array<operDataListItem>
// }

@Entry
@Component
export struct ZhSingleRow06 {
  @State compDTO: CompDTO = {} as CompDTO
  @State likeBl: boolean = false;

  build() {
    Column() {
      //顶部
      if (this.compDTO.operDataList?.length > 0) {
        this.CompHeader(this.compDTO)
      }

      Column(){
        Text(this.compDTO.operDataList[0]?.commentInfo?.commentTitle)
          .maxLines(4)
          .textOverflow({overflow: TextOverflow.Ellipsis})
          .lineHeight(23)
          .fontSize(16)
          .margin({bottom: 10})
          .padding({bottom: 10})
          .textAlign(TextAlign.Start)
          .width('100%')
          .border({width: {bottom: 1}})
          .borderColor(0xf4f4f4)


        Row() {
          Image($r('app.media.icon_clip'))
            .width(16)
            .height(16)
            .margin({right: 5})
          Text(this.compDTO.operDataList[0]?.commentInfo?.newsTitle)
            .maxLines(1)
            .textOverflow({overflow: TextOverflow.Ellipsis})
            .fontSize(14)
            .fontColor(0x666666)
        }
        .justifyContent(FlexAlign.Start)
        .width('100%')
      }
      .width("100%")
      .padding({top: 12, bottom: 12, left: 10, right: 10})
      .backgroundColor(0xf9f9f9)
      .borderRadius(4)
      .margin({bottom: 12})
      .onClick(() => {
        ProcessUtils.commentGotoWeb(this.compDTO.operDataList[0]?.commentInfo as commentInfo)
      })

      Row() {
        Text(DateTimeUtils.getCommentTime(this.compDTO.operDataList[0]?.commentInfo?.publishTime))
          .fontSize(14)
          .fontColor(0x999999)

        Row(){
          Image(this.likeBl ? $r('app.media.icon_like_select') : $r('app.media.icon_like'))
            .width(16)
            .height(16)
            .margin({right: 3})

          Text('点赞')
            .fontSize(14)
            .fontColor(0x999999)
        }
        .onClick(() => {
          if (this.likeBl) {
            this.likeBl = false;
          } else {
            this.likeBl = true;
          }
        })
      }
      .justifyContent(FlexAlign.SpaceBetween)
      .width('100%')
    }
    .padding({
      left: $r('app.float.card_comp_pagePadding_lf'),
      right: $r('app.float.card_comp_pagePadding_lf'),
      top: $r('app.float.card_comp_pagePadding_tb'),
      bottom: $r('app.float.card_comp_pagePadding_tb')
    })
    .backgroundColor($r('app.color.white'))
  }

  @Builder
  CompHeader(item: CompDTO) {
    Row() {
      Row() {
        Image(item.operDataList[0]?.commentInfo?.userHeaderUrl ? item.operDataList[0].commentInfo.userHeaderUrl : $r('app.media.default_head'))
          .width(32)
          .height(32)
          .borderRadius(16)
          .margin({right: 8})
        Text(item.operDataList[0]?.commentInfo?.userName)
          .lineHeight(32)
          .fontSize(14)
          .fontColor(0x222222)
          .maxLines(1)
          .textOverflow({overflow: TextOverflow.Ellipsis})
      }
      .onClick(() => {
        ProcessUtils.commentGotoWeb(item.operDataList[0]?.commentInfo as commentInfo)
      })

      Row() {
        Image($r("app.media.icon_elite_comment"))
          .width(45)
          .height(22)
          .margin({ right: 1 })
        Image($r("app.media.more"))
          .width(14)
          .height(14)
      }
      .onClick(() => {
        WDRouterRule.jumpWithPage(WDRouterPage.QualityCommentsPage)
      })
    }
    .margin({bottom: 10})
    .justifyContent(FlexAlign.SpaceBetween)
    .width('100%')
  }
}

@Extend(Text)
function textOverflowStyle(maxLine: number) {
  .maxLines(maxLine)
  .textOverflow({ overflow: TextOverflow.Ellipsis })
}

@Component
struct CreatorItem {
  @Prop item: ContentDTO
  @State rmhIsAttention: number = 0
  build() {
    ListItem() {
      Column() {
        Flex({direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceBetween}) {
          Column() {
            Row() {
              Image('')
                .width(20)
                .height(20)
                .margin({right: 4})
                .border({width: 1, color: 0xcccccc, radius: 10})
              Text('立志之间')
                .fontColor(0x212228)
                .fontSize(12)
            }
          }

          Column() {
            Row() {
              Image($r('app.media.icon_like_no'))
                .width(16)
                .height(16)
                .margin({right: 4})
              Text('3835')
                .fontSize(14)
                .fontColor(0x999999)
            }
          }
        }
        .margin({top: 10, left: 10, right: 10, bottom: 8})

        Text('就业不仅是民生问题,也是发展问题,就业不仅是民生问题,也是发展问题,就业不仅是民生问题,也是发展问题,')
          .maxLines(2)
          .textOverflow({overflow: TextOverflow.Ellipsis})
          .margin({left: 10, right: 10, bottom: 8})
          .fontSize(17)
          .fontColor(0x212228)
          .lineHeight(25)

        Row() {
          Image('')
            .width(66)
            .height(44)
            .borderRadius({topLeft: 3, topRight: 0, bottomLeft: 3, bottomRight: 0})
          Text('原文|强化就业优先政策 健全就业促进机制原文|强化就业优先政策 健全就业促进机制原文|强化就业优先政策 健全就业促进机制')
            .margin({left: 8})
            .width(172)
            .maxLines(2)
            .textOverflow({overflow: TextOverflow.Ellipsis})
        }
        .linearGradient({
          direction: GradientDirection.Right,
          colors: [[0xffffff, 0.0],[0xffffff, 0.8], [0xf9f9f9, 1.0]]
        })
      }
      .width(276)
      .height(150)
      .margin({ right: 10 })
      .borderWidth(1)
      .borderColor($r('app.color.color_EDEDED'))
      .borderRadius($r('app.float.image_border_radius'))
      .backgroundColor(0xf9f9f9)
    }
    .onClick(() => {
      console.log('跳转到rmh');
    })
  }

  /**
   * 关注号主 TODO 这里后面需要抽离
   */
  handleAccention(item: ContentDTO, status: number) {
    this.rmhIsAttention = this.rmhIsAttention ? 0 : 1
    return
    // 未登录,跳转登录
    if (!HttpUtils.getUserId()) {
      WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
      return
    }

    const params: postInteractAccentionOperateParams = {
      attentionUserType: item.rmhInfo?.userType || '', //被关注用户类型(1 普通用户 2 视频号 3 矩阵号)
      attentionUserId: item.rmhInfo?.userId || '', // 被关注用户号主id
      attentionCreatorId: item.rmhInfo?.rmhId || '', // 被关注用户号主id
      // userType: 1,
      // userId: '1', // TODO 用户id需要从本地获取
      status: status,
    }
    PageRepository.postInteractAccentionOperate(params).then(res => {
      console.log(TAG, '关注号主==', JSON.stringify(res.data))
      if (status === 1) {
        this.rmhIsAttention = 0
      } else {
        this.rmhIsAttention = 1
      }
    })
  }
}