| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 | ////  ASAddressListViewController.m//  Asteria////  Created by iOS on 2024/5/7.//#import "ASAddressListViewController.h"#import "ASAddressViewModel.h"#import "ASMineAddressCell.h"#import "ASEditAddressViewController.h"@interface ASAddressListViewController () <UITableViewDelegate,UITableViewDataSource>@property (nonatomic, strong) UIView *bottomV;@property (nonatomic, strong) UIButton *addNewBt;@property (nonatomic, strong) UITableView *tableV;@property (nonatomic, strong) NSArray <ASAddressModel *>*addArr;@end@implementation ASAddressListViewController- (void)viewDidLoad {    [super viewDidLoad];    [self loadSubV];        [self setEmptyTip:@"No Addresses"];        self.titleStr = @"SHIPPING ADDRESS";    __weak typeof(self) weak_self = self;    self.tableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{        [weak_self getData];    }];    }- (void)viewWillAppear:(BOOL)animated {    [super viewWillAppear:animated];    [self.tableV.mj_header beginRefreshing];    }- (void)getData {    __weak typeof(self) weakSelf = self;    [ASUserInfoManager.shared baseInfoNet:^{        [weakSelf.tableV.mj_header endRefreshing];        weakSelf.addArr = ASUserInfoManager.shared.userInfo.addresses;        if (weakSelf.addArr.count == 0) {            [weakSelf showEmptyV:weakSelf.tableV];        } else {            [weakSelf hiddenEmpty];        }        [weakSelf.tableV reloadData];    }];}- (void)loadSubV {    [self.view addSubview:self.tableV];        [self.view addSubview:self.bottomV];    [self.bottomV addSubview:self.addNewBt];    [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) {        make.top.equalTo(self.customNavBar.mas_bottom);        make.left.right.equalTo(self.view);    }];    [self.bottomV mas_makeConstraints:^(MASConstraintMaker *make) {        make.left.right.equalTo(self.view);        make.top.equalTo(self.tableV.mas_bottom);        make.height.equalTo(@65);        make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);    }];    [self.addNewBt mas_makeConstraints:^(MASConstraintMaker *make) {        make.top.equalTo(self.bottomV).offset(10);        make.left.equalTo(self.bottomV).offset(20);        make.center.equalTo(self.bottomV);        make.height.equalTo(@45);    }];    }- (UIButton *)addNewBt {    if (!_addNewBt) {        UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];        [bt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];//        bt.layer.borderWidth = 1;//        bt.layer.borderColor = [UIColor blackColor].CGColor;//        bt.layer.cornerRadius = 4;//        bt.layer.masksToBounds = true;        bt.backgroundColor = UIColor.blackColor;        [bt setTitle:@"+ NEW ADDRESS" forState:UIControlStateNormal];        [bt addTarget:self action:@selector(addNewbtAction) forControlEvents:UIControlEventTouchUpInside];        bt.titleLabel.font = [UIFont fontWithName:Rob_Medium size:18];        _addNewBt = bt;    }    return _addNewBt;}-(UIView *)bottomV {    if (!_bottomV) {        UIView *v = [UIView new];        v.frame = CGRectMake(0, 0, KScreenWidth, 70);        v.backgroundColor = [UIColor whiteColor];        _bottomV = v;    }    return _bottomV;}- (UITableView *)tableV {    IPhoneXHeigh    if (!_tableV) {        UITableView *tabV = [[UITableView alloc] initWithFrame:CGRectMake(securitytop_Y, 0, KScreenWidth, security_H) style:UITableViewStylePlain];        tabV.backgroundColor = [UIColor whiteColor];        [tabV registerClass:[ASMineAddressCell class] forCellReuseIdentifier:@"ASMineAddressCell"];        tabV.delegate = self;        tabV.dataSource = self;        tabV.rowHeight = UITableViewAutomaticDimension;        tabV.estimatedRowHeight = 100;        tabV.separatorStyle = UITableViewCellSeparatorStyleNone;        _tableV = tabV;    }    return _tableV;}- (void)addNewbtAction {    ASEditAddressViewController *vc = [ASEditAddressViewController new];    ///当添加地址时,默认地址都改为美国地址    ASAddressModel *model = [ASAddressModel defualtData];    vc.m =  model;    vc.isEdit = false;    vc.isCartEdit = self.isSelMode;    __weak typeof(self) weakSelf = self;    vc.saveSuccess = ^(ASAddressModel * _Nonnull addressM) {//        if (weakSelf.selectAddressBlock) {//            weakSelf.selectAddressBlock(addressM);//            [weakSelf.navigationController popViewControllerAnimated:true];//        }    };    [self.navigationController pushViewController:vc animated:true];}#pragma mark - UITableViewDelegate,UITableViewDataSource- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {    }- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {        return self.addArr.count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    ASMineAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASMineAddressCell" forIndexPath:indexPath];    ASAddressModel *m = self.addArr[indexPath.row];    [cell setData:m];    if(self.isSelMode){        cell.checkBtn.hidden = NO;          if([m.Id isEqualToString:self.sel_Id]){            cell.checkBtn.selected = YES;        }else{            cell.checkBtn.selected = NO;        }        [cell setCheckBack:^{            if (self.selectAddressBlock) {                self.selectAddressBlock(m);            }            [self.navigationController popViewControllerAnimated:YES];        }];            }else{        cell.checkBtn.hidden = YES;    }    __weak typeof(self) weakSelf = self;    [cell setEditBack:^{        // 去编辑地址        ASEditAddressViewController *vc = [ASEditAddressViewController new];        vc.m = m;        vc.isEdit = true;        vc.isCartEdit = weakSelf.isSelMode;        vc.saveSuccess = ^(ASAddressModel * _Nonnull addressM) {            if (weakSelf.selectAddressBlock) {                weakSelf.selectAddressBlock(addressM);                [weakSelf.navigationController popViewControllerAnimated:true];            }        };        [weakSelf.navigationController pushViewController:vc animated:true];    }];    return  cell;}-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{    return 0.1;}-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{    return 0.1;}@end
 |