
import 'package:liftmanager/internal/bbs/page/hospital_page.dart';
import 'package:liftmanager/internal/wode/page/collect_page.dart';
import 'package:liftmanager/internal/bbs/page/tab/question/question_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   QuestionListPresenter extends BasePagePresenter<HospitalPageState> {

  Future getQuestionList(int page) async {
    await NewApiService().getQuestionList(page,10,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);
    });
  }
}

class   QuestionListPresenterSeconds extends BasePagePresenter<QuestionListState> {

  Future getQuestionList(int page,int brandId,String name,String title) async {
    await NewApiService().getQuestionList(page,10,brandId,name,title,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);
    });
  }
}

// class   QuestionListPresenterThird extends BasePagePresenter<CollectPageState> {

//   Future getQuestionList(int page,int userId) async {
//     await NewApiService().getQuestionList(page,3,null,userId,null,null,onSuccess: (res) {
//       view.closeProgress();
//       print(res);
//       print(33333334);
//       if (res != null) {
//         view.providerQuestion.setHasMore(res.records.length == 3);
//         if(page == 1){
//           view.providerQuestion.list.clear();
//           if (res.records.isEmpty) {
//             view.providerQuestion.setStateType(StateType.empty);
//           } else {
//             view.providerQuestion.addAll(res.records);
//           }
//         }else{
//           view.providerQuestion.addAll(res.records);
//         }

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