ASPointsViewModel.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. self.extraPathList = [NSMutableArray array];
  16. }
  17. return self;
  18. }
  19. - (void)getExtraList:(void(^)(BOOL hasNext, NSString *msg))com {
  20. __weak typeof(self) weakSelf = self;
  21. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  22. [ASNetTools.shared getWithPath:getExtraPoints param:dic success:^(id _Nonnull json) {
  23. NSMutableArray *arr = [ASExtraPointsModel mj_objectArrayWithKeyValuesArray:json];
  24. weakSelf.extraPathList = arr;
  25. com(true, @"");
  26. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  27. com(false, msg);
  28. }];
  29. }
  30. - (void)getAllList:(NSInteger)page com:(void(^)(BOOL hasNext, NSString *msg))com {
  31. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  32. dic[@"page"] = [NSString stringWithFormat:@"%ld", page];
  33. dic[@"obtained"] = @"0";
  34. dic[@"used"] = @"0";
  35. [ASNetTools.shared getWithPath:getPointsDetailUrl param:dic success:^(id _Nonnull json) {
  36. NSInteger pagesize = [NSString stringWithFormat:@"%@", json[@"pageSize"]].integerValue;
  37. NSArray *list = json[@"list"];
  38. NSMutableArray *arr = [ASPointDetailModel mj_objectArrayWithKeyValuesArray:list];
  39. if (page == 1) {
  40. self.allList = arr;
  41. } else {
  42. [self.allList addObjectsFromArray:arr];
  43. }
  44. if (arr.count >= pagesize){
  45. com(true, @"");
  46. } else {
  47. com(false, @"");
  48. }
  49. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  50. com(false, msg);
  51. }];
  52. }
  53. - (void)getUsedList:(NSInteger)page com:(void(^)(BOOL hasNext, NSString *msg))com{
  54. NSMutableDictionary *dic = [NSMutableDictionary dictionary];
  55. dic[@"page"] = [NSString stringWithFormat:@"%ld", page];
  56. dic[@"used"] = @"1";
  57. dic[@"obtained"] = @"0";
  58. [ASNetTools.shared getWithPath:getPointsDetailUrl param:dic success:^(id _Nonnull json) {
  59. NSInteger pagesize = [NSString stringWithFormat:@"%@", json[@"pageSize"]].integerValue;
  60. NSArray *list = json[@"list"];
  61. NSMutableArray *arr = [ASPointDetailModel mj_objectArrayWithKeyValuesArray:list];
  62. if (page == 1) {
  63. self.usedList = arr;
  64. } else {
  65. [self.usedList addObjectsFromArray:arr];
  66. }
  67. if (arr.count >= pagesize){
  68. com(true, @"");
  69. } else {
  70. com(false, @"");
  71. }
  72. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  73. com(false, msg);
  74. }];
  75. }
  76. @end