ASCouponsListViewModel.m 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // ASCouponsListViewModel.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/11/30.
  6. //
  7. #import "ASCouponsListViewModel.h"
  8. @implementation ASCouponsListViewModel
  9. - (instancetype)init
  10. {
  11. self = [super init];
  12. if (self) {
  13. self.couponList = [NSMutableArray array];
  14. }
  15. return self;
  16. }
  17. - (void)getCouponList:(NSInteger)page com:(void(^)(BOOL hasNext, NSString *msg))com {
  18. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  19. dic[@"page"] = [NSString stringWithFormat:@"%ld", page];
  20. [ASNetTools.shared getWithPath:getUserCouponUrl param:dic success:^(id _Nonnull json) {
  21. NSInteger pagesize = [NSString stringWithFormat:@"%@", json[@"pageSize"]].integerValue;
  22. NSArray *list = json[@"list"];
  23. NSMutableArray *arr = [ASCouponsModel mj_objectArrayWithKeyValuesArray:list];
  24. if (page == 1) {
  25. self.couponList = arr;
  26. } else {
  27. [self.couponList addObjectsFromArray:arr];
  28. }
  29. if (arr.count >= pagesize){
  30. com(true, @"");
  31. } else {
  32. com(false, @"");
  33. }
  34. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  35. com(false, msg);
  36. }];
  37. }
  38. @end