PeopleShipHomePage.ets 5.45 KB
import router from '@ohos.router'
import { PeopleShipHomePageNavComponent } from '../peopleShipHomePage/PeopleShipHomeNavComponent'
import { PeopleShipHomePageTopComponent } from '../peopleShipHomePage/PeopleShipHomePageTopComponent'
import { Logger } from 'wdKit'
import { PeopleShipHomePageDataModel } from '../../viewmodel/PeopleShipHomePageDataModel'
import { PeopleShipHomeListComponent } from '../peopleShipHomePage/PeopleShipHomeListComponent'
import { QueryListIsFollowedItem } from '../../viewmodel/QueryListIsFollowedItem'
import { HttpUtils } from 'wdNetwork/Index'
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'
import { PageRepository } from '../../repository/PageRepository'
import {
  postInteractAccentionOperateParams,
  PeopleShipUserDetailData,
  ArticleCountData
} from 'wdBean'

@Entry
@Component
struct PeopleShipHomePage {
  // Todo 传入数据  后续在修改
  creatorId: string = (router.getParams() as Record<string, string>)['creatorId'];
  // 页面详情数据
  @Provide detailModel: PeopleShipUserDetailData = {} as PeopleShipUserDetailData
  // 每个分类数量
  @State articleModel: ArticleCountData = {} as ArticleCountData
  // 总滑动空间
  scroller: Scroller = new Scroller()
  // 顶部透明度
  @State topOpacity: number = 0
  //发布数量
  @State publishCount: number = 0
  // 是否关注
  @Provide isAttention: string = '0'
  // 是否开始更新关注
  @Provide @Watch('handleChangeAttentionStata') isLoadingAttention: boolean = false
  //关注显示
  @Prop attentionOpacity: boolean = false
  @Provide topHeight: number = 400

  build() {

    Stack({ alignContent: Alignment.TopStart }) {
      // 头部返回
      PeopleShipHomePageNavComponent({
        attentionOpacity: this.attentionOpacity,
        topOpacity: this.topOpacity,
        detailModel: this.detailModel
      })
        .height($r('app.float.top_bar_height'))
        .zIndex(100)
        .backgroundColor(Color.Transparent)

      if (this.detailModel && this.detailModel.userName) {
        Scroll(this.scroller) {
          Column() {
            // 顶部相关
            PeopleShipHomePageTopComponent({
              creatorId: this.creatorId,
              detailModel: this.detailModel,
              publishCount: this.publishCount,
              topHeight: this.topHeight
            })
              .width("100%")
              .height(this.topHeight)
              .backgroundColor(Color.White)

            // 列表
            PeopleShipHomeListComponent({
              publishCount: this.publishCount,
              creatorId: this.creatorId
            })

          }
          .width("100%")
          .justifyContent(FlexAlign.Start)
          // .height(this.publishCount == 0 ? '100%' : '')
        }
        .edgeEffect(EdgeEffect.None)
        .friction(0.6)
        .backgroundColor(Color.White)
        .scrollBar(BarState.Off)
        .width('100%')
        .height('100%')
        .onScroll(() => {
          // this.topOpacity = yOffset / (this.getDeviceHeight() * 0.2)
          this.topOpacity = this.scroller.currentOffset().yOffset / 100
          if (this.scroller.currentOffset().yOffset >= this.topHeight - 66) {
            this.attentionOpacity = true
          } else {
            this.attentionOpacity = false
          }
          console.log(`全局请求失败拦截,message:${this.topOpacity}`)
          // System.out.println("输出高度:"+ AttrHelper.vp2px(height,this));

        })
      }

    }

  }

  async aboutToAppear() {

    try {
      // 获取页面信息
      this.detailModel = await PeopleShipHomePageDataModel.getPeopleShipHomePageDetailInfo(this.creatorId, '', '')
      Logger.debug('PeopleShipHomePage', '获取页面信息', `${JSON.stringify(this.detailModel)}`)

      // 获取关注
      // 登录后获取,是否关注
      if (HttpUtils.getUserId()) {
        let followList: QueryListIsFollowedItem[] = await PeopleShipHomePageDataModel.getHomePageFollowListStatusData(this.creatorId)
        Logger.debug('PeopleShipHomePage', '获取关注信息', `${JSON.stringify(followList)}`)
        this.findFollowStata(followList)
      }

    } catch (exception) {

    }


  }

  findFollowStata(followList: QueryListIsFollowedItem[]) {
    if (followList.length > 0) {
      let item: QueryListIsFollowedItem = followList[0]
      Logger.debug('PeopleShipHomePage', '关注', `${JSON.stringify(item.status)}`)
      this.isAttention = item.status
    }
  }

  handleChangeAttentionStata() {

    if (!this.isLoadingAttention) {
      return
    }
    // 未登录,跳转登录
    if (!HttpUtils.getUserId()) {
      this.isLoadingAttention = false
      WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
      return
    }

    let status = 0
    if (this.isAttention == '0') {
      status = 1
    }
    const params: postInteractAccentionOperateParams = {
      attentionUserType: this.detailModel.userType || '', //被关注用户类型(1 普通用户 2 视频号 3 矩阵号)
      attentionUserId: this.detailModel.userId || '', // 被关注用户号主id
      attentionCreatorId: this.creatorId || '', // 被关注用户号主id
      // userType: 1,
      // userId: HttpUrlUtils.getUserId(),
      status: status,
    }
    PageRepository.postInteractAccentionOperate(params).then(res => {
      if (this.isAttention == '1') {
        this.isAttention = '0'
      } else {
        this.isAttention = '1'
      }
      this.isLoadingAttention = false
    })
      .catch(() => {
        this.isLoadingAttention = false
      })
  }
}