MinePageUserSimpleInfoUI.ets 5.39 KB
import { StringUtils, UserDataLocal } from 'wdKit'
import { WDRouterPage, WDRouterRule } from 'wdRouter'
import MinePageDatasModel from '../../model/MinePageDatasModel'
const TAG = "MinePageUserSimpleInfoUI"


@Component
export default struct MinePageUserSimpleInfoUI {
  @Watch('loginStateChange') @Prop isLogin :boolean
  @State userName:string = "登陆注册"
  @State headPhotoUrl:string = ""
  userType:string = "1"
  @State levelHead:string = ""
  @State levelId:number = 0

  loginStateChange(){
    if(this.isLogin){
      this.getUserInfo()
    }else{
      this.headPhotoUrl = ""
      this.levelHead = ""
    }
  }

  build(){
    Row(){
      //头像
      Stack(){
        Image(this.headPhotoUrl==""?$r('app.media.default_head'):this.headPhotoUrl)
          .alt($r('app.media.default_head'))
          .width('100lpx')
          .height('100lpx')
          .objectFit(ImageFit.Cover)
          .borderRadius(50)

        if(StringUtils.isNotEmpty(this.levelHead)){
          Image(this.levelHead)
            .width('130lpx')
            .height('130lpx')
            .objectFit(ImageFit.Cover)
            .borderRadius(50)
        }
      }.width('130lpx')
      .height('130lpx')
      .alignContent(Alignment.Center)
      .onClick(()=>{
        this.jumpLogin()
      })

      if(this.isLogin){
        //昵称信息
        Column(){
          Row(){
            Text(this.userName)
              .fontColor($r('app.color.color_222222'))
              .maxLines(1)
              .fontWeight(FontWeight.Bold)
              .textOverflow({ overflow: TextOverflow.Ellipsis })
              .fontSize('33lpx')
              .lineHeight("46lpx")

            Image($r('app.media.mine_user_edit'))
              .width('27lpx')
              .height('27lpx')
              .margin({left:'15lpx'})
              .objectFit(ImageFit.Cover)
            Blank()
          }.width('100%')
          .onClick(()=>{
            this.jumpLogin()
          })

          Stack(){
            Image($r('app.media.mine_grade_bg'))
              .width('84lpx')
              .height('29lpx')
              .objectFit(ImageFit.Auto)
            Text(`等级${this.levelId}`)
              .textAlign(TextAlign.Center)
              .fontColor($r('app.color.white'))
              .fontSize('19lpx')
              .width('50lpx')
              .height('29lpx')
          }.margin({top:'15lpx'})
        }.alignItems(HorizontalAlign.Start)
        .margin({top:'12lpx',left:'17lpx'})
        .width('352lpx')
      }else{
        Row(){
          Text("登录注册")
            .fontColor($r('app.color.color_222222'))
            .textOverflow({ overflow: TextOverflow.Ellipsis })
            .fontSize('33lpx')

          Image($r('app.media.mine_user_edit'))
            .width('11lpx')
            .height('20lpx')
            .margin({left:'15lpx'})
            .objectFit(ImageFit.Cover)
          Blank()
        }.onClick(()=>{
          this.jumpLogin()
        })
        .margin({top:'11lpx',left:'17lpx'})
        .width('352lpx')
      }

      Blank()

      Stack({alignContent:Alignment.Start}){
        Text("签到")
          .textAlign(TextAlign.Start)
          .width('108lpx')
          .height('46lpx')
          .fontColor($r('app.color.color_AD6000'))
          .backgroundColor($r('app.color.color_FFC460'))
          .fontWeight(500)
          .position({x:'23lpx'})
          .padding({left:'35lpx'})
        Image($r("app.media.mine_sign_icon"))
          .width('50lpx')
          .height('50lpx')
      }.width('131lpx')
      .visibility(Visibility.Hidden)
    }.backgroundColor($r('app.color.white'))
    .setFullWidth()
    .padding({top:'31lpx',left:'46lpx'})
  }

  @Styles setFullWidthAndHeight(){
    .width('100%')
    .height('100%')
  }

  @Styles setFullWidth(){
    .width('100%')
  }

  @Styles setFullHeight(){
    .height('100%')
  }

  getUserInfo(){
    MinePageDatasModel.getUserDetailData(getContext(this)).then((value)=>{
      if(value!=null){
        this.userName = value.userName
        this.headPhotoUrl = value.headPhotoUrl
        UserDataLocal.setUserHeaderUrl(value.headPhotoUrl)

        this.userType = value.userType
        UserDataLocal.setUserType(value.userType)

        if(this.userType === "1"){
          if(StringUtils.isNotEmpty(value.honoraryIcon)){
            this.levelHead = value.honoraryIcon
            return
          }
          if(StringUtils.isNotEmpty(value.avatarFrame)){
            this.levelHead = value.avatarFrame
          }
        }
      }
      this.getUserLevel()
    }).catch((err:Error)=>{
      console.log(TAG,JSON.stringify(err))
    })
  }
  getUserLevel(){
    MinePageDatasModel.getUserLevelData(getContext(this)).then((value)=>{
      if(value!=null){
        if(StringUtils.isEmpty(this.levelHead)){
          if(this.userType === "1"){
            if(value.levelHead != undefined){
              this.levelHead = value.levelHead
            }
          }
        }
        if(value.levelId != undefined){
          this.levelId = value.levelId
          UserDataLocal.setUserLevel(this.levelId)
        }

        if(StringUtils.isNotEmpty(this.levelHead)){
          UserDataLocal.setUserLevelHeaderUrl(this.levelHead + "")
        }
      }
    }).catch((err:Error)=>{
      console.log(TAG,JSON.stringify(err))
    })
  }

  jumpLogin(){
    if(!this.isLogin){
      WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
    }else {
      WDRouterRule.jumpWithPage(WDRouterPage.mineHomePage)
    }
  }
}