personnel_provider.dart
9.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 'package:flutter/material.dart';
import 'package:one_key/constant/constant.dart';
import 'package:one_key/constant/error.dart';
import 'package:one_key/models/filter_btn_model.dart';
import 'package:one_key/models/get_seller_info_model.dart';
import 'package:one_key/models/get_seller_user_by_sellerid_model.dart';
import 'package:one_key/models/personnel_manage_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';
/**
* 员工管理
*/
class PersonnelProvider extends ChangeNotifier {
PersonnelManageModelData dataMap;
String password = '';
List<FilterBtnModel> sellerManageList = []; //经理数据 ---- 商家编辑页面
int manageSelIndex; //当前选中
///商家详情编辑页面 ------ 获取经理数据
Future<List<FilterBtnModel>> getSellerUserBySellerid(BuildContext context,
{isShowLoading = true}) 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_seller_user_by_sellerid,
data: params, showLoading: false)
.catchError((error) {
print(error.toString());
if (error is MyError) {}
});
if (baseResp.code == Constant.status_success) {
List<GetSellerUserBySelleridSunModel> sunmodel =
GetSellerUserBySelleridModel.fromJson(baseResp.responseData).data;
sellerManageList = [];
if (sunmodel != null && sunmodel.length > 0) {
for (GetSellerUserBySelleridSunModel item in sunmodel) {
if (item.nickName != null) {
FilterBtnModel model = FilterBtnModel();
model.id = item.id;
model.title = item.nickName + '(${item.roleName})';
sellerManageList.add(model);
}
}
}
} else {
if (baseResp != null) {
Utils.showToast(baseResp.msg ?? "");
}
}
FilterBtnModel model = FilterBtnModel();
model.id = '';
model.title = '全店未分配客户资源';
sellerManageList.insert(0, model);
return sellerManageList;
}
/// 获取店员列表
getAuthUserLists(BuildContext context, Map<String, String> params,
{showLoading = false}) async {
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 (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;
dataMap = PersonnelManageModel.fromJson(baseResp.responseData).data;
dataMap.admin.hasWechatNum = 0;
for (PersonnelManageSunModel item in dataMap.admin.listdata) {
if (item.openid != null && item.openid != 'null' && item.openid != '') {
dataMap.admin.hasWechatNum++;
}
}
dataMap.cashier.hasWechatNum = 0;
for (PersonnelManageSunModel item in dataMap.cashier.listdata) {
if (item.openid != null && item.openid != 'null' && item.openid != '') {
dataMap.cashier.hasWechatNum++;
}
}
dataMap.manager.hasWechatNum = 0;
for (PersonnelManageSunModel item in dataMap.manager.listdata) {
if (item.openid != null && item.openid != 'null' && item.openid != '') {
dataMap.manager.hasWechatNum++;
}
}
dataMap.shopowner.hasWechatNum = 0;
for (PersonnelManageSunModel item in dataMap.shopowner.listdata) {
if (item.openid != null && item.openid != 'null' && item.openid != '') {
dataMap.shopowner.hasWechatNum++;
}
}
dataMap.waiter.hasWechatNum = 0;
for (PersonnelManageSunModel item in dataMap.waiter.listdata) {
if (item.openid != null && item.openid != 'null' && item.openid != '') {
dataMap.waiter.hasWechatNum++;
}
}
} else {
Utils.showToast(baseResp.msg ?? "");
}
notifyListeners();
return dataMap;
}
/// 添加店员
Future<bool> addSellerClerk(BuildContext context, Map<String, String> params,
{showLoading = false}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.add_seller_clerk,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
});
if (baseResp != null && baseResp.code == Constant.status_success) {
if (baseResp.data != '') {
return true;
}
} else {
Utils.showToast(baseResp.msg ?? "");
}
return false;
}
/// 删除店员
Future<bool> delSellerClerk(BuildContext context, Map<String, String> params,
{showLoading = false}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.delete_auth_user,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
});
if (baseResp != null && baseResp.code == Constant.status_success) {
if (baseResp.data.length == 1 && baseResp.data[0] == 1) {
return true;
}
} else {
Utils.showToast(baseResp.msg ?? "");
}
return false;
}
/// 编辑店员
Future<bool> editAuthUser(BuildContext context, Map<String, String> params,
{showLoading = false}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.edit_auth_user,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
});
if (baseResp != null && baseResp.code == Constant.status_success) {
if (baseResp.data.length == 1 && baseResp.data[0] == 1) {
return true;
}
} else {
Utils.showToast(baseResp.msg ?? "");
}
return false;
}
/// 账号表-员工绑定手机号
Future<bool> bindPhoneSellerUser(
BuildContext context, Map<String, String> params,
{showLoading = false}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.bind_phone_seller_user,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
});
if (baseResp != null && baseResp.code == Constant.status_success) {
if (baseResp.data == 1) {
return true;
}
} else {
Utils.showToast(baseResp.msg ?? "");
}
return false;
}
///根据商家ID获取商家信息
Future<GetSellerInfoSunModel> getSellerById(BuildContext context) async {
UserModel userModel = Provider.of<UserModel>(context, listen: false);
Map<String, String> params = {
"sellerid": userModel.user.sellerid,
};
BaseResp<Map<String, dynamic>> baseResp = await DioUtil()
.request<Map<String, dynamic>>(
context, Method.get, HttpUrl.get_seller_info,
data: params)
.catchError((error) {
print(error.toString());
});
GetSellerInfoSunModel itemModel;
if (baseResp == null) return itemModel;
if (baseResp.code == Constant.status_success) {
if (int.parse(baseResp.status) != Constant.status_success) {
Utils.showToast(baseResp.msg ?? "");
return itemModel;
}
if (baseResp.responseData['data'] != null) {
itemModel = GetSellerInfoModel.fromJson(baseResp.responseData).data;
} else {
Utils.showToast(baseResp.msg ?? "");
}
return itemModel;
}
}
/// 设置商家接单人
Future<bool> setUserIsCall(BuildContext context, Map<String, String> params,
{showLoading = false}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.set_user_is_call,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
});
if (baseResp != null && baseResp.code == Constant.status_success) {
if (baseResp.data == 1) {
return true;
}
} else {
Utils.showToast(baseResp.msg ?? "");
}
return false;
}
/// 设置商家接单人
getPassword(BuildContext context, Map<String, String> params,
{showLoading = false}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.get_password,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
});
if (baseResp != null && baseResp.code == Constant.status_success) {
password = baseResp.data;
notifyListeners();
} else {
Utils.showToast(baseResp.msg ?? "");
}
}
/// 员工密码修改
Future<bool> updatePassword(BuildContext context, Map<String, String> params,
{showLoading = false}) async {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.get, HttpUrl.update_password,
data: params, showLoading: showLoading)
.catchError((error) {
print(error.toString());
});
if (baseResp != null && baseResp.code == Constant.status_success) {
if (baseResp.data == 1) {
return true;
}
} else {
Utils.showToast(baseResp.msg ?? "");
}
return false;
}
}