123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- //
- // XYWalletViewController.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2019/12/23.
- // Copyright © 2019 翟玉磊. All rights reserved.
- //
- #import "XYWalletViewController.h"
- #import "XYRechargeItemsViewController.h"
- #import "XYCoinDetailViewController.h"
- #import "XYWalletListViewModel.h"
- #import "XYWalletListTableViewCell.h"
- #import "XYWalletListCellModel.h"
- #import "XYWithdrawViewController.h"
- #import "XYWalletVirtualCoinListTableViewCell.h"
- #import "XYWalletBankListViewController.h"
- #import "XYBankIdentityCardVerIfyViewController.h"
- #import "XYWalletStartAddBankCardViewController.h"
- #import "XYNewWithdrawViewController.h"
- @interface XYWalletViewController ()<XYWalletListTableViewCellDelegate>
- @property (nonatomic, readwrite, strong) XYWalletListViewModel *viewModel;
- @end
- @implementation XYWalletViewController
- /// 重写init方法,配置你想要的属性
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- /// 设置
- [self _setup];
-
- /// 设置导航栏
- [self _setupNavigationItem];
-
- /// 设置子控件
- [self _setupSubViews];
-
- /// 布局子空间
- [self _makeSubViewsConstraints];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- [self tableViewDidTriggerHeaderRefresh];
- }
- #pragma mark — Override
- - (void)bindViewModel {
- self.viewModel = [XYWalletListViewModel new];
- }
- - (void)tableViewDidTriggerHeaderRefresh {
- [self.viewModel loadData:^(id responseModel) {
- [self tableViewDidFinishTriggerHeader:YES reload:YES];
- [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:@"" offsetTop:200 hasData:self.viewModel.dataSource.count>0 hasError:NO reloadBlock:nil];
- } failure:^(NSError *error) {
- [self tableViewDidFinishTriggerHeader:YES reload:YES];
- [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:error.domain offsetTop:200 hasData:self.viewModel.dataSource.count>0 hasError:error!=nil reloadBlock:nil];
- }];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
- XYWalletListCellModel *model = self.viewModel.dataSource[indexPath.row];
- if (model.walletType == Wallet_Type_Star_Virtual) {
- return [XYWalletVirtualCoinListTableViewCell cellWithTableView:tableView];
- }
- return [XYWalletListTableViewCell cellWithTableView:tableView];
- }
- - (void)configureCell:(XYWalletListTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
- XYWalletListCellModel *model = self.viewModel.dataSource[indexPath.row];
- [cell configureModel:object];
- [cell setIndexPath:indexPath rowsInSection:self.viewModel.dataSource.count];
- if (model.walletType != Wallet_Type_Star_Virtual) {
- cell.delegate = self;
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- XYWalletListCellModel *model = self.viewModel.dataSource[indexPath.row];
- return model.cellHeight;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- XYWalletListCellModel *model = self.viewModel.dataSource[indexPath.row];
- if (model.walletType == Wallet_Type_Star_Virtual) {
- BaseWebViewController *controller = [BaseWebViewController new];
- controller.requestUrl = [XYAppConfigModel getUrlVirtualCoin];
- [self.navigationController pushViewController:controller animated:YES];
- }
- }
- #pragma mark — XYWalletListTableViewCellDelegate
- - (void)operationActionAtIndex:(NSIndexPath *)indexPath {
- XYWalletListCellModel *model = self.viewModel.dataSource[indexPath.row];
- switch (model.walletType) {
- case Wallet_Type_Star_Diamond:
- // 充值
- [self.navigationController pushViewController:XYRechargeItemsViewController.new animated:YES];
- break;
- case Wallet_Type_Star_Coin:
- // 转出
- [self.navigationController pushViewController:XYWithdrawViewController.new animated:YES];
- break;
- case Wallet_Type_Star_Yuan:
- // 兑换
- {
- NSString *url = [XYAppConfigModel getUrlCoinShop];
- if (StringIsNotEmpty(url)) {
- BaseWebViewController *controller = [BaseWebViewController new];
- controller.requestUrl = url;
- [self.navigationController pushViewController:controller animated:YES];
- }
- }
- break;
- case Wallet_Type_Star_Dust:
- // 星尘提现
- {
- if ([XYUserInfoManager nowUser].isAuth && [XYUserInfoManager nowUser].isBankcardBind) {
- [self withdrawalDust];
- }else {
- [[XYUserAPIManager new] getProfileSuccessHandler:^(ZYLResponseModel *responseModel) {
- [self withdrawalDust];
- } failureHandler:^(ZYLNetworkError *error) {
-
- }];
- }
- }
- break;
- case Wallet_Type_Gold_Coin:
- // 兑换商城
- {
- BaseWebViewController *controller = [BaseWebViewController new];
- controller.requestUrl = [XYAppConfigModel getUrlCoinShop];
- [self.navigationController pushViewController:controller animated:YES];
- }
- break;
- default:
- break;
- }
- }
- - (void)otherOperationActionAtIndex:(NSIndexPath *)indexPath {
- XYWalletListCellModel *model = self.viewModel.dataSource[indexPath.row];
- switch (model.walletType) {
- case Wallet_Type_Star_Dust:
- {
- if (![XYUserInfoManager nowUser].isAuth) {
- CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:kLocalizedString(@"提示") message:kLocalizedString(@"使用兑换功能,需要实名认证。") sure:kLocalizedString(@"去认证") cancel:kLocalizedString(@"放弃") selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
- if ([title isEqualToString:kLocalizedString(@"去认证")]) {
- XYBankIdentityCardVerIfyViewController *controller = XYBankIdentityCardVerIfyViewController.new;
- controller.targetAction = 3;
- [self.navigationController pushViewController:controller animated:YES];
- }
- }];
- [al show];
- }else {
- NSString *url = ApplicationDelegate.appConfigModel.transDiamondUrl;
- if (StringIsNotEmpty(url)) {
- BaseWebViewController *controller = [BaseWebViewController new];
- controller.requestUrl = url;
- [self.navigationController pushViewController:controller animated:YES];
- }
- }
- }
- break;
-
- default:
- break;
- }
- }
- - (void)withdrawalDust {
- if (![XYUserInfoManager nowUser].isAuth) {
- CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:kLocalizedString(@"提示") message:kLocalizedString(@"使用转出功能,需要实名认证。") sure:kLocalizedString(@"去认证") cancel:kLocalizedString(@"放弃") selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
- if ([title isEqualToString:kLocalizedString(@"去认证")]) {
- XYBankIdentityCardVerIfyViewController *controller = XYBankIdentityCardVerIfyViewController.new;
- controller.targetAction = 1;
- [self.navigationController pushViewController:controller animated:YES];
- }
- }];
- [al show];
- return;
- }
- if (![XYUserInfoManager nowUser].isBankcardBind) {
- CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:kLocalizedString(@"提示") message:kLocalizedString(@"使用转出功能需添加一张支持提现的储蓄卡") sure:kLocalizedString(@"添加储蓄卡") cancel:kLocalizedString(@"取消") selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
- if ([title isEqualToString:kLocalizedString(@"添加储蓄卡")]) {
- XYWalletStartAddBankCardViewController * controller = XYWalletStartAddBankCardViewController.new;
- controller.targetAction = 1;
- [self.navigationController pushViewController:controller animated:YES];
- }
- }];
- [al show];
- return;
- }
- // 提现界面
- XYNewWithdrawViewController *controller = XYNewWithdrawViewController.new;
- [self.navigationController pushViewController:controller animated:YES];
- }
- - (void)lookDetailActionAtIndex:(NSIndexPath *)indexPath {
- XYWalletListCellModel *model = self.viewModel.dataSource[indexPath.row];
- XYCoinDetailViewController *controller = XYCoinDetailViewController.new;
- controller.wallet_Type = model.walletType;
- [self.navigationController pushViewController:controller animated:YES];
- }
- #pragma mark - 事件处理Or辅助方法
- - (void)rightButtonAction:(id)sender {
- if ([XYUserInfoManager nowUser].isAuth) {
- [self.navigationController pushViewController:XYWalletBankListViewController.new animated:YES];
- }else {
- [[XYUserAPIManager new] getProfileSuccessHandler:^(ZYLResponseModel *responseModel) {
- CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:kLocalizedString(@"提示") message:kLocalizedString(@"绑定银行卡需要实名认证") sure:kLocalizedString(@"去认证") cancel:kLocalizedString(@"放弃") selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
- if ([title isEqualToString:kLocalizedString(@"去认证")]) {
- [self.navigationController pushViewController:XYBankIdentityCardVerIfyViewController.new animated:YES];
- }
- }];
- [al show];
- } failureHandler:^(ZYLNetworkError *error) {
-
- }];
- }
- }
- #pragma mark - 初始化
- - (void)_setup{
- self.navigationItem.title = kLocalizedString(@"我的钱包");
- }
- #pragma mark - 设置导航栏
- - (void)_setupNavigationItem{
- if (![AppDelegate sharedDelegate].isVersionStatus) {
- self.navigationItem.rightBarButtonItem = [UIBarButtonItem systemItemWithTitle:kLocalizedString(@"银行卡") titleColor:Color_TextFont imageName:nil target:self selector:@selector(rightButtonAction:) textType:YES];
- }
- }
- #pragma mark - 设置子控件
- - (void)_setupSubViews{
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraints{
- }
- #pragma mark - Setter & Getter
- @end
|