// // ASSettingViewController.m // Asteria // // Created by iOS on 2023/7/5. // #import "ASSettingViewController.h" #import "ASSettingListCell.h" #import "ASInfomationSetController.h" #import "ASHelpListViewController.h" @interface ASSettingViewController () @property (nonatomic, strong) UIView *bottomV; @property (nonatomic, strong) UILabel *versionLb; @property (nonatomic, strong) UITableView *tableV; @property (nonatomic, strong) NSArray *titleArr; @property (nonatomic, strong) NSArray *detailArr; @end @implementation ASSettingViewController - (void)viewDidLoad { [super viewDidLoad]; self.titleStr = @"Setting"; [self setNavRightSearch:^{ }]; self.statusBgV.backgroundColor = Col_FFF; self.customNavBar.backgroundColor = Col_FFF; [self loadSubVs]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self configData]; } - (void)configData { self.titleArr = @[@"INFORMATION", @"SHIPPING ADDRESS", @"SUBSCRIBE", @"CUSTOMER SERVICE", @"HELP & SUPPORT", @"LOG OUT", @"DELETE ACCOUNT"]; /* KWLoginedManager.shareInstance.isLogined ? @[@"Information", @"Shipping Address", // @"Account Settings", @"Subscribe", @"Customer Service", @"Help & Support", @"Log Out", @"Delete Account"] : @[@"Infomation", @"Shipping Address", // @"Account Settings", @"Subscribe", @"Customer Service", @"Help & Support"]; */ self.detailArr = @[@"", @"",@"",@"",@"",@"",@"",@""]; [self.tableV reloadData]; } - (void)loadSubVs { [self.view addSubview:self.tableV]; [self.bottomV addSubview:self.versionLb]; [self.versionLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.bottomV).offset(66); make.left.equalTo(self.bottomV).offset(20); make.centerX.equalTo(self.bottomV); make.height.equalTo(@20); }]; [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.customNavBar.mas_bottom); make.left.right.equalTo(self.view); make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom); }]; } - (UILabel *)versionLb { if (!_versionLb) { UILabel *lb = [UILabel new]; NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"]; lb.text = [NSString stringWithFormat:@"V%@",app_Version]; lb.textColor = Col_000; lb.textAlignment = NSTextAlignmentCenter; lb.font = [UIFont fontWithName:Rob_Regular size:12]; lb.numberOfLines = 1; _versionLb = lb; } return _versionLb; } -(UIView *)bottomV { if (!_bottomV) { UIView *v = [UIView new]; v.frame = CGRectMake(0, 0, KScreenWidth, 100); v.backgroundColor = _F8F8F8; _bottomV = v; } return _bottomV; } - (UITableView *)tableV { if (!_tableV) { UITableView *tabV = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; tabV.backgroundColor = _F8F8F8; [tabV registerClass:[ASSettingListCell class] forCellReuseIdentifier:@"ASSettingListCell"]; tabV.delegate = self; tabV.dataSource = self; tabV.rowHeight = UITableViewAutomaticDimension; tabV.estimatedRowHeight = 100; tabV.separatorStyle = UITableViewCellSeparatorStyleNone; UIView *v = [UIView new]; v.frame = CGRectMake(0, 0, KScreenWidth, 10); v.backgroundColor = _F8F8F8; tabV.tableHeaderView = v; tabV.tableFooterView = self.bottomV; _tableV = tabV; } return _tableV; } #pragma mark - UITableViewDelegate,UITableViewDataSource - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { switch (indexPath.row) { case 0:{ ASInfomationSetController *vc = [ASInfomationSetController new]; [self.navigationController pushViewController:vc animated:true]; break; } case 1:{ // if (![self checkLogin:true]) { // return; // } // KWAddressListViewController *vc = [KWAddressListViewController new]; // vc.addressType = AddressTypeSettingAddress; // [self.navigationController pushViewController:vc animated:true]; break; } case 3:{ ASHelpListViewController *vc = [ASHelpListViewController new]; vc.isHelp = false; [self.navigationController pushViewController:vc animated:true]; break; } case 4:{ ASHelpListViewController *vc = [ASHelpListViewController new]; vc.isHelp = true; [self.navigationController pushViewController:vc animated:true]; break; } case 5: { [self logout]; break; } case 6: { [self showDeleteAccountAlert]; break; } default: break; } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.titleArr.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ASSettingListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ASSettingListCell" forIndexPath:indexPath]; [cell setTitle:self.titleArr[indexPath.row] points:self.detailArr[indexPath.row] enable:true]; if (((indexPath.row == _titleArr.count - 1) || (indexPath.row == _titleArr.count - 2))) { cell.moreIcon.hidden = true; } else { cell.moreIcon.hidden = false; } cell.switchBtn.hidden = !(indexPath.row == 2); if (indexPath.row == 2) { BOOL isSub = ASUserInfoManager.shared.userInfo.is_subscribed; [cell.switchBtn setIsOpen:isSub animate:false]; __weak typeof(self) weakSelf = self; [cell.switchBtn setClickBack:^{ [weakSelf configSubscrib:!isSub]; }]; } else { cell.switchBtn.clickBack = nil; } return cell; } // MARK: - 退出登录 - (void)logout { [MBProgressHUD showHUDAddedTo:self.view animated:true]; __weak typeof(self) weak_self = self; [ASNetTools.shared postWithPath:postLogOut param:@{} success:^(id _Nonnull json) { [MBProgressHUD hideHUDForView:weak_self.view animated:true]; [weak_self popAndToLogin]; } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { [MBProgressHUD hideHUDForView:weak_self.view animated:true]; NSLog(@"err:%@",code); [weak_self.view makeToast:@"Oh No, Bad Net"]; }]; } - (void)configSubscrib:(BOOL)is_subscribed { NSDictionary *param = @{ @"customer":@{ @"email": ASUserInfoManager.shared.userInfo.email, @"firstname": ASUserInfoManager.shared.userInfo.firstname, @"lastname": ASUserInfoManager.shared.userInfo.lastname, @"extension_attributes":@{ @"is_subscribed":[NSNumber numberWithBool:is_subscribed] } } }; __weak typeof(self) weakSelf = self; [MBProgressHUD showHUDAddedTo:self.view animated:true]; [ASNetTools.shared putWithPath:putUserInfo param:param success:^(id _Nonnull json) { [MBProgressHUD hideHUDForView:weakSelf.view animated:true]; ASUserInfoManager.shared.userInfo.is_subscribed = is_subscribed; [weakSelf.tableV reloadData]; } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { [MBProgressHUD hideHUDForView:weakSelf.view animated:true]; [weakSelf.view makeToast:@"Bad Net"]; [weakSelf.tableV reloadData]; }]; } // MARK: - 注销账号 - (void)showDeleteAccountAlert { __weak typeof(self) weakSelf = self; 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:^{ } cancelBlock:^{ [weakSelf deleteAccount:@""]; // [weakSelf showDeletedReasonInput]; }]; window.vc.titleLb.text = @"Delete Account?"; [window.vc.sureBt setTitle:@"No" forState:UIControlStateNormal]; [window.vc.cancelBt setTitleColor:UIColor.whiteColor forState:UIControlStateNormal]; NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:@"Yes"]; [attStr setAttributes:@{ NSFontAttributeName:[UIFont fontWithName:Rob_Regular size:16], NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle], NSUnderlineColorAttributeName:[UIColor colorWithHexString:@"#000000"], NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#000000"] } range:NSMakeRange(0, attStr.length)]; [window.vc.cancelBt setAttributedTitle:attStr forState:UIControlStateNormal]; [window.vc.cancelBt mas_remakeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(window.vc.sureBt); make.height.equalTo(@35); make.right.equalTo(window.vc.sureBt.mas_left).offset(-20); make.left.greaterThanOrEqualTo(window.vc.contentV).offset(20); }]; } //- (void)showDeletedReasonInput { // __weak typeof(self) weakSelf = self; // [APHomeActiveWindow show:@"Deleted Account" des:@"Dear user, could you tell me the reason for leaving?" sureBlock:^(NSString *reason) { // NSString *str = @""; // if (!reason.isEmpty) { // str = reason; // } // [weakSelf deleteAccount:str]; // } cancelBlock:^{ // }]; //} - (void)deleteAccount:(NSString *)msg { [MBProgressHUD showHUDAddedTo:self.view animated:true]; __weak typeof(self) weakSelf = self; [ASNetTools.shared delWithPath:deleteUser param:@{} success:^(id _Nonnull json) { [MBProgressHUD hideHUDForView:weakSelf.view animated:true]; [weakSelf popAndToLogin]; } faild:^(NSString * _Nonnull code, NSString * _Nonnull msg) { [MBProgressHUD hideHUDForView:weakSelf.view animated:true]; [weakSelf.view makeToast:@"Oh No, Bad Net"]; }]; } @end