
import 'package:flutter/cupertino.dart';
import 'package:liftmanager/internal/heavy/page/heavy_lift_list_page.dart';
import 'package:liftmanager/mvp/base_page_presenter.dart';
import 'package:liftmanager/net/api_service.dart';
import 'package:liftmanager/widgets/state_layout.dart';

class HeavyLiftListPresenter extends BasePagePresenter<HeavyLiftListPageState> {

  Future searchLift(BuildContext context,String projectId,String text, int page, bool isShowDialog) async {
    await ApiService(context: context).searchHeavyLift(projectId,page,20,text,onSuccess: (data) {
      view.closeProgress();
      if (data != null) {
        view.provider.setHasMore(data.rows.length == 20);
        if(page == 1){
          view.provider.list.clear();
          if (data.rows.isEmpty) {
            view.provider.setStateType(StateType.empty);
          } else {
            view.provider.addAll(data.rows);
          }
        }else{
          view.provider.addAll(data.rows);
        }

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