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 router from '@ohos.router';
17import geoLocationManager from '@ohos.geoLocationManager';
18import { BusinessError } from '@ohos.base';
19
20import grantPermission from '../utils/PermissionUtils';
21import Logger from '../utils/Logger';
22
23const TAG: string = '[Index]';
24
25@Entry
26@Component
27struct Index {
28  private latitude: string = '';
29  private longitude: string = '';
30
31  // 获取定位服务
32  getLocation(): void {
33    let locationChange = (err: BusinessError, location: geoLocationManager.Location) => {
34      if (err) {
35        console.log('locationChanger: err=' + JSON.stringify(err));
36      }
37      if (location) {
38        this.latitude = location.latitude.toString();
39        this.longitude = location.longitude.toString();
40        console.log('locationChanger: location=' + JSON.stringify(location));
41        Logger.info(TAG, `this.latitude  ${this.latitude}`);
42        Logger.info(TAG, `this.longitude  ${this.longitude}`);
43      }
44    };
45    try {
46      geoLocationManager.getCurrentLocation(locationChange);
47    } catch (err) {
48      console.error("errCode:" + err.code + ",errMessage:" + err.message);
49    }
50  }
51
52  async aboutToAppear() {
53    // 申请权限
54    await grantPermission().then(res => {
55      this.getLocation();
56      Logger.info(TAG, `权限申请成功  ${JSON.stringify(res)}`);
57    }).catch((rej: BusinessError) => {
58      Logger.info(TAG, `权限申请失败  ${JSON.stringify(rej)}`);
59    })
60  }
61
62  build() {
63    Column() {
64      Row() {
65        Row() {
66          Text($r('app.string.index_coffee'))
67            .fontSize(16)
68            .fontColor($r('app.color.index_font'))
69            .fontWeight(FontWeight.Medium)
70            .margin({ left: 15 })
71          Blank()
72          Button($r('app.string.index_search'))
73            .fontColor($r('app.color.index_font'))
74            .fontSize(18)
75            .width(80)
76            .height('90%')
77            .backgroundColor($r('app.color.index_search_btn_bg'))
78            .margin({ right: 4 })
79        }
80        .margin({ top: 10, bottom: 10 })
81        .layoutWeight(1)
82        .height('7%')
83        .backgroundColor(Color.White)
84        .borderRadius(24)
85
86        Image($r('app.media.icon'))
87          .objectFit(ImageFit.Contain)
88          .width(35)
89          .height(35)
90          .margin({ left: 20 })
91          .id('sweep')
92      }
93      .padding({ left: 18, right: 18 })
94      .width('100%')
95
96      Row() {
97        Column() {
98          Text($r('app.string.index_text'))
99            .width('100%')
100            .margin({ left: 5 })
101            .textAlign(TextAlign.Start)
102          Row() {
103            Image($r('app.media.icon'))
104              .height(38)
105              .width(38)
106              .id('business')
107              .onClick(() => {
108                router.push({ url: 'pages/takeaway/Business' });
109              })
110            Image($r('app.media.icon'))
111              .height(38)
112              .width(38)
113              .id('buy')
114              .onClick(() => {
115                router.push({ url: 'pages/buy/Buy' });
116              })
117            Image($r('app.media.icon'))
118              .height(38)
119              .width(38)
120            Image($r('app.media.icon'))
121              .height(38)
122              .width(38)
123            Image($r('app.media.icon'))
124              .height(38)
125              .width(38)
126          }
127          .margin({ top: 12 })
128          .width('100%')
129          .justifyContent(FlexAlign.SpaceAround)
130
131          Row() {
132            Text($r('app.string.index_takeaway'))
133              .onClick(() => {
134                router.push({ url: 'pages/takeaway/Business' });
135              })
136            Text($r('app.string.index_buy'))
137              .onClick(() => {
138                router.push({ url: 'pages/buy/Buy' });
139              })
140            Text($r('app.string.index_convenient'))
141            Text($r('app.string.index_general_merchandise'))
142            Text($r('app.string.index_medicine'))
143          }
144          .margin({ top: 8 })
145          .width('100%')
146          .justifyContent(FlexAlign.SpaceAround)
147        }
148      }
149      .height('15%')
150      .width('100%')
151      .padding(8)
152      .margin({ left: 12, right: 12 })
153      .backgroundColor(Color.White)
154      .borderRadius(8)
155
156      Scroll() {
157        Column() {
158          Row({ space: 60 }) {
159            Image($r('app.media.icon'))
160              .height(160)
161              .width(160)
162
163            Image($r('app.media.icon'))
164              .height(160)
165              .width(160)
166          }
167          .width('90%')
168          .justifyContent(FlexAlign.Center)
169
170          Row({ space: 60 }) {
171            Image($r('app.media.icon'))
172              .height(160)
173              .width(160)
174
175            Image($r('app.media.icon'))
176              .height(160)
177              .width(160)
178          }
179          .width('90%')
180          .justifyContent(FlexAlign.Center)
181          .margin({ top: 12 })
182
183          Row({ space: 60 }) {
184            Image($r('app.media.icon'))
185              .height(160)
186              .width(160)
187
188            Image($r('app.media.icon'))
189              .height(160)
190              .width(160)
191          }
192          .width('90%')
193          .justifyContent(FlexAlign.Center)
194          .margin({ top: 12 })
195
196          Row({ space: 60 }) {
197            Image($r('app.media.icon'))
198              .height(160)
199              .width(160)
200
201            Image($r('app.media.icon'))
202              .height(160)
203              .width(160)
204          }
205          .width('90%')
206          .justifyContent(FlexAlign.Center)
207          .margin({ top: 12 })
208
209          Row({ space: 60 }) {
210            Image($r('app.media.icon'))
211              .height(160)
212              .width(160)
213
214            Image($r('app.media.icon'))
215              .height(160)
216              .width(160)
217          }
218          .width('90%')
219          .justifyContent(FlexAlign.Center)
220          .margin({ top: 12 })
221
222          Row({ space: 60 }) {
223            Image($r('app.media.icon'))
224              .height(160)
225              .width(160)
226
227            Image($r('app.media.icon'))
228              .height(160)
229              .width(160)
230          }
231          .width('90%')
232          .justifyContent(FlexAlign.Center)
233          .margin({ top: 12 })
234
235          Row({ space: 60 }) {
236            Image($r('app.media.icon'))
237              .height(160)
238              .width(160)
239
240            Image($r('app.media.icon'))
241              .height(160)
242              .width(160)
243          }
244          .width('90%')
245          .justifyContent(FlexAlign.Center)
246          .margin({ top: 12 })
247        }
248      }
249      .width('100%')
250      .height('65%')
251      .padding(8)
252      .margin({ left: 12, right: 12, top: 12, bottom: 120 })
253      .backgroundColor(Color.White)
254      .borderRadius(8)
255
256      Column() {
257        Row() {
258          Image($r('app.media.icon'))
259            .height(38)
260            .width(38)
261          Image($r('app.media.icon'))
262            .height(38)
263            .width(38)
264          Image($r('app.media.icon'))
265            .height(38)
266            .width(38)
267          Image($r('app.media.icon'))
268            .height(38)
269            .width(38)
270          Image($r('app.media.icon'))
271            .height(38)
272            .width(38)
273        }
274        .margin({ top: 12 })
275        .width('100%')
276        .justifyContent(FlexAlign.SpaceAround)
277
278        Row() {
279          Text($r('app.string.index_recommend'))
280          Text($r('app.string.index_optimization'))
281          Text($r('app.string.index_video'))
282          Text($r('app.string.index_message'))
283          Text($r('app.string.index_me'))
284        }
285        .margin({ top: 8, bottom: 8 })
286        .width('100%')
287        .justifyContent(FlexAlign.SpaceAround)
288      }
289      .position({ y: '90%' })
290      .backgroundColor(Color.White)
291    }
292    .backgroundColor($r('app.color.index_bg'))
293    .width('100%')
294    .height('100%')
295  }
296}