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

class   ExpertCommentListPresenter extends BasePagePresenter<ExpertDetailState> {
  Future getExpertCommentList(int page,int expertId,
  {Function(int length) getLength}
  ) async {
    await NewApiService().getExpertCommentList(page,4,expertId,onSuccess: (res) {
      view.closeProgress();
      if (res != null) {
        getLength(res.records.length);
        view.provider.setHasMore(res.records.length == 4);
        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);
    });
  }
}
