ASSettingViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. //
  2. // ASSettingViewController.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/7/5.
  6. //
  7. #import "ASSettingViewController.h"
  8. #import "ASSettingListCell.h"
  9. #import "ASInfomationSetController.h"
  10. #import "ASHelpListViewController.h"
  11. #import "ASAddressListViewController.h"
  12. @interface ASSettingViewController () <UITableViewDelegate,UITableViewDataSource>
  13. @property (nonatomic, strong) UIView *bottomV;
  14. @property (nonatomic, strong) UILabel *versionLb;
  15. @property (nonatomic, strong) UITableView *tableV;
  16. @property (nonatomic, strong) NSArray *titleArr;
  17. @property (nonatomic, strong) NSArray *detailArr;
  18. @end
  19. @implementation ASSettingViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. self.titleStr = @"Setting";
  23. [self setNavRightSearch:^{
  24. }];
  25. self.statusBgV.backgroundColor = Col_FFF;
  26. self.customNavBar.backgroundColor = Col_FFF;
  27. [self loadSubVs];
  28. }
  29. - (void)viewWillAppear:(BOOL)animated {
  30. [super viewWillAppear:animated];
  31. [self configData];
  32. }
  33. - (void)configData {
  34. self.titleArr = @[@"INFORMATION",
  35. @"SHIPPING ADDRESS",
  36. @"SUBSCRIBE",
  37. // @"CUSTOMER SERVICE",
  38. @"HELP & SUPPORT",
  39. @"LOG OUT",
  40. @"DELETE ACCOUNT"];
  41. /*
  42. KWLoginedManager.shareInstance.isLogined ? @[@"Information",
  43. @"Shipping Address",
  44. // @"Account Settings",
  45. @"Subscribe",
  46. @"Customer Service",
  47. @"Help & Support",
  48. @"Log Out", @"Delete Account"] : @[@"Infomation",
  49. @"Shipping Address",
  50. // @"Account Settings",
  51. @"Subscribe",
  52. @"Customer Service",
  53. @"Help & Support"];
  54. */
  55. self.detailArr = @[@"", @"",@"",@"",@"",@"",@"",@""];
  56. [self.tableV reloadData];
  57. }
  58. - (void)loadSubVs {
  59. [self.view addSubview:self.tableV];
  60. [self.bottomV addSubview:self.versionLb];
  61. [self.versionLb mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.top.equalTo(self.bottomV).offset(66);
  63. make.left.equalTo(self.bottomV).offset(20);
  64. make.centerX.equalTo(self.bottomV);
  65. make.height.equalTo(@20);
  66. }];
  67. [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.top.equalTo(self.customNavBar.mas_bottom);
  69. make.left.right.equalTo(self.view);
  70. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  71. }];
  72. }
  73. - (UILabel *)versionLb {
  74. if (!_versionLb) {
  75. UILabel *lb = [UILabel new];
  76. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  77. NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
  78. lb.text = [NSString stringWithFormat:@"V%@",app_Version];
  79. lb.textColor = Col_000;
  80. lb.textAlignment = NSTextAlignmentCenter;
  81. lb.font = [UIFont fontWithName:Rob_Regular size:12];
  82. lb.numberOfLines = 1;
  83. _versionLb = lb;
  84. }
  85. return _versionLb;
  86. }
  87. -(UIView *)bottomV {
  88. if (!_bottomV) {
  89. UIView *v = [UIView new];
  90. v.frame = CGRectMake(0, 0, KScreenWidth, 100);
  91. v.backgroundColor = _F8F8F8;
  92. _bottomV = v;
  93. }
  94. return _bottomV;
  95. }
  96. - (UITableView *)tableV {
  97. if (!_tableV) {
  98. UITableView *tabV = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  99. tabV.backgroundColor = _F8F8F8;
  100. [tabV registerClass:[ASSettingListCell class] forCellReuseIdentifier:@"ASSettingListCell"];
  101. tabV.delegate = self;
  102. tabV.dataSource = self;
  103. tabV.rowHeight = UITableViewAutomaticDimension;
  104. tabV.estimatedRowHeight = 100;
  105. tabV.separatorStyle = UITableViewCellSeparatorStyleNone;
  106. UIView *v = [UIView new];
  107. v.frame = CGRectMake(0, 0, KScreenWidth, 10);
  108. v.backgroundColor = _F8F8F8;
  109. tabV.tableHeaderView = v;
  110. tabV.tableFooterView = self.bottomV;
  111. _tableV = tabV;
  112. }
  113. return _tableV;
  114. }
  115. #pragma mark - UITableViewDelegate,UITableViewDataSource
  116. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  117. switch (indexPath.row) {
  118. case 0:{
  119. ASInfomationSetController *vc = [ASInfomationSetController new];
  120. [self.navigationController pushViewController:vc animated:true];
  121. break;
  122. }
  123. case 1:{
  124. ASAddressListViewController *vc = [ASAddressListViewController new];
  125. [self.navigationController pushViewController:vc animated:true];
  126. break;
  127. }
  128. case 3:{
  129. ASHelpListViewController *vc = [ASHelpListViewController new];
  130. [self.navigationController pushViewController:vc animated:true];
  131. break;
  132. }
  133. case 4: {
  134. [self logout];
  135. break;
  136. }
  137. case 5: {
  138. [self showDeleteAccountAlert];
  139. break;
  140. }
  141. default:
  142. break;
  143. }
  144. }
  145. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  146. return self.titleArr.count;
  147. }
  148. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  149. ASSettingListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASSettingListCell" forIndexPath:indexPath];
  150. [cell setTitle:self.titleArr[indexPath.row] points:self.detailArr[indexPath.row] enable:true];
  151. if (((indexPath.row == _titleArr.count - 1) || (indexPath.row == _titleArr.count - 2))) {
  152. cell.moreIcon.hidden = true;
  153. } else {
  154. cell.moreIcon.hidden = false;
  155. }
  156. cell.switchBtn.hidden = !(indexPath.row == 2);
  157. if (indexPath.row == 2) {
  158. BOOL isSub = ASUserInfoManager.shared.userInfo.is_subscribed;
  159. [cell.switchBtn setIsOpen:isSub animate:false];
  160. __weak typeof(self) weakSelf = self;
  161. [cell.switchBtn setClickBack:^{
  162. [weakSelf configSubscrib:!isSub];
  163. }];
  164. } else {
  165. cell.switchBtn.clickBack = nil;
  166. }
  167. return cell;
  168. }
  169. // MARK: - 退出登录
  170. - (void)logout {
  171. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  172. __weak typeof(self) weak_self = self;
  173. [ASNetTools.shared postWithPath:postLogOut param:@{} success:^(id _Nonnull json) {
  174. [MBProgressHUD hideHUDForView:weak_self.view animated:true];
  175. [weak_self popAndToLogin];
  176. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  177. [MBProgressHUD hideHUDForView:weak_self.view animated:true];
  178. NSLog(@"err:%@",code);
  179. [weak_self.view makeToast:@"Oh No, Bad Net"];
  180. }];
  181. }
  182. - (void)configSubscrib:(BOOL)is_subscribed {
  183. NSDictionary *param = @{
  184. @"customer":@{
  185. @"email": ASUserInfoManager.shared.userInfo.email,
  186. @"firstname": ASUserInfoManager.shared.userInfo.firstname,
  187. @"lastname": ASUserInfoManager.shared.userInfo.lastname,
  188. @"extension_attributes":@{
  189. @"is_subscribed":[NSNumber numberWithBool:is_subscribed]
  190. }
  191. }
  192. };
  193. __weak typeof(self) weakSelf = self;
  194. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  195. [ASNetTools.shared putWithPath:putUserInfo param:param success:^(id _Nonnull json) {
  196. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  197. ASUserInfoManager.shared.userInfo.is_subscribed = is_subscribed;
  198. [weakSelf.tableV reloadData];
  199. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  200. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  201. [weakSelf.view makeToast:@"Bad Net"];
  202. [weakSelf.tableV reloadData];
  203. }];
  204. }
  205. // MARK: - 注销账号
  206. - (void)showDeleteAccountAlert {
  207. __weak typeof(self) weakSelf = self;
  208. ASCustomWindow *window = [ASCustomWindow show:@"Are You Sure To Delete Your Account?\n(This action can't be undone. All the data of your account will be delete)" isMast:false upBlock:^{
  209. } cancelBlock:^{
  210. [weakSelf deleteAccount:@""];
  211. // [weakSelf showDeletedReasonInput];
  212. }];
  213. window.vc.titleLb.text = @"Delete Account?";
  214. [window.vc.sureBt setTitle:@"No" forState:UIControlStateNormal];
  215. [window.vc.cancelBt setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  216. NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:@"Yes"];
  217. [attStr setAttributes:@{
  218. NSFontAttributeName:[UIFont fontWithName:Rob_Regular size:16],
  219. NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle],
  220. NSUnderlineColorAttributeName:[UIColor colorWithHexString:@"#000000"],
  221. NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#000000"]
  222. } range:NSMakeRange(0, attStr.length)];
  223. [window.vc.cancelBt setAttributedTitle:attStr forState:UIControlStateNormal];
  224. [window.vc.cancelBt mas_remakeConstraints:^(MASConstraintMaker *make) {
  225. make.bottom.equalTo(window.vc.sureBt);
  226. make.height.equalTo(@35);
  227. make.right.equalTo(window.vc.sureBt.mas_left).offset(-20);
  228. make.left.greaterThanOrEqualTo(window.vc.contentV).offset(20);
  229. }];
  230. }
  231. //- (void)showDeletedReasonInput {
  232. // __weak typeof(self) weakSelf = self;
  233. // [APHomeActiveWindow show:@"Deleted Account" des:@"Dear user, could you tell me the reason for leaving?" sureBlock:^(NSString *reason) {
  234. // NSString *str = @"";
  235. // if (!reason.isEmpty) {
  236. // str = reason;
  237. // }
  238. // [weakSelf deleteAccount:str];
  239. // } cancelBlock:^{
  240. // }];
  241. //}
  242. - (void)deleteAccount:(NSString *)msg {
  243. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  244. __weak typeof(self) weakSelf = self;
  245. [ASNetTools.shared delWithPath:deleteUser param:@{} success:^(id _Nonnull json) {
  246. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  247. [weakSelf popAndToLogin];
  248. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  249. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  250. [weakSelf.view makeToast:@"Oh No, Bad Net"];
  251. }];
  252. }
  253. @end