ASSettingViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. [self.navigationController pushViewController:vc animated:true];
  134. break;
  135. }
  136. case 4: {
  137. [self logout];
  138. break;
  139. }
  140. case 5: {
  141. [self showDeleteAccountAlert];
  142. break;
  143. }
  144. default:
  145. break;
  146. }
  147. }
  148. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  149. return self.titleArr.count;
  150. }
  151. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  152. ASSettingListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASSettingListCell" forIndexPath:indexPath];
  153. [cell setTitle:self.titleArr[indexPath.row] points:self.detailArr[indexPath.row] enable:true];
  154. if (((indexPath.row == _titleArr.count - 1) || (indexPath.row == _titleArr.count - 2))) {
  155. cell.moreIcon.hidden = true;
  156. } else {
  157. cell.moreIcon.hidden = false;
  158. }
  159. cell.switchBtn.hidden = !(indexPath.row == 2);
  160. if (indexPath.row == 2) {
  161. BOOL isSub = ASUserInfoManager.shared.userInfo.is_subscribed;
  162. [cell.switchBtn setIsOpen:isSub animate:false];
  163. __weak typeof(self) weakSelf = self;
  164. [cell.switchBtn setClickBack:^{
  165. [weakSelf configSubscrib:!isSub];
  166. }];
  167. } else {
  168. cell.switchBtn.clickBack = nil;
  169. }
  170. return cell;
  171. }
  172. // MARK: - 退出登录
  173. - (void)logout {
  174. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  175. __weak typeof(self) weak_self = self;
  176. [ASNetTools.shared postWithPath:postLogOut param:@{} success:^(id _Nonnull json) {
  177. [MBProgressHUD hideHUDForView:weak_self.view animated:true];
  178. [weak_self popAndToLogin];
  179. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  180. [MBProgressHUD hideHUDForView:weak_self.view animated:true];
  181. NSLog(@"err:%@",code);
  182. [weak_self.view makeToast:@"Oh No, Bad Net"];
  183. }];
  184. }
  185. - (void)configSubscrib:(BOOL)is_subscribed {
  186. NSDictionary *param = @{
  187. @"customer":@{
  188. @"email": ASUserInfoManager.shared.userInfo.email,
  189. @"firstname": ASUserInfoManager.shared.userInfo.firstname,
  190. @"lastname": ASUserInfoManager.shared.userInfo.lastname,
  191. @"extension_attributes":@{
  192. @"is_subscribed":[NSNumber numberWithBool:is_subscribed]
  193. }
  194. }
  195. };
  196. __weak typeof(self) weakSelf = self;
  197. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  198. [ASNetTools.shared putWithPath:putUserInfo param:param success:^(id _Nonnull json) {
  199. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  200. ASUserInfoManager.shared.userInfo.is_subscribed = is_subscribed;
  201. [weakSelf.tableV reloadData];
  202. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  203. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  204. [weakSelf.view makeToast:@"Bad Net"];
  205. [weakSelf.tableV reloadData];
  206. }];
  207. }
  208. // MARK: - 注销账号
  209. - (void)showDeleteAccountAlert {
  210. __weak typeof(self) weakSelf = self;
  211. 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:^{
  212. } cancelBlock:^{
  213. [weakSelf deleteAccount:@""];
  214. // [weakSelf showDeletedReasonInput];
  215. }];
  216. window.vc.titleLb.text = @"Delete Account?";
  217. [window.vc.sureBt setTitle:@"No" forState:UIControlStateNormal];
  218. [window.vc.cancelBt setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  219. NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:@"Yes"];
  220. [attStr setAttributes:@{
  221. NSFontAttributeName:[UIFont fontWithName:Rob_Regular size:16],
  222. NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle],
  223. NSUnderlineColorAttributeName:[UIColor colorWithHexString:@"#000000"],
  224. NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#000000"]
  225. } range:NSMakeRange(0, attStr.length)];
  226. [window.vc.cancelBt setAttributedTitle:attStr forState:UIControlStateNormal];
  227. [window.vc.cancelBt mas_remakeConstraints:^(MASConstraintMaker *make) {
  228. make.bottom.equalTo(window.vc.sureBt);
  229. make.height.equalTo(@35);
  230. make.right.equalTo(window.vc.sureBt.mas_left).offset(-20);
  231. make.left.greaterThanOrEqualTo(window.vc.contentV).offset(20);
  232. }];
  233. }
  234. //- (void)showDeletedReasonInput {
  235. // __weak typeof(self) weakSelf = self;
  236. // [APHomeActiveWindow show:@"Deleted Account" des:@"Dear user, could you tell me the reason for leaving?" sureBlock:^(NSString *reason) {
  237. // NSString *str = @"";
  238. // if (!reason.isEmpty) {
  239. // str = reason;
  240. // }
  241. // [weakSelf deleteAccount:str];
  242. // } cancelBlock:^{
  243. // }];
  244. //}
  245. - (void)deleteAccount:(NSString *)msg {
  246. [MBProgressHUD showHUDAddedTo:self.view animated:true];
  247. __weak typeof(self) weakSelf = self;
  248. [ASNetTools.shared delWithPath:deleteUser param:@{} success:^(id _Nonnull json) {
  249. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  250. [weakSelf popAndToLogin];
  251. } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) {
  252. [MBProgressHUD hideHUDForView:weakSelf.view animated:true];
  253. [weakSelf.view makeToast:@"Oh No, Bad Net"];
  254. }];
  255. }
  256. @end