SecondView.ets 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import { DeerSearch } from '../components/DeerSearch'
  2. import { SecondViewModel } from './viewModel/SecondViewModel'
  3. import { CustomTextStyle } from '../style/CustomTextStyle'
  4. import { bookItemComp } from '../components/BuilderIndex'
  5. @ComponentV2
  6. export struct SecondView {
  7. vm: SecondViewModel = new SecondViewModel()
  8. build() {
  9. Column(){
  10. Row({space: 12}){
  11. Row({space: 6}){
  12. Text('年龄选择')
  13. .attributeModifier(new CustomTextStyle({size: 14, weight: 600}))
  14. Image($r('[basic].media.icon_expension'))
  15. .width(10)
  16. .height(8)
  17. .rotate({ angle: this.vm.openAgeDialog ? 180 : 0 })
  18. .animation({duration: 200, curve: Curve.Smooth})
  19. }
  20. .borderRadius(18)
  21. .backgroundColor('#FFFECF2F')
  22. .border({width: 2, color: '#FF000000'})
  23. .padding({left: 15, top: 8, right: 15, bottom: 8})
  24. .bindMenu(this.ageSelect())
  25. .onClick(() => { if(!this.vm.openAgeDialog) this.vm.openAgeDialog = true })
  26. DeerSearch({showSearchButton: false, enable: false})
  27. .layoutWeight(1)
  28. }
  29. .width("100%")
  30. .padding({left: 16, right: 16, top: this.vm.safeTop, bottom: 20})
  31. .linearGradient( this.vm.openTypeDialog ? {colors: [['#FFF2C0', 0], ['#FFF3C6', 1]]} : undefined)
  32. Column(){
  33. RelativeContainer(){
  34. // 页面的 Title
  35. Column(){
  36. Row(){
  37. Row(){
  38. List({space: 22, scroller: this.vm.categoryControl}){
  39. ForEach(this.vm.categoryList, (item: string, index) => {
  40. ListItem(){
  41. Column(){
  42. Text(item)
  43. .zIndex(99)
  44. .onClick(() => { this.vm.changeCategory(index) })
  45. .attributeModifier(new CustomTextStyle({size: 16, weight: 600, color: this.vm.categoryIndex == index ? '#FF111111' : '#FF777777'}))
  46. if(this.vm.categoryIndex == index){
  47. Image($r('[basic].media.icon_SelectBg'))
  48. .width(45)
  49. .height(16)
  50. .margin({top:-10})
  51. .transition(TransitionEffect.asymmetric(TransitionEffect.move(TransitionEdge.TOP), TransitionEffect.move(TransitionEdge.TOP)).animation({ duration: 100, curve: Curve.Smooth }))
  52. }
  53. }
  54. .alignItems(HorizontalAlign.Center)
  55. }
  56. })
  57. }
  58. .height(40)
  59. .width("100%")
  60. .scrollBar(BarState.Off)
  61. .listDirection(Axis.Horizontal)
  62. }.layoutWeight(1)
  63. Row(){
  64. Image($r('[basic].media.icon_expension'))
  65. .width(10)
  66. .height(8)
  67. .rotate({ angle: this.vm.openTypeDialog ? 180 : 0 })
  68. .animation({duration: 200, curve: Curve.Smooth})
  69. }
  70. .padding({left: 16, top: 2})
  71. .onClick(() => { this.vm.openCategoryDialog() })
  72. }.alignItems(VerticalAlign.Top)
  73. Row(){
  74. Row(){
  75. ForEach(['最新', '最热'], (item: string, index: number) => {
  76. Text(item)
  77. .borderRadius(15)
  78. .padding({left: 12, top: 5, right: 12, bottom: 5})
  79. .attributeModifier(new CustomTextStyle({size: 14, weight: 600}))
  80. .border({width: 2, color: this.vm.sortType == index ? '#FF000000' : Color.Transparent})
  81. .backgroundColor(this.vm.sortType == index ? '#FFFECF2F' : Color.Transparent)
  82. .onClick(() => { this.vm.changeSortType(index) })
  83. })
  84. }
  85. Row({space: 16}){
  86. Row({space: 6}){
  87. Blank()
  88. .width(14)
  89. .aspectRatio(1)
  90. .borderRadius(2)
  91. .border({width: 2, color: '#FF000000'})
  92. .backgroundColor(this.vm.isRead ? '#FFFECF2F' : Color.White)
  93. Text('未读')
  94. .attributeModifier(new CustomTextStyle({size: 14, weight: 400}))
  95. }.onClick(() => { this.vm.changeIsRead() })
  96. Text(this.vm.showMode ? '封面模式' : '列表模式')
  97. .onClick(() => { this.vm.changeShowMode() })
  98. .attributeModifier(new CustomTextStyle({size: 14, weight: 400}))
  99. }
  100. }
  101. .width("100%")
  102. .margin({top: 10})
  103. .justifyContent(FlexAlign.SpaceBetween)
  104. }
  105. .width("100%")
  106. .id('classify')
  107. .backgroundColor(Color.White)
  108. .borderRadius({bottomLeft: 20, bottomRight: 20})
  109. .padding({left: 16, right: 16, bottom: 18})
  110. .alignRules({
  111. left: { anchor: '__container__', align: HorizontalAlign.Start },
  112. top: { anchor: '__container__', align: VerticalAlign.Top }
  113. })
  114. // 书籍列表项
  115. Column(){
  116. List({space: 12}){
  117. ListItem()
  118. Repeat(this.vm.bookList)
  119. .each((item) => {
  120. bookItemComp(item.item, () => {})
  121. })
  122. }
  123. .width("100%")
  124. .height("100%")
  125. .scrollBar(BarState.Off)
  126. }
  127. .id('list')
  128. .width("100%")
  129. .layoutWeight(1)
  130. .padding({left: 16, right: 16})
  131. .backgroundColor(Color.Transparent)
  132. .alignRules({
  133. left: { anchor: '__container__', align: HorizontalAlign.Start },
  134. top: { anchor: 'classify', align: VerticalAlign.Bottom }
  135. })
  136. // 分类弹窗
  137. if(this.vm.openTypeDialog){
  138. Column(){
  139. Column(){
  140. Row(){
  141. Column(){
  142. Text('选择分类')
  143. .zIndex(99)
  144. .attributeModifier(new CustomTextStyle({size: 16, weight: 600}))
  145. Image($r('[basic].media.icon_SelectBg'))
  146. .width(45)
  147. .height(16)
  148. .margin({top:-10})
  149. }
  150. Column(){
  151. Image($r('[basic].media.icon_expension'))
  152. .width(10)
  153. .height(8)
  154. .rotate({ angle: this.vm.openTypeDialog ? 180 : 0 })
  155. .animation({duration: 200, curve: Curve.Smooth})
  156. }
  157. .width(50)
  158. .height(24)
  159. .alignItems(HorizontalAlign.End)
  160. .justifyContent(FlexAlign.Center)
  161. .onClick(() => { this.vm.openCategoryDialog() })
  162. }
  163. .width("100%")
  164. .justifyContent(FlexAlign.SpaceBetween)
  165. Grid(){
  166. ForEach(this.vm.categoryList, (item: string, index: number) => {
  167. GridItem(){
  168. Text(item)
  169. .width('100%')
  170. .borderRadius(18)
  171. .textAlign(TextAlign.Center)
  172. .padding({top: 6, bottom: 6})
  173. .backgroundColor(this.vm.categoryIndex == index ? '#FFFECF2F' : '#FFFFFF')
  174. .border({width: 2, color: this.vm.categoryIndex == index ? '#FF000000' : '#FFFFFF'})
  175. .attributeModifier(new CustomTextStyle({size: 16, weight: 400}))
  176. .onClick(() => {
  177. this.vm.changeCategory(index, true)
  178. this.vm.openCategoryDialog()
  179. })
  180. }
  181. })
  182. }
  183. .rowsGap(14)
  184. .columnsGap(23)
  185. .margin({top: 13})
  186. .maxCount(Math.abs(this.vm.categoryList.length/3))
  187. .columnsTemplate('repeat(3, 1fr)')
  188. }
  189. .width("100%")
  190. .onClick(() => {})
  191. .padding({left: 17, right: 17, bottom: 13})
  192. .borderRadius({bottomLeft: 16, bottomRight: 16})
  193. .linearGradient({colors: [['#FFF3C6', 0], ['#FFF9E4', 1]]})
  194. .transition(TransitionEffect.translate({ y: -20 })
  195. .animation({ duration: 200, curve: Curve.Friction}))
  196. }
  197. .width("100%")
  198. .height("100%")
  199. .backgroundColor('rgba(0, 0, 0, 0.5)')
  200. .onClick(() => { this.vm.openCategoryDialog() })
  201. .alignRules({
  202. left: { anchor: '__container__', align: HorizontalAlign.Start },
  203. top: { anchor: '__container__', align: VerticalAlign.Top }
  204. })
  205. }
  206. }
  207. .width('100%')
  208. .height('100%')
  209. .backgroundColor('#F7F9FA')
  210. }
  211. .width('100%')
  212. .layoutWeight(1)
  213. }
  214. .width('100%')
  215. .height('100%')
  216. }
  217. @Builder
  218. ageSelect(){
  219. Column({space: 17}){
  220. ForEach(['0-2岁', '3-6岁', '7-10岁', '10岁+'], (item: string, index) => {
  221. Text(item)
  222. .attributeModifier(new CustomTextStyle({size: 14, weight: 600}))
  223. })
  224. }
  225. .margin(-4)
  226. .borderRadius(20)
  227. .border({width: 2, color: '#FF000000'})
  228. .padding({left: 32, right: 32, top: 19, bottom: 19})
  229. .onDisAppear(() => { this.vm.openAgeDialog = false })
  230. }
  231. }