YMMyEarningsWithdrawalAmountView.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // YMMyEarningsWithdrawalAmountView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/29.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMMyEarningsWithdrawalAmountView.h"
  9. #import "YMMyEarningsViewModel.h"
  10. #import "YMMyEarningsWithdrawalAmountCell.h"
  11. #import "CHTCollectionViewWaterfallLayout.h"
  12. @interface YMMyEarningsWithdrawalAmountView ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout,CHTCollectionViewDelegateWaterfallLayout>
  13. /// 我的收益VM
  14. @property (nonatomic, strong) YMMyEarningsViewModel *viewModel;
  15. /// 提现金额项目提示标签
  16. @property (nonatomic, strong) UILabel *withdrawalAmountItemTipsLb;
  17. /// 提现金额项目排版
  18. @property (nonatomic, strong) CHTCollectionViewWaterfallLayout *withdrawalAmountItemLayout;
  19. /// 提现金额项目容器列表
  20. @property (nonatomic, strong) UICollectionView *withdrawalAmountItemCollectionView;
  21. @end
  22. @implementation YMMyEarningsWithdrawalAmountView
  23. - (void)ym_setupViews{
  24. [self addSubview:self.withdrawalAmountItemTipsLb];
  25. [self addSubview:self.withdrawalAmountItemCollectionView];
  26. [self setNeedsUpdateConstraints];
  27. [self updateConstraintsIfNeeded];
  28. }
  29. - (void)updateConstraints{
  30. [self.withdrawalAmountItemTipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.top.equalTo(self).offset(adapt(20));
  32. make.left.equalTo(self).offset(adapt(18));
  33. }];
  34. [self.withdrawalAmountItemCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.top.equalTo(self.withdrawalAmountItemTipsLb.mas_bottom).offset(adapt(12));
  36. make.left.equalTo(self);
  37. make.right.equalTo(self);
  38. make.bottom.equalTo(self).offset(adapt(-10));
  39. }];
  40. [super updateConstraints];
  41. }
  42. - (void)ym_bindViewModel:(YMMyEarningsViewModel *)viewModel{
  43. if (!viewModel) {
  44. return;
  45. }
  46. _viewModel = viewModel;
  47. @weakify(self)
  48. [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  49. @strongify(self)
  50. [self.withdrawalAmountItemCollectionView reloadData];
  51. [self.withdrawalAmountItemCollectionView layoutIfNeeded];
  52. //刷新高度
  53. CGFloat withdrawalAmountItemCollectionViewHeight = self.withdrawalAmountItemCollectionView.collectionViewLayout.collectionViewContentSize.height;
  54. [self.withdrawalAmountItemCollectionView mas_updateConstraints:^(MASConstraintMaker *make) {
  55. make.height.mas_equalTo(withdrawalAmountItemCollectionViewHeight);
  56. }];
  57. }];
  58. }
  59. #pragma mark - UICollectionViewDataSource
  60. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  61. return 1;
  62. }
  63. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  64. return self.viewModel.withdrawalAmountItemDataArray.count;
  65. }
  66. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  67. YMMyEarningsWithdrawalAmountCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YMMyEarningsWithdrawalAmountCell class]) forIndexPath:indexPath];
  68. [cell ym_bindViewModel:self.viewModel.withdrawalAmountItemDataArray[indexPath.item]];
  69. return cell;
  70. }
  71. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  72. UICollectionReusableView *reusableView = nil;
  73. reusableView.backgroundColor = [UIColor clearColor];
  74. return reusableView;
  75. }
  76. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  77. return CGSizeZero;
  78. }
  79. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
  80. return CGSizeZero;
  81. }
  82. #pragma mark - UICollectionViewDelegate
  83. - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  84. // if (self.viewModel.userRemainingPoints <= self.viewModel.withdrawalAmountItemDataArray[indexPath.item].withdrawalPointsRequirement) {
  85. // [ZCHUDHelper showTitle:@"可提现余额不足" showtime:1.5];
  86. // return NO;
  87. // }
  88. return YES;
  89. }
  90. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  91. [self.viewModel.getWithdrawalAmountSubject sendNext:@(self.viewModel.withdrawalAmountItemDataArray[indexPath.item].withdrawalAmount)];
  92. }
  93. #pragma mark - CHTCollectionViewDelegateWaterfallLayout
  94. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  95. return CGSizeMake(adapt(110), adapt(68));
  96. }
  97. - (UILabel *)withdrawalAmountItemTipsLb{
  98. if (!_withdrawalAmountItemTipsLb) {
  99. _withdrawalAmountItemTipsLb = [[UILabel alloc]init];
  100. _withdrawalAmountItemTipsLb.font = LCFont(13);
  101. _withdrawalAmountItemTipsLb.textColor = HexColorFromRGB(0x161330);
  102. _withdrawalAmountItemTipsLb.textAlignment = NSTextAlignmentLeft;
  103. _withdrawalAmountItemTipsLb.text = @"请选择所需金币";
  104. }
  105. return _withdrawalAmountItemTipsLb;
  106. }
  107. - (CHTCollectionViewWaterfallLayout *)withdrawalAmountItemLayout{
  108. if (!_withdrawalAmountItemLayout) {
  109. _withdrawalAmountItemLayout = [[CHTCollectionViewWaterfallLayout alloc] init];
  110. _withdrawalAmountItemLayout.columnCount = 3;
  111. _withdrawalAmountItemLayout.sectionInset = UIEdgeInsetsMake(adapt(10), adapt(10), adapt(10), adapt(10));
  112. }
  113. return _withdrawalAmountItemLayout;
  114. }
  115. - (UICollectionView *)withdrawalAmountItemCollectionView{
  116. if (!_withdrawalAmountItemCollectionView) {
  117. _withdrawalAmountItemCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.withdrawalAmountItemLayout];
  118. _withdrawalAmountItemCollectionView.delegate = self;
  119. _withdrawalAmountItemCollectionView.dataSource = self;
  120. _withdrawalAmountItemCollectionView.showsVerticalScrollIndicator = NO;
  121. _withdrawalAmountItemCollectionView.showsHorizontalScrollIndicator = NO;
  122. _withdrawalAmountItemCollectionView.backgroundColor = UIColor.clearColor;
  123. [_withdrawalAmountItemCollectionView registerClass:[YMMyEarningsWithdrawalAmountCell class] forCellWithReuseIdentifier:NSStringFromClass([YMMyEarningsWithdrawalAmountCell class])];
  124. }
  125. return _withdrawalAmountItemCollectionView;
  126. }
  127. @end