You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

267 lines
12 KiB

//
// WXYZ_CancelAccountViewController.m
// WXReader
//
// Created by Andrew on 2019/12/21.
// Copyright © 2019 Andrew. All rights reserved.
//
#import "WXYZ_CancelAccountViewController.h"
#import "TFWebViewController.h"
#import "AppDelegate.h"
#import "WXYZ_CancelAccountTableViewCell.h"
@interface WXYZ_CancelAccountViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) UIButton *agreementButton;
@property (nonatomic, strong) UIButton *applyButton;
@end
@implementation WXYZ_CancelAccountViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)initialize
{
[self setNavigationBarTitle:TFLocalizedString(@"注销账号")];
}
- (void)createSubviews
{
self.dataSourceArray = [NSMutableArray arrayWithArray:@[
@[TFLocalizedString(@"账号安全"), TFLocalizedString(@"最好使用常用设备提交申请,注销申请审核后,注销操作立即生效。")],
@[TFLocalizedString(@"账号状态"), TFLocalizedString(@"申请注销的账号应为正常使用中的状态,应处于未封禁或未被审查的状态。")],
@[TFLocalizedString(@"账号财产已结清"), TFLocalizedString(@"申请注销的账号无有效状态的会员,没有余额等;且没有任何未结清、未完成的交易。")]
]];
self.mainTableView.delegate = self;
self.mainTableView.dataSource = self;
// self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET, 0);
[self.mainTableView setTableHeaderView:self.headerView];
self.mainTableView.tableFooterView = [self footerView];
[self.view addSubview:self.mainTableView];
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(PUB_NAVBAR_HEIGHT);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT - (PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET) - kMargin);
}];
self.applyButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.applyButton.alpha = 0.6;
self.applyButton.backgroundColor = kRedColor;
[self.applyButton setTitle:TFLocalizedString(@"申请注销") forState:UIControlStateNormal];
[self.applyButton addTarget:self action:@selector(applyClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.applyButton];
[self.applyButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.view.mas_bottom).with.offset(- PUB_TABBAR_OFFSET);
make.left.mas_equalTo(0);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
}];
[self.mainTableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellName = @"WXYZ_CancelAccountTableViewCell";
WXYZ_CancelAccountTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[WXYZ_CancelAccountTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.titleString = [self.dataSourceArray objectAtIndex:indexPath.row][0];
cell.detailString = [self.dataSourceArray objectAtIndex:indexPath.row][1];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
//section头间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
CGFloat height = [TFViewHelper getDynamicHeightWithLabelFont:kBoldFont15 labelWidth:SCREEN_WIDTH labelText:TFLocalizedString(@"申请注销前,您的账号需要注意以下条款:") maxHeight:MAXFLOAT];
return height + kMargin;
}
//section头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
CGFloat height = [TFViewHelper getDynamicHeightWithLabelFont:kBoldFont15 labelWidth:SCREEN_WIDTH labelText:TFLocalizedString(@"申请注销前,您的账号需要注意以下条款:") maxHeight:MAXFLOAT];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, height + kMargin)];
view.backgroundColor = [UIColor clearColor];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(kHalfMargin, kMargin, SCREEN_WIDTH - kHalfMargin - kHalfMargin, height)];
titleLabel.numberOfLines = 2;
titleLabel.text = TFLocalizedString(@"申请注销前,您的账号需要注意以下条款:");
titleLabel.textColor = kBlackColor;
titleLabel.font = kBoldFont15;
[view addSubview:titleLabel];
return view;
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (UIView *)footerView {
UIView *view = nil;
if (SCREEN_HEIGHT <= 667.0) {
view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kLabelHeight + kLabelHeight)];
} else {
view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kLabelHeight + kHalfMargin)];
}
view.backgroundColor = [UIColor clearColor];
if (!self.agreementButton) {
self.agreementButton = [UIButton buttonWithType:UIButtonTypeCustom];
// self.agreementButton.frame = CGRectMake(kHalfMargin, kHalfMargin, 30, 30);
self.agreementButton.selected = NO;
self.agreementButton.adjustsImageWhenHighlighted = NO;
[self.agreementButton setImageEdgeInsets:UIEdgeInsetsMake(7, 0, 7, 14)];
[self.agreementButton setImage:[UIImage imageNamed:@"audio_download_unselect"] forState:UIControlStateNormal];
[self.agreementButton setImage:[UIImage imageNamed:@"audio_download_select"] forState:UIControlStateSelected];
[self.agreementButton addTarget:self action:@selector(agreementClick) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:self.agreementButton];
[self.agreementButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(view);
make.left.equalTo(view).offset(kHalfMargin);
make.width.height.mas_equalTo(30.0);
}];
WS(weakSelf)
NSString *prefix = TFLocalizedString(@"我已阅读并接受");
NSString *suffix = TFLocalizedString(@"《用户注销协议》");
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@", prefix, suffix]];
text.lineSpacing = 5;
text.font = kMainFont;
[text setTextHighlightRange:NSMakeRange(prefix.length, suffix.length) color:kMainColor backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
TFWebViewController *vc = [[TFWebViewController alloc] init];
vc.navTitle = TFLocalizedString(@"用户注销协议");
AppDelegate *delegate = (AppDelegate *)kRCodeSync([UIApplication sharedApplication].delegate);
vc.URLString = delegate.checkSettingModel.protocol_list.logoff ?: [NSString stringWithFormat:@"%@%@?language=%@", APIURL, Log_Off, TFLanguageManager.serverLocalized];
[weakSelf.navigationController pushViewController:vc animated:YES];
}];
[text setTextHighlightRange:NSMakeRange(0, 7) color:kBlackColor backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
[weakSelf agreementClick];
}];
YYLabel *tipsLabel = [[YYLabel alloc] init];
tipsLabel.numberOfLines = 0;
tipsLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 2 * kMargin;
tipsLabel.attributedText = text;
tipsLabel.textAlignment = NSTextAlignmentLeft;
tipsLabel.userInteractionEnabled = YES;
[view addSubview:tipsLabel];
[tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(view).offset(kMargin + 10);
make.centerY.equalTo(self.agreementButton);
make.width.mas_equalTo(SCREEN_WIDTH - (kMargin + kMargin));
}];
}
return view;
}
- (UIView *)headerView
{
if (!_headerView) {
NSString *str = TFLocalizedString(@"重要提醒:个人账号可以申请注销。为了避免被盗号或非本人操作所带来的损失,注销前需要确认账号所属,以及可能涉及的虚拟财产结算。");
_headerView = [[UIView alloc] init];
_headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, [TFViewHelper getDynamicHeightWithLabelFont:kMainFont labelWidth:(SCREEN_WIDTH - (kMargin + kHalfMargin)) labelText:str] + 80 + 2 * kMargin);
_headerView.backgroundColor = [UIColor whiteColor];
UIView *headerBackView = [[UIView alloc] init];
headerBackView.backgroundColor = kGrayViewColor;
headerBackView.layer.cornerRadius = 12;
[_headerView addSubview:headerBackView];
[headerBackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.top.mas_equalTo(kHalfMargin);
make.width.mas_equalTo(SCREEN_WIDTH - kMargin);
make.height.mas_equalTo(_headerView.mas_height).with.offset(- kHalfMargin);
}];
UIImageView *headerImageView = [[UIImageView alloc] init];
headerImageView.image = [UIImage imageNamed:@"cancel_account"];
[_headerView addSubview:headerImageView];
[headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kMargin);
make.centerX.mas_equalTo(_headerView.mas_centerX);
make.width.height.mas_equalTo(80);
}];
UILabel *headerLabel = [[UILabel alloc] init];
headerLabel.numberOfLines = 0;
headerLabel.font = kMainFont;
headerLabel.textColor = kColorRGB(96, 106, 100);
[_headerView addSubview:headerLabel];
[headerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin + kHalfMargin);
make.top.mas_equalTo(headerImageView.mas_bottom).with.offset(kHalfMargin);
make.width.mas_equalTo(SCREEN_WIDTH - 2 * (kMargin + kHalfMargin));
make.height.mas_equalTo([TFViewHelper getDynamicHeightWithLabelFont:kMainFont labelWidth:(SCREEN_WIDTH - (kMargin + kHalfMargin)) labelText:str]);
}];
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithAttributedString:[[NSAttributedString alloc] initWithString:str]];
// [attributeString addAttribute:NSFontAttributeName value:kBoldMainFont range:NSMakeRange(0, 5)];
headerLabel.attributedText = attributeString;
}
return _headerView;
}
- (void)agreementClick
{
self.agreementButton.selected = !self.agreementButton.selected;
if (self.agreementButton.selected) {
self.applyButton.alpha = 1;
} else {
self.applyButton.alpha = 0.6;
}
}
- (void)applyClick
{
if (self.agreementButton.selected) {
WS(weakSelf)
[TFNetworkTools POST:Cancel_Account parameters:nil model:nil success:^(BOOL isSuccess, id _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
[TFUserInfoManager logout];
weakSelf.agreementButton.selected = NO;
weakSelf.applyButton.alpha = 0.6;
[weakSelf.navigationController popToRootViewControllerAnimated:YES];
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"注销成功")];
}
} failure:nil];
}
}
@end