| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 | ////  ASAddressViewModel.m//  Asteria////  Created by iOS on 2024/5/7.//#import "ASAddressViewModel.h"@implementation ASAddressViewModel- (void)upAddress:(ASAddressModel *)addressModel complate:(void(^)(BOOL,NSString *))complate {    [ASNetTools.shared formData_postWithPath:saveAddress param:addressModel.params success:^(id _Nonnull json) {//        [ASUserInfoManager.shared getInfo];        complate(true, @"");    } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {        complate(false, msg);    }];}- (void)deleteAnAddress:(ASAddressModel *)addressModel complate:(void(^)(BOOL,NSString *))complate {    //    [ASNetTools.shared postWithPath:delAddress param:@{@"id":addressModel.Id} success:^(id _Nonnull json) {//        [ASUserInfoManager.shared getInfo];//        complate(true, @"");//    } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {//        complate(false, msg);//    }];        [ASNetTools.shared formData_postWithPath:delAddress param:@{@"id":addressModel.Id} success:^(id _Nonnull json) {//        [ASUserInfoManager.shared getInfo];        complate(true, @"");    } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {        complate(false, msg);    }];    //    [ASNetTools.shared getWithPath:delAddress param:@{@"id":addressModel.Id} success:^(id _Nonnull json) {//        //    } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {//        //    }];}- (void)getCountryList:(void(^)(void))success  {    [ASNetTools.shared getWithPath:CountryList param:@{} success:^(id _Nonnull json) {        NSArray *list = json;        NSMutableArray *arr = [KWCountryAddressModel mj_objectArrayWithKeyValuesArray:list];        NSMutableArray *result = [NSMutableArray array];                NSMutableArray *keysArr = [[NSMutableArray alloc] initWithCapacity:1];        for (KWCountryAddressModel *m in arr) {            if (m.full_name_english == nil || m.full_name_english.isEmpty) {                continue;            }                        [keysArr addObject:m.full_name_english];            [result addObject:m];        }                NSArray *sortedArray = [keysArr sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2){            return [obj1 compare:obj2 options:NSNumericSearch];        }];                NSMutableArray *sortArray = [[NSMutableArray alloc] initWithCapacity:1];                for (int i = 0; i < sortedArray.count; i++) {            NSString *sortStr = [sortedArray objectAtIndex:i];                        for (KWCountryAddressModel *m in result) {                if ([m.full_name_english isEqualToString:sortStr]) {                    [sortArray addObject:m];                    [result removeObject:m];                    break;                }            }        }        self.countryArr = sortArray;               success();            } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {        self.countryArr = [NSMutableArray array];        success();    }];}- (void)getProvinceList:(NSString *)country_id  success:(void(^)(void))success {    self.hadGetProvince = false;    self.provinceArr = [NSMutableArray array];    if (country_id == nil || country_id.isEmpty) {        success();        return;    }    for (KWCountryAddressModel *m in self.countryArr) {        if (m.country_id == nil || m.country_id.isEmpty) {            continue;        }        if ([m.country_id isEqualToString:country_id] && m.available_regions != nil) {            self.hadGetProvince = true;            self.provinceArr = [NSMutableArray arrayWithArray:m.available_regions];            break;        }    }    success();}- (NSArray *)countryNameList {    NSMutableArray *arr = [NSMutableArray array];    for (KWCountryAddressModel* item in self.countryArr) {        [arr addObject:item.full_name_english];    }    return arr;}- (NSArray *)provinceNameList {    NSMutableArray *arr = [NSMutableArray array];    for (KWProvinceAddressModel* item in self.provinceArr) {        [arr addObject:item.name];    }    return arr;}@end
 |