TypeScript class Shops{ name:string img:ResourceStr price:number status:number constructor(name:string,img:ResourceStr,price:number,status:number) { this.name = name this.img = img this.price = price this.status = status } } @Entry @Component struct ListUi { private shops:Array= [ new Shops(“华为mate70旗舰手机”,$r(“app.media.down”),8999,500), new Shops(“华为mate70旗舰手机”,$r(“app.media.down”),9999,200), new Shops(“华为mate70旗舰手机”,$r(“app.media.down”),10999,0), new Shops(“华为mate70旗舰手机”,$r(“app.media.down”),10999,0), new Shops(“华为mate70旗舰手机”,$r(“app.media.down”),10999,0), new Shops(“华为mate70旗舰手机”,$r(“app.media.down”),10999,0), new Shops(“华为mate70旗舰手机”,$r(“app.media.down”),10999,0), new Shops(“华为mate70旗舰手机”,$r(“app.media.down”),10999,0), new Shops(“华为mate70旗舰手机”,$r(“app.media.down”),10999,0), new Shops(“华为mate70旗舰手机”,$r(“app.media.down”),10999,0) ] build() { Column(){ Row(){ Text(“商品列表”) .fontSize(30) } .width(“90%”) .height(“60”) List(){ ForEach(this.shops,(item:Shops) =>{ ListItem(){ Row(){ Image(item.img) .width(100) Column({space:4}){ if (item.status) { Text(item.name) .fontWeight(FontWeight.Bold) Text(“原价:¥”+item.price) .fontColor(“#c7c7c7”) .decoration({type:TextDecorationType.LineThrough}) .fontSize(14) Text(“折扣价:¥”+(item.price – item.status)) .fontColor(“red”) Text(“补贴:¥”+item.status) .fontColor(“red”) } else{ Text(item.name) .fontWeight(FontWeight.Bold) Text(“¥”+item.price) .fontColor(“red”) } } .alignItems(HorizontalAlign.Start) } .width(“90%”) .backgroundColor(“#ffffff”) .height(“15%”) .borderRadius(8) .margin({bottom:10}) } }) } } .width(“100%”) .height(“100%”) .backgroundColor(“#c7c7c7”) } }
|