ASAddressListViewController.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. //
  2. // ASAddressListViewController.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2024/5/7.
  6. //
  7. #import "ASAddressListViewController.h"
  8. #import "ASAddressViewModel.h"
  9. #import "ASMineAddressCell.h"
  10. #import "ASEditAddressViewController.h"
  11. @interface ASAddressListViewController () <UITableViewDelegate,UITableViewDataSource>
  12. @property (nonatomic, strong) UIView *bottomV;
  13. @property (nonatomic, strong) UIButton *addNewBt;
  14. @property (nonatomic, strong) UITableView *tableV;
  15. @property (nonatomic, strong) NSArray <ASAddressModel *>*addArr;
  16. @end
  17. @implementation ASAddressListViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. [self loadSubV];
  21. [self setEmptyTip:@"No Addresses"];
  22. self.titleStr = @"SHIPPING ADDRESS";
  23. __weak typeof(self) weak_self = self;
  24. self.tableV.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  25. [weak_self getData];
  26. }];
  27. }
  28. - (void)viewWillAppear:(BOOL)animated {
  29. [super viewWillAppear:animated];
  30. [self.tableV.mj_header beginRefreshing];
  31. }
  32. - (void)getData {
  33. __weak typeof(self) weakSelf = self;
  34. [ASUserInfoManager.shared baseInfoNet:^{
  35. [weakSelf.tableV.mj_header endRefreshing];
  36. weakSelf.addArr = ASUserInfoManager.shared.userInfo.addresses;
  37. if (weakSelf.addArr.count == 0) {
  38. [weakSelf showEmptyV:weakSelf.tableV];
  39. } else {
  40. [weakSelf hiddenEmpty];
  41. }
  42. [weakSelf.tableV reloadData];
  43. }];
  44. }
  45. - (void)loadSubV {
  46. [self.view addSubview:self.tableV];
  47. [self.view addSubview:self.bottomV];
  48. [self.bottomV addSubview:self.addNewBt];
  49. [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.top.equalTo(self.customNavBar.mas_bottom);
  51. make.left.right.equalTo(self.view);
  52. }];
  53. [self.bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.left.right.equalTo(self.view);
  55. make.top.equalTo(self.tableV.mas_bottom);
  56. make.height.equalTo(@65);
  57. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  58. }];
  59. [self.addNewBt mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.top.equalTo(self.bottomV).offset(10);
  61. make.left.equalTo(self.bottomV).offset(20);
  62. make.center.equalTo(self.bottomV);
  63. make.height.equalTo(@45);
  64. }];
  65. }
  66. - (UIButton *)addNewBt {
  67. if (!_addNewBt) {
  68. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  69. [bt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  70. // bt.layer.borderWidth = 1;
  71. // bt.layer.borderColor = [UIColor blackColor].CGColor;
  72. // bt.layer.cornerRadius = 4;
  73. // bt.layer.masksToBounds = true;
  74. bt.backgroundColor = UIColor.blackColor;
  75. [bt setTitle:@"+ NEW ADDRESS" forState:UIControlStateNormal];
  76. [bt addTarget:self action:@selector(addNewbtAction) forControlEvents:UIControlEventTouchUpInside];
  77. bt.titleLabel.font = [UIFont fontWithName:Rob_Medium size:18];
  78. _addNewBt = bt;
  79. }
  80. return _addNewBt;
  81. }
  82. -(UIView *)bottomV {
  83. if (!_bottomV) {
  84. UIView *v = [UIView new];
  85. v.frame = CGRectMake(0, 0, KScreenWidth, 70);
  86. v.backgroundColor = [UIColor whiteColor];
  87. _bottomV = v;
  88. }
  89. return _bottomV;
  90. }
  91. - (UITableView *)tableV {
  92. IPhoneXHeigh
  93. if (!_tableV) {
  94. UITableView *tabV = [[UITableView alloc] initWithFrame:CGRectMake(securitytop_Y, 0, KScreenWidth, security_H) style:UITableViewStylePlain];
  95. tabV.backgroundColor = [UIColor whiteColor];
  96. [tabV registerClass:[ASMineAddressCell class] forCellReuseIdentifier:@"ASMineAddressCell"];
  97. tabV.delegate = self;
  98. tabV.dataSource = self;
  99. tabV.rowHeight = UITableViewAutomaticDimension;
  100. tabV.estimatedRowHeight = 100;
  101. tabV.separatorStyle = UITableViewCellSeparatorStyleNone;
  102. _tableV = tabV;
  103. }
  104. return _tableV;
  105. }
  106. - (void)addNewbtAction {
  107. ASEditAddressViewController *vc = [ASEditAddressViewController new];
  108. ///当添加地址时,默认地址都改为美国地址
  109. ASAddressModel *model = [ASAddressModel defualtData];
  110. vc.m = model;
  111. vc.isEdit = false;
  112. vc.isCartEdit = self.isSelMode;
  113. __weak typeof(self) weakSelf = self;
  114. vc.saveSuccess = ^(ASAddressModel * _Nonnull addressM) {
  115. // if (weakSelf.selectAddressBlock) {
  116. // weakSelf.selectAddressBlock(addressM);
  117. // [weakSelf.navigationController popViewControllerAnimated:true];
  118. // }
  119. };
  120. [self.navigationController pushViewController:vc animated:true];
  121. }
  122. #pragma mark - UITableViewDelegate,UITableViewDataSource
  123. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  124. }
  125. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  126. return self.addArr.count;
  127. }
  128. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  129. ASMineAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASMineAddressCell" forIndexPath:indexPath];
  130. ASAddressModel *m = self.addArr[indexPath.row];
  131. [cell setData:m];
  132. if(self.isSelMode){
  133. cell.checkBtn.hidden = NO;
  134. if([m.Id isEqualToString:self.sel_Id]){
  135. cell.checkBtn.selected = YES;
  136. }else{
  137. cell.checkBtn.selected = NO;
  138. }
  139. [cell setCheckBack:^{
  140. if (self.selectAddressBlock) {
  141. self.selectAddressBlock(m);
  142. }
  143. [self.navigationController popViewControllerAnimated:YES];
  144. }];
  145. }else{
  146. cell.checkBtn.hidden = YES;
  147. }
  148. __weak typeof(self) weakSelf = self;
  149. [cell setEditBack:^{
  150. // 去编辑地址
  151. ASEditAddressViewController *vc = [ASEditAddressViewController new];
  152. vc.m = m;
  153. vc.isEdit = true;
  154. vc.isCartEdit = weakSelf.isSelMode;
  155. vc.saveSuccess = ^(ASAddressModel * _Nonnull addressM) {
  156. if (weakSelf.selectAddressBlock) {
  157. weakSelf.selectAddressBlock(addressM);
  158. [weakSelf.navigationController popViewControllerAnimated:true];
  159. }
  160. };
  161. [weakSelf.navigationController pushViewController:vc animated:true];
  162. }];
  163. return cell;
  164. }
  165. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  166. return 0.1;
  167. }
  168. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  169. return 0.1;
  170. }
  171. @end