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 { BusinessError } from '@ohos.base';
18import GroupBuyController from '../../controller/GroupBuyController';
19import Logger from '../../utils/Logger';
20import { getStringData } from '../../utils/ResourceDataHandle';
21import { SelfPickUpInfo } from '../../data/Server'
22
23const TAG: string = '[SelfPickUp]';
24
25@Entry
26@Component
27struct SelfPickUp {
28  private groupBuyController: GroupBuyController = new GroupBuyController();
29  @State selfPickUpList: Array<SelfPickUpInfo> = []; // 站点列表
30  @State longitude: string = getStringData($r('app.string.buy_longitude')); // 经度
31  @State latitude: string = getStringData($r('app.string.buy_latitude')); // 纬度
32
33  aboutToAppear() {
34    Logger.info(TAG, 'aboutToAppear begin');
35    this.groupBuyController.getGroupBuyList(this.longitude, this.latitude).then((res: SelfPickUpInfo[]) => {
36      Logger.info(TAG, `aboutToAppear then res= ${JSON.stringify(res)}`);
37      this.selfPickUpList = res;
38      Logger.info(TAG, `aboutToAppear forEach this.selfPickUpList= ${JSON.stringify(this.selfPickUpList)}`);
39    }).catch((err: BusinessError) => {
40      Logger.info(TAG, `aboutToAppear catch err= ${JSON.stringify(err)}`);
41    })
42  }
43
44  build() {
45    Column() {
46      Row() {
47        Image($r('app.media.icon'))
48          .height(24)
49          .width(24)
50          .margin({ top: 20 })
51          .onClick(() => {
52            router.back();
53          })
54        .id('selfPickUpBack')
55
56        Row() {
57          Image($r('app.media.icon'))
58            .height(18)
59            .width(18)
60            .margin({ left: 12 })
61          Text($r('app.string.self_ponit'))
62            .fontSize(16)
63            .fontColor($r('app.color.business_font'))
64            .fontWeight(FontWeight.Medium)
65            .margin({ left: 12 })
66          Blank()
67        }
68        .height('100%')
69        .margin({ left: 12, top: 20 })
70        .layoutWeight(1)
71        .backgroundColor(Color.White)
72        .borderRadius(24)
73      }
74      .justifyContent(FlexAlign.Center)
75      .margin({ top: 4 })
76      .width('90%')
77      .height('6%')
78
79      Column() {
80        Row() {
81          Text($r('app.string.self_near'))
82            .fontSize(24)
83            .fontWeight(10)
84          Blank()
85        }
86        .margin({ top: 24 })
87        .width('95%')
88
89        Row({ space: 20 }) {
90          Text($r('app.string.self_cold'))
91            .fontColor($r('app.color.pd_font_gray'))
92            .textAlign(TextAlign.Center)
93            .padding({ left: 12, right: 12, top: 6, bottom: 6 })
94            .borderRadius(8)
95            .backgroundColor($r('app.color.index_bg'))
96
97          Text($r('app.string.self_door'))
98            .fontColor($r('app.color.pd_font_gray'))
99            .textAlign(TextAlign.Center)
100            .padding({ left: 12, right: 12, top: 6, bottom: 6 })
101            .borderRadius(8)
102            .backgroundColor($r('app.color.index_bg'))
103
104          Text($r('app.string.self_service'))
105            .fontColor($r('app.color.pd_font_gray'))
106            .textAlign(TextAlign.Center)
107            .padding({ left: 12, right: 12, top: 6, bottom: 6 })
108            .borderRadius(8)
109            .backgroundColor($r('app.color.index_bg'))
110        }
111        .margin({ top: 12 })
112        .width('90%')
113
114        Scroll() {
115          Column() {
116            ForEach(this.selfPickUpList, (selfPickUp: SelfPickUpInfo) => {
117              Row() {
118                Row() {
119                  Image($r('app.media.icon'))
120                    .width(100)
121                    .height(100)
122                }
123                .height('100%')
124                .alignItems(VerticalAlign.Top)
125
126                Column() {
127                  Row() {
128                    Text(selfPickUp.name)
129                      .textOverflow({ overflow: TextOverflow.Ellipsis })
130                      .fontSize(18)
131                      .fontWeight(5)
132                  }
133                  .width('100%')
134
135                  Row() {
136                    Text(selfPickUp.address.split('')
137                      .join('\u200B'))
138                      .textAlign(TextAlign.Start)
139                      .textOverflow({ overflow: TextOverflow.Ellipsis })
140                      .maxLines(2)
141                      .fontSize(16)
142                      .lineHeight(20)
143                      .fontWeight(5)
144                      .fontColor($r('app.color.pd_font_gray'))
145                  }
146                  .width('100%')
147                  .margin({ top: 4 })
148
149                  Row() {
150                    Text($r('app.string.self_cold'))
151                      .fontColor($r('app.color.self_cold_font'))
152                      .fontSize(14)
153                      .fontWeight(5)
154                      .borderWidth(1)
155                      .borderColor($r('app.color.self_cold_bg'))
156                  }
157                  .justifyContent(FlexAlign.Start)
158                  .width('100%')
159                  .margin({ top: 8 })
160
161                  Row() {
162                    Text(getStringData($r('app.string.self_walk')) + selfPickUp.distance)
163                      .fontSize(18)
164                  }
165                  .margin({ left: 6 })
166                  .width('100%')
167                  .margin({ top: 8 })
168                }
169                .width('50%')
170                .height('100%')
171                .margin({ left: 12, right: 12 })
172                .justifyContent(FlexAlign.Start)
173
174                Row() {
175                  Button($r('app.string.self_choose'))
176                    .fontColor(Color.Black)
177                    .backgroundColor($r('app.color.business_buy_back'))
178                }
179                .height('100%')
180                .alignItems(VerticalAlign.Bottom)
181              }
182              .width('95%')
183              .height('20%')
184              .margin({ top: 24 })
185            }, (selfPickUp: SelfPickUpInfo) => JSON.stringify(selfPickUp))
186          }
187          .margin({ bottom: 150 })
188        }
189      }
190      .borderRadius(8)
191      .backgroundColor(Color.White)
192      .width('90%')
193      .height('95%')
194      .margin({ top: 24 })
195    }
196    .backgroundColor($r('app.color.index_bg'))
197    .width('100%')
198    .height('100%')
199  }
200}