store_wine_provider.dart
9.74 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
import 'dart:convert';
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 '../models/out_wine_record_model.dart';
import '../models/phone_code_model.dart';
import '../models/wine_manage_model.dart';
import '../net/base_resp.dart';
import '../net/dio_util.dart';
import '../net/http_url.dart';
import '../utils/utils.dart';
/**
* 餐厅详情
*/
class StoreWineProvider with ChangeNotifier {
PageState pageStateAll = PageState.Loading; //全部在店
PageState pageStateRecord = PageState.Loading; //取酒记录单个存酒
PageState pageStateDetail = PageState.Loading; //存酒详情
PageState pageStateDetailRecord = PageState.Success; //出库记录列表详情
PageState pageStateRecordHome = PageState.Loading; //取酒记录首页
List<WineManageModel> wineManageList; //存酒列表数据
WineManageModel wineManageDetail; //存酒详情数据
List<OutWineRecordSunModel> outWineRecordData; //某个存酒详情的出库记录
List<OutWineRecordSunModel> outWineRecordHomeData; //存酒详情的出库记录
String code; //验证码
// PhoneCodeSunModel phoneCodeSunModel;
/// 给手机发送短信验证码
Future<bool> getPhoneCode(BuildContext context, Map<String, String> params,
{isShowLoading = true}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(
context, Method.post, HttpUrl.send_vc_code,
data: params, showLoading: false)
.catchError((error) {});
if (baseResp.code == Constant.status_success) {
if (baseResp.data == null) {
return false;
} else {
//解析解析
if(jsonDecode( baseResp.data)['status'] == 'success'){
return true;
}else{
return false;
}
}
} else {
if (baseResp != null) {
Utils.showToast(baseResp.msg ?? "");
}
return false;
}
}
// 设置商家存酒管理员
Future<bool> setStoreWineBySellerUser(
BuildContext context, Map<String, String> params,
{bool showLoading = true}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(
context, Method.post, HttpUrl.set_store_wine_by_seller_user,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
Utils.showToast('设置商家存酒管理员失败,请重试');
return false;
});
if (baseResp.code == Constant.status_success) {
if (baseResp.data == 0 || baseResp.data == 1) {
return true;
} else {
Utils.showToast('设置商家存酒管理员失败,请重试');
}
} else {
Utils.showToast(baseResp.msg ?? '设置商家存酒管理员失败');
}
return false;
}
// 商家新建存酒
Future<bool> setStoreWineBySeller(
BuildContext context, Map<String, String> params,
{bool showLoading = true}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.post, HttpUrl.set_store_wine_by_seller,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
if (params['id'] != null) {
Utils.showToast('修改存酒失败,请重试');
} else {
Utils.showToast('新建存酒失败,请重试');
}
return false;
});
if (baseResp.code == Constant.status_success) {
if (params['id'] != null) {
//修改存酒信息
if (baseResp.data == 1 || baseResp.data == 0) {
return true;
} else {
Utils.showToast('修改存酒失败,请重试');
}
} else {
if (baseResp.data is Map && baseResp.data['id'] is String) {
return true;
} else {
Utils.showToast('新建存酒失败,请重试');
}
}
} else {
if (params['id'] != null) {
Utils.showToast(baseResp.msg ?? '修改存酒失败,请重试');
} else {
Utils.showToast(baseResp.msg ?? '新建存酒失败,请重试');
}
}
return false;
}
// 获取存酒列表
Future<bool> getStoreWineBySeller(
BuildContext context, Map<String, String> params,
{bool showLoading = true}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.post, HttpUrl.get_store_wine_by_seller,
data: params,
showLoading:
pageStateAll == PageState.Loading ? false : showLoading)
.catchError((error) {
pageStateAll = PageState.ConnectivityError;
print(error.toString());
Utils.showToast('获取存酒列表失败,请重试');
notifyListeners();
return false;
});
if (baseResp.code == Constant.status_success) {
if (baseResp.data == false) {
pageStateAll = PageState.Empty;
} else {
wineManageList = WineManageFaModel.fromJson(baseResp.responseData).data;
print(wineManageList);
// wineManageList.sort((a, b) => a.cdate.compareTo(b.cdate));
// print(wineManageList);
if (wineManageList.length == 0) {
pageStateAll = PageState.Empty;
} else {
pageStateAll = PageState.Success;
}
}
notifyListeners();
return true;
} else {
Utils.showToast(baseResp.msg);
pageStateAll = PageState.ConnectivityError;
}
notifyListeners();
return false;
}
// 取酒出库提交
Future<bool> setStoreWineBySellerCheck(
BuildContext context, Map<String, String> params,
{bool showLoading = true}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(
context, Method.post, HttpUrl.set_store_wine_by_seller_check,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
Utils.showToast('存酒出库失败,请重试');
return false;
});
if (baseResp.code == Constant.status_success) {
if (baseResp.data is Map && baseResp.data['id'] is String) {
return true;
} else {
Utils.showToast('存酒出库失败,请重试');
}
} else {
Utils.showToast(baseResp.msg ?? '存酒出库失败,请重试');
}
return false;
}
// 获取存酒详情
Future<bool> getStoreWineById(
BuildContext context, Map<String, String> params,
{bool showLoading = true}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.post, HttpUrl.get_store_wine_by_id,
data: params,
showLoading:
pageStateDetail == PageState.Loading ? false : showLoading)
.catchError((error) {
pageStateDetail = PageState.ConnectivityError;
print(error.toString());
Utils.showToast('获取存酒详情失败');
notifyListeners();
return false;
});
if (baseResp.code == Constant.status_success) {
if (baseResp.data is Map) {
wineManageDetail = WineManageModel.fromJson(baseResp.data);
pageStateDetail = PageState.Success;
} else {
pageStateDetail = PageState.Empty;
}
notifyListeners();
return true;
} else {
Utils.showToast(baseResp.msg ?? '获取存酒详情失败');
pageStateDetail = PageState.ConnectivityError;
}
notifyListeners();
return false;
}
// 根据存酒ID获取取酒记录
Future<bool> getStoreWineCheckByWid(
BuildContext context, Map<String, String> params,
{bool showLoading = true}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(
context, Method.post, HttpUrl.get_store_wine_check_by_wid,
data: params,
showLoading:
pageStateRecord == PageState.Loading ? false : showLoading)
.catchError((error) {
pageStateRecord = PageState.ConnectivityError;
print(error.toString());
Utils.showToast('获取取酒记录失败');
notifyListeners();
return false;
});
if (baseResp.code == Constant.status_success) {
outWineRecordData =
OutWineRecordModel.fromJson(baseResp.responseData).data;
if (outWineRecordData.length == 0) {
pageStateRecord = PageState.Empty;
} else {
pageStateRecord = PageState.Success;
}
notifyListeners();
return true;
} else {
Utils.showToast(baseResp.msg ?? '获取取酒记录失败');
pageStateRecord = PageState.ConnectivityError;
}
notifyListeners();
return false;
}
// 获取取酒记录
Future<bool> getStoreWineCheckList(
BuildContext context, Map<String, String> params,
{bool showLoading = true}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(
context, Method.post, HttpUrl.get_store_wine_check_list,
data: params,
showLoading:
pageStateRecordHome == PageState.Loading ? false : showLoading)
.catchError((error) {
pageStateRecordHome = PageState.ConnectivityError;
print(error.toString());
Utils.showToast('获取取酒记录失败');
notifyListeners();
return false;
});
if (baseResp.code == Constant.status_success) {
outWineRecordHomeData =
OutWineRecordModel.fromJson(baseResp.responseData).data;
if (outWineRecordHomeData.length == 0) {
pageStateRecordHome = PageState.Empty;
} else {
pageStateRecordHome = PageState.Success;
}
notifyListeners();
return true;
} else {
Utils.showToast(baseResp.msg ?? '获取取酒记录失败');
pageStateRecordHome = PageState.ConnectivityError;
}
notifyListeners();
return false;
}
}