ASAddressViewModel.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // ASAddressViewModel.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2024/5/7.
  6. //
  7. #import "ASAddressViewModel.h"
  8. @implementation ASAddressViewModel
  9. - (void)upAddress:(ASAddressModel *)addressModel complate:(void(^)(BOOL,NSString *))complate {
  10. [ASNetTools.shared formData_postWithPath:saveAddress param:addressModel.params success:^(id _Nonnull json) {
  11. // [ASUserInfoManager.shared getInfo];
  12. complate(true, @"");
  13. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  14. complate(false, msg);
  15. }];
  16. }
  17. - (void)deleteAnAddress:(ASAddressModel *)addressModel complate:(void(^)(BOOL,NSString *))complate {
  18. // [ASNetTools.shared postWithPath:delAddress param:@{@"id":addressModel.Id} success:^(id _Nonnull json) {
  19. // [ASUserInfoManager.shared getInfo];
  20. // complate(true, @"");
  21. // } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  22. // complate(false, msg);
  23. // }];
  24. [ASNetTools.shared formData_postWithPath:delAddress param:@{@"id":addressModel.Id} success:^(id _Nonnull json) {
  25. // [ASUserInfoManager.shared getInfo];
  26. complate(true, @"");
  27. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  28. complate(false, msg);
  29. }];
  30. // [ASNetTools.shared getWithPath:delAddress param:@{@"id":addressModel.Id} success:^(id _Nonnull json) {
  31. //
  32. // } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  33. //
  34. // }];
  35. }
  36. - (void)getCountryList:(void(^)(void))success {
  37. [ASNetTools.shared getWithPath:CountryList param:@{} success:^(id _Nonnull json) {
  38. NSArray *list = json;
  39. NSMutableArray *arr = [KWCountryAddressModel mj_objectArrayWithKeyValuesArray:list];
  40. NSMutableArray *result = [NSMutableArray array];
  41. NSMutableArray *keysArr = [[NSMutableArray alloc] initWithCapacity:1];
  42. for (KWCountryAddressModel *m in arr) {
  43. if (m.full_name_english == nil || m.full_name_english.isEmpty) {
  44. continue;
  45. }
  46. [keysArr addObject:m.full_name_english];
  47. [result addObject:m];
  48. }
  49. NSArray *sortedArray = [keysArr sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2){
  50. return [obj1 compare:obj2 options:NSNumericSearch];
  51. }];
  52. NSMutableArray *sortArray = [[NSMutableArray alloc] initWithCapacity:1];
  53. for (int i = 0; i < sortedArray.count; i++) {
  54. NSString *sortStr = [sortedArray objectAtIndex:i];
  55. for (KWCountryAddressModel *m in result) {
  56. if ([m.full_name_english isEqualToString:sortStr]) {
  57. [sortArray addObject:m];
  58. [result removeObject:m];
  59. break;
  60. }
  61. }
  62. }
  63. self.countryArr = sortArray;
  64. success();
  65. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  66. self.countryArr = [NSMutableArray array];
  67. success();
  68. }];
  69. }
  70. - (void)getProvinceList:(NSString *)country_id success:(void(^)(void))success {
  71. self.hadGetProvince = false;
  72. self.provinceArr = [NSMutableArray array];
  73. if (country_id == nil || country_id.isEmpty) {
  74. success();
  75. return;
  76. }
  77. for (KWCountryAddressModel *m in self.countryArr) {
  78. if (m.country_id == nil || m.country_id.isEmpty) {
  79. continue;
  80. }
  81. if ([m.country_id isEqualToString:country_id] && m.available_regions != nil) {
  82. self.hadGetProvince = true;
  83. self.provinceArr = [NSMutableArray arrayWithArray:m.available_regions];
  84. break;
  85. }
  86. }
  87. success();
  88. }
  89. - (NSArray *)countryNameList {
  90. NSMutableArray *arr = [NSMutableArray array];
  91. for (KWCountryAddressModel* item in self.countryArr) {
  92. [arr addObject:item.full_name_english];
  93. }
  94. return arr;
  95. }
  96. - (NSArray *)provinceNameList {
  97. NSMutableArray *arr = [NSMutableArray array];
  98. for (KWProvinceAddressModel* item in self.provinceArr) {
  99. [arr addObject:item.name];
  100. }
  101. return arr;
  102. }
  103. @end