XYPersonalCenterWalletTableViewCell.m 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. //
  2. // XYPersonalCenterWalletTableViewCell.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/5/19.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYPersonalCenterWalletTableViewCell.h"
  9. #import "XYRechargeItemsViewController.h"
  10. #import "XYPersonalCenterHeaderItemView.h"
  11. #import "XYWalletViewController.h"
  12. @interface XYPersonalCenterWalletTableViewCell ()
  13. @property (nonatomic, strong) UILabel *titleLabel;
  14. @property (nonatomic, strong) UILabel *balanceLabel;
  15. @property (nonatomic, strong) UIButton *rechargeButton;
  16. @property (nonatomic, strong) UIView *line;
  17. @property (nonatomic, strong) UILabel *starYuanLabel;
  18. @property (nonatomic, strong) UIButton *detailsButton;
  19. @property (nonatomic, strong) NSMutableArray *itemViews;
  20. @end
  21. @implementation XYPersonalCenterWalletTableViewCell
  22. #pragma mark — Public
  23. + (instancetype)cellWithTableView:(UITableView *)tableView {
  24. static NSString * const cellId = @"XYPersonalCenterWalletTableViewCell";
  25. XYPersonalCenterWalletTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  26. if (cell == nil) {
  27. cell = [[XYPersonalCenterWalletTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
  28. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  29. }
  30. return cell;
  31. }
  32. - (void)configureModel:(id)model {
  33. self.titleLabel.text = [NSString stringWithFormat:kLocalizedString(@"我的%@"), @"钱包"/*App_CoinName(Wallet_Type_Star_Diamond)*/];
  34. if ([XYUserInfoManager nowUser]) {
  35. self.balanceLabel.text = [NSString stringWithFormat:@"%@", [XYUserInfoManager nowUser].coinBalance];
  36. self.starYuanLabel.text = [NSString stringWithFormat:@"%@ %@", App_CoinName(Wallet_Type_Star_Dust), [XYUserInfoManager nowUser].dustBalance];
  37. }else {
  38. self.balanceLabel.text = @"0";
  39. self.starYuanLabel.text = [NSString stringWithFormat:@"%@ %@", App_CoinName(Wallet_Type_Star_Dust), @"0"];
  40. }
  41. for (UIView *view in self.itemViews) {
  42. [view removeFromSuperview];
  43. }
  44. [self.itemViews removeAllObjects];
  45. int itemCount = 3;
  46. CGFloat width = (self.f_width) / itemCount;
  47. CGFloat y = 44;
  48. for (NSInteger i = 0; i < itemCount; i++) {
  49. XYPersonalCenterHeaderItemView *item = [[XYPersonalCenterHeaderItemView alloc] initWithFrame:CGRectMake(width * i, y, width, 44.0f)];
  50. item.lineView.image = ImageNamed(@"icon_anchor_head_line");
  51. item.tag = i;
  52. switch (i) {
  53. case 0:
  54. [item setupTitle:[NSString stringWithFormat:@"%@余额",App_CoinName(Wallet_Type_Star_Diamond)] content:[HandleString caluteWValue:[[XYUserInfoManager nowUser].coinBalance integerValue]]];
  55. break;
  56. case 1:
  57. [item setupTitle:[NSString stringWithFormat:@"%@余额",App_CoinName(Wallet_Type_Star_Dust)] content:[HandleString caluteWValue:[[XYUserInfoManager nowUser].dustBalance integerValue]]];
  58. break;
  59. case 2:
  60. [item setupTitle:[NSString stringWithFormat:@"%@余额",App_CoinName(Wallet_Type_Gold_Coin)] content:[HandleString caluteWValue:[[XYUserInfoManager nowUser].goldBalance integerValue]]];
  61. item.lineView.hidden = YES;
  62. break;
  63. default:
  64. break;
  65. }
  66. [self.contentView addSubview:item];
  67. [self.itemViews addObject:item];
  68. WeakSelf
  69. [item setItemClickActionBlock:^(NSInteger index) {
  70. if (index == 0) {
  71. [StatisticsManager event:@"my_wealth_diamond_click"];
  72. }else if (index == 1){
  73. [StatisticsManager event:@"my_wealth_pinkdiamond_click"];
  74. }else if (index == 2){
  75. [StatisticsManager event:@"my_wealth_goldcoin_click"];
  76. }
  77. XYWalletViewController *vc = [[XYWalletViewController alloc] init];
  78. [[AppDelegate sharedDelegate].getCurrentController.navigationController pushViewController:vc animated:YES];
  79. }];
  80. }
  81. }
  82. - (void)setIndexPath:(NSIndexPath *)indexPath rowsInSection:(NSInteger)rows {
  83. }
  84. #pragma mark — Action
  85. - (void)rechargeButtonAction:(id)sender {
  86. // 我的Tab,点我的钻石-[充值]的次数
  87. [StatisticsManager event:@"my_wealth_recharge_click"];
  88. [[ApplicationDelegate getCurrentController].navigationController pushViewController:XYRechargeItemsViewController.new animated:YES];
  89. }
  90. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  91. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  92. [self _setup];
  93. [self _setupSubViews];
  94. [self _makeSubViewsConstraint];
  95. }
  96. return self;
  97. }
  98. #pragma mark - 配置属性
  99. - (void)_setup {
  100. }
  101. #pragma mark - 设置子控件
  102. - (void)_setupSubViews {
  103. [self.contentView addSubview:self.titleLabel];
  104. [self.contentView addSubview:self.balanceLabel];
  105. [self.contentView addSubview:self.rechargeButton];
  106. [self.contentView addSubview:self.line];
  107. [self.contentView addSubview:self.starYuanLabel];
  108. [self.contentView addSubview:self.detailsButton];
  109. }
  110. #pragma mark - 布局子控件
  111. - (void)_makeSubViewsConstraint {
  112. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.left.equalTo(self.contentView).offset(SPACING_EDGE);
  114. make.top.equalTo(self.contentView).offset(14.0f);
  115. make.height.equalTo(@17.0f);
  116. }];
  117. [self.balanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.left.equalTo(self.contentView).offset(SPACING_EDGE);
  119. make.top.equalTo(self.titleLabel.mas_bottom).offset(7.0f);
  120. make.height.equalTo(@33.0f);
  121. make.right.equalTo(self.rechargeButton.mas_left).offset(-10.0f);
  122. }];
  123. [self.rechargeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  124. make.right.equalTo(self.contentView).offset(-15.0f);
  125. make.centerY.equalTo(self.balanceLabel);
  126. make.width.equalTo(@60.0f);
  127. make.height.equalTo(@28.0f);
  128. }];
  129. [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
  130. make.left.equalTo(self.contentView).offset(9.0f);
  131. make.right.equalTo(self.contentView).offset(-9.0f);
  132. make.top.equalTo(self.balanceLabel.mas_bottom).offset(13.0f);
  133. make.height.equalTo(@(LINE_HEIGHT));
  134. }];
  135. [self.starYuanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  136. make.left.equalTo(self.contentView).offset(SPACING_EDGE);
  137. make.top.equalTo(self.line.mas_bottom).offset(11.0f);
  138. make.height.equalTo(@18.0f);
  139. make.right.equalTo(self.detailsButton.mas_left).offset(-10.0f);
  140. }];
  141. [self.detailsButton mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.right.equalTo(self.contentView).offset(-SPACING_EDGE);
  143. make.centerY.equalTo(self.titleLabel);
  144. make.height.equalTo(@30.0f);
  145. make.width.equalTo(@80.0f);
  146. }];
  147. [self.rechargeButton addViewBorder:Color_TextRed redian:14.0f];
  148. [self.detailsButton buttonDistance:7.0f direction:right];
  149. }
  150. #pragma mark - Getter/Setter
  151. - (UILabel *)titleLabel {
  152. if (!_titleLabel) {
  153. _titleLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font_B(14)];
  154. _titleLabel.text = [NSString stringWithFormat:kLocalizedString(@"我的%@"), @"钱包"/*App_CoinName(Wallet_Type_Star_Diamond)*/];
  155. }
  156. return _titleLabel;
  157. }
  158. - (UILabel *)balanceLabel {
  159. if (!_balanceLabel) {
  160. _balanceLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font_B(24)];
  161. _balanceLabel.text = [XYUserInfoManager nowUser].coinBalance;
  162. _balanceLabel.hidden = YES;
  163. }
  164. return _balanceLabel;
  165. }
  166. - (UIButton *)rechargeButton {
  167. if (!_rechargeButton) {
  168. _rechargeButton = [UIButton createButtonTextColor:Color_TextRed textFont:Font(12)];
  169. [_rechargeButton setTitle:kLocalizedString(@"充值") forState:UIControlStateNormal];
  170. [_rechargeButton addTarget:self action:@selector(rechargeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  171. _rechargeButton.hidden = YES;
  172. }
  173. return _rechargeButton;
  174. }
  175. - (UIView *)line {
  176. if (!_line) {
  177. _line = [UIView new];
  178. _line.backgroundColor = Color_line;
  179. _line.hidden = YES;
  180. }
  181. return _line;
  182. }
  183. - (UILabel *)starYuanLabel {
  184. if (!_starYuanLabel) {
  185. _starYuanLabel = [UILabel createLabelTextColor:Color_Nakaguro fount:Font(13)];
  186. _starYuanLabel.hidden = YES;
  187. }
  188. return _starYuanLabel;
  189. }
  190. - (UIButton *)detailsButton {
  191. if (!_detailsButton) {
  192. _detailsButton = [UIButton createButtonTextColor:Color_TextGray textFont:Font(12)];
  193. [_detailsButton setTitle:kLocalizedString(@" ") forState:UIControlStateNormal];
  194. [_detailsButton setImage:arrowMore() forState:UIControlStateNormal];
  195. _detailsButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  196. _detailsButton.userInteractionEnabled = NO;
  197. }
  198. return _detailsButton;
  199. }
  200. - (NSMutableArray *)itemViews{
  201. if (_itemViews == nil) {
  202. _itemViews = [[NSMutableArray alloc] init];
  203. }
  204. return _itemViews;
  205. }
  206. @end