ASSettingViewController.m 10 KB

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