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 */
15import http from '@ohos.net.http';
16import Logger from '../utils/Logger';
17import Constant from '../utils/Constant';
18import NetworkModel from '../model/NetworkModel';
19import LoginResult from '../data/LoginResult';
20
21const TAG: string = '[GroupBuyController]';
22
23export default class GroupBuyController {
24  private networkModel: NetworkModel = new NetworkModel();
25
26  public async getGroupBuyList(longitude: string, latitude: string): Promise<any> {
27    Logger.info(TAG, `GroupBuyList longitude->${longitude},latitude->${latitude}`);
28    let extraData = {
29      longitude: longitude,
30      latitude: latitude
31    };
32    Logger.info(TAG, `GroupBuyList extraData->${JSON.stringify(extraData)}`);
33    let userInfo: LoginResult = AppStorage.get('userInfo')!
34    let response = await this.networkModel.request(Constant.ACTION_GROUP_BUY, http.RequestMethod.GET, extraData, userInfo.token);
35    Logger.info(TAG, `GroupBuyList response->${JSON.stringify(response)}`);
36    // 拿到响应中服务端返回的数据
37    Logger.info(TAG, `GroupBuyList response.result->${JSON.stringify(response.result)}`);
38    let data = response.result.toString();
39    Logger.info(TAG, `GroupBuyList data->${JSON.stringify(data)}`);
40    // 将其转成Json数据
41    let jsonData = JSON.parse(data);
42    Logger.info(TAG, `GroupBuyList jsonData->${JSON.stringify(jsonData)}`);
43    let result = null; // 站点数据
44    if (jsonData && jsonData.result) {
45      result = jsonData.result.records;
46    }
47    return result;
48  }
49}