/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2022-12-05 17:13:57
 * @LastEditTime : 2023-07-20 15:32:13
 * @Description  : Do not edit
 */

part of 'index.dart';

class _Store with ChangeNotifier {
  final BuildContext context;
  _Store(this.context);

  List<CommunityModel> list = [];
  List<CommunityModel> searchList = [];
  List<CommunityModel> allList = [];
  final communityGlobalStore = GetIt.I.get<CommunityGlobalStore>();
  final appGlobalStore = GetIt.I.get<AppGlobalStore>();

  ///从储存中取出的当前小区
  CommunityModel? get currentCommunity => communityGlobalStore.data;

  ///选中之后将小区写入储存 然后返回上一页
  onPick(i) async {
    await communityGlobalStore.setCommunity(i);
    if (i.id != null) {
      appGlobalStore.onInitSassNewsList();
    }
    notifyListeners();
    WNavUtil.instance!.pop();
  }

  ///获取用户管辖的小区列表
  getCommunitysList() async {
    var res = await EmployeeApi.getDomainCommunitysList();
    list = res.data ?? [];
    allList = res.data ?? [];
    notifyListeners();
  }

  /// 搜索小区
  onNameInput(value) async {
    if (value == '' || value == null) {
      list = allList;
    } else {
      list = allList.where((v) => v.name!.contains(value)).toList();
    }
    notifyListeners();
  }
}
