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.

298 lines
10 KiB

//
// TFUpgradeMemberController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/13.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFUpgradeMemberController.h"
#import "TFWebViewController.h"
#import "TFUpgradeMemberModel.h"
#import "TFRechargeModel.h"
#import "TFUpgradeMemberViewCell.h"
#import "TFMemberPrivilegeViewCell.h"
#import "TFMemberInstructionsViewCell.h"
#import "TFUpgradeMemberHeaderView.h"
#import "TFIAPManager.h"
@interface TFUpgradeMemberController ()<UITableViewDelegate, UITableViewDataSource, TFIAPManagerResultsDelegate>
{
UILabel *priceLabel;
UIButton *confirmButton;
NSInteger goodsSelectIndex;
NSInteger payStyleIndex;
}
@property (nonatomic ,strong) TFUpgradeMemberHeaderView *headerView;
@property (nonatomic ,strong) TFUpgradeMemberModel *memberModel;
@end
@implementation TFUpgradeMemberController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarLightContentStyle];
}
- (void)initialize
{
[self setNavigationBarTitle:TFLocalizedString(@"开通会员")];
self.navigationBar.backgroundColor = kColorRGB(46, 46, 48);
self.navigationBar.navTitleLabel.textColor = kWhiteColor;
[self.navigationBar setLightLeftButton];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Login_Success object:nil];
self.view.backgroundColor = kGrayViewColor;
goodsSelectIndex = 0;
[TFIAPManager sharedManager].delegate = self;
}
- (void)createSubviews
{
self.mainTableViewGroup.delegate = self;
self.mainTableViewGroup.dataSource = self;
[self.view addSubview:self.mainTableViewGroup];
[self.mainTableViewGroup mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(SCREEN_HEIGHT - PUB_TABBAR_HEIGHT);
}];
self.headerView = [[TFUpgradeMemberHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, PUB_NAVBAR_HEIGHT + kGeometricHeight(SCREEN_WIDTH - kMargin, 1053, 215) + 30)];
[self.mainTableViewGroup setTableHeaderView:self.headerView];
UIView *toolBar = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - PUB_TABBAR_HEIGHT, SCREEN_WIDTH, PUB_TABBAR_HEIGHT)];
toolBar.backgroundColor = kWhiteColor;
toolBar.layer.shadowColor = [UIColor blackColor].CGColor;
toolBar.layer.shadowOffset = CGSizeMake(0, 0);
toolBar.layer.shadowOpacity = 0.1f;
toolBar.layer.shadowRadius = 1.0f;
[self.view addSubview:toolBar];
confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
confirmButton.adjustsImageWhenHighlighted = NO;
[confirmButton setBackgroundImage:[UIImage imageNamed:@"member_pay_btn"] forState:UIControlStateNormal];
[confirmButton setTitle:TFLocalizedString(@"立即开通") forState:UIControlStateNormal];
[confirmButton setTitleColor:kColorRGBA(122, 70, 0, 1) forState:UIControlStateNormal];
[confirmButton.titleLabel setFont:[UIFont boldSystemFontOfSize:kFontSize14]];
[confirmButton addTarget:self action:@selector(confirmButtonClick) forControlEvents:UIControlEventTouchUpInside];
[toolBar addSubview:confirmButton];
[confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(toolBar.mas_right);
make.top.mas_equalTo(0);
make.width.mas_equalTo(150);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
}];
priceLabel = [[UILabel alloc] init];
priceLabel.font = kMainFont;
priceLabel.textColor = kBlackColor;
[toolBar addSubview:priceLabel];
[priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.top.mas_equalTo(0);
make.right.mas_equalTo(confirmButton.mas_left);
make.height.mas_equalTo(confirmButton.mas_height);
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 1 && (self.memberModel.about.count <= 0 || !self.memberModel.about)) {
return 0;
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.section) {
case 0: {
WS(weakSelf)
TFUpgradeMemberViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFUpgradeMemberViewCell"];
if (!cell) {
cell = [[TFUpgradeMemberViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFUpgradeMemberViewCell"];
}
cell.goodsList = self.memberModel.list;
cell.selectItemBlock = ^(NSInteger itemIndex) {
SS(strongSelf)
strongSelf->goodsSelectIndex = itemIndex;
strongSelf->payStyleIndex = 0;
[weakSelf.mainTableViewGroup reloadData];
};
cell.selectionStyle = UITableViewCellAccessoryNone;
return cell;
}
break;
case 1:
{
TFMemberPrivilegeViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFMemberPrivilegeViewCell"];
if (!cell) {
cell = [[TFMemberPrivilegeViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFMemberPrivilegeViewCell"];
}
cell.privilege = self.memberModel.privilege;
cell.selectionStyle = UITableViewCellAccessoryNone;
return cell;
}
break;
case 2:
{
TFMemberInstructionsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFMemberInstructionsViewCell"];
if (!cell) {
cell = [[TFMemberInstructionsViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFMemberInstructionsViewCell"];
}
cell.about = self.memberModel.about;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
break;
default:
break;
}
return [[UITableViewCell alloc] init];
}
//section头间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 2 && (self.memberModel.about.count <= 0 || !self.memberModel.about)) {
return CGFLOAT_MIN;
}
return 50;
}
//section头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (!self.memberModel) {
return [[UIView alloc] init];
}
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
view.backgroundColor = [UIColor whiteColor];
UILabel *headerTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(kHalfMargin, 0, SCREEN_WIDTH - kHalfMargin, 50)];
if (section == 0) {
headerTitleLabel.text = TFLocalizedString(@"会员套餐");
} else if (section == 1) {
headerTitleLabel.text = TFLocalizedString(@"会员特权");
} else {
headerTitleLabel.text = TFLocalizedString(@"会员说明");
}
headerTitleLabel.font = kBoldFont15;
headerTitleLabel.textColor = kBlackColor;
[view addSubview:headerTitleLabel];
NSMutableAttributedString *priceString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@", TFLocalizedString(@"总计:"), [self.memberModel.list objectAtIndex:goodsSelectIndex].fat_price?:@""]];
NSString *str = [self.memberModel.list objectAtIndex:goodsSelectIndex].fat_price?:@"";
[priceString addAttribute:NSFontAttributeName value:kBoldFont22 range:NSMakeRange(priceString.length - str.length, str.length)];
[priceString addAttribute:NSForegroundColorAttributeName value:kColorRGB(228, 185, 122) range:NSMakeRange(priceString.length - str.length, str.length)];
priceLabel.attributedText = priceString;
return view;
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if (section == 2 && (self.memberModel.about.count <= 0 || !self.memberModel.about)) {
return CGFLOAT_MIN;
}
return kHalfMargin;
}
// section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if (!self.memberModel) {
return [[UIView alloc] init];
}
UIView *view = [[UIView alloc] init];
view.backgroundColor = kGrayViewColor;
return view;
}
#pragma mark IApRequestResultsDelegate
- (void)requestSuccess
{
dispatch_async(dispatch_get_main_queue(), ^{
self.mainTableViewGroup.userInteractionEnabled = YES;
if (self.paySuccessBlock) {
self.paySuccessBlock();
}
[self netRequest];
});
}
- (void)filedWithErrorCode:(NSInteger)errorCode andError:(NSString *)error
{
dispatch_async(dispatch_get_main_queue(), ^{
self.mainTableViewGroup.userInteractionEnabled = YES;
});
}
- (void)confirmButtonClick
{
if (!TFUserInfoManager.isLogin) {
[TFLoginOptionsViewController presentLoginView:nil];
return;
}
if (self.memberModel.list.count > 0) {
TFGoodsModel *goodsModel = [self.memberModel.list objectOrNilAtIndex:goodsSelectIndex];
self.mainTableViewGroup.userInteractionEnabled = NO;
[[TFIAPManager sharedManager] requestProductWithId:[NSString stringWithFormat:@"%@", goodsModel.apple_id]];
}
}
- (void)netRequest
{
WS(weakSelf)
[TFNetworkTools POST:Member_Center parameters:nil model:TFUpgradeMemberModel.class success:^(BOOL isSuccess, TFUpgradeMemberModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
weakSelf.headerView.userModel = t_model.user;
weakSelf.memberModel = t_model;
}
[weakSelf.mainTableViewGroup reloadData];
} failure:nil];
}
@end