MOGoldBeanViewController.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. //
  2. // MOGoldBeanViewController.m
  3. // MiMoLive
  4. //
  5. // Created by MiMo on 2025/8/25.
  6. //
  7. #import "MOGoldBeanViewController.h"
  8. #import "MOGoldBeanData.h"
  9. #import "MOGoldBeanItemView.h"
  10. #import "MOExhangeDiamondView.h"
  11. #import "MOExhangeCashView.h"
  12. #import "MOWebViewController.h"
  13. @interface MOGoldBeanViewController ()
  14. @property (nonatomic, strong) UIButton *goldBeanButton;
  15. @property (nonatomic, strong) MOGoldBeanItemView *diamondItemView;
  16. @property (nonatomic, strong) MOGoldBeanItemView *coinItemView;
  17. @property (nonatomic, strong) MOGoldBeanData *dataModel;
  18. @end
  19. @implementation MOGoldBeanViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. [self setupUI];
  23. [self loadData];
  24. }
  25. - (void)loadData {
  26. WEAKSELF
  27. [kHttpManager getGoldBeanInfoWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  28. if (kCode_Success) {
  29. MOLogV(@"getGoldBean: %@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  30. NSDictionary *baseDict = data[@"data"];
  31. MOGoldBeanData *goldBeanData = [MOGoldBeanData modelWithJSON:baseDict];
  32. weakSelf.dataModel = goldBeanData;
  33. [weakSelf.goldBeanButton setTitle:[NSString stringWithFormat:@"%zd", goldBeanData.amount] forState:UIControlStateNormal];
  34. self.coinItemView.hidden = YES;
  35. if (goldBeanData.convertCash) {
  36. self.coinItemView.hidden = NO;
  37. }
  38. self.diamondItemView.hidden = YES;
  39. if (goldBeanData.convertDiamond) {
  40. self.diamondItemView.hidden = NO;
  41. }
  42. }
  43. }];
  44. }
  45. - (void)setupUI {
  46. self.view.backgroundColor = [UIColor clearColor];
  47. [self.view addSubview:self.goldBeanButton];
  48. [self.goldBeanButton mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.top.mas_equalTo(20);
  50. make.height.mas_equalTo(37);
  51. make.left.mas_equalTo(10);
  52. make.right.mas_equalTo(-10);
  53. }];
  54. [self.view addSubview:self.diamondItemView];
  55. [self.diamondItemView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.top.equalTo(self.goldBeanButton.mas_bottom).offset(20);
  57. make.left.mas_equalTo(12);
  58. make.right.mas_equalTo(-12);
  59. make.height.mas_equalTo(60);
  60. }];
  61. [self.view addSubview:self.coinItemView];
  62. [self.coinItemView mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.top.equalTo(self.diamondItemView.mas_bottom).offset(8);
  64. make.left.mas_equalTo(12);
  65. make.right.mas_equalTo(-12);
  66. make.height.mas_equalTo(60);
  67. }];
  68. }
  69. //兑换钻石
  70. - (void)diamondItemViewAction {
  71. MOExhangeDiamondView *exchangeDiamondView = [[MOExhangeDiamondView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT)];
  72. WEAKSELF
  73. exchangeDiamondView.exchangeSuccessBlock = ^{
  74. [weakSelf loadData];
  75. if (weakSelf.exchangeSuccessBlock) {
  76. weakSelf.exchangeSuccessBlock();
  77. }
  78. };
  79. exchangeDiamondView.dataModel = self.dataModel;
  80. [exchangeDiamondView show];
  81. }
  82. //收益改变
  83. - (void)coinItemViewAction {
  84. if (self.dataModel.needBindBankCard) {
  85. MOWebViewController *vc = [[MOWebViewController alloc] init];
  86. NSString *urlStr = [NSString stringWithFormat:@"%@/#/withdrawCenterIndex",kNetPath_Web_Base];
  87. vc.webUrl = [NSURL URLWithString:urlStr];
  88. vc.hidesBottomBarWhenPushed = YES;
  89. [self.navigationController mo_pushViewController:vc animated:YES];
  90. WEAKSELF
  91. vc.closeViewBlock = ^{
  92. [weakSelf loadData];
  93. };
  94. return;
  95. }
  96. MOExhangeCashView *exchangeCashView = [[MOExhangeCashView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT)];
  97. WEAKSELF
  98. exchangeCashView.exchangeSuccessBlock = ^{
  99. [weakSelf loadData];
  100. };
  101. exchangeCashView.dataModel = self.dataModel;
  102. [exchangeCashView show];
  103. }
  104. - (UIButton *)goldBeanButton {
  105. if (!_goldBeanButton) {
  106. _goldBeanButton = [[UIButton alloc] init];
  107. [_goldBeanButton setImage:[UIImage imageNamed:@"icon_gold_bean"] forState:UIControlStateNormal];
  108. _goldBeanButton.titleLabel.font = [MOTextTools poppinsSemiBoldFont:30];
  109. [_goldBeanButton setTitleColor:kBaseTextColor_1 forState:UIControlStateNormal];
  110. _goldBeanButton.userInteractionEnabled = NO;
  111. _goldBeanButton.titleLabel.adjustsFontSizeToFitWidth = YES;
  112. }
  113. return _goldBeanButton;
  114. }
  115. - (MOGoldBeanItemView *)diamondItemView {
  116. if (!_diamondItemView) {
  117. _diamondItemView = [[MOGoldBeanItemView alloc] initWithIconName:@"icon_gold_diamond" title:NSLocalString(@"A90002")];
  118. _diamondItemView.userInteractionEnabled = YES;
  119. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(diamondItemViewAction)];
  120. [_diamondItemView addGestureRecognizer:tap];
  121. }
  122. return _diamondItemView;
  123. }
  124. - (MOGoldBeanItemView *)coinItemView {
  125. if (!_coinItemView) {
  126. _coinItemView = [[MOGoldBeanItemView alloc] initWithIconName:@"icon_gold_coin" title:NSLocalString(@"A90003")];
  127. _coinItemView.userInteractionEnabled = YES;
  128. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(coinItemViewAction)];
  129. [_coinItemView addGestureRecognizer:tap];
  130. }
  131. return _coinItemView;
  132. }
  133. @end