
import 'package:liftmanager/internal/wode/page/collect_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   MixListPresenter extends BasePagePresenter<CollectPageState> {

  Future getQuestionList(int page) async {
    await NewApiService().getCollectQuestionList(page,10,onSuccess: (res) {
    // await NewApiService().getQuestionList(page,3,null,1,null,null,null,onSuccess: (res) {
      view.closeProgress();
      print(res);
      print(33333334);
      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);
    });
  }

  Future getVideoList(int page) async {
    await NewApiService().getCollectVideoList(page,10,onSuccess: (res) {
  // Future getVideoList(int page,int userId) async {
  //   await NewApiService().getVideoList(page,3,null,1,userId,null,onSuccess: (res) {
      print('我的视频列表');
      print(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);
    });
  }

  Future getPositionList(int page) async {

    await NewApiService().getCollectPositionList(page, 10,
    // await NewApiService().getPositionList(page, 10, null, 1,userId,null,
        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);
    });
  }

  Future getShopList(int page) async {
    await NewApiService().getCollectProductList(page,10,onSuccess: (res) {
    // await NewApiService().getShopList(page,10,null,1,userId,null,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);
    });
  }
}
