SPSBMailAddressListViewController.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. //
  2. // SPSBMailAddressListViewController.m
  3. // 我的社保
  4. //
  5. // Created by jiaxian_he on 2021/5/13.
  6. //
  7. #import "SPSBMailAddressListViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "UIViewController+SPSBNetworkManager.h"
  10. #import "SPSBMailingAddressListModel.h"
  11. #import "UIViewController+SPSBDefault.h"
  12. #import <CALayer+JXHShadow.h>
  13. #import "SPSBConfirmAlertViewController.h"
  14. #import "SPSBEditMailAddressViewController.h"
  15. @interface SPSBMailAddressListViewController () {
  16. UIView *_addressView;
  17. UIView *_noDataView;
  18. SPSBMailingAddressListModel *_data;
  19. }
  20. @end
  21. @implementation SPSBMailAddressListViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. [self setupUI];
  25. [self getData];
  26. }
  27. #pragma mark - Action
  28. - (void)addAddressAction {
  29. SPSBEditMailAddressViewController *vc = SPSBEditMailAddressViewController.new;
  30. vc.spsb_editType = SPSBEditMailAddressTypeAdd;
  31. vc.spsb_data = [SPSBMailingAddressListModel getModelWithDictionary:@{}];
  32. @weakify(self)
  33. vc.spsb_completion = ^(SPSBMailingAddressListModel * _Nonnull data) {
  34. @strongify(self)
  35. self->_data = data;
  36. [self reloadView];
  37. };
  38. [self.navigationController pushViewController:vc animated:true];
  39. }
  40. - (void)deleteAddress {
  41. SPSBConfirmAlertViewController *vc = [SPSBConfirmAlertViewController alertWithTitle:@"删除后将无法恢复" content:@"是否删除该信息"];
  42. [vc setCancelButtonTitle:nil titleColor:nil action:^{
  43. }];
  44. @weakify(self)
  45. [vc setConfirmButtonTitle:@"删除" titleColor:nil action:^{
  46. @strongify(self)
  47. [self deleteAction];
  48. }];
  49. [self presentViewController:vc animated:false completion:nil];
  50. }
  51. - (void)editAddress {
  52. SPSBEditMailAddressViewController *vc = SPSBEditMailAddressViewController.new;
  53. vc.spsb_editType = SPSBEditMailAddressTypeChange;
  54. vc.spsb_data = [_data copy];
  55. @weakify(self)
  56. vc.spsb_completion = ^(SPSBMailingAddressListModel * _Nonnull data) {
  57. @strongify(self)
  58. self->_data = data;
  59. [self reloadView];
  60. };
  61. [self.navigationController pushViewController:vc animated:true];
  62. }
  63. #pragma mark - NetworkAction
  64. - (void)getData {
  65. @weakify(self)
  66. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在加载" isLogin:true url:spsb_appUrl(SPSBUrlGetMailingAddress) urlParameters:nil parameters:nil success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  67. @strongify(self)
  68. [self getDataSuccess:data];
  69. return @"";
  70. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  71. @strongify(self)
  72. [self getDataFailure:error];
  73. return @"加载失败";
  74. }];
  75. }
  76. - (void)getDataSuccess:(id)data {
  77. _data = [SPSBMailingAddressListModel getModelWithDictionary:data[@"data"]];
  78. if (_data.spsb_u_name.length > 0) {
  79. [self addAddressView];
  80. } else {
  81. [self addNoDataView];
  82. }
  83. }
  84. - (void)getDataFailure:(NSError *)error {
  85. self.view.backgroundColor = spsb_FFFFFF_color(1.f);
  86. @weakify(self)
  87. [self setDefaultViewWithError:error image:nil action:^{
  88. @strongify(self)
  89. self.view.backgroundColor = spsb_F5F5F5_color();
  90. [self removeDefaultView];
  91. [self getData];
  92. }];
  93. }
  94. - (void)deleteAction {
  95. @weakify(self)
  96. [self networkUseMethod:SPSBNetworkMethodPOST loadingTips:@"正在删除" isLogin:true url:spsb_appUrl(SPSBUrlDeleteMailingAddress) urlParameters:nil parameters:nil success:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  97. @strongify(self)
  98. [self -> _addressView removeFromSuperview];
  99. [self addNoDataView];
  100. return @"";
  101. } failure:^NSString * _Nullable(NSError * _Nonnull error, id _Nullable data) {
  102. @strongify(self)
  103. [self getDataFailure:error];
  104. return @"删除失败";
  105. }];
  106. }
  107. #pragma mark - UI
  108. - (void)setupUI {
  109. self.title = @"邮寄信息";
  110. self.view.backgroundColor = spsb_F5F5F5_color();
  111. }
  112. - (void)reloadView {
  113. [_addressView removeFromSuperview];
  114. [_noDataView removeFromSuperview];
  115. [self addAddressView];
  116. }
  117. - (void)addAddressView {
  118. _addressView = [self createBgView];
  119. [self.view addSubview: _addressView];
  120. [_addressView makeConstraints:^(JXHConstraintMaker *make) {
  121. make.top.equalTo(self.view.safetop).offset(12);
  122. make.leading.equalTo(10);
  123. make.trailing.equalTo(-10);
  124. }];
  125. UILabel *firstLabel = [UILabel convenienceWithFont:spsb_semiboldFont(16) text:[NSString stringWithFormat:@"%@ %@", _data.spsb_u_name, _data.spsb_phone] textColor:spsb_333333_color()];
  126. [_addressView addSubview:firstLabel];
  127. [firstLabel makeConstraints:^(JXHConstraintMaker *make) {
  128. make.top.equalTo(21);
  129. make.leading.equalTo(20);
  130. }];
  131. NSString *address = [NSString stringWithFormat:@"%@%@", _data.spsb_area, _data.spsb_address];
  132. UILabel *secondLabel = [UILabel convenienceWithFont:spsb_font(14) textColor:spsb_666666_color() limitWidth:jxh_screenWidth() - 60];
  133. [secondLabel setAttributedStringWithText:address lineSpacing:6];
  134. [_addressView addSubview:secondLabel];
  135. [secondLabel makeConstraints:^(JXHConstraintMaker *make) {
  136. make.top.equalTo(firstLabel.bottom).offset(15);
  137. make.leading.equalTo(20);
  138. make.trailing.equalTo(-20);
  139. }];
  140. UIView *line = [_addressView createLine];
  141. [line makeConstraints:^(JXHConstraintMaker *make) {
  142. make.top.equalTo(secondLabel.bottom).offset(18);
  143. make.leading.equalTo(20);
  144. make.trailing.equalTo(0);
  145. make.height.equalTo(jxh_onePixe());
  146. }];
  147. UIView *buttonView = [[UIView alloc] init];
  148. buttonView.backgroundColor = [UIColor whiteColor];
  149. [_addressView addSubview:buttonView];
  150. [buttonView makeConstraints:^(JXHConstraintMaker *make) {
  151. make.top.equalTo(line.bottom);
  152. make.leading.and.trailing.and.bottom.equalTo(0);
  153. make.height.equalTo(44);
  154. }];
  155. UIButton *deleteButton = [UIButton convenienceWithTarget:self action:@selector(deleteAddress)];
  156. [deleteButton setImage:jxh_getImage(purchasers_delete) state:JXHButtonControlStateNormal];
  157. [buttonView addSubview:deleteButton];
  158. [deleteButton makeConstraints:^(JXHConstraintMaker *make) {
  159. make.trailing.equalTo(-6);
  160. make.top.and.bottom.equalTo(0);
  161. make.width.equalTo(44);
  162. }];
  163. UIButton *editButton = [UIButton convenienceWithTarget:self action:@selector(editAddress)];
  164. [editButton setImage:jxh_getImage(purchasers_edit) state:JXHButtonControlStateNormal];
  165. [buttonView addSubview:editButton];
  166. [editButton makeConstraints:^(JXHConstraintMaker *make) {
  167. make.trailing.equalTo(deleteButton.leading).offset(-10);
  168. make.top.and.bottom.equalTo(0);
  169. make.width.equalTo(44);
  170. }];
  171. }
  172. - (void)addNoDataView {
  173. _noDataView = [self createBgView];
  174. [self.view addSubview:_noDataView];
  175. [_noDataView makeConstraints:^(JXHConstraintMaker *make) {
  176. make.top.equalTo(self.view.safetop).offset(12);
  177. make.leading.equalTo(10);
  178. make.trailing.equalTo(-10);
  179. make.height.equalTo(130);
  180. }];
  181. UIButton *button = [UIButton convenienceWithTarget:self action:@selector(addAddressAction)];
  182. [_noDataView addSubview:button];
  183. [button makeConstraints:^(JXHConstraintMaker *make) {
  184. make.edges.equalTo(self->_noDataView);
  185. }];
  186. UIView *contentView = UIView.new;
  187. contentView.userInteractionEnabled = false;
  188. contentView.backgroundColor = spsb_FFFFFF_color(1.f);
  189. [button addSubview:contentView];
  190. [contentView makeConstraints:^(JXHConstraintMaker *make) {
  191. make.center.equalTo(button);
  192. }];
  193. UIImageView *icon = [[UIImageView alloc] initWithImage:jxh_getImage(purchasers_add)];
  194. [contentView addSubview:icon];
  195. [icon makeConstraints:^(JXHConstraintMaker *make) {
  196. make.leading.equalTo(0);
  197. make.top.greaterThanOrEqualTo(0);
  198. make.bottom.lessThanOrEqualTo(0);
  199. make.centerY.equalTo(contentView);
  200. }];
  201. UILabel *label = [UILabel convenienceWithFont:spsb_font(15) text:@"添加邮寄地址" textColor:spsb_3296FB_color()];
  202. [contentView addSubview:label];
  203. [label makeConstraints:^(JXHConstraintMaker *make) {
  204. make.leading.equalTo(icon.trailing).offset(7);
  205. make.trailing.equalTo(0);
  206. make.top.greaterThanOrEqualTo(0);
  207. make.bottom.lessThanOrEqualTo(0);
  208. make.centerY.equalTo(contentView);
  209. }];
  210. }
  211. - (UIView *)createBgView {
  212. UIView *view = UIView.new;
  213. view.backgroundColor = spsb_FFFFFF_color(1.f);
  214. [view.layer setShadowWithOffset:(CGSize){0, 2} alpha:0.03 blur:4 color:spsb_000000_color(1.f) cornerRadius:0];
  215. return view;
  216. }
  217. @end