XYWalletViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. //
  2. // XYWalletViewController.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2019/12/23.
  6. // Copyright © 2019 翟玉磊. All rights reserved.
  7. //
  8. #import "XYWalletViewController.h"
  9. #import "XYRechargeItemsViewController.h"
  10. #import "XYCoinDetailViewController.h"
  11. #import "XYWalletListViewModel.h"
  12. #import "XYWalletListTableViewCell.h"
  13. #import "XYWalletListCellModel.h"
  14. #import "XYWithdrawViewController.h"
  15. #import "XYWalletVirtualCoinListTableViewCell.h"
  16. #import "XYWalletBankListViewController.h"
  17. #import "XYBankIdentityCardVerIfyViewController.h"
  18. #import "XYWalletStartAddBankCardViewController.h"
  19. #import "XYNewWithdrawViewController.h"
  20. @interface XYWalletViewController ()<XYWalletListTableViewCellDelegate>
  21. @property (nonatomic, readwrite, strong) XYWalletListViewModel *viewModel;
  22. @end
  23. @implementation XYWalletViewController
  24. /// 重写init方法,配置你想要的属性
  25. - (instancetype)init
  26. {
  27. self = [super init];
  28. if (self) {
  29. }
  30. return self;
  31. }
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. /// 设置
  35. [self _setup];
  36. /// 设置导航栏
  37. [self _setupNavigationItem];
  38. /// 设置子控件
  39. [self _setupSubViews];
  40. /// 布局子空间
  41. [self _makeSubViewsConstraints];
  42. }
  43. - (void)viewWillAppear:(BOOL)animated {
  44. [super viewWillAppear:animated];
  45. [self tableViewDidTriggerHeaderRefresh];
  46. }
  47. #pragma mark — Override
  48. - (void)bindViewModel {
  49. self.viewModel = [XYWalletListViewModel new];
  50. }
  51. - (void)tableViewDidTriggerHeaderRefresh {
  52. [self.viewModel loadData:^(id responseModel) {
  53. [self tableViewDidFinishTriggerHeader:YES reload:YES];
  54. [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:@"" offsetTop:200 hasData:self.viewModel.dataSource.count>0 hasError:NO reloadBlock:nil];
  55. } failure:^(NSError *error) {
  56. [self tableViewDidFinishTriggerHeader:YES reload:YES];
  57. [self.tableView zyl_configEmptyViewWithType:ZYLEmptyDataViewTypeDefault emptyInfo:@"" errorInfo:error.domain offsetTop:200 hasData:self.viewModel.dataSource.count>0 hasError:error!=nil reloadBlock:nil];
  58. }];
  59. }
  60. - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  61. XYWalletListCellModel *model = self.viewModel.dataSource[indexPath.row];
  62. if (model.walletType == Wallet_Type_Star_Virtual) {
  63. return [XYWalletVirtualCoinListTableViewCell cellWithTableView:tableView];
  64. }
  65. return [XYWalletListTableViewCell cellWithTableView:tableView];
  66. }
  67. - (void)configureCell:(XYWalletListTableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  68. XYWalletListCellModel *model = self.viewModel.dataSource[indexPath.row];
  69. [cell configureModel:object];
  70. [cell setIndexPath:indexPath rowsInSection:self.viewModel.dataSource.count];
  71. if (model.walletType != Wallet_Type_Star_Virtual) {
  72. cell.delegate = self;
  73. }
  74. }
  75. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  76. XYWalletListCellModel *model = self.viewModel.dataSource[indexPath.row];
  77. return model.cellHeight;
  78. }
  79. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  80. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  81. XYWalletListCellModel *model = self.viewModel.dataSource[indexPath.row];
  82. if (model.walletType == Wallet_Type_Star_Virtual) {
  83. BaseWebViewController *controller = [BaseWebViewController new];
  84. controller.requestUrl = [XYAppConfigModel getUrlVirtualCoin];
  85. [self.navigationController pushViewController:controller animated:YES];
  86. }
  87. }
  88. #pragma mark — XYWalletListTableViewCellDelegate
  89. - (void)operationActionAtIndex:(NSIndexPath *)indexPath {
  90. XYWalletListCellModel *model = self.viewModel.dataSource[indexPath.row];
  91. switch (model.walletType) {
  92. case Wallet_Type_Star_Diamond:
  93. // 充值
  94. [self.navigationController pushViewController:XYRechargeItemsViewController.new animated:YES];
  95. break;
  96. case Wallet_Type_Star_Coin:
  97. // 转出
  98. [self.navigationController pushViewController:XYWithdrawViewController.new animated:YES];
  99. break;
  100. case Wallet_Type_Star_Yuan:
  101. // 兑换
  102. {
  103. NSString *url = [XYAppConfigModel getUrlCoinShop];
  104. if (StringIsNotEmpty(url)) {
  105. BaseWebViewController *controller = [BaseWebViewController new];
  106. controller.requestUrl = url;
  107. [self.navigationController pushViewController:controller animated:YES];
  108. }
  109. }
  110. break;
  111. case Wallet_Type_Star_Dust:
  112. // 星尘提现
  113. {
  114. if ([XYUserInfoManager nowUser].isAuth && [XYUserInfoManager nowUser].isBankcardBind) {
  115. [self withdrawalDust];
  116. }else {
  117. [[XYUserAPIManager new] getProfileSuccessHandler:^(ZYLResponseModel *responseModel) {
  118. [self withdrawalDust];
  119. } failureHandler:^(ZYLNetworkError *error) {
  120. }];
  121. }
  122. }
  123. break;
  124. case Wallet_Type_Gold_Coin:
  125. // 兑换商城
  126. {
  127. BaseWebViewController *controller = [BaseWebViewController new];
  128. controller.requestUrl = [XYAppConfigModel getUrlCoinShop];
  129. [self.navigationController pushViewController:controller animated:YES];
  130. }
  131. break;
  132. default:
  133. break;
  134. }
  135. }
  136. - (void)otherOperationActionAtIndex:(NSIndexPath *)indexPath {
  137. XYWalletListCellModel *model = self.viewModel.dataSource[indexPath.row];
  138. switch (model.walletType) {
  139. case Wallet_Type_Star_Dust:
  140. {
  141. if (![XYUserInfoManager nowUser].isAuth) {
  142. CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:kLocalizedString(@"提示") message:kLocalizedString(@"使用兑换功能,需要实名认证。") sure:kLocalizedString(@"去认证") cancel:kLocalizedString(@"放弃") selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
  143. if ([title isEqualToString:kLocalizedString(@"去认证")]) {
  144. XYBankIdentityCardVerIfyViewController *controller = XYBankIdentityCardVerIfyViewController.new;
  145. controller.targetAction = 3;
  146. [self.navigationController pushViewController:controller animated:YES];
  147. }
  148. }];
  149. [al show];
  150. }else {
  151. NSString *url = ApplicationDelegate.appConfigModel.transDiamondUrl;
  152. if (StringIsNotEmpty(url)) {
  153. BaseWebViewController *controller = [BaseWebViewController new];
  154. controller.requestUrl = url;
  155. [self.navigationController pushViewController:controller animated:YES];
  156. }
  157. }
  158. }
  159. break;
  160. default:
  161. break;
  162. }
  163. }
  164. - (void)withdrawalDust {
  165. if (![XYUserInfoManager nowUser].isAuth) {
  166. CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:kLocalizedString(@"提示") message:kLocalizedString(@"使用转出功能,需要实名认证。") sure:kLocalizedString(@"去认证") cancel:kLocalizedString(@"放弃") selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
  167. if ([title isEqualToString:kLocalizedString(@"去认证")]) {
  168. XYBankIdentityCardVerIfyViewController *controller = XYBankIdentityCardVerIfyViewController.new;
  169. controller.targetAction = 1;
  170. [self.navigationController pushViewController:controller animated:YES];
  171. }
  172. }];
  173. [al show];
  174. return;
  175. }
  176. if (![XYUserInfoManager nowUser].isBankcardBind) {
  177. CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:kLocalizedString(@"提示") message:kLocalizedString(@"使用转出功能需添加一张支持提现的储蓄卡") sure:kLocalizedString(@"添加储蓄卡") cancel:kLocalizedString(@"取消") selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
  178. if ([title isEqualToString:kLocalizedString(@"添加储蓄卡")]) {
  179. XYWalletStartAddBankCardViewController * controller = XYWalletStartAddBankCardViewController.new;
  180. controller.targetAction = 1;
  181. [self.navigationController pushViewController:controller animated:YES];
  182. }
  183. }];
  184. [al show];
  185. return;
  186. }
  187. // 提现界面
  188. XYNewWithdrawViewController *controller = XYNewWithdrawViewController.new;
  189. [self.navigationController pushViewController:controller animated:YES];
  190. }
  191. - (void)lookDetailActionAtIndex:(NSIndexPath *)indexPath {
  192. XYWalletListCellModel *model = self.viewModel.dataSource[indexPath.row];
  193. XYCoinDetailViewController *controller = XYCoinDetailViewController.new;
  194. controller.wallet_Type = model.walletType;
  195. [self.navigationController pushViewController:controller animated:YES];
  196. }
  197. #pragma mark - 事件处理Or辅助方法
  198. - (void)rightButtonAction:(id)sender {
  199. if ([XYUserInfoManager nowUser].isAuth) {
  200. [self.navigationController pushViewController:XYWalletBankListViewController.new animated:YES];
  201. }else {
  202. [[XYUserAPIManager new] getProfileSuccessHandler:^(ZYLResponseModel *responseModel) {
  203. CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:kLocalizedString(@"提示") message:kLocalizedString(@"绑定银行卡需要实名认证") sure:kLocalizedString(@"去认证") cancel:kLocalizedString(@"放弃") selctedBlock:^(NSInteger index, NSString * _Nonnull title) {
  204. if ([title isEqualToString:kLocalizedString(@"去认证")]) {
  205. [self.navigationController pushViewController:XYBankIdentityCardVerIfyViewController.new animated:YES];
  206. }
  207. }];
  208. [al show];
  209. } failureHandler:^(ZYLNetworkError *error) {
  210. }];
  211. }
  212. }
  213. #pragma mark - 初始化
  214. - (void)_setup{
  215. self.navigationItem.title = kLocalizedString(@"我的钱包");
  216. }
  217. #pragma mark - 设置导航栏
  218. - (void)_setupNavigationItem{
  219. if (![AppDelegate sharedDelegate].isVersionStatus) {
  220. self.navigationItem.rightBarButtonItem = [UIBarButtonItem systemItemWithTitle:kLocalizedString(@"银行卡") titleColor:Color_TextFont imageName:nil target:self selector:@selector(rightButtonAction:) textType:YES];
  221. }
  222. }
  223. #pragma mark - 设置子控件
  224. - (void)_setupSubViews{
  225. }
  226. #pragma mark - 布局子控件
  227. - (void)_makeSubViewsConstraints{
  228. }
  229. #pragma mark - Setter & Getter
  230. @end