123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- //
- // YMAccountBalancePayMethodView.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/28.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMAccountBalancePayMethodView.h"
- #import "YMAccountBalanceViewModel.h"
- #import "YMAccountBalancePayMethodCell.h"
- @interface YMAccountBalancePayMethodView ()<UITableViewDataSource, UITableViewDelegate>
- /// 账户余额VM
- @property (nonatomic, strong) YMAccountBalanceViewModel *viewModel;
- /// 支付方式提示标签
- @property (nonatomic, strong) UILabel *payMethodTipsLb;
- /// 容器列表
- @property (nonatomic, strong) UITableView *contentTableView;
- @end
- @implementation YMAccountBalancePayMethodView
- - (void)ym_setupViews{
- self.backgroundColor = UIColor.clearColor;
- [self addSubview:self.payMethodTipsLb];
- [self addSubview:self.contentTableView];
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints{
-
- [self.payMethodTipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(adapt(10));
- make.left.equalTo(self).offset(adapt(10));
- }];
-
- [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.payMethodTipsLb.mas_bottom).offset(adapt(10));
- make.left.equalTo(self);
- make.right.equalTo(self);
- make.bottom.equalTo(self).offset(adapt(-10));
- }];
-
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(YMAccountBalanceViewModel *)viewModel{
- if (!viewModel) {
- return;
- }
-
- _viewModel = viewModel;
-
- @weakify(self)
- [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
- @strongify(self)
- [self.contentTableView reloadData];
- [self.contentTableView layoutIfNeeded];
- //刷新高度
- CGFloat contentTableViewHeight = self.contentTableView.contentSize.height;
- [self.contentTableView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(contentTableViewHeight);
- }];
- ///默认选中
- if ([YMGlobalUtils shared].payMethodDataArray.count > 0) {
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
- [self.contentTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
- [self tableView:self.contentTableView didSelectRowAtIndexPath:indexPath];
- }
- }];
-
-
- }
- #pragma mark - UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [YMGlobalUtils shared].payMethodDataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- YMAccountBalancePayMethodCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMAccountBalancePayMethodCell class])];
- if (!cell) {
- cell = [[YMAccountBalancePayMethodCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMAccountBalancePayMethodCell class])];
- }
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- [cell ym_bindViewModel:[YMGlobalUtils shared].payMethodDataArray[indexPath.item]];
- return cell;
- }
- #pragma mark - UITableViewDelegate
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return adapt(50);
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
- return nil;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- return nil;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [self.viewModel.selectedPayMethodTypeSubject sendNext:[YMGlobalUtils shared].payMethodDataArray[indexPath.item].payCode];
- }
- - (UILabel *)payMethodTipsLb{
- if (!_payMethodTipsLb) {
- _payMethodTipsLb = [[UILabel alloc]init];
- _payMethodTipsLb.font = LCFont(11);
- _payMethodTipsLb.textColor = HexColorFromRGB(0x000000);
- _payMethodTipsLb.textAlignment = NSTextAlignmentLeft;
- _payMethodTipsLb.text = @"请选择支付方式:";
- }
- return _payMethodTipsLb;
- }
- - (UITableView *)contentTableView{
- if (!_contentTableView) {
- _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
- _contentTableView.delegate = self;
- _contentTableView.dataSource = self;
- _contentTableView.estimatedRowHeight = 0;
- _contentTableView.estimatedSectionHeaderHeight = 0;
- _contentTableView.estimatedSectionFooterHeight = 0;
- _contentTableView.showsVerticalScrollIndicator = NO;
- _contentTableView.showsHorizontalScrollIndicator = NO;
- _contentTableView.separatorColor = UIColor.clearColor;
- _contentTableView.backgroundColor = UIColor.clearColor;
- _contentTableView.scrollEnabled = NO;
- [_contentTableView registerClass:[YMAccountBalancePayMethodCell class] forCellReuseIdentifier:NSStringFromClass([YMAccountBalancePayMethodCell class])];
- }
- return _contentTableView;
- }
- @end
|