BillingInformation.ets 5.6 KB
import preferencesUtil from '../utils/preferences'
import { promptAction } from '@kit.ArkUI';
import { AxiosResponse } from '@ohos/axios'
import { headerTest, headerRow, companyData } from '../api/userType'
import { getHeaderInfo, updateHeaderInfo, addHeaderInfo } from '../api/user'

let companyId = preferencesUtil.get('XF_COMPANY_ID', 65) as number

@Entry
@Component
struct EditUser {
  @Builder indicatorBuilder(icon: ResourceStr) {
    Image(icon)
  }
  @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:            '',
  }
  @State isEdit: boolean = false
  @State headerInfo: headerRow = {
    account: '',
    bank: '',
    address: '',
    phone: '',
    companyId: '',
    companyName: '',
    businessLicenseNo: ''
  }
  async onPageShow() {
    if(preferencesUtil.get('XF_COMPANY_INFO', '') !== '') {
      this.companyInfo = JSON.parse(preferencesUtil.get('XF_COMPANY_INFO', '') as string)
      this.headerInfo.businessLicenseNo = this.companyInfo.businessLicenseNo
      this.headerInfo.companyName = this.companyInfo.companyName
    }
    let res: AxiosResponse<headerTest> = await getHeaderInfo({pageSize: 1, pageNum: 1, companyId: companyId})
    this.isEdit = res.data.rows.length > 0
    if(res.data.rows.length > 0){
      this.headerInfo = res.data.rows[0]
    }
  }
  build() {
    Column(){
      Column(){
        Column(){
          Row(){
            Row(){
              Image($r('app.media.require')).width(20)
              Text('公司名称')
            }.margin({right: 15})
            Text(this.headerInfo?.companyName).layoutWeight(1).padding({top: 10, bottom: 10})
          }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
          Row(){
            Row(){
              Image($r('app.media.require')).width(20)
              Text('统一信用代码')
            }.margin({right: 15})
            Text(this.headerInfo?.businessLicenseNo).layoutWeight(1).padding({top: 10, bottom: 10})
          }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
          Row(){
            Row(){
              Image($r('app.media.require')).width(20)
              Text('对公账户')
            }
            TextInput({placeholder: '请输入对公账户', text: $$this.headerInfo.account})
              .backgroundColor('#fff').layoutWeight(1).type(InputType.Number)
          }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
          Row(){
            Row(){
              Image($r('app.media.require')).width(20)
              Text('开户行')
            }
            TextInput({placeholder: '请输入开户行', text: $$this.headerInfo.bank})
              .backgroundColor('#fff').layoutWeight(1)
          }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
          Row(){
            Row(){
              Image($r('app.media.require')).width(20)
              Text('公司电话')
            }
            TextInput({placeholder: '请输入公司电话', text: $$this.headerInfo.phone})
              .backgroundColor('#fff').layoutWeight(1)
          }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
          Row(){
            Row(){
              Image($r('app.media.require')).width(20)
              Text('公司地址')
            }
            TextInput({placeholder: '请输入公司地址', text: $$this.headerInfo.address})
              .backgroundColor('#fff').layoutWeight(1)
          }.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
        }.backgroundColor('#fff').width('100%').padding({left: 5, right: 5}).borderRadius(10)
      }.padding(10).margin({bottom: 20, top: 10}).width('100%').layoutWeight(1)
      Row({ space: 10}){
        Text('提交').borderRadius(5).layoutWeight(1).height(30).fontColor('#fff')
          .backgroundColor('#1B65FD').fontSize(14).textAlign(TextAlign.Center)
          .onClick(async () => {
            if(this.isEdit) {
              await updateHeaderInfo(this.headerInfo)
              promptAction.showToast({
                message: '修改成功',
                duration: 2000
              })
            } else {
              await addHeaderInfo(this.headerInfo)
              promptAction.showToast({
                message: '新增成功',
                duration: 2000
              })
            }
          })
      }.width('100%').height(40).backgroundColor('#fff').padding({left: 10, right: 10})
    }.width('100%').height('100%').backgroundColor('#f2f3f7')
  }
}