SearchResultComponent.ets
4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { ContentDTO } from 'wdBean/Index'
import { LazyDataSource, UserDataLocal } from 'wdKit/Index'
import { HttpUrlUtils } from 'wdNetwork/Index'
import SearcherAboutDataModel from '../../model/SearcherAboutDataModel'
import { SearchSuggestRequestItem } from '../../viewmodel/SearchSuggestRequestItem'
import { CardParser } from '../CardParser'
import { EmptyComponent } from '../view/EmptyComponent'
import { SearchResultContentComponent } from './SearchResultContentComponent'
const TAG = "SearchResultComponent"
/**
* 搜索结果
* 搜索结果为null(空布局 + 为你推荐)
*/
@Component
export struct SearchResultComponent {
@Prop count: string[]
@Prop searchText: string
@Prop isGetRequest:boolean = false;
@State currentIndex: number = 0
private controller: TabsController = new TabsController()
fontColor: string = '#999999'
selectedFontColor: string = '#000000'
@State data: LazyDataSource<ContentDTO> = new LazyDataSource();
@State suggest_count: number = 0;
@State isLoading: boolean = false
scroller: Scroller = new Scroller()
aboutToAppear(): void {
if (this.count.length === 0 && this.isGetRequest == true) {
this.getSuggestData()
}
}
getSuggestData() {
this.isLoading = true
let request: SearchSuggestRequestItem = new SearchSuggestRequestItem(2, "", "", HttpUrlUtils.getImei(), UserDataLocal.userId, 8, "")
SearcherAboutDataModel.getSearchSuggestData(request, getContext(this)).then((value) => {
value.forEach((item) => {
this.data.push(item)
})
this.data.notifyDataReload()
this.suggest_count = this.data.totalCount()
this.isLoading = false
})
}
build() {
Column() {
if (this.count != null && this.count.length === 0 && this.isGetRequest == true) {
List() {
ListItem() {
//缺省图
EmptyComponent({emptyType:4})
.height('612lpx')
.width('100%')
}
if(this.suggest_count > 0){
ListItem() {
Row() {
Image($r('app.media.search_suggest_icon'))
.width('6lpx')
.height('31lpx')
.objectFit(ImageFit.Cover)
.interpolation(ImageInterpolation.High)
.margin({ right: '10lpx' })
Text("为你推荐")
.textAlign(TextAlign.Start)
.fontWeight('600lpx')
.fontSize('33lpx')
.lineHeight('46lpx')
.fontColor($r('app.color.color_222222'))
}.height('84lpx')
.padding({ left: '31lpx', right: '31lpx' })
.width('100%')
.alignItems(VerticalAlign.Center)
}
}
LazyForEach(this.data, (item: ContentDTO, index: number) => {
ListItem() {
Column() {
CardParser({contentDTO:item})
if (index != this.data.totalCount() - 1) {
Divider()
.width('100%')
.height('1lpx')
.color($r('app.color.color_F5F5F5'))
.strokeWidth('1lpx')
}
}
}
})
}
.cachedCount(6)
.edgeEffect(EdgeEffect.None)
.scrollBar(BarState.Off)
.height('100%')
.onReachEnd(() => {
if (!this.isLoading) {
this.getSuggestData()
}
})
} else {
Tabs({ barPosition: BarPosition.Start, controller: this.controller }) {
ForEach(this.count, (item: string, index: number) => {
TabContent() {
SearchResultContentComponent({ keywords: this.searchText, searchType: item })
}.tabBar(this.TabBuilder(index, item))
}, (item: string, index: number) => index.toString())
}
.vertical(false)
.barMode(BarMode.Fixed)
.barWidth('100%')
.barHeight('84lpx')
.animationDuration(0)
.onChange((index: number) => {
this.currentIndex = index
})
.width('100%')
.layoutWeight(1)
}
}.width('100%')
.margin({ top: '12lpx' })
}
@Builder
TabBuilder(index: number, item: string) {
Stack() {
Text(item)
.height('38lpx')
.fontSize('33lpx')
.fontWeight(this.currentIndex === index ? 600 : 400)
.fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
.lineHeight('38lpx')
if (this.currentIndex === index) {
Divider()
.width('31lpx')
.height('4lpx')
.color('#ED2800')
.strokeWidth('4lpx')
.margin({ top: '50lpx' })
.id("divTag")
}
}.onClick(() => {
this.currentIndex = index
this.controller.changeIndex(this.currentIndex)
})
.height('100%')
.margin({ right: '9lpx' })
.padding({ left: '31lpx', right: index === this.count.length - 1 ? "31lpx" : "0lpx" })
}
}