notebook_model.dart
8.65 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import 'dart:async';
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/notebook.dart';
import 'package:one_key/models/seller_hide_conf_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/provider/user_model.dart';
import 'package:one_key/utils/utils.dart';
import 'package:provider/provider.dart';
import '../models/get_board_model.dart';
import '../models/note_book_only_model.dart';
class NoteBookModel extends ChangeNotifier {
List<Notebook> notebooks = []; //订单列表
String totalmorning = ""; //一天统计
String totalnoon = ""; //一天统计
String totalnight = ""; //一天统计
String totalmeal1 = ""; //一天统计
String totalmeal2 = ""; //一天统计
PageState pageState = PageState.Loading;
bool isSimple = true;
List<NoteBookOnlySunModel>? notebooksSort = [];
List<SellerHideConfiSunModel>? sellerHideConfiData = [];
//获取商家隐藏订单日期配置列表
Future<List<SellerHideConfiSunModel>?> getSellerHideConf(
BuildContext context) async {
try {
BaseResp<dynamic> baseResp = await DioUtil().request<dynamic>(
context, Method.get, HttpUrl.get_seller_hide_conf,
showLoading: false);
if (baseResp != null && baseResp.code == Constant.status_success) {
sellerHideConfiData = SellerHideConfiModel.fromJson(
baseResp.responseData as Map<String, dynamic>)
.data ??
[];
}
return sellerHideConfiData;
} catch (error) {
print(error.toString());
return [];
}
}
//获取已预订订单
getReserveList(BuildContext context, Map<String, String?> params,
{bool needLoading = false, bool showLoading = true}) async {
if (needLoading) {
pageState = PageState.Loading;
showLoading = false;
notifyListeners();
}
// pageState = PageState.Loading;
// notifyListeners();
try {
BaseResp<List?> baseResp = await DioUtil().request<List>(
context, Method.get, HttpUrl.get_reserve_list,
data: params, showLoading: needLoading ? false : showLoading);
if (baseResp == null) return;
notebooks = [];
if (baseResp.code == Constant.status_success) {
notebooks = baseResp.data!.map<Notebook>((value) {
return Notebook.fromJson(value);
}).toList();
// notebooks.removeWhere((element) => element.id == null);
if (notebooks.isEmpty) {
pageState = PageState.Empty;
} else {
if (notebooks.length > 0) {
if (isSimple) {
for (Notebook item in notebooks) {
item.issimple = true;
}
} else {
for (Notebook item in notebooks) {
item.issimple = false;
}
}
}
pageState = PageState.Success;
}
} else {
Utils.showToast(baseResp.msg ?? "");
}
notifyListeners();
return notebooks;
} catch (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();
}
}
//获取已预订订单
Future<List<NoteBookOnlySunModel>?> getReserveListSort(
BuildContext context, Map<String, String?> params, DateTime now,
{bool needLoading = false, bool showLoading = true}) async {
if (needLoading) {
pageState = PageState.Loading;
showLoading = false;
notifyListeners();
}
// pageState = PageState.Loading;
// notifyListeners();
try {
BaseResp<List?> baseResp = await DioUtil().request<List>(
context, Method.get, HttpUrl.get_reserve_list_also_order,
data: params, showLoading: needLoading ? false : showLoading);
if (baseResp == null) return null;
List<NoteBookOnlySunModel>? tempSort = [];
notebooksSort = [];
if (baseResp.code == Constant.status_success) {
print(sellerHideConfiData);
int limitNum = -1;
if (sellerHideConfiData!.length > 0) {
int index = sellerHideConfiData!
.indexWhere((element) => element.sid == params['sid']);
if (index != -1) {
//存在配置
// "str": "3-2"
// 判断请求的日期是周一到周四还是其他
String str = sellerHideConfiData![index].str ?? '';
List<String> config = str.split('-');
if (now.weekday == 1 ||
now.weekday == 2 ||
now.weekday == 3 ||
now.weekday == 4) {
//周一到周四
limitNum = int.parse(config[0]);
} else {
limitNum = int.parse(config[1]);
}
}
}
tempSort = NoteBookOnlyModel.fromJson(
baseResp.responseData as Map<String, dynamic>)
.data;
if (limitNum != -1) {
if (tempSort!.length > limitNum) {
notebooksSort = tempSort.sublist(0, limitNum);
} else {
notebooksSort = tempSort;
}
} else {
notebooksSort = tempSort;
}
if (notebooksSort!.isEmpty) {
pageState = PageState.Empty;
} else {
if (notebooksSort!.length > 0) {
if (isSimple) {
for (NoteBookOnlySunModel item in notebooksSort!) {
item.issimple = true;
}
} else {
for (NoteBookOnlySunModel item in notebooksSort!) {
item.issimple = false;
}
}
}
pageState = PageState.Success;
}
} else {
Utils.showToast(baseResp.msg ?? "");
}
notifyListeners();
return notebooksSort;
} catch (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();
}
return null;
}
simpleStateOnly() {
if (notebooksSort!.length > 0) {
if (isSimple) {
for (NoteBookOnlySunModel item in notebooksSort!) {
item.issimple = true;
}
} else {
for (NoteBookOnlySunModel item in notebooksSort!) {
item.issimple = false;
}
}
}
}
simpleState() {
if (notebooks.length > 0) {
if (isSimple) {
for (Notebook item in notebooks) {
item.issimple = true;
}
} else {
for (Notebook item in notebooks) {
item.issimple = false;
}
}
}
}
//获取订单统计数目
getReserveCountDay(BuildContext context, Map<String, String?> params) async {
try {
BaseResp<Map<String, dynamic>?> baseResp = await DioUtil()
.request<Map<String, dynamic>>(
context, Method.get, HttpUrl.reserve_count_day,
data: params, showLoading: false);
if (baseResp != null && baseResp.code == Constant.status_success) {
int morning = int.parse(baseResp.data!["morning"].toString());
int noon = int.parse(baseResp.data!["noon"].toString());
int night = int.parse(baseResp.data!["night"].toString());
int meal1 = int.parse(baseResp.data!["four"].toString());
int meal2 = int.parse(baseResp.data!["five"].toString());
// UserModel userModel = Provider.of<UserModel>(context, listen: false);
// total = "已订" + (morning + noon + night).toString();
// if (userModel.user.morning.isNotEmpty) {
totalmorning = "($morning)";
// }
// if (userModel.user.noon.isNotEmpty) {
totalnoon = "($noon)";
// }
// if (userModel.user.night.isNotEmpty) {
totalnight = "($night)";
// }
// if (userModel.user.meal1.isNotEmpty) {
totalmeal1 = "($meal1)";
// }
// if (userModel.user.night.isNotEmpty) {
totalmeal2 = "($meal2)";
// }
notifyListeners();
}
} catch (error) {
print(error.toString());
}
}
}