|
@@ -1,3 +1,6 @@
|
|
|
+import 'package:domain/entity/visitor_page_entity.dart';
|
|
|
+import 'package:domain/repository/main_repository.dart';
|
|
|
+import 'package:plugin_platform/http/dio/dio_cancelable_mixin.dart';
|
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
import 'package:shared/utils/log_utils.dart';
|
|
|
import 'package:widgets/load_state_layout.dart';
|
|
@@ -8,21 +11,23 @@ import 'visitor_active_state.dart';
|
|
|
part 'visitor_active_view_model.g.dart';
|
|
|
|
|
|
@riverpod
|
|
|
-class VisitorActiveViewModel extends _$VisitorActiveViewModel {
|
|
|
+class VisitorActiveViewModel extends _$VisitorActiveViewModel with DioCancelableMixin {
|
|
|
+ late final MainRepository _mainRepository;
|
|
|
var _curPage = 1; //请求参数当前的页面
|
|
|
var _needShowPlaceholder = true; //是否展示LoadingView
|
|
|
|
|
|
// Refresh 控制器
|
|
|
final EasyRefreshController refreshController = EasyRefreshController(
|
|
|
- controlFinishRefresh: true, //允许刷新
|
|
|
- controlFinishLoad: true, //允许加载
|
|
|
+ controlFinishRefresh: true, //允许刷新
|
|
|
+ controlFinishLoad: true, //允许加载
|
|
|
);
|
|
|
|
|
|
@override
|
|
|
VisitorActiveState build() {
|
|
|
+ _mainRepository = ref.read(mainRepositoryProvider);
|
|
|
final state = VisitorActiveState(datas: []);
|
|
|
//初始化默认调用接口
|
|
|
- Log.d("VisitorActiveViewModel 执行build");
|
|
|
+ registerCancellation();
|
|
|
return state;
|
|
|
}
|
|
|
|
|
@@ -34,100 +39,72 @@ class VisitorActiveViewModel extends _$VisitorActiveViewModel {
|
|
|
// Refresh 刷新事件
|
|
|
Future onRefresh() async {
|
|
|
_curPage = 1;
|
|
|
- fetchAppliedStaffList();
|
|
|
+ fetchList();
|
|
|
}
|
|
|
|
|
|
// Refresh 加载事件
|
|
|
Future loadMore() async {
|
|
|
_curPage++;
|
|
|
- fetchAppliedStaffList();
|
|
|
+ fetchList();
|
|
|
}
|
|
|
|
|
|
// 重试请求
|
|
|
Future retryRequest() async {
|
|
|
_curPage = 1;
|
|
|
_needShowPlaceholder = true;
|
|
|
- fetchAppliedStaffList();
|
|
|
+ fetchList();
|
|
|
}
|
|
|
|
|
|
/// 获取服务器数据
|
|
|
- Future fetchAppliedStaffList() async {
|
|
|
+ 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);
|
|
|
- // }
|
|
|
+ // 获取列表
|
|
|
+ var listResult = await _mainRepository.fetchVisitorList(
|
|
|
+ type: "active",
|
|
|
+ curPage: _curPage,
|
|
|
+ cancelToken: cancelToken,
|
|
|
+ );
|
|
|
|
|
|
-
|
|
|
- await Future.delayed(const Duration(milliseconds: 1500));
|
|
|
-
|
|
|
- final List<String> list = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"];
|
|
|
-
|
|
|
- if (_curPage == 1) {
|
|
|
- //刷新的方式
|
|
|
- state = state.copyWith(datas: list);
|
|
|
- refreshController.finishRefresh();
|
|
|
-
|
|
|
- //更新展示的状态
|
|
|
- changeLoadingState(LoadState.State_Success, null);
|
|
|
+ // 处理数据
|
|
|
+ if (listResult.isSuccess) {
|
|
|
+ handleList(listResult.data?.list);
|
|
|
} else {
|
|
|
- //加载更多
|
|
|
- final allList = state.datas;
|
|
|
- allList.addAll(list);
|
|
|
- state.datas.addAll(list);
|
|
|
-
|
|
|
- refreshController.finishLoad();
|
|
|
-
|
|
|
- state = state.copyWith(datas: allList);
|
|
|
+ changeLoadingState(LoadState.State_Error, listResult.errorMsg);
|
|
|
}
|
|
|
|
|
|
// 最后赋值
|
|
|
_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);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
+ // 处理数据与展示的逻辑
|
|
|
+ void handleList(List<VisitorPageList>? list) {
|
|
|
+ if (list != null && list.isNotEmpty) {
|
|
|
+ //有数据,判断是刷新还是加载更多的数据
|
|
|
+ if (_curPage == 1) {
|
|
|
+ //刷新的方式
|
|
|
+ state = state.copyWith(datas: list);
|
|
|
+ refreshController.finishRefresh();
|
|
|
+
|
|
|
+ //更新展示的状态
|
|
|
+ changeLoadingState(LoadState.State_Success, null);
|
|
|
+ } else {
|
|
|
+ //加载更多
|
|
|
+ state.datas.addAll(List<VisitorPageList>.from(state.datas)..addAll(list));
|
|
|
+ refreshController.finishLoad();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (_curPage == 1) {
|
|
|
+ //展示无数据的布局
|
|
|
+ state = state.copyWith(datas: []);
|
|
|
+ changeLoadingState(LoadState.State_Empty, null);
|
|
|
+ refreshController.finishRefresh();
|
|
|
+ } else {
|
|
|
+ //展示加载完成,没有更多数据了
|
|
|
+ refreshController.finishLoad(IndicatorResult.noMore);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|