feast_model.dart
12.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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
import 'package:flutter/material.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:provider/provider.dart';
import '../constant/constant.dart';
import '../constant/error.dart';
import '../models/classify_model.dart';
import '../models/filter_btn_model.dart';
import '../models/get_seller_user_by_sellerid_model.dart';
import '../models/get_staff_model.dart';
import '../models/personnel_manage_model.dart';
import '../models/wine_model.dart';
import '../net/base_resp.dart';
import '../net/dio_util.dart';
import '../net/http_url.dart';
import '../utils/utils.dart';
class FeastModel extends ChangeNotifier {
PageState pageState = PageState.Success;
List<FilterBtnModel> sellerManageList = []; //经理数据 ---- 商家编辑页面
PageState pageStatePersonnalHome = PageState.Loading; //员工管理
List<String> selectPersonnalData = [];
bool checkValue = false;
List<String> getPersonnalList = []; //宴会员工
PageState pageStateType = PageState.Loading; //宴会类型
List<ClassifySunModel> classifyData = [];
PageState pageStateWine = PageState.Loading; //酒水
List<WineSunModel> wineData = [];
/***
*
* 宴会员工
*/
//全选按钮执行“全选”
addAllMy() async {
//把数据状态全部改成true,即选中状态
selectPersonnalData = [];
for (var i = 0; i < sellerManageList.length; i++) {
sellerManageList[i].select = true;
selectPersonnalData.add(sellerManageList[i].id);
}
checkValue = true;
notifyListeners();
}
//全选按钮执行“全不选”
cancelAllMy() async {
selectPersonnalData = [];
//把数据状态全部改成false,即不选中状态
for (var i = 0; i < sellerManageList.length; i++) {
sellerManageList[i].select = false;
}
checkValue = false;
notifyListeners();
}
//选中
addDataMy(int index) {
// userHistorys[index].select = true;
selectPersonnalData.add(sellerManageList[index].id);
notifyListeners();
}
//未选中
cancelDataMy(int index) {
// userHistorys[index].select = false;
selectPersonnalData
.removeWhere((element) => element == sellerManageList[index].id);
notifyListeners();
}
//获取全选按钮的状态 true or false
getCheckValueMy() {
bool temp = sellerManageList.any((value) {
return value.select == false;
});
if (temp == true) {
checkValue = false;
} else {
checkValue = true;
}
notifyListeners();
}
FilterBtnModel returnModel(PersonnelManageSunModel item) {
FilterBtnModel model = FilterBtnModel();
model.id = item.id;
model.title = item.nickName ?? item.account;
model.account = item.account;
model.phone = item.phone;
return model;
}
/// 获取店员列表
Future<bool> getAuthUserLists(BuildContext context,
{showLoading = false}) async {
Map<String, String> params = {
"sellerid": Provider.of<UserModel>(context, listen: false).user.sellerid,
};
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.get_auth_user_lists,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
if (error is MyError) {
switch (error.type) {
case 1:
pageStatePersonnalHome = PageState.ConnectivityError;
break;
case 2:
pageStatePersonnalHome = PageState.ConnectivityTimeOut;
break;
default:
pageStatePersonnalHome = PageState.ConnectivityError;
break;
}
}
notifyListeners();
return false;
});
if (baseResp != null && baseResp.code == Constant.status_success) {
Map data = baseResp.data;
Map<String, dynamic> tempData = {};
data.forEach((key, value) {
String keyTemp = key.split('_')[0];
String role_id = key.split('_')[1];
tempData[keyTemp] = {'listdata': value, 'role_id': role_id};
});
baseResp.responseData['data'] = tempData;
PersonnelManageModelData dataMap =
PersonnelManageModel.fromJson(baseResp.responseData).data;
sellerManageList = [];
for (PersonnelManageSunModel item in dataMap.admin.listdata) {
FilterBtnModel model = returnModel(item);
model.roleName = '管理员';
sellerManageList.add(model);
}
for (PersonnelManageSunModel item in dataMap.cashier.listdata) {
FilterBtnModel model = returnModel(item);
model.roleName = '收银员';
sellerManageList.add(model);
}
for (PersonnelManageSunModel item in dataMap.manager.listdata) {
FilterBtnModel model = returnModel(item);
model.roleName = '客户经理';
sellerManageList.add(model);
}
for (PersonnelManageSunModel item in dataMap.shopowner.listdata) {
FilterBtnModel model = returnModel(item);
model.roleName = '店长';
sellerManageList.add(model);
}
for (PersonnelManageSunModel item in dataMap.waiter.listdata) {
FilterBtnModel model = returnModel(item);
model.roleName = '服务员';
sellerManageList.add(model);
}
pageStatePersonnalHome = PageState.Success;
notifyListeners();
return true;
} else {
Utils.showToast(baseResp.msg ?? "");
pageStatePersonnalHome = PageState.ConnectivityError;
notifyListeners();
return false;
}
}
///添加宴会员工
Future<dynamic> addStaff(BuildContext context, Map<String, String> params,
{isShowLoading = true}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.add_staff,
data: params, showLoading: isShowLoading)
.catchError((error) {
print(error.toString());
if (error is MyError) {}
return false;
});
if (baseResp.code == Constant.status_success) {
// if (baseResp.data == 1) {
return true;
// } else {
// return false;
// }
} else {
if (baseResp != null) {
Utils.showToast(baseResp.msg ?? "");
}
return false;
}
}
///获取宴会员工
Future<bool> getStaff(BuildContext context, {isShowLoading = true}) async {
Map<String, String> params = {
"sid": Provider.of<UserModel>(context, listen: false).user.sellerid,
};
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.get_staff,
data: params, showLoading: isShowLoading)
.catchError((error) {
print(error.toString());
if (error is MyError) {}
return false;
});
getPersonnalList = [];
GetStaffModel getStaffModel = GetStaffModel.fromJson(baseResp.responseData);
if (getStaffModel.ret == Constant.status_success) {
List<GetStaffSunModel> data = getStaffModel.data;
data.forEach((element) {
getPersonnalList.add(element.userId);
});
return true;
} else {
Utils.showToast(baseResp.msg ?? "");
return false;
}
}
/**
* 宴会类型
*/
///添加宴会类型
Future<dynamic> setClassify(BuildContext context, Map<String, String> params,
{isShowLoading = true}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.set_classify,
data: params, showLoading: isShowLoading)
.catchError((error) {
print(error.toString());
if (error is MyError) {}
return false;
});
if (baseResp.code == Constant.status_success) {
// if (baseResp.data == 1) {
return true;
// } else {
// return false;
// }
} else {
if (baseResp != null) {
Utils.showToast(baseResp.msg ?? "");
}
return false;
}
}
///获取宴会类型
Future<bool> getClassify(BuildContext context, {isShowLoading = true}) async {
Map<String, String> params = {
"sid": Provider.of<UserModel>(context, listen: false).user.sellerid,
};
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.get_classify,
data: params, showLoading: isShowLoading)
.catchError((error) {
print(error.toString());
if (error is MyError) {
switch (error.type) {
case 1:
pageStateType = PageState.ConnectivityError;
break;
case 2:
pageStateType = PageState.ConnectivityTimeOut;
break;
default:
pageStateType = PageState.ConnectivityError;
break;
}
}
notifyListeners();
return false;
});
ClassifyModel classifyModel = ClassifyModel.fromJson(baseResp.responseData);
if (classifyModel.ret == Constant.status_success) {
classifyData = classifyModel.data;
if (classifyData.length == 0) {
pageStateType = PageState.Empty;
} else {
pageStateType = PageState.Success;
}
notifyListeners();
return true;
} else {
Utils.showToast(baseResp.msg ?? "");
pageStateType = PageState.ConnectivityError;
notifyListeners();
return false;
}
}
///删除宴会类型
Future<dynamic> delClassify(BuildContext context, Map<String, String> params,
{isShowLoading = true}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.del_classify,
data: params, showLoading: isShowLoading)
.catchError((error) {
print(error.toString());
if (error is MyError) {}
return false;
});
if (baseResp.code == Constant.status_success) {
// if (baseResp.data == 1) {
return true;
// } else {
// return false;
// }
} else {
if (baseResp != null) {
Utils.showToast(baseResp.msg ?? "");
}
return false;
}
}
/**
* 酒水
*/
///添加酒水
Future<dynamic> setWine(BuildContext context, Map<String, String> params,
{isShowLoading = true}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.set_wine,
data: params, showLoading: isShowLoading)
.catchError((error) {
print(error.toString());
if (error is MyError) {}
return false;
});
if (baseResp.code == Constant.status_success) {
// if (baseResp.data == 1) {
return true;
// } else {
// return false;
// }
} else {
if (baseResp != null) {
Utils.showToast(baseResp.msg ?? "");
}
return false;
}
}
///获取酒水
Future<bool> getWine(BuildContext context, {isShowLoading = true}) async {
Map<String, String> params = {
"sid": Provider.of<UserModel>(context, listen: false).user.sellerid,
};
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.get_wine,
data: params, showLoading: isShowLoading)
.catchError((error) {
print(error.toString());
if (error is MyError) {
switch (error.type) {
case 1:
pageStateWine = PageState.ConnectivityError;
break;
case 2:
pageStateWine = PageState.ConnectivityTimeOut;
break;
default:
pageStateWine = PageState.ConnectivityError;
break;
}
}
notifyListeners();
return false;
});
WineModel wineModel = WineModel.fromJson(baseResp.responseData);
if (wineModel.ret == Constant.status_success) {
wineData = wineModel.data;
if (wineData.length == 0) {
pageStateWine = PageState.Empty;
} else {
pageStateWine = PageState.Success;
}
notifyListeners();
return true;
} else {
Utils.showToast(baseResp.msg ?? "");
pageStateWine = PageState.ConnectivityError;
notifyListeners();
return false;
}
}
///删除酒水
Future<dynamic> delWine(BuildContext context, Map<String, String> params,
{isShowLoading = true}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.del_wine,
data: params, showLoading: isShowLoading)
.catchError((error) {
print(error.toString());
if (error is MyError) {}
return false;
});
if (baseResp.code == Constant.status_success) {
// if (baseResp.data == 1) {
return true;
// } else {
// return false;
// }
} else {
if (baseResp != null) {
Utils.showToast(baseResp.msg ?? "");
}
return false;
}
}
}