亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

《仿盒馬》app開發技術分享-- 商品詳情頁(10)

標簽:
鴻蒙 HarmonyOS

技术栈

Appgallery connect

开发准备

上一节我们实现了自定义标题栏和商品详情的数据接收,我们已经拿到了想要的数据,这一节我们要丰富商品详情页的内容。商品详情页面我们需要展示的是商品的各个属性参数、商品的图片、商品规格、活动详情等

功能分析

商品详情页面的结构需要我们去用比较多的布局去处理,首先因为商品详情页面对的数据足够多,需要他能够实现滚动查看信息,然后我们需要在底部固定加入购物车和立即购买按钮,并且我们加购之后,我们也要在页面中即使响应购物车中的商品数。同时给到用户便捷跳转到购物车的按钮

代码实现

我们先进行数据的填充,因为上一节我们已经接收到数据,所以我们直接吧数据打印到text上,对着数据进行填充,同时还能帮我们暂时丰富一下页面内容,查看滑动的效果,页面完善之后我们再去删掉即可

Text(JSON.stringify(this.productParams))
.fontColor(Color.Black)

然后我们根据设计的样式进行数据填充,要注意滚动和底部布局的固定,挑选合适的布局容器

Stack({alignContent:Alignment.Bottom}){
Scroll(this.scroller){
Column() {
CommonTopBar({ title: “商品详情”, alpha: 0, titleAlignment: TextAlign.Center ,backButton:true})
Image(this.productParams.url)
.width(‘100%’)
.height(300)
Text(JSON.stringify(this.productParams))
.fontColor(Color.Black)
Column({space:10}){
Row(){
if (this.productParams.promotion_spread_price>0){
Text(){
Span(“¥”)
.fontSize(14)
.fontColor(Color.Red)
Span(this.productParams.promotion_spread_price+"")
.fontSize(20)
.fontColor(Color.Red)
}
}else {
Text(){
Span(“¥”)
.fontSize(14)
.fontColor(Color.Red)
Span(this.productParams.price+"")
.fontSize(20)
.fontColor(Color.Red)
}
}

            Text("¥"+this.productParams.original_price+"")
              .fontColor('#999')
              .decoration({
                type: TextDecorationType.LineThrough,
                color: Color.Gray
              })
              .fontSize(16)
              .margin({left:10})

            if (this.productParams.promotion_spread_price>0){
              Row(){
                Text("每件立减"+(this.productParams.price-this.productParams.promotion_spread_price)+"元")
                  .fontSize(14)
                  .borderRadius(20)
                  .backgroundColor("#FB424C")
                  .padding(3)
                  .textAlign(TextAlign.Center)
                Text("每人限购"+this.productParams.max_loop_amount+"件")
                  .margin({left:5})
                  .fontSize(14)
                  .borderRadius(20)
                  .backgroundColor("#FB424C")
                  .padding(3)
                  .textAlign(TextAlign.Center)
              }
              .padding({top:2,bottom:2,left:10})
            }



          }
          .padding(10)

          if (this.productParams.promotion_spread_price>0){
            Text(this.productParams.endTime)
              .fontSize(14)
              .borderRadius(20)
              .backgroundColor("#FB424C")
              .padding(3)
              .margin({left:10})
              .textAlign(TextAlign.Center)
          }

          Text(this.productParams.name)
            .fontSize(20)
            .fontColor(Color.Black)
            .margin({left:10})
            .fontWeight(FontWeight.Bold)
          Text(this.productParams.text_message)
            .fontSize(14)
            .fontColor(Color.Black)
            .margin({left:10})
          Row(){
            Text()
            Text("销量 "+this.productParams.sales_volume)
              .fontSize(14)
              .fontColor(Color.Black)
          }
          .padding(10)
          .width('100%')
          .justifyContent(FlexAlign.SpaceBetween)


          Divider().width('100%')
            .height(5).backgroundColor("#f7f7f7")
          Row(){
            Text("发货")
              .fontColor(Color.Gray)
              .fontSize(14)

            Text(this.productParams.delivery_time+"")
              .fontSize(14)
              .margin({left:20})
              .fontColor(Color.Black)
          }
          .padding(10)
          .width('100%')
          .justifyContent(FlexAlign.Start)
          Divider().width('100%')
            .height(5).backgroundColor("#f7f7f7")
          Row(){
            Text("参数")
              .fontColor(Color.Gray)
              .fontSize(14)

            Text("储藏条件:")
              .margin({left:20})
              .fontSize(14)
              .fontColor(Color.Black)
            Text(this.productParams.parameter)
              .fontSize(14)
              .fontColor(Color.Black)
          }
          .padding(10)

          .width('100%')
          .justifyContent(FlexAlign.Start)
          Divider().width('100%')
            .height(5).backgroundColor("#f7f7f7")


          Row(){
            Text("规格")
              .fontColor(Color.Gray)
              .fontSize(14)

            Column(){
              Text("请选择规格")
            }
          }
          .padding(10)
          .width('100%')
          .justifyContent(FlexAlign.Start)
          Divider().width('100%')
            .height(5).backgroundColor("#f7f7f7")
        }
        .alignItems(HorizontalAlign.Start)
      }
      .alignItems(HorizontalAlign.Start)
      .backgroundColor(Color.White)


  }
  .padding({bottom:80})
  .height('100%')
  .width('100%')
  Row(){
    Image($r('app.media.product_details_cart'))
      .width(35)
      .height(35)
      .objectFit(ImageFit.Contain)


    Blank()

    Text("加入购物车")
      .padding(10)
      .width(100)
      .textAlign(TextAlign.Center)
      .backgroundColor("#FCDB29")
      .fontColor(Color.White)
      .borderRadius({topLeft:15,bottomLeft:15})

    Text(" 立即购买 ")
      .padding(10)
      .textAlign(TextAlign.Center)
      .width(100)
      .backgroundColor(Color.Red)
      .fontColor(Color.White)
      .borderRadius({topRight:15,bottomRight:15})
  }
  .padding(15)
  .justifyContent(FlexAlign.SpaceBetween)
  .width('100%')
  .backgroundColor(Color.White)
}
.backgroundColor(Color.White)

到这里我们的商品详情页面的内容已经比较完善了

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
全棧工程師
手記
粉絲
1
獲贊與收藏
4

關注作者,訂閱最新文章

閱讀免費教程

  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消