|
...
|
...
|
@@ -4,6 +4,7 @@ import 'package:lpinyin/lpinyin.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/customer_list_model.dart';
|
|
|
|
import 'package:one_key/models/guest_manage_model.dart';
|
|
|
|
import 'package:one_key/models/user_history_entity.dart';
|
|
|
|
import 'package:one_key/net/base_resp.dart';
|
|
...
|
...
|
@@ -16,17 +17,24 @@ import 'package:provider/provider.dart'; |
|
|
|
|
|
|
|
class CustomerProvider extends ChangeNotifier {
|
|
|
|
PageState pageState = PageState.Loading;
|
|
|
|
List<UserHistoryEntity> userHistorys = []; //历史录入(总)
|
|
|
|
List<UserHistoryEntity> userHistorysShow = []; //历史录入展示
|
|
|
|
List<CustomerListSunModel> userHistorys = []; //客户列表(总)
|
|
|
|
List<CustomerListSunModel> userHistorysShow = []; //全部展示
|
|
|
|
List<CustomerListSunModel> userHistorysShowHuoyue = []; //活跃展示
|
|
|
|
List<CustomerListSunModel> userHistorysShowChenshui = []; //沉睡展示
|
|
|
|
List<CustomerListSunModel> userHistorysShowLiushi = []; //流失展示
|
|
|
|
|
|
|
|
TextEditingController controller = TextEditingController(); //搜索框
|
|
|
|
|
|
|
|
PageState pageStateMyHome = PageState.Loading;
|
|
|
|
PageState pageStateHuoyue = PageState.Loading;
|
|
|
|
PageState pageStateChenshui = PageState.Loading;
|
|
|
|
PageState pageStateLiushi = PageState.Loading;
|
|
|
|
GuestManageSunModel guestSunmodel;
|
|
|
|
|
|
|
|
//获取历史录入
|
|
|
|
getUserHistorys(BuildContext context, Map<String, String> params) async {
|
|
|
|
//用来获取客户列表
|
|
|
|
getCustomerList(BuildContext context, Map<String, String> params) async {
|
|
|
|
BaseResp<List> baseResp = await DioUtil()
|
|
|
|
.request<List>(context, Method.get, HttpUrl.get_reserve_user,
|
|
|
|
.request<List>(context, Method.get, HttpUrl.get_customer_list,
|
|
|
|
data: params, showLoading: false)
|
|
|
|
.catchError((error) {
|
|
|
|
print(error.toString());
|
|
...
|
...
|
@@ -46,14 +54,14 @@ class CustomerProvider extends ChangeNotifier { |
|
|
|
notifyListeners();
|
|
|
|
});
|
|
|
|
if (baseResp != null && baseResp.code == Constant.status_success) {
|
|
|
|
userHistorys = baseResp.data.map<UserHistoryEntity>((value) {
|
|
|
|
return UserHistoryEntity.fromJson(value);
|
|
|
|
userHistorys = baseResp.data.map<CustomerListSunModel>((value) {
|
|
|
|
return CustomerListSunModel.fromJson(value);
|
|
|
|
}).toList();
|
|
|
|
if (userHistorys.length == 0) {
|
|
|
|
pageState = PageState.Empty;
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < userHistorys.length; i++) {
|
|
|
|
UserHistoryEntity item = userHistorys[i];
|
|
|
|
CustomerListSunModel item = userHistorys[i];
|
|
|
|
item.pinyinFirst = '';
|
|
|
|
item.pinyinList = [];
|
|
|
|
item.pinyinList = [];
|
|
...
|
...
|
@@ -78,63 +86,154 @@ class CustomerProvider extends ChangeNotifier { |
|
|
|
|
|
|
|
userHistorys[i] = item;
|
|
|
|
}
|
|
|
|
userHistorysShow = userHistorys;
|
|
|
|
userHistorysShow = userHistorys; //全部客户列表信息
|
|
|
|
userHistorysShowHuoyue = [];
|
|
|
|
userHistorysShowChenshui = [];
|
|
|
|
userHistorysShowLiushi = [];
|
|
|
|
for (CustomerListSunModel item in userHistorysShow) {
|
|
|
|
if (item.attr == '活跃') {
|
|
|
|
userHistorysShowHuoyue.add(item);
|
|
|
|
} else if (item.attr == '沉睡') {
|
|
|
|
userHistorysShowChenshui.add(item);
|
|
|
|
} else if (item.attr == '流失') {
|
|
|
|
userHistorysShowLiushi.add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (userHistorysShowHuoyue.length > 0) {
|
|
|
|
pageStateHuoyue = PageState.Success;
|
|
|
|
} else {
|
|
|
|
pageStateHuoyue = PageState.Empty;
|
|
|
|
}
|
|
|
|
if (userHistorysShowChenshui.length > 0) {
|
|
|
|
pageStateChenshui = PageState.Success;
|
|
|
|
} else {
|
|
|
|
pageStateChenshui = PageState.Empty;
|
|
|
|
}
|
|
|
|
if (userHistorysShowLiushi.length > 0) {
|
|
|
|
pageStateLiushi = PageState.Success;
|
|
|
|
} else {
|
|
|
|
pageStateLiushi = PageState.Empty;
|
|
|
|
}
|
|
|
|
pageState = PageState.Success;
|
|
|
|
}
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// //获取历史录入
|
|
|
|
// 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 (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 != null && baseResp.code == Constant.status_success) {
|
|
|
|
// userHistorys = baseResp.data.map<UserHistoryEntity>((value) {
|
|
|
|
// return UserHistoryEntity.fromJson(value);
|
|
|
|
// }).toList();
|
|
|
|
// if (userHistorys.length == 0) {
|
|
|
|
// pageState = PageState.Empty;
|
|
|
|
// } else {
|
|
|
|
// for (int i = 0; i < userHistorys.length; i++) {
|
|
|
|
// UserHistoryEntity item = userHistorys[i];
|
|
|
|
// item.pinyinFirst = '';
|
|
|
|
// item.pinyinList = [];
|
|
|
|
// item.pinyinList = [];
|
|
|
|
// if (item.rname != null) {
|
|
|
|
// item.pinyin =
|
|
|
|
// PinyinHelper.getPinyin(item.rname).replaceAll(' ', '');
|
|
|
|
// List<String> pinyinList =
|
|
|
|
// PinyinHelper.getPinyin(item.rname).split(' ');
|
|
|
|
|
|
|
|
// String pinyinAll = ''; //组装全拼组合
|
|
|
|
// for (int j = 0; j < pinyinList.length; j++) {
|
|
|
|
// String letter = pinyinList[j];
|
|
|
|
// pinyinAll += pinyinList[j];
|
|
|
|
// item.pinyinList.add(pinyinAll);
|
|
|
|
// if (letter.length > 0) {
|
|
|
|
// item.pinyinFirst += pinyinList[j].substring(0, 1);
|
|
|
|
// } else {
|
|
|
|
// item.pinyinFirst += '';
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// userHistorys[i] = item;
|
|
|
|
// }
|
|
|
|
// userHistorysShow = userHistorys;
|
|
|
|
// pageState = PageState.Success;
|
|
|
|
// }
|
|
|
|
// notifyListeners();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
searchData(String key) {
|
|
|
|
if (key == '') {
|
|
|
|
userHistorysShow = userHistorys;
|
|
|
|
pageState = PageState.Success;
|
|
|
|
} else {
|
|
|
|
userHistorysShow = [];
|
|
|
|
|
|
|
|
for (int i = 0; i < userHistorys.length; i++) {
|
|
|
|
String name = userHistorys[i].rname;
|
|
|
|
String pinyinFirst = userHistorys[i].pinyinFirst;
|
|
|
|
// String pinyin = userHistorys[i].pinyin;
|
|
|
|
String phone = userHistorys[i].phone;
|
|
|
|
List<String> pinyinList = userHistorys[i].pinyinList;
|
|
|
|
if ((name != null && name.contains(key)) ||
|
|
|
|
(pinyinFirst != null && pinyinFirst.contains(key)) ||
|
|
|
|
(phone != null && phone.contains(key)) ||
|
|
|
|
(pinyinList != null && pinyinList.contains(key))) {
|
|
|
|
userHistorysShow.add(userHistorys[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// for (int i = 0; i < contacts.length; i++) {
|
|
|
|
// String name = contacts[i].rname;
|
|
|
|
// String pinyinFirst = contacts[i].pinyinFirst;
|
|
|
|
// List<String> pinyinList = contacts[i].pinyinList;
|
|
|
|
// // String pinyin = contacts[i].pinyin;
|
|
|
|
// String phone = contacts[i].phone;
|
|
|
|
// if ((name != null && name.contains(key)) ||
|
|
|
|
// (pinyinFirst != null && pinyinFirst.contains(key)) ||
|
|
|
|
// (phone != null && phone.contains(key)) ||
|
|
|
|
// (pinyinList != null && pinyinList.contains(key))) {
|
|
|
|
// contactsShow.add(contacts[i]);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
if (userHistorysShow.length == 0) {
|
|
|
|
pageState = PageState.Empty;
|
|
|
|
notifyListeners();
|
|
|
|
} else {
|
|
|
|
if (userHistorys.length > 0) {
|
|
|
|
if (key == '') {
|
|
|
|
userHistorysShow = userHistorys;
|
|
|
|
pageState = PageState.Success;
|
|
|
|
} else {
|
|
|
|
userHistorysShow = [];
|
|
|
|
|
|
|
|
for (int i = 0; i < userHistorys.length; i++) {
|
|
|
|
String name = userHistorys[i].rname;
|
|
|
|
String pinyinFirst = userHistorys[i].pinyinFirst;
|
|
|
|
// String pinyin = userHistorys[i].pinyin;
|
|
|
|
String phone = userHistorys[i].phone;
|
|
|
|
List<String> pinyinList = userHistorys[i].pinyinList;
|
|
|
|
if ((name != null && name.contains(key)) ||
|
|
|
|
(pinyinFirst != null && pinyinFirst.contains(key)) ||
|
|
|
|
(phone != null && phone.contains(key)) ||
|
|
|
|
(pinyinList != null && pinyinList.contains(key))) {
|
|
|
|
userHistorysShow.add(userHistorys[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// for (int i = 0; i < contacts.length; i++) {
|
|
|
|
// String name = contacts[i].rname;
|
|
|
|
// String pinyinFirst = contacts[i].pinyinFirst;
|
|
|
|
// List<String> pinyinList = contacts[i].pinyinList;
|
|
|
|
// // String pinyin = contacts[i].pinyin;
|
|
|
|
// String phone = contacts[i].phone;
|
|
|
|
// if ((name != null && name.contains(key)) ||
|
|
|
|
// (pinyinFirst != null && pinyinFirst.contains(key)) ||
|
|
|
|
// (phone != null && phone.contains(key)) ||
|
|
|
|
// (pinyinList != null && pinyinList.contains(key))) {
|
|
|
|
// contactsShow.add(contacts[i]);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
if (userHistorysShow.length == 0) {
|
|
|
|
pageState = PageState.Empty;
|
|
|
|
notifyListeners();
|
|
|
|
} else {
|
|
|
|
pageState = PageState.Success;
|
|
|
|
}
|
|
|
|
// if (contactsShow.length == 0) {
|
|
|
|
// pageStateRight = PageState.Empty;
|
|
|
|
// } else {
|
|
|
|
// pageStateRight = PageState.Success;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// if (contactsShow.length == 0) {
|
|
|
|
// pageStateRight = PageState.Empty;
|
|
|
|
// } else {
|
|
|
|
// pageStateRight = PageState.Success;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
handleList(userHistorysShow, needRefresh: true);
|
|
|
|
handleList(userHistorysShow, needRefresh: true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleList(List<UserHistoryEntity> list, {bool needRefresh = false}) {
|
|
|
|
handleList(List<CustomerListSunModel> list, {bool needRefresh = false}) {
|
|
|
|
if (list == null || list.isEmpty) return;
|
|
|
|
for (int i = 0, length = list.length; i < length; i++) {
|
|
|
|
String pinyin = '';
|
|
...
|
...
|
@@ -173,7 +272,7 @@ class CustomerProvider extends ChangeNotifier { |
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
Map<String, String> params = {
|
|
|
|
'uid': Provider.of<UserModel>(context, listen: false).user.openid
|
|
|
|
'uid': Provider.of<UserModel>(context, listen: false).user.openid
|
|
|
|
};
|
|
|
|
BaseResp<dynamic> baseResp = await DioUtil()
|
|
|
|
.request<dynamic>(context, Method.get, HttpUrl.guest_manage,
|
...
|
...
|
|