LiveFollowComponent.ets 4.26 KB
/**
 * 直播详情 关注相关信息
 */
import {
  ContentDetailRequest,
  postInteractAccentionOperateParams
} from 'wdDetailPlayApi/src/main/ets/request/ContentDetailRequest';
import { ContentDetailDTO, Params, postBatchAttentionStatusParams, RmhInfoDTO } from 'wdBean/Index';
import { SpConstants } from 'wdConstant/Index';
import { Logger, SPHelper, ToastUtils } from 'wdKit/Index';
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import { MultiPictureDetailViewModel } from '../../viewmodel/MultiPictureDetailViewModel';

const TAG = 'LiveFollowComponent'

@Component
export struct LiveFollowComponent {
  @Prop rmhInfo: RmhInfoDTO
  @Consume contentDetailData: ContentDetailDTO
  @Consume @Watch('getBatchAttentionStatus') pageShow: number

  aboutToAppear(): void {
    this.getBatchAttentionStatus()
  }

  /**
   * 默认未关注 点击去关注
   */
  @State followStatus: String = '0';

  build() {
    Stack() {
      Stack()
        .height(22)
        .width(150)
        .backgroundColor('#000000')
        .opacity(0.3)
        .borderRadius({
          topLeft: 90,
          bottomLeft: 90
        })
      Row() {
        Image(this.rmhInfo.rmhHeadUrl)
          .width(24)
          .height(24)
          .borderRadius(90)
          .onClick(() => {
            // 跳转到号主页
            if (this.contentDetailData.rmhInfo?.cnMainControl === 1) {
              const params: Params = {
                creatorId: this.contentDetailData.rmhInfo.rmhId,
                pageID: ''
              }
              WDRouterRule.jumpWithPage(WDRouterPage.peopleShipHomePage, params)
            }
          })
        Text(this.rmhInfo.rmhName)
          .fontColor(Color.White)
          .maxLines(1)
          .fontWeight(500)
          .fontSize('12fp')
          .layoutWeight(1)
          .margin({
            left: 4,
            right: 6
          })
        Blank()
        Text(this.followStatus === '0' ? '关注' : '已关注')
          .fontColor(Color.White)
          .fontWeight(500)
          .fontSize('10fp')
          .padding({
            left: 8,
            right: 8,
            top: 3,
            bottom: 3
          })
          .borderRadius(2)
          .margin({ right: 2 })
          .backgroundColor(this.followStatus === '0' ? $r('app.color.color_ED2800') : $r('app.color.color_CCCCCC'))
          .visibility(this.followStatus === '0' ? Visibility.Visible : Visibility.None)
          .onClick(() => {
            this.handleAccention()
          })
      }
      .height(22)
      .width(150)
    }
  }

  /**
   * 查询当前登录用户是否关注作品号主
   * */
  private async getBatchAttentionStatus() {
    try {
      const params: postBatchAttentionStatusParams = {
        creatorIds: [{ creatorId: this.rmhInfo?.rmhId ?? '' }]
      }
      let data = await MultiPictureDetailViewModel.getBatchAttentionStatus(params)
      this.followStatus = data[0]?.status;
      Logger.info(TAG, `followStatus:${JSON.stringify(this.followStatus)}`)
    } catch (exception) {

    }
  }

  /**
   * 关注号主
   */
  async handleAccention() {
    // 未登录,跳转登录
    const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
    if (!user_id) {
      WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
      return
    }

    const params2: postInteractAccentionOperateParams = {
      attentionUserType: this.rmhInfo?.userType || '', //被关注用户类型(1 普通用户 2 视频号 3 矩阵号)
      attentionUserId: this.rmhInfo?.userId || '', // 被关注用户号主id
      attentionCreatorId: this.rmhInfo?.rmhId || '', // 被关注用户号主id
      status: this.followStatus == '0' ? 1 : 0,
    }
    ContentDetailRequest.postInteractAccentionOperate(params2).then(res => {
      console.log('关注号主==', JSON.stringify(res.data))
      if (this.followStatus == '1') {
        this.followStatus = '0'
      } else {
        this.followStatus = '1'
        // 弹窗样式与何时调用待确认
        ContentDetailRequest.postPointLevelOperate({ operateType: 6 }).then((res) => {
          console.log('关注号主获取积分==', JSON.stringify(res.data))
          if (res.data?.showToast) {
            ToastUtils.showToast(res.data.ruleName + '+' + res.data.rulePoint + '积分', 1000);
          }
        })
      }
    })
  }
}