
import 'package:liftmanager/internal/bbs/page/work_place.dart';
import 'package:liftmanager/mvp/base_page_presenter.dart';
import 'package:liftmanager/net/api_service.dart';
import 'package:liftmanager/widgets/state_layout.dart';
import 'package:flustars/flustars.dart';
import 'package:liftmanager/common/common.dart';

class   LiftcaseListPresenter extends BasePagePresenter<WorkPlaceState> {
  Future getLiftcaseList(int page) async {
    await NewApiService().getLiftCasesListPage({
      "pageNum": page,
      "pageSize": 10,
      "type": 'WORKBENCH',
      "createUserId": null,
      "chargerId": int.parse(SpUtil.getString(Constant.userId))
    },2,onSuccess: (res) {
      view.closeProgress();
      if (res != null) {
        view.provider.setHasMore(res.records.length == 10);
        if(page == 1){
          view.provider.list.clear();
          if (res.records.isEmpty) {
            view.provider.setStateType(StateType.empty);
          } else {
            view.provider.addAll(res.records);
          }
        }else{
          view.provider.addAll(res.records);
        }

      } else {
        /// 加载失败
        view.provider.setHasMore(false);
        view.provider.setStateType(StateType.empty);
      }
    }, onError: (code, msg) {
      view.closeProgress();
      view.provider.setHasMore(false);
      view.provider.setStateType(StateType.network);
    });
  }
}
