Commit 09d474cb8e2868b4d9dccf2613c1f75166653ae9

Authored by wdn127929
1 parent 0b80d8cd

刷新和加载中bug

... ... @@ -10,7 +10,9 @@ import 'package:one_key/route/navigator_util.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
import '../../../../utils/event_bus.dart';
import '../../../../utils/screen_util.dart';
class MyContactListPage extends StatefulWidget {
... ... @@ -31,11 +33,50 @@ class _MyContactListPageState extends State<MyContactListPage> {
// List<contan> _contacts = [];
double susItemHeight = ScreenUtil().setWidth(10);
ItemScrollController controller = ItemScrollController();
ItemPositionsListener positon = ItemPositionsListener.create();
@override
void initState() {
super.initState();
// loadData();
widget.provider.myHandleList(widget.contacts);
positon.itemPositions.addListener(_itemPositonChanaged
// print('${positon.itemPositions.value.last.index}');
// // positon.itemPositions.value
// if (positon.itemPositions.value.last.index ==
// widget.contacts.length - 1) {
// //上拉加载方法
// bus.emit('onload_guest_list');
// }
);
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
positon.itemPositions.removeListener(_itemPositonChanaged);
}
_itemPositonChanaged() {
// ItemPosition itemPosition = positon.itemPositions.value.first;
print('${positon.itemPositions.value.last.index}');
// positon.itemPositions.value
if (positon.itemPositions.value.last.index == 1) {
bus.emit(
'onrefresh_guest_list_my',
);
}
if (positon.itemPositions.value.last.index == widget.contacts.length - 1) {
//上拉加载方法,最底部
bus.emit(
'onload_guest_list_my',
(widget.contacts.length / 10) < 1
? 1
: (widget.contacts.length / 10).toInt());
}
}
// void loadData() async {
... ... @@ -674,6 +715,8 @@ class _MyContactListPageState extends State<MyContactListPage> {
return AzListView(
indexBarItemHeight: w(12),
data: widget.contacts,
itemScrollController: controller,
itemPositionsListener: positon,
itemCount: widget.contacts.length,
itemBuilder: (BuildContext context, int index) {
// if (index == 0) return _buildHeader();
... ...
... ... @@ -54,7 +54,6 @@ class _MyCustomerListPageState extends State<MyCustomerListPage>
List<String> timeTilte = ['等于', '小于', '大于'];
int filterHydIndex = 0;
List pageData = [];
int page = 1;
@override
... ... @@ -86,15 +85,27 @@ class _MyCustomerListPageState extends State<MyCustomerListPage>
// item.select = true;
// // item.select = false;
// }
for (FilterBtnModel item in customerProvider.filterHydList) {
item.select = false;
// if (item.id == '${customerProvider.index}') {
// item.select = true;
// }
// for (FilterBtnModel item in customerProvider.filterHydList) {
// item.select = false;
// // if (item.id == '${customerProvider.index}') {
// // item.select = true;
// // }
// }
int selectNum = 0;
customerProvider.filterHydList.forEach((element) {
if (element.select) {
selectNum++;
}
});
if (selectNum <= 1) {
//选中一个或者0个
for (FilterBtnModel item in customerProvider.filterHydList) {
item.select = false;
}
}
}
page = 1;
pageData = [];
customerProvider.pageDataMy = [];
_getContantData(first: true);
}
});
... ... @@ -124,14 +135,14 @@ class _MyCustomerListPageState extends State<MyCustomerListPage>
});
bus.on("onload_guest_list_my", (arg) {
print(arg);
if (!pageData.contains(arg)) {
pageData.add(arg);
pageData.removeWhere((element) => element == 0);
if (!customerProvider.pageDataMy.contains(arg)) {
customerProvider.pageDataMy.add(arg);
customerProvider.pageDataMy.removeWhere((element) => element == 0);
_onload();
}
});
bus.on("onrefresh_guest_list_my", (arg) {
if (!pageData.contains(0)) {
if (!customerProvider.pageDataMy.contains(0)) {
_onrefresh();
}
});
... ... @@ -152,7 +163,7 @@ class _MyCustomerListPageState extends State<MyCustomerListPage>
_onrefresh() {
page = 1;
pageData = [0];
customerProvider.pageDataMy = [0];
_getContantData(showLoading: false);
}
... ... @@ -289,9 +300,9 @@ class _MyCustomerListPageState extends State<MyCustomerListPage>
// customerProvider.checkValue = false;
// }
// if (first || customerProvider.checkValue) {
if (first) {
customerProvider.addAllMy();
}
// if (first) {
// customerProvider.addAllMy();
// }
// await customerProvider.searchData(customerProvider.controller.text);
}
... ... @@ -469,14 +480,14 @@ class _MyCustomerListPageState extends State<MyCustomerListPage>
// _searchSellerLocation();
// customerProvider.searchData(value);
page = 1;
pageData = [];
customerProvider.pageDataMy = [];
_getContantData(showLoading: false);
},
onEditingComplete: () {
FocusScope.of(context)
.requestFocus(FocusNode()); //点击空白处隐藏键盘
page = 1;
pageData = [];
customerProvider.pageDataMy = [];
_getContantData(showLoading: false);
// contantShowModel.searchData(
// contantShowModel.controller.text);
... ... @@ -508,7 +519,7 @@ class _MyCustomerListPageState extends State<MyCustomerListPage>
FocusScope.of(context)
.requestFocus(FocusNode()); //点击空白处隐藏键盘
page = 1;
pageData = [];
customerProvider.pageDataMy = [];
_getContantData(showLoading: false);
}));
},
... ... @@ -687,7 +698,7 @@ class _MyCustomerListPageState extends State<MyCustomerListPage>
showFilter = false;
});
page = 1;
pageData = [];
customerProvider.pageDataMy = [];
_getContantData();
}, tapWhiteBack: () {
Navigator.of(context).pop();
... ... @@ -1521,7 +1532,7 @@ class _MyCustomerListPageState extends State<MyCustomerListPage>
pageState: model.pageState,
callback: () {
page = 1;
pageData = [];
customerProvider.pageDataMy = [];
_getContantData();
},
emptyMsg: "暂时没有客户哦",
... ...
... ... @@ -64,8 +64,6 @@ class _CustomerListPageState extends State<CustomerListPage>
bool distribution = false;
int page = 1;
List pageData = [];
@override
void initState() {
distribution = widget.distribution;
... ... @@ -95,15 +93,27 @@ class _CustomerListPageState extends State<CustomerListPage>
// item.select = true;
// // item.select = false;
// }
for (FilterBtnModel item in customerProvider.filterHydList) {
item.select = false;
// if (item.id == '${customerProvider.index}') {
// item.select = true;
// }
// for (FilterBtnModel item in customerProvider.filterHydList) {
// item.select = false;
// // if (item.id == '${customerProvider.index}') {
// // item.select = true;
// // }
// }
int selectNum = 0;
customerProvider.filterHydList.forEach((element) {
if (element.select) {
selectNum++;
}
});
if (selectNum <= 1) {
//选中一个或者0个
for (FilterBtnModel item in customerProvider.filterHydList) {
item.select = false;
}
}
}
page = 1;
pageData = [];
customerProvider.pageData = [];
_getContantData(first: true);
}
});
... ... @@ -128,9 +138,12 @@ class _CustomerListPageState extends State<CustomerListPage>
// }
page = 1;
_getContantData(first: first);
// _getSellerGuestManage();
// _getContantData(first: first);
_filterLabelList();
_getSellerGuestManage();
_getManagerAndList();
// _getManagerAndList();
});
bus.on("refresh_guest_list", (arg) {
... ... @@ -139,14 +152,14 @@ class _CustomerListPageState extends State<CustomerListPage>
bus.on("onload_guest_list", (arg) {
print(arg);
if (!pageData.contains(arg)) {
pageData.add(arg);
pageData.removeWhere((element) => element == 0);
if (!customerProvider.pageData.contains(arg)) {
customerProvider.pageData.add(arg);
customerProvider.pageData.removeWhere((element) => element == 0);
_onload();
}
});
bus.on("onrefresh_guest_list", (arg) {
if (!pageData.contains(0)) {
if (!customerProvider.pageData.contains(0)) {
_onrefresh();
}
});
... ... @@ -160,6 +173,11 @@ class _CustomerListPageState extends State<CustomerListPage>
super.dispose();
}
_getManagerAndList() async {
await _getSellerGuestManage();
await _getContantData();
}
_onload() {
page++;
_getContantData(showLoading: false, load: true);
... ... @@ -167,7 +185,7 @@ class _CustomerListPageState extends State<CustomerListPage>
_onrefresh() {
page = 1;
pageData = [0];
customerProvider.pageData = [0];
_getContantData(showLoading: false);
}
... ... @@ -184,6 +202,9 @@ class _CustomerListPageState extends State<CustomerListPage>
// model.id = item.id;
model1.title = '未分配经理';
model1.select = false;
if (distribution) {
model1.select = true;
}
customerProvider.filterManageList.add(model1);
if (model != null &&
model.sellerUser != null &&
... ... @@ -285,28 +306,28 @@ class _CustomerListPageState extends State<CustomerListPage>
//
//
// params['uid'] 经理ID
if (first && widget.uidStr != null && widget.uidStr != '') {
params['uid'] = widget.uidStr;
} else {
String uid = '';
List<FilterBtnModel> tempfilterManage =
List.from(customerProvider.filterManageList);
if (tempfilterManage.length > 0) {
tempfilterManage.removeAt(0);
}
for (FilterBtnModel item in tempfilterManage) {
if (item.select) {
uid += '${item.id},';
}
// if (first && widget.uidStr != null && widget.uidStr != '') {
// params['uid'] = widget.uidStr;
// } else {
String uid = '';
List<FilterBtnModel> tempfilterManage =
List.from(customerProvider.filterManageList);
if (tempfilterManage.length > 0) {
tempfilterManage.removeAt(0);
}
for (FilterBtnModel item in tempfilterManage) {
if (item.select) {
uid += '${item.id},';
}
}
if (uid.length > 0) {
if (uid.endsWith(',')) {
uid = uid.substring(0, uid.length - 1);
}
params['uid'] = uid;
if (uid.length > 0) {
if (uid.endsWith(',')) {
uid = uid.substring(0, uid.length - 1);
}
params['uid'] = uid;
}
// }
// if (customerProvider.controllerstime.text.trim().length > 0) {
// params['stime'] = customerProvider.controllerstime.text;
... ... @@ -357,16 +378,16 @@ class _CustomerListPageState extends State<CustomerListPage>
}
}
print(customerProvider.filterManageList);
if (first) {
if (distribution) {
params['distribution'] = '1';
}
} else {
if (customerProvider.filterManageList.length > 0 &&
customerProvider.filterManageList[0].select) {
params['distribution'] = '1';
}
// if (first) {
// if (distribution) {
// params['distribution'] = '1';
// }
// } else {
if (customerProvider.filterManageList.length > 0 &&
customerProvider.filterManageList[0].select) {
params['distribution'] = '1';
}
// }
await customerProvider.getCustomerBySeller(context, params,
showLoading: load);
... ... @@ -377,9 +398,9 @@ class _CustomerListPageState extends State<CustomerListPage>
// customerProvider.checkValue = false;
// }
// if (first || customerProvider.checkValue) {
if (first) {
customerProvider.addAll();
}
// if (first) {
// customerProvider.addAll();
// }
}
// ///选中的联系人widget
... ... @@ -557,14 +578,14 @@ class _CustomerListPageState extends State<CustomerListPage>
// _searchSellerLocation();
// customerProvider.searchData(value);
page = 1;
pageData = [];
customerProvider.pageData = [];
_getContantData(showLoading: false);
},
onEditingComplete: () {
FocusScope.of(context)
.requestFocus(FocusNode()); //点击空白处隐藏键盘
page = 1;
pageData = [];
customerProvider.pageData = [];
_getContantData(showLoading: false);
// contantShowModel.searchData(
// contantShowModel.controller.text);
... ... @@ -595,7 +616,7 @@ class _CustomerListPageState extends State<CustomerListPage>
FocusScope.of(context)
.requestFocus(FocusNode()); //点击空白处隐藏键盘
page = 1;
pageData = [];
customerProvider.pageData = [];
_getContantData(showLoading: false);
// customerProvider.searchData('');
}));
... ... @@ -780,7 +801,7 @@ class _CustomerListPageState extends State<CustomerListPage>
showFilter = false;
});
page = 1;
pageData = [];
customerProvider.pageData = [];
_getContantData();
}, tapWhiteBack: () {
Navigator.of(context).pop();
... ... @@ -1631,7 +1652,7 @@ class _CustomerListPageState extends State<CustomerListPage>
model.pageState = PageState.Loading;
model.notifyListeners();
page = 1;
pageData = [];
customerProvider.pageData = [];
_getContantData();
},
emptyMsg: "暂时没有客户哦",
... ...
... ... @@ -89,6 +89,8 @@ class CustomerProvider extends ChangeNotifier {
bool manageSelAll = false;
List<FilterBtnModel> filterManageList = []; //经理
List pageData = [];
List pageDataMy = [];
//获取全选按钮的状态 true or false
getCheckhydSelAll() {
bool temp = filterHydList.any((value) {
... ... @@ -390,12 +392,26 @@ class CustomerProvider extends ChangeNotifier {
break;
}
}
String page = params['page'];
int pageInt = int.parse(page) - 1;
if (pageDataMy.contains(pageInt)) {
pageDataMy.remove(pageInt);
}
notifyListeners();
});
if (baseResp != null && baseResp.code == Constant.status_success) {
// userHistorys = CustomerListModel.fromJson(baseResp.responseData).data;
if (params['page'] == '1') {
userHistorys = CustomerListModel.fromJson(baseResp.responseData).data;
// userHistorys = CustomerListModel.fromJson(baseResp.responseData).data;
selectCustomer = [];
List<CustomerListSunModel> temp =
CustomerListModel.fromJson(baseResp.responseData).data;
List<CustomerListSunModel> temp1 = await addDataSelectMy(temp);
userHistorys = temp1;
getCheckValueMy();
labelsValueMy();
if (userHistorys.length == 0) {
pageState = PageState.Empty;
} else {
... ... @@ -403,8 +419,15 @@ class CustomerProvider extends ChangeNotifier {
}
} else {
pageState = PageState.Success;
userHistorys
.addAll(CustomerListModel.fromJson(baseResp.responseData).data);
// userHistorys
// .addAll(CustomerListModel.fromJson(baseResp.responseData).data);
List<CustomerListSunModel> temp =
CustomerListModel.fromJson(baseResp.responseData).data;
List<CustomerListSunModel> temp1 = await addDataSelectMy(temp);
userHistorys.addAll(temp1);
getCheckValueMy();
labelsValueMy();
}
if (userHistorys.length > 0) {
List<String> idList = [];
... ... @@ -445,6 +468,12 @@ class CustomerProvider extends ChangeNotifier {
myHandleList(userHistorys, needRefresh: true);
}
notifyListeners();
} else {
String page = params['page'];
int pageInt = int.parse(page) - 1;
if (pageDataMy.contains(pageInt)) {
pageDataMy.remove(pageInt);
}
}
// if (baseResp != null && baseResp.code == Constant.status_success) {
// userHistorys = baseResp.data.map<CustomerListSunModel>((value) {
... ... @@ -907,6 +936,24 @@ class CustomerProvider extends ChangeNotifier {
notifyListeners();
}
Future<List<CustomerListSunModel>> addDataSelectMy(
List<CustomerListSunModel> data) async {
//把数据状态全部改成true,即选中状态
// selectCustomerSeller = [];
// for (var i = 0; i < data.length; i++) {
// if (data[i].gid != null) {
// data[i].select = true;
// selectCustomer.add(data[i]);
// }
// }
for (var i = 0; i < data.length; i++) {
data[i].select = true;
selectCustomer.add(data[i]);
}
return data;
}
labelsValueMy() {
List<String> tempLabel = [];
for (CustomerListSunModel item in userHistorys) {
... ... @@ -1374,6 +1421,21 @@ class CustomerProvider extends ChangeNotifier {
notifyListeners();
}
//
Future<List<CustomerBySellerSunModel>> addDataSelect(
List<CustomerBySellerSunModel> data) async {
//把数据状态全部改成true,即选中状态
// selectCustomerSeller = [];
for (var i = 0; i < data.length; i++) {
if (data[i].gid != null) {
data[i].select = true;
selectCustomerSeller.add(data[i]);
}
}
return data;
}
labelsValue() {
List<String> tempLabel = [];
for (CustomerBySellerSunModel item in customerBySellerList) {
... ... @@ -1456,12 +1518,24 @@ class CustomerProvider extends ChangeNotifier {
break;
}
}
String page = params['page'];
int pageInt = int.parse(page) - 1;
if (pageData.contains(pageInt)) {
pageData.remove(pageInt);
}
notifyListeners();
});
if (baseResp != null && baseResp.code == Constant.status_success) {
if (params['page'] == '1') {
customerBySellerList =
selectCustomerSeller = [];
List<CustomerBySellerSunModel> temp =
CustomerBySellerModel.fromJson(baseResp.responseData).data;
List<CustomerBySellerSunModel> temp1 = await addDataSelect(temp);
customerBySellerList = temp1;
getCheckValue();
labelsValue();
// notifyListeners();
if (customerBySellerList.length == 0) {
pageState = PageState.Empty;
} else {
... ... @@ -1469,8 +1543,12 @@ class CustomerProvider extends ChangeNotifier {
}
} else {
pageState = PageState.Success;
customerBySellerList
.addAll(CustomerBySellerModel.fromJson(baseResp.responseData).data);
List<CustomerBySellerSunModel> temp =
CustomerBySellerModel.fromJson(baseResp.responseData).data;
List<CustomerBySellerSunModel> temp1 = await addDataSelect(temp);
customerBySellerList.addAll(temp1);
getCheckValue();
labelsValue();
}
if (customerBySellerList.length > 0) {
... ... @@ -1539,6 +1617,12 @@ class CustomerProvider extends ChangeNotifier {
handleList(customerBySellerList, needRefresh: true);
}
notifyListeners();
} else {
String page = params['page'];
int pageInt = int.parse(page) - 1;
if (pageData.contains(pageInt)) {
pageData.remove(pageInt);
}
}
}
... ...