import 'package:flutter/cupertino.dart';
import 'package:liftmanager/internal/sign/page/sign_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 SignListPresenter extends BasePagePresenter<SignListPageState> {
  Future signList(BuildContext context,pageIndex,pageSize,clockTime) async {
    await ApiService(context: context).signList(pageIndex,pageSize,clockTime,onSuccess: (data) {
      if (data != null) {
        view.provider.setHasMore(data.rows.length == pageSize);
        view.provider.list.clear();
        if (data.rows.isEmpty) {
          view.provider.setStateType(StateType.empty);
        } else {
          view.provider.addAll(data.rows);
          view.provider.setStateType(StateType.empty);
        }
      } else {
        /// 加载失败
        view.provider.setHasMore(false);
        view.provider.setStateType(StateType.empty);
      }
    }, onError: (code, msg) {
      view.provider.setHasMore(false);
      view.provider.setStateType(StateType.network);
    });
  }
}
