BookSearchResultPage.ets 3.1 KB

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