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 BusinessController from '../../controller/BusinessController';
18import { BusinessInfo } from '../../data/Server';
19import Logger from '../../utils/Logger';
20import { getStringData } from '../../utils/ResourceDataHandle';
21import { BusinessError } from '@ohos.base';
22
23const TAG: string = '[Business]';
24
25@Extend(Row) function rowStyle() {
26  .borderRadius(8)
27  .backgroundColor($r('app.color.index_bg'))
28  .margin({ top: 8 })
29  .padding({ left: 24, right: 24, top: 8, bottom: 8 })
30}
31
32@Extend(Row) function rowStyleShop() {
33  .backgroundColor(Color.White)
34  .width('90%')
35  .height(150)
36  .borderRadius(8)
37  .margin({ top: 12 })
38  .padding(12)
39}
40
41@Entry
42@Component
43struct Business {
44  private businessController: BusinessController = new BusinessController();
45  @State businessList: Array<BusinessInfo> = []; // 商家列表
46  @State longitude: string = getStringData($r('app.string.buy_longitude')); // 经度
47  @State latitude: string = getStringData($r('app.string.buy_latitude')); // 纬度
48
49  aboutToAppear() {
50    Logger.info(TAG, 'aboutToAppear begin');
51    this.businessController.getBusinessList(this.longitude, this.latitude).then((res: BusinessInfo[]) => {
52      Logger.info(TAG, `aboutToAppear then res= ${JSON.stringify(res)}`);
53      this.businessList = res;
54    }).catch((err: BusinessError) => {
55      Logger.info(TAG, `aboutToAppear catch err= ${JSON.stringify(err)}`);
56    })
57  }
58
59  build() {
60    Column() {
61      Row() {
62        Image($r('app.media.icon'))
63          .height(24)
64          .width(24)
65          .onClick(() => {
66            router.back();
67          })
68
69        Row() {
70          Image($r('app.media.icon'))
71            .height(18)
72            .width(18)
73            .margin({ left: 12 })
74          Text($r('app.string.business_noodles'))
75            .fontSize(18)
76            .fontColor($r('app.color.business_font'))
77            .fontWeight(FontWeight.Medium)
78            .margin({ left: 12 })
79          Blank()
80          Button($r('app.string.index_search'))
81            .fontColor($r('app.color.index_font'))
82            .fontSize(18)
83            .width(75)
84            .height('85%')
85            .backgroundColor($r('app.color.index_search_btn_bg'))
86            .margin({ right: 4 })
87        }
88        .height('100%')
89        .border({ color: $r('app.color.business_border'), width: 2 })
90        .margin({ left: 12, top: 10, bottom: 10 })
91        .layoutWeight(1)
92        .backgroundColor(Color.White)
93        .borderRadius(24)
94      }
95      .width('90%')
96      .height('8%')
97
98      Row() {
99        Row() {
100          Text($r('app.string.business_less_delivery'))
101            .fontSize(18)
102        }
103        .rowStyle()
104
105        Row() {
106          Text($r('app.string.business_zero'))
107            .fontSize(18)
108        }
109        .rowStyle()
110
111        Row() {
112          Text($r('app.string.business_order_minus'))
113            .fontSize(18)
114        }
115        .rowStyle()
116      }
117      .justifyContent(FlexAlign.SpaceAround)
118      .width('90%')
119      .height('8%')
120
121      Scroll() {
122        Column() {
123          ForEach(this.businessList, (business: BusinessInfo, index: number) => {
124            Row() {
125              Image($r('app.media.icon'))
126                .width(125)
127                .height(125)
128              Column() {
129                Row() {
130                  Text(business.name)
131                    .fontSize(24)
132                    .fontWeight(5)
133                }
134                .width('100%')
135
136                Row() {
137                  Text(getStringData($r('app.string.business_score')) + business.score)
138                    .fontColor($r('app.color.business_score'))
139                    .fontSize(20)
140                    .fontWeight(5)
141                  Text(getStringData($r('app.string.business_monthly_sale')) + business.monthlySale)
142                    .fontSize(12)
143                    .fontWeight(5)
144                    .margin({ left: 6 })
145                  Text(getStringData($r('app.string.business_per_capita')) + business.perCapita)
146                    .fontSize(12)
147                    .fontWeight(5)
148                    .margin({ left: 6 })
149                  Row() {
150                    Text($r('app.string.business_delivery'))
151                      .fontColor($r('app.color.business_delivery'))
152                      .fontSize(12)
153                      .fontWeight(5)
154                      .margin({ left: 6, right: 6 })
155                  }
156                  .margin({ left: 6 })
157                  .borderWidth(2)
158                  .border({ color: $r('app.color.business_delivery_bg') })
159                }
160                .width('100%')
161                .margin({ top: 4 })
162
163                Row() {
164                  Text(getStringData($r('app.string.business_give')) + business.startPrice)
165                    .fontSize(12)
166                    .fontWeight(5)
167                  Text(getStringData($r('app.string.business_distribution')) + business.deliveryPrice)
168                    .fontSize(12)
169                    .fontWeight(5)
170                    .margin({ left: 6 })
171                  Blank()
172                  Text(business.deliveryTime + getStringData($r('app.string.business_min')))
173                    .fontSize(12)
174                    .fontWeight(5)
175                    .margin({ left: 12, right: 6 })
176                  Text(business.distance + getStringData($r('app.string.business_m')))
177                    .fontSize(12)
178                    .fontWeight(5)
179                }
180                .width('100%')
181                .margin({ top: 4 })
182
183                Row() {
184                  Row() {
185                    Text($r('app.string.business_good_shop'))
186                      .fontColor($r('app.color.business_good_shop'))
187                      .fontSize(12)
188                      .fontWeight(5)
189                  }
190                  .backgroundColor($r('app.color.business_good_shop_bg'))
191
192                  Row() {
193                    Text($r('app.string.business_buy_back'))
194                      .fontColor($r('app.color.business_buy_back'))
195                      .fontSize(12)
196                      .fontWeight(5)
197                  }
198                  .margin({ left: 6 })
199                  .backgroundColor($r('app.color.business_buy_back_bg'))
200                }
201                .width('100%')
202                .margin({ top: 8 })
203
204                Row() {
205                  Text($r('app.string.business_reduce'))
206                    .fontColor(Color.Red)
207                    .fontSize(12)
208                    .fontWeight(5)
209                    .borderWidth(2)
210                    .border({ color: Color.Red })
211                }
212                .width('100%')
213                .margin({ top: 6 })
214              }
215              .justifyContent(FlexAlign.Start)
216              .height('90%')
217              .width('60%')
218              .margin({ left: 12, right: 12 })
219            }
220            .rowStyleShop()
221            .onClick(() => {
222              router.push({
223                url: 'pages/takeaway/Commodity',
224                params: {
225                  businessId: business.id,
226                  businessName: business.name,
227                  businessScore: business.score,
228                  businessSale: business.monthlySale,
229                  businessTime: business.deliveryTime,
230                  businessRank: business.ranking
231                }
232              });
233            })
234            .id('business' + index)
235          })
236        }
237      }
238      .borderRadius(8)
239      .margin({ left: 12, right: 12, top: 12, bottom: 200 })
240      .width('95%')
241      .height('85%')
242      .backgroundColor($r('app.color.index_bg'))
243
244      Column() {
245        Row() {
246          Image($r('app.media.icon'))
247            .height(38)
248            .width(38)
249          Image($r('app.media.icon'))
250            .height(38)
251            .width(38)
252          Image($r('app.media.icon'))
253            .height(38)
254            .width(38)
255          Image($r('app.media.icon'))
256            .height(38)
257            .width(38)
258        }
259        .margin({ top: 12 })
260        .width('100%')
261        .justifyContent(FlexAlign.SpaceAround)
262
263        Row() {
264          Text($r('app.string.business_takeaway'))
265          Text($r('app.string.business_vip'))
266          Text($r('app.string.business_order'))
267          Text($r('app.string.business_more'))
268        }
269        .margin({ top: 8, bottom: 8 })
270        .width('100%')
271        .justifyContent(FlexAlign.SpaceAround)
272      }
273      .backgroundColor(Color.White)
274      .position({ y: '92%' })
275    }
276    .width('100%')
277    .height('100%')
278  }
279}
280