
import 'package:liftmanager/internal/wode/page/redbao_page.dart';
import 'package:liftmanager/internal/wode/page/coupon_page.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:liftmanager/utils/log_util.dart';

class   RedtListPresenter extends BasePagePresenter<RedbaoPageState> {

  Future getRedList(int page) async {
    await NewApiService().getCouponListPage(page,8,1,2,1,onSuccess: (res) {
      LogUtil.d(res);
      LogUtil.d(666663);
      view.closeProgress();
      if (res != null) {
        view.provider.setHasMore(res.records.length == 8);
        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);
    });
  }
}

class   CoupontListPresenter extends BasePagePresenter<CouponPageState> {

  Future getRedList(int page,int usedFlag) async {
    await NewApiService().getCouponListPage(page,8,usedFlag,1,1,onSuccess: (res) {
      LogUtil.d(res);
      LogUtil.d(666663);
      view.closeProgress();
      if (res != null) {
        view.provider.setHasMore(res.records.length == 8);
        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);
    });
  }
}


