SearchResultComponent.ets
6.5 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import { CompDTO, ContentDTO } from 'wdBean/Index'
import { LazyDataSource, NetworkUtil, UserDataLocal } from 'wdKit/Index'
import { HttpUtils } 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()
onClickTryAgain?: () => void;
@State isConnectNetwork : boolean = NetworkUtil.isNetConnected()
@Prop percent:number = 1
@Prop sameSearch:number = 0
aboutToAppear(): void {
if (this.count.length === 0 && this.isGetRequest == true) {
this.getSuggestData()
}
}
getSuggestData() {
this.isLoading = true
let request: SearchSuggestRequestItem = new SearchSuggestRequestItem(2, "", "", HttpUtils.getImei(), UserDataLocal.getUserId(), 8, "")
SearcherAboutDataModel.getSearchSuggestData(request, getContext(this)).then((value) => {
value.forEach((item) => {
if(item.objectType != "13"){
this.data.push(item)
}
})
this.data.notifyDataReload()
this.suggest_count = this.data.totalCount()
this.isLoading = false
if(this.suggest_count === 0 && value.length > 0){
this.suggest_count = -1
if(!this.isLoading){
this.getSuggestData()
}
}else if(this.suggest_count <= 20 && value.length > 0){
if(!this.isLoading){
this.getSuggestData()
}
}
})
}
build() {
Column() {
if (this.count != null && this.count.length === 0 && this.isGetRequest == true) {
List() {
ListItem() {
//缺省图
if(this.isConnectNetwork){
EmptyComponent({emptyType:4})
.height('70%')
.width('100%')
}else{
EmptyComponent({ emptyType: 1,emptyHeight:"100%" ,retry: () => {
this.isConnectNetwork = NetworkUtil.isNetConnected()
if(this.isConnectNetwork){
if (this.onClickTryAgain !== undefined) {
this.onClickTryAgain()
}
}
}})
.height("100%")
.width('100%')
}
}
if(this.suggest_count > 0){
ListItem() {
Row() {
Image($r('app.media.search_suggest_icon'))
.width(`${this.calcHeight(6)}lpx`)
.height(`${this.calcHeight(31)}lpx`)
.objectFit(ImageFit.Cover)
.interpolation(ImageInterpolation.High)
.margin({ right: `${this.calcHeight(10)}lpx` })
Text("为你推荐")
.textAlign(TextAlign.Start)
.fontWeight(600)
.fontSize(`${this.calcHeight(33)}lpx`)
.lineHeight(`${this.calcHeight(46)}lpx`)
.fontColor($r('app.color.color_222222'))
}.height(`${this.calcHeight(84)}lpx`)
.padding({ left: `${this.calcHeight(31)}lpx`, right: `${this.calcHeight(31)}lpx` })
.width('100%')
.alignItems(VerticalAlign.Center)
}
}
LazyForEach(this.data, (item: ContentDTO, index: number) => {
ListItem() {
Column() {
CardParser({compDTO:new CompDTO,contentDTO:item})
if (index != this.data.totalCount() - 1) {
Divider()
.width('100%')
.height(`${this.calcHeight(1)}lpx`)
.color($r('app.color.color_F5F5F5'))
.strokeWidth(`${this.calcHeight(1)}lpx`)
}
}
}
})
}
.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 ,sameSearch:this.sameSearch,isCurrentShow:this.currentIndex === index})
}.tabBar(this.TabBuilder(index, item))
.layoutWeight(1)
}, (item: string) => item)
}
.vertical(false)
.barMode(BarMode.Fixed)
.barWidth('100%')
.barHeight(`${this.calcHeight(84)}lpx`)
.animationDuration(0)
.width('100%')
.scrollable(false)
.layoutWeight(1)
}
}.width('100%')
.layoutWeight(1)
.margin({ top: `${this.calcHeight(12)}lpx` })
}
@Builder
TabBuilder(index: number, item: string) {
Stack() {
Text(item)
.height(`${this.calcHeight(38)}lpx`)
.fontSize(`${this.calcHeight(33)}lpx`)
.fontWeight(this.currentIndex === index ? 600 : 400)
.fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
.lineHeight(`${this.calcHeight(38)}lpx`)
if (this.currentIndex === index) {
Divider()
.width(`${this.calcHeight(31)}lpx`)
.height(`${this.calcHeight(4)}lpx`)
.color('#ED2800')
.strokeWidth(`${this.calcHeight(4)}lpx`)
.margin({ top: `${this.calcHeight(50)}lpx` })
.id("divTag")
}
}.onClick(() => {
this.currentIndex = index
this.controller.changeIndex(this.currentIndex)
})
.height('100%')
.margin({ right: `${this.calcHeight(9)}lpx` })
.padding({ left: `${this.calcHeight(31)}lpx`, right: index === this.count.length - 1 ? `${this.calcHeight(31)}lpx` : "0lpx" })
}
calcHeight(value:number): number{
return value * this.percent
}
}