import 'package:flutter/cupertino.dart';
import 'package:liftmanager/common/user_db.dart';
import 'package:liftmanager/internal/team/page/team_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 TeamListPresenter extends BasePagePresenter<TeamListPageState> {
  Future myTeamList(BuildContext context) async {
    await ApiService(context: context).teamList(onSuccess: (data) {
      if (data != null) {
        view.provider.list.clear();
        if (data.isEmpty) {
          view.provider.setStateType(StateType.empty);
        } else {
          view.provider.addAll(data);
        }
      } else {
        /// 加载失败
        view.provider.setHasMore(false);
        view.provider.setStateType(StateType.empty);
      }
    }, onError: (code, msg) {
      view.provider.setHasMore(false);
      view.provider.setStateType(StateType.network);
    });
  }

  Future changeTeam(BuildContext context,companyId) async{
    await ApiService(context: context).changTeam(companyId,onSuccess: (res) {
      if (res != null) {
        User().setCurrentUser(res);
        myTeamList(context);
      }
    }, onError: (code, msg) {

    });
  }
}
