ASAddressViewModel.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. for (KWCountryAddressModel *m in arr) {
  42. if (m.full_name_english == nil || m.full_name_english.isEmpty) {
  43. continue;
  44. }
  45. [result addObject:m];
  46. }
  47. self.countryArr = result;
  48. success();
  49. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  50. self.countryArr = [NSMutableArray array];
  51. success();
  52. }];
  53. }
  54. - (void)getProvinceList:(NSString *)country_id success:(void(^)(void))success {
  55. self.hadGetProvince = false;
  56. self.provinceArr = [NSMutableArray array];
  57. if (country_id == nil || country_id.isEmpty) {
  58. success();
  59. return;
  60. }
  61. for (KWCountryAddressModel *m in self.countryArr) {
  62. if (m.country_id == nil || m.country_id.isEmpty) {
  63. continue;
  64. }
  65. if ([m.country_id isEqualToString:country_id] && m.available_regions != nil) {
  66. self.hadGetProvince = true;
  67. self.provinceArr = [NSMutableArray arrayWithArray:m.available_regions];
  68. break;
  69. }
  70. }
  71. success();
  72. }
  73. - (NSArray *)countryNameList {
  74. NSMutableArray *arr = [NSMutableArray array];
  75. for (KWCountryAddressModel* item in self.countryArr) {
  76. [arr addObject:item.full_name_english];
  77. }
  78. return arr;
  79. }
  80. - (NSArray *)provinceNameList {
  81. NSMutableArray *arr = [NSMutableArray array];
  82. for (KWProvinceAddressModel* item in self.provinceArr) {
  83. [arr addObject:item.name];
  84. }
  85. return arr;
  86. }
  87. @end