BookSearchResultPage.ets 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { BookItem, YTHeader } from 'basic'
  2. import { BookItemComp } from '../../components/BookItemComp';
  3. import { bookListItemComp } from '../../components/BuilderIndex';
  4. import { ytEmptyComp } from '../../components/ytComp/ytEmptyComp';
  5. import { BookListItem } from '../../model/BookModelIndex';
  6. import { CustomTextStyle } from '../../style/CustomTextStyle';
  7. import { BookSearchResultViewModel } from '../viewModel/BookSearchResultViewModel';
  8. @ComponentV2
  9. struct BookSearchResultPage {
  10. @Param @Require vm: BookSearchResultViewModel;
  11. build() {
  12. NavDestination() {
  13. Column() {
  14. YTHeader({ defaultStyle: {title: '搜索'}, bgc: Color.White })
  15. Row({space: 130}){
  16. ForEach(['图书', '书单'], (item: string, index) => {
  17. Column(){
  18. Text(item + `(${index == 0 ? this.vm.book.length : this.vm.bookList.length})`)
  19. .zIndex(99)
  20. .onClick(() => { this.vm.changeCategory(index) })
  21. .attributeModifier(new CustomTextStyle({size: 16, weight: 600, color: this.vm.categoryIndex == index ? '#FF111111' : '#FF777777'}))
  22. if(this.vm.categoryIndex == index){
  23. Image($r('[basic].media.icon_SelectBg'))
  24. .width(45)
  25. .height(16)
  26. .margin({top:-10})
  27. .transition(TransitionEffect.translate({ y: -10 })
  28. .animation({ duration: 100, curve: Curve.Friction}))
  29. }
  30. }
  31. .height(30)
  32. .width(120)
  33. .alignItems(HorizontalAlign.Center)
  34. })
  35. }
  36. .height(80)
  37. .width('100%')
  38. .backgroundColor(Color.White)
  39. .padding({top: 10})
  40. .justifyContent(FlexAlign.Center)
  41. .borderRadius({bottomLeft: 8, bottomRight: 8})
  42. Tabs({controller: this.vm.tabControl}){
  43. TabContent(){
  44. this.BookItemList()
  45. }
  46. TabContent(){
  47. this.BookList()
  48. }
  49. }.width('100%')
  50. .layoutWeight(1)
  51. .barHeight(0)
  52. }
  53. .width('100%').height('100%')
  54. .backgroundColor('#F7F9FA')
  55. }
  56. .hideTitleBar(true)
  57. }
  58. // 书籍列表
  59. @Builder
  60. BookItemList() {
  61. ytEmptyComp({ dataSource: this.vm.book, keyStr: '书籍' }){
  62. List({space: 16}){
  63. ListItem()
  64. Repeat(this.vm.book)
  65. .each((item: RepeatItem<BookItem>) => {
  66. ListItem(){
  67. BookItemComp({item: item.item, addCar: () => {
  68. item.item.schoolbagFlag = '1'
  69. }})
  70. }
  71. })
  72. ListItem()
  73. }.width('100%').height('100%')
  74. .padding({left: 17, right: 17})
  75. }
  76. }
  77. // 书单列表
  78. @Builder
  79. BookList() {
  80. ytEmptyComp({ dataSource: this.vm.bookList, keyStr: '书单' }){
  81. List({space: 16}){
  82. ListItem()
  83. Repeat(this.vm.bookList)
  84. .each((item: RepeatItem<BookListItem>) => {
  85. ListItem(){
  86. bookListItemComp(item)
  87. }
  88. })
  89. ListItem()
  90. }.width('100%').height('100%')
  91. .padding({left: 17, right: 17})
  92. }
  93. }
  94. }
  95. @Builder
  96. function BookSearchResultBuilder(_: string, key: string) {
  97. BookSearchResultPage({ vm: new BookSearchResultViewModel(key) })
  98. }