/*
 * @Author: XianKaiQun
 * @Date: 2020-04-22 14:25:17
 * @LastEditors  : WuWei
 * @LastEditTime : 2023-11-16 10:03:23
 * @Descripttion: 
 */
part of 'index.dart';

class _Store with ChangeNotifier {
  final BuildContext context;
  late Map args;
  _Store(this.context) {
    args =
        ModalRoute.of(context)!.settings.arguments as Map<dynamic, dynamic>? ??
            {};
  }
  final scorllViewKey = GlobalKey<WisScrollViewState>();
  final communityGlobalStore = GetIt.I.get<CommunityGlobalStore>();

  ///从储存中取出的当前小区 拿出来可能是空
  CommunityModel? get currentCommunity => communityGlobalStore.data;

  late Map<String, dynamic> params = {
    'pageNum': 1,
    'pageSize': 20,
  };

  List<HouseBillsModel> list = [];

  Future getList({bool isLoad = true}) async {
    if (!isLoad) params['pageNum'] = 1;
    var res = await AssetBillApi.getHouseBillsList({
      ...params,
      'communityId': args['communityId'],
      'buildId': args['buildId'],
    });
    final _data = res.data;
    final _list = _data?.list ?? [];
    if ((_data?.total ?? 0) == 0) {
      scorllViewKey.currentState?.isEmpty();
    } else if ((_data?.pages ?? 0) <= (_data?.pageNum ?? 0)) {
      scorllViewKey.currentState?.isLast();
    } else {
      params['pageNum']++;
    }
    isLoad ? list.addAll(_list) : list = _list;
    notifyListeners();
  }

  route2detail(HouseBillsModel item) {
    Navigator.pushNamed(
      context,
      'bill/detail',
      arguments: {
        'assetId': item.houseId,
        'assetType': 'house',
        'assetFullName': item.assetFullName,
      },
    );
  }

  /// 手机收单详情页
  route2ReciptDetail(HouseBillsModel item) {
    late Map params = {
      'assetId': item.houseId,
      'assetType': 'house',
      'assetFullName': item.assetFullName,
    };
    Navigator.pushNamed(context, 'receipt/detail', arguments: params);
  }
}
