YMAccountBalancePayMethodView.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // YMAccountBalancePayMethodView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/28.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMAccountBalancePayMethodView.h"
  9. #import "YMAccountBalanceViewModel.h"
  10. #import "YMAccountBalancePayMethodCell.h"
  11. @interface YMAccountBalancePayMethodView ()<UITableViewDataSource, UITableViewDelegate>
  12. /// 账户余额VM
  13. @property (nonatomic, strong) YMAccountBalanceViewModel *viewModel;
  14. /// 支付方式提示标签
  15. @property (nonatomic, strong) UILabel *payMethodTipsLb;
  16. /// 容器列表
  17. @property (nonatomic, strong) UITableView *contentTableView;
  18. @end
  19. @implementation YMAccountBalancePayMethodView
  20. - (void)ym_setupViews{
  21. self.backgroundColor = UIColor.clearColor;
  22. [self addSubview:self.payMethodTipsLb];
  23. [self addSubview:self.contentTableView];
  24. [self setNeedsUpdateConstraints];
  25. [self updateConstraintsIfNeeded];
  26. }
  27. - (void)updateConstraints{
  28. [self.payMethodTipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.top.equalTo(self).offset(adapt(10));
  30. make.left.equalTo(self).offset(adapt(10));
  31. }];
  32. [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.top.equalTo(self.payMethodTipsLb.mas_bottom).offset(adapt(10));
  34. make.left.equalTo(self);
  35. make.right.equalTo(self);
  36. make.bottom.equalTo(self).offset(adapt(-10));
  37. }];
  38. [super updateConstraints];
  39. }
  40. - (void)ym_bindViewModel:(YMAccountBalanceViewModel *)viewModel{
  41. if (!viewModel) {
  42. return;
  43. }
  44. _viewModel = viewModel;
  45. @weakify(self)
  46. [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  47. @strongify(self)
  48. [self.contentTableView reloadData];
  49. [self.contentTableView layoutIfNeeded];
  50. //刷新高度
  51. CGFloat contentTableViewHeight = self.contentTableView.contentSize.height;
  52. [self.contentTableView mas_updateConstraints:^(MASConstraintMaker *make) {
  53. make.height.mas_equalTo(contentTableViewHeight);
  54. }];
  55. ///默认选中
  56. if ([YMGlobalUtils shared].payMethodDataArray.count > 0) {
  57. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
  58. [self.contentTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
  59. [self tableView:self.contentTableView didSelectRowAtIndexPath:indexPath];
  60. }
  61. }];
  62. }
  63. #pragma mark - UITableViewDataSource
  64. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  65. return 1;
  66. }
  67. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  68. return [YMGlobalUtils shared].payMethodDataArray.count;
  69. }
  70. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  71. YMAccountBalancePayMethodCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMAccountBalancePayMethodCell class])];
  72. if (!cell) {
  73. cell = [[YMAccountBalancePayMethodCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMAccountBalancePayMethodCell class])];
  74. }
  75. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  76. [cell ym_bindViewModel:[YMGlobalUtils shared].payMethodDataArray[indexPath.item]];
  77. return cell;
  78. }
  79. #pragma mark - UITableViewDelegate
  80. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  81. return adapt(50);
  82. }
  83. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  84. return nil;
  85. }
  86. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  87. return CGFLOAT_MIN;
  88. }
  89. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  90. return nil;
  91. }
  92. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  93. return CGFLOAT_MIN;
  94. }
  95. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  96. [self.viewModel.selectedPayMethodTypeSubject sendNext:[YMGlobalUtils shared].payMethodDataArray[indexPath.item].payCode];
  97. }
  98. - (UILabel *)payMethodTipsLb{
  99. if (!_payMethodTipsLb) {
  100. _payMethodTipsLb = [[UILabel alloc]init];
  101. _payMethodTipsLb.font = LCFont(11);
  102. _payMethodTipsLb.textColor = HexColorFromRGB(0x000000);
  103. _payMethodTipsLb.textAlignment = NSTextAlignmentLeft;
  104. _payMethodTipsLb.text = @"请选择支付方式:";
  105. }
  106. return _payMethodTipsLb;
  107. }
  108. - (UITableView *)contentTableView{
  109. if (!_contentTableView) {
  110. _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  111. _contentTableView.delegate = self;
  112. _contentTableView.dataSource = self;
  113. _contentTableView.estimatedRowHeight = 0;
  114. _contentTableView.estimatedSectionHeaderHeight = 0;
  115. _contentTableView.estimatedSectionFooterHeight = 0;
  116. _contentTableView.showsVerticalScrollIndicator = NO;
  117. _contentTableView.showsHorizontalScrollIndicator = NO;
  118. _contentTableView.separatorColor = UIColor.clearColor;
  119. _contentTableView.backgroundColor = UIColor.clearColor;
  120. _contentTableView.scrollEnabled = NO;
  121. [_contentTableView registerClass:[YMAccountBalancePayMethodCell class] forCellReuseIdentifier:NSStringFromClass([YMAccountBalancePayMethodCell class])];
  122. }
  123. return _contentTableView;
  124. }
  125. @end