ASPointsViewModel.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //
  2. // ASPointsViewModel.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/12/2.
  6. //
  7. #import "ASPointsViewModel.h"
  8. @implementation ASPointsViewModel
  9. - (instancetype)init
  10. {
  11. self = [super init];
  12. if (self) {
  13. self.allList = [NSMutableArray array];
  14. self.usedList = [NSMutableArray array];
  15. }
  16. return self;
  17. }
  18. - (void)getAllList:(NSInteger)page com:(void(^)(BOOL hasNext, NSString *msg))com {
  19. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  20. dic[@"page"] = [NSString stringWithFormat:@"%ld", page];
  21. dic[@"obtained"] = @"0";
  22. dic[@"used"] = @"0";
  23. [ASNetTools.shared getWithPath:getPointsDetailUrl param:dic success:^(id _Nonnull json) {
  24. NSInteger pagesize = [NSString stringWithFormat:@"%@", json[@"pageSize"]].integerValue;
  25. NSArray *list = json[@"list"];
  26. NSMutableArray *arr = [ASPointDetailModel mj_objectArrayWithKeyValuesArray:list];
  27. if (page == 1) {
  28. self.allList = arr;
  29. } else {
  30. [self.allList addObjectsFromArray:arr];
  31. }
  32. if (arr.count >= pagesize){
  33. com(true, @"");
  34. } else {
  35. com(false, @"");
  36. }
  37. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  38. com(false, msg);
  39. }];
  40. }
  41. - (void)getUsedList:(NSInteger)page com:(void(^)(BOOL hasNext, NSString *msg))com{
  42. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  43. dic[@"page"] = [NSString stringWithFormat:@"%ld", page];
  44. dic[@"used"] = @"1";
  45. dic[@"obtained"] = @"0";
  46. [ASNetTools.shared getWithPath:getPointsDetailUrl param:dic success:^(id _Nonnull json) {
  47. NSInteger pagesize = [NSString stringWithFormat:@"%@", json[@"pageSize"]].integerValue;
  48. NSArray *list = json[@"list"];
  49. NSMutableArray *arr = [ASPointDetailModel mj_objectArrayWithKeyValuesArray:list];
  50. if (page == 1) {
  51. self.usedList = arr;
  52. } else {
  53. [self.usedList addObjectsFromArray:arr];
  54. }
  55. if (arr.count >= pagesize){
  56. com(true, @"");
  57. } else {
  58. com(false, @"");
  59. }
  60. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  61. com(false, msg);
  62. }];
  63. }
  64. @end