import 'package:liftmanager/internal/wode/page/reward_record_list.dart';
import 'package:liftmanager/mvp/base_page_presenter.dart';
import 'package:liftmanager/net/api_service.dart';
import 'package:liftmanager/widgets/state_layout.dart';

class RewardRecordListPresenter
    extends BasePagePresenter<RewardRecordListState> {
  Future getShopList(int page) async {
    await NewApiService().getRewardRecordList(page, 10, onSuccess: (res) {
      view.closeProgress();
      if (res != null) {
        view.provider.setHasMore(res.length == 10);
        if (page == 1) {
          view.provider.list.clear();
          if (res.isEmpty) {
            view.provider.setStateType(StateType.empty);
          } else {
            view.provider.addAll(res);
          }
        } else {
          view.provider.addAll(res);
        }
      } else {
        /// 加载失败
        view.provider.setHasMore(false);
        view.provider.setStateType(StateType.empty);
      }
      // view.provider.notifyListeners();
    }, onError: (code, msg) {
      view.closeProgress();
      view.provider.setHasMore(false);
      view.provider.setStateType(StateType.network);
    });
  }
}
