// // ASEditAddressViewController.m // Asteria // // Created by iOS on 2024/5/8. // #import "ASEditAddressViewController.h" #import "ASAddressViewModel.h" #import "InTableScrollView.h" #import "KWTextField.h" #import @interface ASEditAddressViewController () @property (nonatomic, strong) ASAddressViewModel *vm; @property (nonatomic, strong) InTableScrollView *scrollV; @property (nonatomic, strong) UIStackView *totalStackV; @property (nonatomic, strong) NSMutableArray *tfArr; @property (nonatomic, strong) NSMutableArray *errLbArr; @property (nonatomic, strong) NSArray *placeHoldArr; @property (nonatomic, strong) NSArray *errDesArr; @property (nonatomic, strong) UIButton *billTypeBt; @property (nonatomic, strong) UIButton *shipTypeBt; @property (nonatomic, strong) UIButton *saveBt; @property (nonatomic, strong) UIButton *deletBt; @end @implementation ASEditAddressViewController -(ASAddressViewModel *)vm { if (!_vm) { _vm = [ASAddressViewModel new]; } return _vm; } - (instancetype)init { self = [super init]; if (self) { __weak typeof(self) weakSelf = self; [self.vm getCountryList:^{ [weakSelf.vm getProvinceList:weakSelf.m.country_id success:^{}]; }]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; [self setUI]; if (self.isEdit) { [self setTitle:@"EDIT ADDRESS"]; [self.vm getProvinceList:self.m.country_id success:^{}]; [self setEditDefualtData]; } else { if (!self.m) { self.m = [ASAddressModel defualtData]; } else { [self.vm getProvinceList:self.m.country_id success:^{}]; [self setEditDefualtData]; } [self setTitle: @"NEW ADDRESS"]; _deletBt.hidden = true; } if(self.isCartEdit){ [self.saveBt setTitle:@"SAVE AND APPLY" forState:UIControlStateNormal]; } } #pragma mark - **************** EditAddressTypeShippingNewAddress **************** - (void)xxx_tengteng_confignavBarBar{ self.navigationController.navigationBar.hidden = YES; UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [closeBtn setImage:[UIImage imageNamed:@"login_close_black"] forState:UIControlStateNormal]; [closeBtn addTarget:self action:@selector(xxx_closeVC) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:closeBtn]; NSInteger top = IPHONEX ? 44 : 20; closeBtn.frame = CGRectMake((KScreenWidth -44)/2, top, 44, 44); IPhoneXHeigh [self.scrollV mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.view); make.top.mas_equalTo(securitytop_Y +10); make.height.mas_equalTo(security_H -10); }]; } #pragma mark - **************** handle 触发事件**************** -(void)xxx_closeVC{ [self dismissViewControllerAnimated:YES completion:nil]; } - (void)setEditDefualtData { NSArray *arr = @[STR(self.m.firstname), STR(self.m.lastname), STR(self.m.street.firstObject), STR(self.m.postcode), STR(self.m.city), STR(self.m.country), STR(self.m.region.region), STR(self.m.telephone) ]; for (int i= 0 ; i i) { self.tfArr[i].text = arr[i]; } } _billTypeBt.selected = false; _shipTypeBt.selected = false; switch (self.m.addressType) { case 1: [_billTypeBt setSelected:true]; break; case 2: [_shipTypeBt setSelected:true]; break; case 3: [_shipTypeBt setSelected:true]; [_billTypeBt setSelected:true]; default: break; } } - (void)setData { self.placeHoldArr = @[@"* FIRST NAME", @"* LAST NAME", @"* ADDRESS (NO ACCEPTING P0.BOX)", @"* ZIP/POSTAL CODE", @"* CITY", @"* COUNTY", @"* STATE/PROVINCE", @"* TELEPHONE"]; self.errDesArr = @[@"*This Is Mandatory", @"*This Is Mandatory", @"*This Is Mandatory", @"*This Is Mandatory", @"*This Is Mandatory", @"*This Is Mandatory", @"*This Is Mandatory", @"*This Is Mandatory"]; } - (void)setUI { self.tfArr = [NSMutableArray array]; self.errLbArr = [NSMutableArray array]; [self setData]; [self.view addSubview:self.scrollV]; IPhoneXHeigh [self.scrollV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.view); make.top.mas_equalTo(securitytop_Y); // make.top.equalTo(self.customNavBar.mas_bottom); make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom); }]; UIStackView *tStackV = [[UIStackView alloc] init]; tStackV.axis = UILayoutConstraintAxisVertical; tStackV.alignment = UIStackViewAlignmentFill; tStackV.distribution = UIStackViewDistributionFill; tStackV.spacing = 16; self.totalStackV = tStackV; UIStackView *topStackV = [[UIStackView alloc] init]; topStackV.axis = UILayoutConstraintAxisHorizontal; topStackV.alignment = UIStackViewAlignmentFill; topStackV.distribution = UIStackViewDistributionFillEqually; topStackV.spacing = 20; [self.totalStackV addArrangedSubview:topStackV]; [self.tfArr removeAllObjects]; [self.errLbArr removeAllObjects]; for (int i = 0; i 0) { [self showProvincePick]; } else { return true; } } else { [self.view makeToast:@"Please Select Country First"]; } } return false; } - (void)showProvincePick { NSInteger index = 0; for (int i=0;i