ASAddressListViewController.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. [self.navigationController pushViewController:vc animated:true];
  113. }
  114. #pragma mark - UITableViewDelegate,UITableViewDataSource
  115. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  116. }
  117. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  118. return self.addArr.count;
  119. }
  120. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  121. ASMineAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASMineAddressCell" forIndexPath:indexPath];
  122. ASAddressModel *m = self.addArr[indexPath.row];
  123. [cell setData:m];
  124. if(self.isSelMode){
  125. cell.checkBtn.hidden = NO;
  126. if([m.Id isEqualToString:self.sel_Id]){
  127. cell.checkBtn.selected = YES;
  128. }else{
  129. cell.checkBtn.selected = NO;
  130. }
  131. [cell setCheckBack:^{
  132. if (self.selectAddressBlock) {
  133. self.selectAddressBlock(m);
  134. }
  135. [self.navigationController popViewControllerAnimated:YES];
  136. }];
  137. }else{
  138. cell.checkBtn.hidden = YES;
  139. }
  140. @weakify(self)
  141. [cell setEditBack:^{
  142. // @strongify(self)
  143. // // 去编辑地址
  144. // KWEditAddressViewController *vc = [KWEditAddressViewController new];
  145. // vc.m = m;
  146. // vc.isEdit = true;
  147. // if(self.addressType == AddressTypeShippingAddress){
  148. // vc.editAddressType = EditAddressTypeShippingAddress;
  149. // vc.tempListC = self;
  150. // }else{
  151. // vc.editAddressType = EditAddressTypeSettingAddress;
  152. // }
  153. // [self.navigationController pushViewController:vc animated:true];
  154. }];
  155. return cell;
  156. }
  157. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  158. return 0.1;
  159. }
  160. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  161. return 0.1;
  162. }
  163. @end