ASSettingViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. //@property (nonatomic, strong) KWLoginedUserModel *userInfo;
  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. // [self configData];
  29. }
  30. - (void)viewWillAppear:(BOOL)animated {
  31. [super viewWillAppear:animated];
  32. // self.userInfo = [KWLoginedManager.shareInstance getCurrentLoginedUser];
  33. [self configData];
  34. // @weakify(self);
  35. // [KWLoginedManager.shareInstance getUserInfo:^(bool flag) {
  36. // weak_self.userInfo = [KWLoginedManager.shareInstance getCurrentLoginedUser];
  37. // [weak_self configData];
  38. // }];
  39. }
  40. - (void)configData {
  41. self.titleArr = @[@"INFORMATION",
  42. @"SHIPPING ADDRESS",
  43. @"SUBSCRIBE",
  44. @"CUSTOMER SERVICE",
  45. @"HELP & SUPPORT",
  46. @"LOG OUT",
  47. @"DELETE ACCOUNT"];
  48. /*
  49. KWLoginedManager.shareInstance.isLogined ? @[@"Information",
  50. @"Shipping Address",
  51. // @"Account Settings",
  52. @"Subscribe",
  53. @"Customer Service",
  54. @"Help & Support",
  55. @"Log Out", @"Delete Account"] : @[@"Infomation",
  56. @"Shipping Address",
  57. // @"Account Settings",
  58. @"Subscribe",
  59. @"Customer Service",
  60. @"Help & Support"];
  61. */
  62. self.detailArr = @[@"", @"",@"",@"",@"",@"",@"",@""];
  63. [self.tableV reloadData];
  64. }
  65. - (void)loadSubVs {
  66. [self.view addSubview:self.tableV];
  67. [self.bottomV addSubview:self.versionLb];
  68. [self.versionLb mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.top.equalTo(self.bottomV).offset(66);
  70. make.left.equalTo(self.bottomV).offset(20);
  71. make.centerX.equalTo(self.bottomV);
  72. make.height.equalTo(@20);
  73. }];
  74. [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.top.equalTo(self.customNavBar.mas_bottom);
  76. make.left.right.equalTo(self.view);
  77. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  78. }];
  79. }
  80. - (UILabel *)versionLb {
  81. if (!_versionLb) {
  82. UILabel *lb = [UILabel new];
  83. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  84. NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
  85. lb.text = [NSString stringWithFormat:@"V%@",app_Version];
  86. lb.textColor = Col_000;
  87. lb.textAlignment = NSTextAlignmentCenter;
  88. lb.font = [UIFont fontWithName:Rob_Regular size:12];
  89. lb.numberOfLines = 1;
  90. _versionLb = lb;
  91. }
  92. return _versionLb;
  93. }
  94. -(UIView *)bottomV {
  95. if (!_bottomV) {
  96. UIView *v = [UIView new];
  97. v.frame = CGRectMake(0, 0, KScreenWidth, 100);
  98. v.backgroundColor = _F8F8F8;
  99. _bottomV = v;
  100. }
  101. return _bottomV;
  102. }
  103. - (UITableView *)tableV {
  104. if (!_tableV) {
  105. UITableView *tabV = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  106. tabV.backgroundColor = _F8F8F8;
  107. [tabV registerClass:[ASSettingListCell class] forCellReuseIdentifier:@"ASSettingListCell"];
  108. tabV.delegate = self;
  109. tabV.dataSource = self;
  110. tabV.rowHeight = UITableViewAutomaticDimension;
  111. tabV.estimatedRowHeight = 100;
  112. tabV.separatorStyle = UITableViewCellSeparatorStyleNone;
  113. UIView *v = [UIView new];
  114. v.frame = CGRectMake(0, 0, KScreenWidth, 10);
  115. v.backgroundColor = _F8F8F8;
  116. tabV.tableHeaderView = v;
  117. tabV.tableFooterView = self.bottomV;
  118. _tableV = tabV;
  119. }
  120. return _tableV;
  121. }
  122. #pragma mark - UITableViewDelegate,UITableViewDataSource
  123. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  124. switch (indexPath.row) {
  125. case 0:{
  126. // if (![self checkLogin:true]) {
  127. // return;
  128. // }
  129. ASInfomationSetController *vc = [ASInfomationSetController new];
  130. [self.navigationController pushViewController:vc animated:true];
  131. break;
  132. }
  133. case 1:{
  134. // if (![self checkLogin:true]) {
  135. // return;
  136. // }
  137. // KWAddressListViewController *vc = [KWAddressListViewController new];
  138. // vc.addressType = AddressTypeSettingAddress;
  139. // [self.navigationController pushViewController:vc animated:true];
  140. break;
  141. }
  142. case 3:{
  143. ASHelpListViewController *vc = [ASHelpListViewController new];
  144. vc.isHelp = false;
  145. [self.navigationController pushViewController:vc animated:true];
  146. break;
  147. }
  148. case 4:{
  149. ASHelpListViewController *vc = [ASHelpListViewController new];
  150. vc.isHelp = true;
  151. [self.navigationController pushViewController:vc animated:true];
  152. break;
  153. }
  154. // case 5: {
  155. // [self logout];
  156. // break;
  157. // }
  158. // case 6: {
  159. // [self showDeleteAccountAlert];
  160. // break;
  161. // }
  162. default:
  163. break;
  164. }
  165. }
  166. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  167. return self.titleArr.count;
  168. }
  169. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  170. ASSettingListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASSettingListCell" forIndexPath:indexPath];
  171. [cell setTitle:self.titleArr[indexPath.row] points:self.detailArr[indexPath.row] enable:true];
  172. if (//KWLoginedManager.shareInstance.isLogined &&
  173. ((indexPath.row == _titleArr.count - 1) || (indexPath.row == _titleArr.count - 2))) {
  174. cell.moreIcon.hidden = true;
  175. } else {
  176. cell.moreIcon.hidden = false;
  177. }
  178. cell.switchBtn.hidden = !(indexPath.row == 2);
  179. if (indexPath.row == 2) {
  180. [cell.switchBtn setIsOpen:arc4random()%2 == 1 animate:false];
  181. // [cell.switchBtn setIsOpen:self.userInfo.is_subscribed animate:false];
  182. // @weakify(self);
  183. // [cell.switchBtn setClickBack:^{
  184. // [weak_self configSubscrib:!weak_self.userInfo.is_subscribed];
  185. // }];
  186. } else {
  187. cell.switchBtn.clickBack = nil;
  188. }
  189. return cell;
  190. }
  191. // MARK: - 注销账号
  192. - (void)showDeleteAccountAlert {
  193. // @weakify(self);
  194. // KWUpdateAlertWindow *window = [KWUpdateAlertWindow 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:^{
  195. // } cancelBlock:^{
  196. // @strongify(self);
  197. // [self deleteAccount];
  198. //
  199. // }];
  200. // window.vc.titleLb.text = @"Delete Account?";
  201. // [window.vc.sureBt setTitle:@"No" forState:UIControlStateNormal];
  202. // [window.vc.cancelBt setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  203. // NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:@"Yes"];
  204. // [attStr setFont:[UIFont fontWithName:Rob_Regular size:16]];
  205. // [attStr setUnderlineStyle:NSUnderlineStyleSingle];
  206. // [attStr setUnderlineColor:[UIColor colorWithHexString:@"#000000"]];
  207. // [attStr setColor:[UIColor colorWithHexString:@"#000000"]];
  208. // [window.vc.cancelBt setAttributedTitle:attStr forState:UIControlStateNormal];
  209. //
  210. // [window.vc.cancelBt mas_remakeConstraints:^(MASConstraintMaker *make) {
  211. // make.bottom.equalTo(window.vc.sureBt);
  212. // make.height.equalTo(@35);
  213. // make.right.equalTo(window.vc.sureBt.mas_left).offset(-20);
  214. // make.left.greaterThanOrEqualTo(window.vc.contentV).offset(20);
  215. // }];
  216. //
  217. //
  218. }
  219. - (void)deleteAccount {
  220. // [MBProgressHUD showHUDAddedTo:self.view animated:true];
  221. // @weakify(self);
  222. // [PPNetworkHelper POST:DeleteAccount parameters:@{} success:^(id responseObject) {
  223. // [MBProgressHUD hideHUDForView:self.view animated:true];
  224. // if (RequestSuccess) {
  225. // NSLog(@"success:%@",responseObject);
  226. // [XXX_Tabber shareInstance].xxx_barCartBtn.badgeValue = @"0";
  227. // [weak_self popAndToLogin];
  228. //
  229. // } else {
  230. // NSLog(@"fail:%@",RequestErrorMsg);
  231. // [weak_self.view makeToast:RequestErrorMsg];
  232. // }
  233. // } failure:^(NSError *error) {
  234. // [MBProgressHUD hideHUDForView:self.view animated:true];
  235. // NSLog(@"err:%@",error);
  236. // [weak_self.view makeToast:@"Oh No, Bad Net"];
  237. // }];
  238. }
  239. // MARK: - 退出登录
  240. - (void)logout {
  241. // [MBProgressHUD showHUDAddedTo:self.view animated:true];
  242. // @weakify(self);
  243. // [PPNetworkHelper POST:LogoutApi parameters:@{} success:^(id responseObject) {
  244. // [MBProgressHUD hideHUDForView:self.view animated:true];
  245. // if (RequestSuccess) {
  246. // NSLog(@"success:%@",responseObject);
  247. // [XXX_Tabber shareInstance].xxx_barCartBtn.badgeValue = @"0";
  248. // [weak_self popAndToLogin];
  249. //
  250. // } else {
  251. // NSLog(@"fail:%@",RequestErrorMsg);
  252. // [weak_self.view makeToast:RequestErrorMsg];
  253. // }
  254. // } failure:^(NSError *error) {
  255. // [MBProgressHUD hideHUDForView:self.view animated:true];
  256. // NSLog(@"err:%@",error);
  257. // [weak_self.view makeToast:@"Oh No, Bad Net"];
  258. // }];
  259. }
  260. - (void)popAndToLogin {
  261. // [KWLoginedManager.shareInstance clearLoginedUser];
  262. // LoginEntranceC * loginVC = [[LoginEntranceC alloc]init];
  263. // UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:loginVC];
  264. // navC.modalPresentationStyle = UIModalPresentationFullScreen;
  265. // [self.navigationController.viewControllers.firstObject presentViewController:navC animated:YES completion:nil];
  266. // [self.navigationController popToRootViewControllerAnimated:false];
  267. }
  268. //- (void)configSubscrib:(BOOL)is_subscribed {
  269. // NSDictionary *param = @{@"is_subscribed":[NSNumber numberWithBool:is_subscribed]};
  270. // @weakify(self);
  271. // [MBProgressHUD showHUDAddedTo:self.view animated:true];
  272. // [PPNetworkHelper POST:SaveSub parameters:param success:^(id responseObject) {
  273. // [MBProgressHUD hideHUDForView:weak_self.view animated:true];
  274. // if (RequestSuccess) {
  275. // weak_self.userInfo.is_subscribed = is_subscribed;
  276. // [KWLoginedManager.shareInstance getUserInfo:^(bool flag) {
  277. //
  278. // }];
  279. // } else {
  280. // NSString *errMsg = [NSString stringWithFormat:@"%@", RequestErrorMsg];
  281. // [self.view makeToast:errMsg];
  282. // }
  283. // [weak_self.tableV reloadData];
  284. // } failure:^(NSError *error) {
  285. // [MBProgressHUD hideHUDForView:weak_self.view animated:true];
  286. // [self.view makeToast:@"请求失败"];
  287. // [weak_self.tableV reloadData];
  288. // }];
  289. //
  290. //}
  291. @end