项目预览:
项目继续上一篇报告中列表内容,对下方的列表内容进行编辑
代码:
import router from '@ohos.router'
import url from '@ohos.url'
import { CommonConstants } from '../../common/constants/CommonConstants'
//自定义文字样式方法,封装
@Extend(Text) function grayText() {
.fontSize(14)
.fontColor($r('app.color.light_gray'))
}
@Component
export default struct RecordList {
build() {
List({ space: CommonConstants.SPACE_12 }) {
ForEach([1, 2, 3, 4, 5], (item) => {
ListItem() {
Column() {
//分组标题
Row({ space: CommonConstants.SPACE_4 }) {
Image($r('app.media.ic_breakfast'))
.width(24)
Text('早餐')
.fontSize(18)
.fontWeight(CommonConstants.FONT_WEIGHT_700)
Text('建议423-492千卡')
.grayText() //方法,加括号
Blank() //空白
Text('190')
.fontSize(14)
.fontColor($r('app.color.primary_color'))
Text('千卡')
.grayText() //方法,加括号
Image($r('app.media.ic_public_add_norm_filled'))
.width(20)
.fillColor($r('app.color.primary_color'))
}
.width('100%')
.onClick(()=>{
router.pushUrl({url:'pages/ItemIndex'})
})
//组内记录列表
List(){
ForEach([1,2],(item)=>{
ListItem(){
Row({ space: CommonConstants.SPACE_4 }) {
Image($r('app.media.toast'))
.width(50)
Column({ space: CommonConstants.SPACE_4 }) {
Text('全麦').fontWeight(CommonConstants.FONT_WEIGHT_500)
Text('1片').grayText()
}
Blank()
Text('91').grayText()
}
.width('100%')
.padding(CommonConstants.SPACE_6)
}
})
}
.width('100%')
}
.width('100%')
.backgroundColor(Color.White)
.borderRadius(CommonConstants.DEFAULT_18)
.padding(CommonConstants.SPACE_12)
}.swipeAction({end:this.deleteButton.bind(this)})//滑动事件,删除
})
}
.width(CommonConstants.THOUSANDTH_940)
.margin({ top: 15 })
.height('100%')
}
//侧滑删除图标
@Builder deleteButton(){
Image($r('app.media.ic_public_delete_filled'))
.width(40)
.height(40)
.fillColor(Color.White)
.margin(6)//图片间距
.backgroundColor(Color.Red)
.borderRadius(15)
}
}