AddressItemComp.ets 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { Address } from "../model/Address"
  2. import { CustomTextStyle } from "../style/CustomTextStyle"
  3. @ComponentV2
  4. export struct AddressItemComp {
  5. @Param index: number = 0
  6. @Param selectIndex: number = 0
  7. // 0 - 查看 1 - 编辑 2 - 选择 ( icon 不同 ) 3 - 不要 icon
  8. @Param type: 0 | 1 | 2 | 3 = 0
  9. @Param needBorder: boolean = true
  10. @Param isLocation: boolean = true
  11. @Param align_: VerticalAlign = VerticalAlign.Center
  12. @Param address: Address = {
  13. userName: '占三峰',
  14. phone: '13598728343',
  15. address: '高新区火炬园路321号韩菲诗.诚享大厦304室内',
  16. region: '福建-厦门-火炬园',
  17. }
  18. @Event click: () => void
  19. build() {
  20. Row(){
  21. if(this.isLocation){
  22. Image($r('[basic].media.icon_location')).width(24).aspectRatio(1)
  23. } else {
  24. Image($r('[basic].media.icon_send')).width(24).aspectRatio(1)
  25. }
  26. Column({space: 5}){
  27. Text(`${this.address.region?.split('-').join('')}${this.address.address}`)
  28. .attributeModifier(new CustomTextStyle({ size: 14, weight: 400, color: '#FF000000' }))
  29. Row({space: 8}){
  30. Text(this.address.userName).attributeModifier(new CustomTextStyle({ size: 14, weight: 500, color: '#FF000000' }))
  31. Text(this.address.phone).attributeModifier(new CustomTextStyle({ size: 14, weight: 500, color: '#FF000000' }))
  32. }
  33. }
  34. .layoutWeight(1)
  35. .margin({left: 11, right: 19})
  36. .alignItems(HorizontalAlign.Start)
  37. if(this.type == 0) {
  38. Image($r('[basic].media.ic_public_arrow_left'))
  39. .rotate({angle: 180})
  40. .width(24).aspectRatio(1)
  41. } else if (this.type == 1) {
  42. Image($r('[basic].media.icon_edit'))
  43. .width(24).aspectRatio(1)
  44. } else if (this.type == 2) {
  45. if(this.selectIndex == this.index) {
  46. Image($r('[basic].media.icon_select'))
  47. .width(15).aspectRatio(1)
  48. } else {
  49. Row()
  50. .borderRadius(15)
  51. .border({width: 1})
  52. .width(15).aspectRatio(1)
  53. }
  54. }
  55. }.width('100%')
  56. .backgroundColor(Color.White)
  57. .alignItems(this.align_)
  58. .borderRadius(this.needBorder ? 8 : 0)
  59. .border(this.needBorder ? {width: 2, color: '#FF000000'} : null)
  60. .padding({left: 16, right: 16, top: 18, bottom: 18})
  61. }
  62. }