|
@@ -1,4 +1,7 @@
|
|
|
+import 'package:cpt_profile/modules/my_estate/estate_group_data.dart';
|
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
+import 'package:widgets/load_state_layout.dart';
|
|
|
+import 'package:widgets/widget_export.dart';
|
|
|
|
|
|
import 'my_estate_state.dart';
|
|
|
|
|
@@ -8,6 +11,141 @@ part 'my_estate_view_model.g.dart';
|
|
|
class MyEstateViewModel extends _$MyEstateViewModel {
|
|
|
@override
|
|
|
MyEstateState build() {
|
|
|
- return MyEstateState();
|
|
|
+ return MyEstateState(datas: []);
|
|
|
}
|
|
|
+
|
|
|
+ var _curPage = 1; //请求参数当前的页面
|
|
|
+ var _needShowPlaceholder = true; //是否展示LoadingView
|
|
|
+
|
|
|
+ // Refresh 控制器
|
|
|
+ final EasyRefreshController refreshController = EasyRefreshController(
|
|
|
+ controlFinishRefresh: true, //允许刷新
|
|
|
+ controlFinishLoad: true, //允许加载
|
|
|
+ );
|
|
|
+
|
|
|
+ //刷新页面状态
|
|
|
+ void changeLoadingState(LoadState loadState, String? errorMsg) {
|
|
|
+ state = state.copyWith(loadingState: loadState, errorMessage: errorMsg);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Refresh 刷新事件
|
|
|
+ Future onRefresh() async {
|
|
|
+ _curPage = 1;
|
|
|
+ fetchList();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Refresh 加载事件
|
|
|
+ Future loadMore() async {
|
|
|
+ _curPage++;
|
|
|
+ fetchList();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 重试请求
|
|
|
+ Future retryRequest() async {
|
|
|
+ _curPage = 1;
|
|
|
+ _needShowPlaceholder = true;
|
|
|
+ fetchList();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 获取服务器数据
|
|
|
+ Future fetchList() async {
|
|
|
+ if (_needShowPlaceholder) {
|
|
|
+ changeLoadingState(LoadState.State_Loading, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取 Applied 列表
|
|
|
+ // var listResult = await _jobRepository.fetchJobAppliedList(
|
|
|
+ // state.jobId,
|
|
|
+ // state.selectedStatusId,
|
|
|
+ // state.keyword,
|
|
|
+ // curPage: _curPage,
|
|
|
+ // cancelToken: cancelToken,
|
|
|
+ // );
|
|
|
+ //
|
|
|
+ // // 处理数据
|
|
|
+ // if (listResult.isSuccess) {
|
|
|
+ // handleList(listResult.data?.rows);
|
|
|
+ // } else {
|
|
|
+ // errorMessage = listResult.errorMsg;
|
|
|
+ // changeLoadingState(LoadState.State_Error);
|
|
|
+ // }
|
|
|
+
|
|
|
+ await Future.delayed(const Duration(milliseconds: 1500));
|
|
|
+
|
|
|
+ List<EstateGroupData> list = [];
|
|
|
+ if (_curPage > 1) {
|
|
|
+
|
|
|
+ //这里只加载一页吧
|
|
|
+ } else {
|
|
|
+
|
|
|
+ list.add(EstateGroupData()
|
|
|
+ ..groupId = "Parc Life"
|
|
|
+ ..groupDatas = ["1", "2",]);
|
|
|
+
|
|
|
+ list.add(EstateGroupData()
|
|
|
+ ..groupId = "Little India"
|
|
|
+ ..groupDatas = ["1", "2",]);
|
|
|
+
|
|
|
+ list.add(EstateGroupData()
|
|
|
+ ..groupId = "Marina Bay Sands"
|
|
|
+ ..groupDatas = ["1"]);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (_curPage == 1) {
|
|
|
+ //刷新的方式
|
|
|
+ state = state.copyWith(datas: list);
|
|
|
+ refreshController.finishRefresh();
|
|
|
+
|
|
|
+ //更新展示的状态
|
|
|
+ changeLoadingState(LoadState.State_Success, null);
|
|
|
+ } else {
|
|
|
+ //加载更多
|
|
|
+ final allList = state.datas;
|
|
|
+ allList.addAll(list);
|
|
|
+ state.datas.addAll(list);
|
|
|
+
|
|
|
+ // refreshController.finishLoad();
|
|
|
+ refreshController.finishLoad(IndicatorResult.noMore);
|
|
|
+
|
|
|
+ state = state.copyWith(datas: allList);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最后赋值
|
|
|
+ _needShowPlaceholder = false;
|
|
|
+ }
|
|
|
+
|
|
|
+// 处理数据与展示的逻辑
|
|
|
+// void handleList(List<JobAppliedListSGRows>? list) {
|
|
|
+// if (list != null && list.isNotEmpty) {
|
|
|
+// //有数据,判断是刷新还是加载更多的数据
|
|
|
+// if (_curPage == 1) {
|
|
|
+// //刷新的方式
|
|
|
+// state.datas.clear();
|
|
|
+// state.datas.addAll(list);
|
|
|
+// refreshController.finishRefresh();
|
|
|
+//
|
|
|
+// //更新展示的状态
|
|
|
+// changeLoadingState(LoadState.State_Success);
|
|
|
+// } else {
|
|
|
+// //加载更多
|
|
|
+// state.datas.addAll(list);
|
|
|
+// refreshController.finishLoad();
|
|
|
+// update();
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// if (_curPage == 1) {
|
|
|
+// //展示无数据的布局
|
|
|
+// state.datas.clear();
|
|
|
+// changeLoadingState(LoadState.State_Empty);
|
|
|
+// refreshController.finishRefresh();
|
|
|
+// } else {
|
|
|
+// //展示加载完成,没有更多数据了
|
|
|
+// refreshController.finishLoad(IndicatorResult.noMore);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
}
|