Index.ets 4.9 KB
import HomePage from '../components/HomePage'
import MainPage from '../components/MainPage'
import DialogTip from '../dialog/DialogTip'
import { personData, companyData, personCertificateTest, personCertificateRow } from '../api/userType'
import { getPersonalCertificate } from '../api/user'
import preferencesUtil from '../utils/preferences'
import { getNoticeDetail, noticeRow, noticeDetailTest } from '../api/notice'
import { AxiosResponse } from '@ohos/axios'

@Entry
@Component
struct Index {
  // 通知公告
  @State noticeInfo: noticeRow = {
    noticeTitle: '',
    noticeContent: '',
    noticeType: '2'
  }
  // 证书信息
  @State personCertificateInfo: personCertificateRow = {
    certificateName: '',
    certificateLevel: '',
    certificateNo: '',
    certificateId: 1,
    certificateImg: '',
    issueDate: ''
  }
  // 是否为编辑
  @State isEdit: boolean = false
  async aboutToAppear() {
    const noticeRes: AxiosResponse<noticeDetailTest> = await getNoticeDetail(13)
    this.noticeInfo = noticeRes.data.data
    if (preferencesUtil.get('XF_TOKEN', '')) {
      this.dialogController.open()
    }
  }
  @State userInfo: personData = {
    createBy:    '',
    createTime:  '',
    updateBy:    '',
    updateTime:  '',
    remark:      '',
    personId:    0,
    personName:  '',
    email:       '',
    gender:      '',
    birthDate:   '',
    idNo:        '',
    phone:       '',
    personalImg: '',
    idImgFront:  '',
    idImgBack:   '',
    address:     '',
    userId:      0,
    username:    '',
    state:       '',
    companyId:   0,
  }
  @State companyInfo: companyData = {
    createBy:           null,
    createTime:         null,
    updateBy:           null,
    updateTime:         '',
    remark:             null,
    companyId:          65,
    companyName:        '',
    province:           '',
    city:               '',
    county:             '',
    address:            '',
    legalPerson:        null,
    lpTel:              null,
    linkMan:            '',
    lmTel:              '',
    companyTel:         null,
    fax:                null,
    postCode:           null,
    email:              '',
    website:            null,
    floorage:           0,
    siteVoucher:        '',
    businessLicenseNo:  '',
    businessStartTime:  null,
    businessEndTime:    null,
    businessLicensePic: '',
    businessScope:      null,
    peopleNum:          0,
    companyIntroduce:   null,
    registeredCapital:  null,
    compangyPic:        '',
    memo:               null,
    state:              '',
    companyType:        '',
    isShow:             null,
    isValidVedio:       null,
    userId:             0,
    username:           '',
    level:              null,
    regionCode:         null,
    levelModifyDate:    null,
    endTime:            '',
  }
  roleName = preferencesUtil.get('XF_ROLE_NAME', '')
  async onPageShow() {
    let personId = preferencesUtil.get('XF_PERSON_ID', 0)
    if(preferencesUtil.get('XF_PERSON_INFO', '') !== '') {
      this.userInfo = JSON.parse(preferencesUtil.get('XF_PERSON_INFO', '') as string)
    }
    if(preferencesUtil.get('XF_COMPANY_INFO', '') !== '') {
      this.companyInfo = JSON.parse(preferencesUtil.get('XF_COMPANY_INFO', '') as string)
    }
    if(this.roleName == 'person' || this.roleName == 'unapprovedPerson') {
      // 获取个人证书信息
      const result: AxiosResponse<personCertificateTest> = await getPersonalCertificate({pageNum: 1, pageSize: 10, personId: Number(personId)})
      this.isEdit = result.data.rows.length > 0
      if(result.data.rows.length > 0) {
        this.personCertificateInfo = result.data.rows[0]
      }
    }
  }
  @State currentIndex: number = 0
  @Builder tabBuilder(title: string, targetIndex: number, selectedImg: Resource, normalImg: Resource) {
    Column({space: 5}) {
      Image(this.currentIndex === targetIndex ? selectedImg : normalImg)
        .size({ width: 25, height: 25 })
      Text(title)
        .fontColor(this.currentIndex === targetIndex ? '#6D9DFF' : '#999')
    }
    .width('100%')
    .height(50)
    .justifyContent(FlexAlign.Center)
  }
  dialogController: CustomDialogController = new CustomDialogController({
    builder: DialogTip({
      noticeDetail: this.noticeInfo
    }),
    autoCancel: false,
    cornerRadius: 10
  })
  build() {
    Tabs({barPosition: BarPosition.End}){
      TabContent() {
        HomePage()
      }.layoutWeight(1)
      .tabBar(this.tabBuilder('首页', 0, $r('app.media.home_active'), $r('app.media.home')))
      TabContent() {
        MainPage({
          userInfo: this.userInfo,
          companyInfo: this.companyInfo,
          personCertificateInfo: this.personCertificateInfo,
          isEdit: this.isEdit
        })
      }
      .tabBar(this.tabBuilder('我的', 1, $r('app.media.my_active'), $r('app.media.my')))
    }.width('100%').height('100%').onChange(async (index) => {
      this.currentIndex = index
    })
  }
}