1/*
2 * Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import Logger from '../utils/Logger';
17import { getMockSearch } from '../mock/MockData'
18
19const TAG: string = '[SearchComponent]';
20
21@Component
22export default struct SearchComponent {
23  private scroller: Scroller = new Scroller();
24  private searchArr: Array<string> = getMockSearch();
25  @Link inputValue: string
26  @Link isShowResult: boolean // 点击Item改变此值以展示搜索结果页面
27
28  build() {
29    Column() {
30      Scroll(this.scroller) {
31        Column({ space: 4 }) {
32          ForEach(this.searchArr, (item: string, index: number) => {
33            Row() {
34              Image($r('app.media.app_icon'))
35                .width(18)
36                .height(18)
37                .objectFit(ImageFit.Contain)
38                .margin({ left: 14, right: 10 })
39                .opacity(0.8)
40              Text(item)
41                .height(20)
42                .fontColor($r('app.color.COLOR_CCFFFFFF'))
43                .fontSize(20)
44                .fontFamily($r('app.string.Font_family_medium'))
45                .textAlign(TextAlign.Center)
46                .textOverflow({ overflow: TextOverflow.Ellipsis })
47                .margin({ right: 12 })
48              Blank()
49              Image($r('app.media.app_icon'))
50                .width(16)
51                .height(16)
52                .objectFit(ImageFit.Contain)
53                .margin({ right: 14 })
54                .opacity(0.7)
55            }
56            .id(`searchItem_${index+1}`)
57            .width('100%')
58            .height(40)
59            .onClick(e => {
60              // 只有前三条拥有对应的假数据,其他item不做处理
61              if (index < 3) {
62                this.inputValue = item;
63                this.isShowResult = true;
64              }
65            })
66          })
67        }
68        .width('100%')
69      }
70      .scrollable(ScrollDirection.Vertical)
71      .scrollBar(BarState.Off)
72      .width('100%')
73      .height('45%')
74      .align(Alignment.Top)
75
76      Column({ space: 12 }) {
77        Text($r('app.string.Clear_all_search_record'))
78          .fontColor($r('app.color.COLOR_5A5B63'))
79          .fontSize(18)
80          .fontFamily($r('app.string.Font_family_medium'))
81          .textAlign(TextAlign.Center)
82        Divider()
83          .vertical(false)
84          .height(1)
85          .width('90%')
86          .color($r('app.color.COLOR_5A5B63'))
87      }
88      .width('100%')
89      .height(30)
90      .margin({ top: 10 })
91      .justifyContent(FlexAlign.Center)
92      .alignItems(HorizontalAlign.Center)
93    }
94    .width('100%')
95    .height('100%')
96    .backgroundColor($r('app.color.COLOR_151724'))
97  }
98}