base_info_provider.dart
7.87 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
import 'dart:async';
import 'dart:convert';
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/base_info_model.dart';
import 'package:one_key/models/seller_phone_model.dart';
import 'package:one_key/models/table_photo_model.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/utils/utils.dart';
import 'package:provider/provider.dart';
import '../app.dart';
import '../models/user.dart';
class BaseIndoProvider with ChangeNotifier {
BaseInfoSunModel? baseInfoSunModel; //客户经理基础信息
Map<String, List<String?>> photoList = {}; //商家图片信息
PageState pageState = PageState.Loading;
TextEditingController phoneController = TextEditingController();
TextEditingController nameController = TextEditingController();
TextEditingController pnumController = TextEditingController();
late List sexList;
List<UserHistoryEntity> userHistorys = []; //历史录入
BaseIndoProvider() {
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
},
{
'title': '贵宾',
'select': sexStr == '4' ? true : false,
'code': '4',
'hasLeftBorder': false
}
];
}
//获取历史录入
getUserHistorys(BuildContext context, Map<String, String?> params) async {
try {
BaseResp<List?> baseResp = await DioUtil().request<List>(
context, Method.post, HttpUrl.get_reserve_user,
data: params, showLoading: false);
if (baseResp != null && baseResp.code == Constant.status_success) {
userHistorys = baseResp.data!.map<UserHistoryEntity>((value) {
return UserHistoryEntity.fromJson(value);
}).toList();
notifyListeners();
}
} catch (error) {
print(error.toString());
}
}
///客户经理添加/修改基本信息
Future<dynamic> setCustomerActivityBaseinfo(
BuildContext context, Map<String, String?> params,
{isShowLoading = true}) async {
try {
BaseResp<dynamic> baseResp = await DioUtil().request<dynamic>(
context, Method.post, HttpUrl.set_customer_activity_baseinfo,
data: params, showLoading: isShowLoading);
if (baseResp.code == Constant.status_success) {
if (baseResp.data != null) {
// coupons = baseResp.data['aid'].split('');
return true;
} else {
// Utils.showToast(baseResp.msg ?? "修改失败");
return false;
}
} else {
// if (baseResp != null) {
// Utils.showToast(baseResp.msg ?? "");
// }
return false;
}
} catch (error) {
print(error.toString());
if (error is MyError) {}
return false;
}
}
///客户经理获取基本信息
Future<bool> getCustomerActivityBaseinfo(
BuildContext context, Map<String, String?> params,
{isShowLoading = true}) async {
try {
BaseResp<dynamic> baseResp = await DioUtil().request<dynamic>(
context, Method.post, HttpUrl.get_customer_activity_baseinfo,
data: params, showLoading: isShowLoading);
if (baseResp.code == Constant.status_success) {
if (baseResp.data == null || baseResp.data == false) {
return false;
} else {
baseInfoSunModel = BaseInfoModel.fromJson(
baseResp.responseData as Map<String, dynamic>)
.data;
// for (int i = 0; i < couponListSelect.length; i++) {
// coupons.add(couponListSelect[i].id);
// // couponsShow.add(couponTemp[i].id);
// }
// hasModify = true;
if (App.sp!.containsKey('user')) {
String s = App.sp!.getString('user')!;
User _user = User.fromJson(json.decode(s));
_user.userphoneMyPage = baseInfoSunModel!.phone;
await UserModel().saveUserInfo(_user);
}
notifyListeners();
return true;
}
} else {
// if (baseResp != null) {
Utils.showToast(baseResp.msg ?? "");
// }
return false;
}
} catch (error) {
if (error is MyError) {
if (error.type != 1) {
Map<String, String?> params = {
'sellerid':
Provider.of<UserModel>(context, listen: false).user!.sellerid,
"uid": Provider.of<UserModel>(context, listen: false).user!.openid,
};
getCustomerActivityBaseinfo(context, params, isShowLoading: false);
}
}
}
return false;
}
// ///根据商家ID获取对应类型图片
// Future<bool> getSellerPhotoById(
// BuildContext context, Map<String, String> params,
// {isShowLoading = true}) async {
// BaseResp<dynamic> baseResp = await DioUtil()
// .request<dynamic>(context, Method.post, HttpUrl.get_seller_photo_by_id,
// data: params, showLoading: isShowLoading)
// !!.catchError((error) {
// print(error.toString());
// if (error is MyError) {}
// });
// if (baseResp.code == Constant.status_success) {
// if (baseResp.data == null || baseResp.data == false) {
// return false;
// } else {
// photoList = SellerPhoneModel.fromJson(baseResp.responseData).data;
// // for (int i = 0; i < couponListSelect.length; i++) {
// // coupons.add(couponListSelect[i].id);
// // // couponsShow.add(couponTemp[i].id);
// // }
// // hasModify = true;
// notifyListeners();
// return true;
// }
// } else {
// if (baseResp != null) {
// Utils.showToast(baseResp.msg ?? "");
// }
// return false;
// }
// }
///App获取多个桌位关联图片
Future<dynamic> getTablesPhoto(
BuildContext context, Map<String, String?> params,
{isShowLoading = true}) async {
try {
BaseResp<dynamic> baseResp = await DioUtil().request<dynamic>(
context, Method.post, HttpUrl.get_tables_photo,
data: params, showLoading: isShowLoading);
if (baseResp.code == Constant.status_success) {
if (baseResp.data == null) {
} else {
List<TablePhotoSunModel?>? tablePhotoList = TablePhotoModel.fromJson(
baseResp.responseData as Map<String, dynamic>)
.data;
String tid = params['tableids']!;
List<String> tids = tid.split(',');
Map<String, List<String?>> photos = {};
for (String tid in tids) {
photos[tid] = [];
}
for (String tid in tids) {
tablePhotoList!.forEach((item) {
// for (TablePhotoSunModel item in tablePhotoList!) {
if (tid == item!.tableid) {
List<String?> list = photos.putIfAbsent(tid, () => []);
list.add(item.url);
photos[tid] = list;
}
});
}
print(photos);
photoList = photos;
// photoList.add(tablePhotoList[i].url);
notifyListeners();
}
} else {
// if (baseResp != null) {
Utils.showToast(baseResp.msg ?? "");
// }
return [];
}
} catch (error) {
print(error.toString());
if (error is MyError) {}
}
}
}