HarmonyOS-记账本-统计信息

今天完成统计卡片统计信息的编写

import { CommonConstants } from '../../common/constants/CommonConstants'
@Component
export default struct Accountant {
  //收入
  getIn:number = 192
  //支出
  getOut:number = 1500
  //月预算
  getBefore:number = 3000

  remainMoney(){
    return this.getBefore+this.getIn-this.getOut
  }
  build() {
    Row({space:CommonConstants.SPACE_6}){
      this.StatsBuilder('收入',this.getIn)
      Stack(){
        Progress({
          value:this.remainMoney() > this.getBefore ? this.getBefore :this.remainMoney(),
          total:this.getBefore,
          type:ProgressType.Ring
        })
          .width(110)
          .style({strokeWidth:CommonConstants.DEFAULT_8})
          .color('#FFCC66')
        this.StatsBuilder('结余',this.remainMoney(),this.getBefore)
      }
      this.StatsBuilder('支出',this.getOut)
    }
    .width('100%')
    .backgroundColor(Color.White)
    .borderRadius(CommonConstants.DEFAULT_18)
    .justifyContent(FlexAlign.SpaceEvenly)
    .padding({top:30,bottom:30})
  }

  @Builder StatsBuilder(label:string,value:number,tips?:number){
    Column({space:CommonConstants.SPACE_6}) {
      Text(label)
        .fontColor($r('app.color.gray'))
        .fontWeight(CommonConstants.FONT_WEIGHT_600)
        .fontColor('#ffcc99')
      Text(''+value.toFixed(2))
        .fontSize(20)
        .fontWeight(CommonConstants.FONT_WEIGHT_700)
        .fontSize(15)
        .fontColor('#ffcc99')
      if (tips) {
        Text('月预算¥'+tips.toFixed(0))
          .fontColor($r('app.color.light_gray'))
          .fontWeight(CommonConstants.FONT_WEIGHT_600)
          .fontSize(10)
      }
    }
  }

}

 

posted @ 2024-02-23 16:49  菜鸟de博客  阅读(12)  评论(0)    收藏  举报