
import 'package:liftmanager/internal/news/page/news_list_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 NewsListPresenterss extends BasePagePresenter<NewsListStateList> {
  Future list(String text, int pageIndex,pageSize,isTop) async{
    await NewApiService().newsList(pageIndex,pageSize,isTop,text,"",onSuccess: (data) {
      view.closeProgress();
      if (data != null) {
        view.provider.setHasMore(data.news.rows.length == 20);
        if(pageIndex == 1){
          view.provider.list.clear();
          if (data.news.rows.isEmpty) {
            view.provider.setStateType(StateType.empty);
          } else {
            view.provider.addAll(data.news.rows);
            print("*-////--------");
          }
        }else{
          view.provider.addAll(data.news.rows);
        }

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

}