notebook_detail_model.dart
8.04 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
import 'package:common_utils/common_utils.dart';
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/manager.dart';
import 'package:one_key/models/notebook_detail.dart';
import 'package:one_key/models/user_history_entity.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/route/navigator_util.dart';
import 'package:one_key/utils/utils.dart';
import 'package:provider/provider.dart';
class NotebookDetailModel extends ChangeNotifier {
PageState pageState = PageState.Loading;
String selectNum;
int selectIndex;
TextEditingController numController = TextEditingController();
String strTF;
String prestrTF;
TextEditingController phoneController = TextEditingController();
TextEditingController nameController = TextEditingController();
List sexList;
List<UserHistoryEntity> userHistorys = []; //历史录入
NotebookDetailModel() {
initSexList();
}
///称谓
initSexList() {
String sexStr = '1';
sexList = [
{
'title': '先生',
'select': sexStr == '1' ? true : false,
'code': '1',
'hasLeftBorder': true
},
{
'title': '女士',
'select': sexStr == '2' ? true : false,
'code': '2',
'hasLeftBorder': false
},
{
'title': '公司',
'select': sexStr == '3' ? true : false,
'code': '3',
'hasLeftBorder': false
}
];
}
//获取历史录入
getUserHistorys(BuildContext context, Map<String, String> params) async {
BaseResp<List> baseResp = await DioUtil()
.request<List>(context, Method.get, HttpUrl.get_reserve_user,
data: params, showLoading: false)
.catchError((error) {
print(error.toString());
});
if (baseResp != null && baseResp.code == Constant.status_success) {
userHistorys = baseResp.data.map<UserHistoryEntity>((value) {
return UserHistoryEntity.fromJson(value);
}).toList();
notifyListeners();
}
}
///获取已预订订单
Future<NotebookDetail> getReserveDetail(
BuildContext context, Map<String, String> params,
{isShowLoading = true, bool showCircle = false}) async {
if (isShowLoading) {
pageState = PageState.Loading;
notifyListeners();
}
BaseResp<Map<String, dynamic>> baseResp = await DioUtil()
.request<Map<String, dynamic>>(
context, Method.get, HttpUrl.reserve_detail,
data: params, showLoading: isShowLoading ? false : showCircle)
.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;
}
notifyListeners();
return NotebookDetail.fromJson(baseResp.data);
} else {
pageState = PageState.ConnectivityError;
if (baseResp != null) {
Utils.showToast(baseResp.msg ?? "");
}
}
}
///获取商家信息
Future<List<Manager>> getManagers(BuildContext context) async {
UserModel userModel = Provider.of<UserModel>(context, listen: false);
Map<String, String> params = {
"seller_id": userModel.user.sellerid,
"seller_openid": userModel.user.openid
};
BaseResp<Map<String, dynamic>> baseResp = await DioUtil()
.request<Map<String, dynamic>>(context, Method.get, HttpUrl.sellerinfo,
data: params, showLoading: false)
.catchError((error) {
print(error.toString());
});
if (baseResp?.code == Constant.status_success) {
return (baseResp.data["manager"] as List)
.map((value) => Manager.fromJson(value as Map<String, dynamic>))
.toList();
}
}
///设置客户经理
setReserveCusmnan(BuildContext context, Map<String, String> params) async {
BaseResp<String> baseResp = await DioUtil()
.request<String>(context, Method.get, HttpUrl.set_reserve_cusman,
data: params)
.catchError((error) {
print(error.toString());
});
if (baseResp.code == Constant.status_success) {
} else {
Utils.showToast(baseResp.msg ?? "");
}
}
//安排在线预订
Future<bool> setReserveStatus(
BuildContext context, Map<String, String> params,
{ifPush = true, showLoading = false}) async {
BaseResp<Map<String, dynamic>> baseResp = await DioUtil()
.request<Map<String, dynamic>>(
context, Method.get, HttpUrl.set_reserve_status,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
});
if (baseResp == null) return false;
if (baseResp.code == Constant.status_success && baseResp.data != null) {
if (ifPush) {
UserModel userModel = Provider.of<UserModel>(context, listen: false);
NavigatorUtil.goNotebookDetailPage(
context, params["rid"], userModel.user.openid,
replace: true);
}
return true;
} else {
Utils.showToast("订单已被处理");
return false;
}
}
//设置消息状态
setMessageStatus(BuildContext context, Map<String, String> params) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.set_message_status,
data: params, showLoading: false)
.catchError((error) {
print(error.toString());
});
if (baseResp.code == Constant.status_success) {
} else {
Utils.showToast(baseResp.msg);
}
}
// 编辑订单附加信息
Future<bool> upReserveInfo(BuildContext context, String rid,
{String actualPum,
String conAmount,
String dateStr,
String cusdem,
String sex,
String name,
String phone,
String ymd,
bool showLoading = false,
bool needToast = true}) async {
Map<String, dynamic> params = {
"rid": rid,
'note_name': Provider.of<UserModel>(context, listen: false).user.account
};
if (actualPum != null) {
params['actual_pum'] = actualPum;
}
if (conAmount != null) {
params['con_amount'] = conAmount;
}
if (dateStr != null) {
String timeStr = ymd + ' ' + dateStr + ':00';
int ddate = DateUtil.getDateMsByTimeStr(timeStr);
params['ddate'] = '${ddate}'.substring(0, 10); //到店时间
}
if (cusdem != null) {
params['cusdem'] = cusdem;
}
if (sex != null) {
params['sex'] = sex;
}
if (name != null) {
params['rname'] = name;
}
if (phone != null && phone != '') {
params['phone'] = phone;
}
bool sucess = await _upReserveInfo(context, params,
showLoading: showLoading, needToast: needToast);
if (sucess) {
if (!showLoading && needToast) {
Utils.showToast("修改成功!");
}
return true;
}
return false;
}
Future<bool> _upReserveInfo(BuildContext context, Map<String, dynamic> params,
{ifPush = true, showLoading = false, bool needToast = true}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.up_reserve_info,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
});
if (baseResp == null) return false;
if (baseResp.code == Constant.status_success && baseResp.data != null) {
return true;
} else {
if (needToast) {
Utils.showToast(baseResp.msg);
}
return false;
}
}
}