BabyInfoPage.ets 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { _YtHeader } from '../components/_YtHeader';
  2. import { IncreaseBabyInfoViewModel } from '../viewModel/IncreaseBabyInfoViewModel';
  3. import { BasicType } from 'basic';
  4. @ComponentV2
  5. struct BabyInfoPage {
  6. @Local vm: IncreaseBabyInfoViewModel = new IncreaseBabyInfoViewModel(false);
  7. build() {
  8. NavDestination() {
  9. Column() {
  10. Column(){
  11. _YtHeader({
  12. _onBackPress: () => { this.vm._onBackPressed() },
  13. rightComp: () => { this.rightComp() },
  14. title: "宝宝信息",
  15. })
  16. Row(){
  17. Row({space: 16}){
  18. Image(this.vm.babyInfo.avatarUrl ?? $r('app.media.default_img'))
  19. .width(60)
  20. .aspectRatio(1)
  21. .borderRadius(14)
  22. .onClick(() => { this.vm.updateAvatar() })
  23. Text(this.vm.babyInfo.days)
  24. }
  25. .alignItems(VerticalAlign.Center)
  26. }
  27. .width("100%")
  28. .justifyContent(FlexAlign.Start)
  29. .padding({top: 25, bottom: 25})
  30. }
  31. .width("100%")
  32. .height(189)
  33. .padding({ top: this.vm.safeTop, left: 24, right: 24 })
  34. Column(){
  35. ForEach(this.vm.forEachData, (item: BasicType, index: number) => {
  36. Column({space: 16}){
  37. if (item.date === 'birthDate') {
  38. InputItem({item: item, value: this.vm.babyInfo.birthday})
  39. } else if (item.date === 'name') {
  40. InputItem({item: item, value: this.vm.babyInfo.name})
  41. } else if (item.date === 'gender') {
  42. InputItem({item: item, value: this.vm.babyInfo.gender === undefined ? undefined : (this.vm.babyInfo.gender == 1 ? '男' : '女') })
  43. }
  44. }
  45. .id(item.id)
  46. .width('100%')
  47. .padding({bottom: 32})
  48. .justifyContent(FlexAlign.Center)
  49. .alignItems(HorizontalAlign.Start)
  50. .alignRules({
  51. top: { anchor: index == 0 ? 'title' : this.vm.forEachData[index - 1].id, align: VerticalAlign.Bottom },
  52. left: { anchor: index == 0 ? 'title' : this.vm.forEachData[index - 1].id, align: HorizontalAlign.Start }
  53. })
  54. })
  55. }
  56. .width('100%')
  57. .layoutWeight(1)
  58. .backgroundColor(Color.White)
  59. .justifyContent(FlexAlign.Start)
  60. .alignItems(HorizontalAlign.Center)
  61. .padding({left: 32, right: 32, top: 24})
  62. .borderRadius({topLeft: 10, topRight: 10})
  63. }
  64. .width('100%')
  65. .height('100%')
  66. .backgroundColor('#CCEBA8')
  67. .alignItems(HorizontalAlign.Center)
  68. .justifyContent(FlexAlign.Start)
  69. }
  70. .hideTitleBar(true)
  71. }
  72. @Builder
  73. rightComp(){
  74. Image($r('app.media.icon_ashBin'))
  75. .width(20)
  76. .aspectRatio(1)
  77. .onClick(() => { this.vm.deleteBaby() })
  78. }
  79. }
  80. @Builder
  81. function BabyInfoPageBuilder() {
  82. BabyInfoPage()
  83. }
  84. // 单个输入框
  85. @ComponentV2
  86. struct InputItem{
  87. @Require @Param item: BasicType
  88. @Require @Param value: string | undefined
  89. build(){
  90. Row(){
  91. Text(this.item.text)
  92. .fontSize(14)
  93. .fontColor('#4F4F4F')
  94. Row({space: 10}){
  95. if(this.value) {
  96. Text(this.value)
  97. .fontSize(16)
  98. .fontColor(Color.Black)
  99. } else {
  100. Text(this.item.message)
  101. .fontSize(16)
  102. .fontColor('rgba(0, 0, 0, 0.6)')
  103. }
  104. Image($r('[basic].media.ic_back'))
  105. .width(10)
  106. .height(20)
  107. .rotate({angle: 180})
  108. }
  109. }
  110. .height(48)
  111. .padding(16)
  112. .width("100%")
  113. .borderRadius(8)
  114. .backgroundColor('#F6F6F6')
  115. .alignItems(VerticalAlign.Center)
  116. .justifyContent(FlexAlign.SpaceBetween)
  117. .border({ width: 0 })
  118. .onClick(this.item.click)
  119. }
  120. }