ASAddressViewModel.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. complate(true, @"");
  11. }
  12. - (void)deleteAnAddress:(ASAddressModel *)addressModel complate:(void(^)(BOOL))complate {
  13. complate(true);
  14. }
  15. - (void)getCountryList:(void(^)(void))success {
  16. [ASNetTools.shared getWithPath:CountryList param:@{} success:^(id _Nonnull json) {
  17. NSArray *list = json;
  18. NSMutableArray *arr = [KWCountryAddressModel mj_objectArrayWithKeyValuesArray:list];
  19. NSMutableArray *result = [NSMutableArray array];
  20. for (KWCountryAddressModel *m in arr) {
  21. if (m.full_name_english == nil || m.full_name_english.isEmpty) {
  22. continue;
  23. }
  24. [result addObject:m];
  25. }
  26. self.countryArr = result;
  27. success();
  28. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  29. self.countryArr = [NSMutableArray array];
  30. success();
  31. }];
  32. }
  33. - (void)getProvinceList:(NSString *)country_id success:(void(^)(void))success {
  34. self.hadGetProvince = false;
  35. self.provinceArr = [NSMutableArray array];
  36. if (country_id == nil || country_id.isEmpty) {
  37. success();
  38. return;
  39. }
  40. for (KWCountryAddressModel *m in self.countryArr) {
  41. if (m.country_id == nil || m.country_id.isEmpty) {
  42. continue;
  43. }
  44. if ([m.country_id isEqualToString:country_id] && m.available_regions != nil) {
  45. self.hadGetProvince = true;
  46. self.provinceArr = [NSMutableArray arrayWithArray:m.available_regions];
  47. break;
  48. }
  49. }
  50. success();
  51. }
  52. - (NSArray *)countryNameList {
  53. NSMutableArray *arr = [NSMutableArray array];
  54. for (KWCountryAddressModel* item in self.countryArr) {
  55. [arr addObject:item.full_name_english];
  56. }
  57. return arr;
  58. }
  59. - (NSArray *)provinceNameList {
  60. NSMutableArray *arr = [NSMutableArray array];
  61. for (KWProvinceAddressModel* item in self.provinceArr) {
  62. [arr addObject:item.name];
  63. }
  64. return arr;
  65. }
  66. @end