1import { CardModel } from "../viewModel/CardModel" 2 3@Component 4export struct GoodItem { 5 @ObjectLink item: CardModel 6 private computedTotalPrice = () => { 7 } 8 9 build() { 10 Flex({ 11 direction: FlexDirection.Row, 12 justifyContent: FlexAlign.SpaceBetween, 13 alignItems: ItemAlign.Center 14 }) { 15 // 复选框 16 Column() { 17 Checkbox({ 18 name: 'checkbox' 19 }) 20 .selectedColor('#ed6f21') 21 .select(this.item.good_checked == 0 ? false : true) 22 .onClick(() => { 23 if (this.item.good_checked == 0) { 24 (this.item.good_checked as number) = 1 25 } else { 26 (this.item.good_checked as number) = 0 27 } 28 // 总价重新计算 29 this.computedTotalPrice() 30 }) 31 } 32 .width(85) 33 34 Column() { 35 Image($r(this.item.good_big_logo)) 36 .width(100) 37 } 38 .width(120) 39 40 Column() { 41 Text(this.item.good_name) 42 .width(150) 43 .maxLines(2) 44 .textOverflow({ 45 overflow: TextOverflow.Ellipsis 46 }) 47 Text(`¥${this.item.good_price}`) 48 .fontColor(Color.Brown) 49 .fontSize(18) 50 51 Row() { 52 Text('-') 53 .width(24) 54 .height(24) 55 .fontWeight(FontWeight.Bold) 56 .onClick(() => { 57 this.item.good_count = this.item.good_count == 0 ? 0 : Number(this.item.good_count) - 1 58 this.computedTotalPrice() 59 }) 60 Text(`${this.item.good_count}`) 61 .fontSize(14) 62 .fontColor(Color.Black) 63 .textAlign(TextAlign.Center) 64 .width(20) 65 .lineHeight(24) 66 Text('+') 67 .width(24) 68 .height(24) 69 .fontWeight(FontWeight.Bold) 70 .onClick(() => { 71 (this.item.good_count as number) += 1 72 this.computedTotalPrice() 73 }) 74 } 75 } 76 .flexGrow(1) 77 } 78 .width('100%') 79 .height(130) 80 .backgroundColor(Color.White) 81 } 82}
Copyright ©2010-2022 比特日记 All Rights Reserved.
Powered By 可尔物语