order_food_provider.dart
3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import 'package:flutter/material.dart';
import 'package:one_key/constant/constant.dart';
import 'package:one_key/constant/error.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/models/created_order_model.dart';
import 'package:one_key/models/reserve_detail_model.dart';
import 'package:one_key/net/base_resp.dart';
import 'package:one_key/net/dio_util.dart';
import 'package:one_key/net/http_url.dart';
import 'package:one_key/utils/utils.dart';
///已选菜品页面
class OrderFoodProvider extends ChangeNotifier {
PageState pageState = PageState.Loading;
List<Map<String, List<Cookbooklist>>> orderList = []; //已点菜单信息
CreatedOrderSunModel createdOrderSunModel;
ReserveDetailSunModel reserveDetailSunModel;
String showTable = '';
///顾客扫桌码点餐-扫码创建订单
getOrderFoodData(BuildContext context, Map<String, String> params,
{isShowLoading = true}) async {
if (isShowLoading) {
pageState = PageState.Loading;
notifyListeners();
}
BaseResp<Map<String, dynamic>> baseResp = await DioUtil()
.request<Map<String, dynamic>>(
context, Method.post, HttpUrl.get_order_food,
data: params, showLoading: false)
.catchError((error) {
print(error.toString());
if (error is MyError) {
switch (error.type) {
case 1:
pageState = PageState.ConnectivityError;
break;
case 2:
pageState = PageState.ConnectivityTimeOut;
break;
default:
pageState = PageState.ConnectivityError;
break;
}
}
notifyListeners();
});
if (baseResp.code == Constant.status_success) {
if (baseResp.data.isEmpty) {
pageState = PageState.Empty;
} else {
pageState = PageState.Success;
createdOrderSunModel =
CreatedOrderModel.fromJson(baseResp.responseData).data;
List<Cookbooklist> cookbooklist =
CreatedOrderModel.fromJson(baseResp.responseData).data.cookbooklist;
Set keysSet = Set();
for (Cookbooklist item in cookbooklist) {
keysSet.add(item.className);
}
List keysList = [];
keysList.addAll(keysSet);
for (int i = 0; i < keysList.length; i++) {
Map<String, List<Cookbooklist>> father = {};
List<Cookbooklist> sun = [];
for (int j = 0; j < cookbooklist.length; j++) {
if (keysList[i] == cookbooklist[j].className) {
sun.add(cookbooklist[j]);
}
}
if (sun.length > 0) {
father[keysList[i]] = sun;
orderList.add(father);
}
}
}
notifyListeners();
} else {
pageState = PageState.ConnectivityError;
notifyListeners();
if (baseResp != null) {
Utils.showToast(baseResp.msg ?? "");
}
}
}
///订座详情页面
getTableInfoData(BuildContext context, Map<String, String> params,
{isShowLoading = true}) async {
BaseResp<Map<String, dynamic>> baseResp = await DioUtil()
.request<Map<String, dynamic>>(
context, Method.post, HttpUrl.get_reserve_detail,
data: params, showLoading: false)
.catchError((error) {});
if (baseResp.code == Constant.status_success) {
if (baseResp.data.isEmpty) {
} else {
//解析解析
reserveDetailSunModel =
ReserveDetailModel.fromJson(baseResp.responseData).data;
}
notifyListeners();
} else {
if (baseResp != null) {
Utils.showToast(baseResp.msg ?? "");
}
}
}
}