// // 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; //@property (nonatomic, strong) KWLoginedUserModel *userInfo; @end @implementation ASSettingViewController - (void)viewDidLoad { [super viewDidLoad]; self.titleStr = @"Setting"; [self setNavRightSearch:^{ }]; self.statusBgV.backgroundColor = Col_FFF; self.customNavBar.backgroundColor = Col_FFF; [self loadSubVs]; // [self configData]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // self.userInfo = [KWLoginedManager.shareInstance getCurrentLoginedUser]; [self configData]; // @weakify(self); // [KWLoginedManager.shareInstance getUserInfo:^(bool flag) { // weak_self.userInfo = [KWLoginedManager.shareInstance getCurrentLoginedUser]; // [weak_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:{ // if (![self checkLogin:true]) { // return; // } 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 (//KWLoginedManager.shareInstance.isLogined && ((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) { [cell.switchBtn setIsOpen:arc4random()%2 == 1 animate:false]; // [cell.switchBtn setIsOpen:self.userInfo.is_subscribed animate:false]; // @weakify(self); // [cell.switchBtn setClickBack:^{ // [weak_self configSubscrib:!weak_self.userInfo.is_subscribed]; // }]; } else { cell.switchBtn.clickBack = nil; } return cell; } // MARK: - 注销账号 - (void)showDeleteAccountAlert { // @weakify(self); // 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:^{ // } cancelBlock:^{ // @strongify(self); // [self deleteAccount]; // // }]; // 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 setFont:[UIFont fontWithName:Rob_Regular size:16]]; // [attStr setUnderlineStyle:NSUnderlineStyleSingle]; // [attStr setUnderlineColor:[UIColor colorWithHexString:@"#000000"]]; // [attStr setColor:[UIColor colorWithHexString:@"#000000"]]; // [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)deleteAccount { // [MBProgressHUD showHUDAddedTo:self.view animated:true]; // @weakify(self); // [PPNetworkHelper POST:DeleteAccount parameters:@{} success:^(id responseObject) { // [MBProgressHUD hideHUDForView:self.view animated:true]; // if (RequestSuccess) { // NSLog(@"success:%@",responseObject); // [XXX_Tabber shareInstance].xxx_barCartBtn.badgeValue = @"0"; // [weak_self popAndToLogin]; // // } else { // NSLog(@"fail:%@",RequestErrorMsg); // [weak_self.view makeToast:RequestErrorMsg]; // } // } failure:^(NSError *error) { // [MBProgressHUD hideHUDForView:self.view animated:true]; // NSLog(@"err:%@",error); // [weak_self.view makeToast:@"Oh No, Bad Net"]; // }]; } // MARK: - 退出登录 - (void)logout { // [MBProgressHUD showHUDAddedTo:self.view animated:true]; // @weakify(self); // [PPNetworkHelper POST:LogoutApi parameters:@{} success:^(id responseObject) { // [MBProgressHUD hideHUDForView:self.view animated:true]; // if (RequestSuccess) { // NSLog(@"success:%@",responseObject); // [XXX_Tabber shareInstance].xxx_barCartBtn.badgeValue = @"0"; // [weak_self popAndToLogin]; // // } else { // NSLog(@"fail:%@",RequestErrorMsg); // [weak_self.view makeToast:RequestErrorMsg]; // } // } failure:^(NSError *error) { // [MBProgressHUD hideHUDForView:self.view animated:true]; // NSLog(@"err:%@",error); // [weak_self.view makeToast:@"Oh No, Bad Net"]; // }]; } - (void)popAndToLogin { // [KWLoginedManager.shareInstance clearLoginedUser]; // LoginEntranceC * loginVC = [[LoginEntranceC alloc]init]; // UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:loginVC]; // navC.modalPresentationStyle = UIModalPresentationFullScreen; // [self.navigationController.viewControllers.firstObject presentViewController:navC animated:YES completion:nil]; // [self.navigationController popToRootViewControllerAnimated:false]; } //- (void)configSubscrib:(BOOL)is_subscribed { // NSDictionary *param = @{@"is_subscribed":[NSNumber numberWithBool:is_subscribed]}; // @weakify(self); // [MBProgressHUD showHUDAddedTo:self.view animated:true]; // [PPNetworkHelper POST:SaveSub parameters:param success:^(id responseObject) { // [MBProgressHUD hideHUDForView:weak_self.view animated:true]; // if (RequestSuccess) { // weak_self.userInfo.is_subscribed = is_subscribed; // [KWLoginedManager.shareInstance getUserInfo:^(bool flag) { // // }]; // } else { // NSString *errMsg = [NSString stringWithFormat:@"%@", RequestErrorMsg]; // [self.view makeToast:errMsg]; // } // [weak_self.tableV reloadData]; // } failure:^(NSError *error) { // [MBProgressHUD hideHUDForView:weak_self.view animated:true]; // [self.view makeToast:@"请求失败"]; // [weak_self.tableV reloadData]; // }]; // //} @end