123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- import 'package:domain/entity/response/job_list_applied_staff_search_entity.dart';
- import 'package:domain/repository/job_repository.dart';
- import 'package:flutter/material.dart';
- import 'package:plugin_basic/basic_export.dart';
- import 'package:plugin_platform/http/dio/dio_cancelable_mixin.dart';
- import 'package:shared/utils/log_utils.dart';
- import 'package:widgets/load_state_layout.dart';
- import 'package:widgets/widget_export.dart';
- class AppliedAddStaffController extends GetxController with DioCancelableMixin {
- final JobRepository _jobRepository = Get.find();
- TextEditingController searchController = TextEditingController();
- var _curPage = 1;
- var _needShowPlaceholder = true;
- //页面PlaceHolder的展示
- LoadState loadingState = LoadState.State_Success;
- String? errorMessage;
- String keyword = "";
- String? jobId = null;
- List<JobListAppliedStaffSearchRows> datas = [];
- //刷新页面状态
- void changeLoadingState(LoadState state) {
- loadingState = state;
- update();
- }
- // Refresh 控制器
- final EasyRefreshController refreshController = EasyRefreshController(
- controlFinishRefresh: true,
- controlFinishLoad: true,
- );
- // Refresh 刷新事件
- Future onRefresh() async {
- _curPage = 1;
- fetchAllStaffList();
- }
- // Refresh 加载事件
- Future loadMore() async {
- _curPage++;
- fetchAllStaffList();
- }
- // 重试请求
- Future retryRequest() async {
- _curPage = 1;
- _needShowPlaceholder = true;
- fetchAllStaffList();
- }
- /// 获取列表数据
- Future fetchAllStaffList() async {
- if (_needShowPlaceholder) {
- changeLoadingState(LoadState.State_Loading);
- }
- // 获取 Staff 列表
- var listResult = await _jobRepository.searchStaffList(
- jobId,
- keyword,
- curPage: _curPage,
- cancelToken: cancelToken,
- );
- // 处理数据
- if (listResult.isSuccess) {
- handleList(listResult.data?.rows);
- } else {
- errorMessage = listResult.errorMsg;
- changeLoadingState(LoadState.State_Error);
- }
- // 最后赋值
- _needShowPlaceholder = false;
- }
- // 处理数据与展示的逻辑
- void handleList(List<JobListAppliedStaffSearchRows>? list) {
- if (list != null && list.isNotEmpty) {
- //有数据,判断是刷新还是加载更多的数据
- if (_curPage == 1) {
- //刷新的方式
- datas.clear();
- datas.addAll(list);
- refreshController.finishRefresh();
- //更新展示的状态
- changeLoadingState(LoadState.State_Success);
- } else {
- //加载更多
- datas.addAll(list);
- refreshController.finishLoad();
- update();
- }
- } else {
- if (_curPage == 1) {
- //展示无数据的布局
- datas.clear();
- changeLoadingState(LoadState.State_Empty);
- refreshController.finishRefresh();
- } else {
- //展示加载完成,没有更多数据了
- refreshController.finishLoad(IndicatorResult.noMore);
- }
- }
- }
- //搜索
- void doSearch(String keyword) {
- this.keyword = keyword;
- refreshController.callRefresh();
- }
- @override
- void onReady() {
- super.onReady();
- fetchAllStaffList();
- }
- @override
- void onClose() {
- datas.clear();
- super.onClose();
- }
- }
|