123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- //
- // YMMyEarningsWithdrawalAmountView.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/29.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMMyEarningsWithdrawalAmountView.h"
- #import "YMMyEarningsViewModel.h"
- #import "YMMyEarningsWithdrawalAmountCell.h"
- #import "CHTCollectionViewWaterfallLayout.h"
- @interface YMMyEarningsWithdrawalAmountView ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout,CHTCollectionViewDelegateWaterfallLayout>
- /// 我的收益VM
- @property (nonatomic, strong) YMMyEarningsViewModel *viewModel;
- /// 提现金额项目提示标签
- @property (nonatomic, strong) UILabel *withdrawalAmountItemTipsLb;
- /// 提现金额项目排版
- @property (nonatomic, strong) CHTCollectionViewWaterfallLayout *withdrawalAmountItemLayout;
- /// 提现金额项目容器列表
- @property (nonatomic, strong) UICollectionView *withdrawalAmountItemCollectionView;
- @end
- @implementation YMMyEarningsWithdrawalAmountView
- - (void)ym_setupViews{
- [self addSubview:self.withdrawalAmountItemTipsLb];
- [self addSubview:self.withdrawalAmountItemCollectionView];
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints{
-
- [self.withdrawalAmountItemTipsLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(adapt(20));
- make.left.equalTo(self).offset(adapt(18));
- }];
-
- [self.withdrawalAmountItemCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.withdrawalAmountItemTipsLb.mas_bottom).offset(adapt(12));
- make.left.equalTo(self);
- make.right.equalTo(self);
- make.bottom.equalTo(self).offset(adapt(-10));
- }];
-
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(YMMyEarningsViewModel *)viewModel{
- if (!viewModel) {
- return;
- }
-
- _viewModel = viewModel;
-
- @weakify(self)
- [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
- @strongify(self)
- [self.withdrawalAmountItemCollectionView reloadData];
- [self.withdrawalAmountItemCollectionView layoutIfNeeded];
- //刷新高度
- CGFloat withdrawalAmountItemCollectionViewHeight = self.withdrawalAmountItemCollectionView.collectionViewLayout.collectionViewContentSize.height;
- [self.withdrawalAmountItemCollectionView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(withdrawalAmountItemCollectionViewHeight);
- }];
-
- }];
- }
- #pragma mark - UICollectionViewDataSource
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.viewModel.withdrawalAmountItemDataArray.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- YMMyEarningsWithdrawalAmountCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YMMyEarningsWithdrawalAmountCell class]) forIndexPath:indexPath];
- [cell ym_bindViewModel:self.viewModel.withdrawalAmountItemDataArray[indexPath.item]];
- return cell;
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
- UICollectionReusableView *reusableView = nil;
- reusableView.backgroundColor = [UIColor clearColor];
- return reusableView;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
- return CGSizeZero;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
- return CGSizeZero;
- }
- #pragma mark - UICollectionViewDelegate
- - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- // if (self.viewModel.userRemainingPoints <= self.viewModel.withdrawalAmountItemDataArray[indexPath.item].withdrawalPointsRequirement) {
- // [ZCHUDHelper showTitle:@"可提现余额不足" showtime:1.5];
- // return NO;
- // }
- return YES;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- [self.viewModel.getWithdrawalAmountSubject sendNext:@(self.viewModel.withdrawalAmountItemDataArray[indexPath.item].withdrawalAmount)];
- }
- #pragma mark - CHTCollectionViewDelegateWaterfallLayout
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- return CGSizeMake(adapt(110), adapt(68));
- }
- - (UILabel *)withdrawalAmountItemTipsLb{
- if (!_withdrawalAmountItemTipsLb) {
- _withdrawalAmountItemTipsLb = [[UILabel alloc]init];
- _withdrawalAmountItemTipsLb.font = LCFont(13);
- _withdrawalAmountItemTipsLb.textColor = HexColorFromRGB(0x161330);
- _withdrawalAmountItemTipsLb.textAlignment = NSTextAlignmentLeft;
- _withdrawalAmountItemTipsLb.text = @"请选择所需金币";
- }
- return _withdrawalAmountItemTipsLb;
- }
- - (CHTCollectionViewWaterfallLayout *)withdrawalAmountItemLayout{
- if (!_withdrawalAmountItemLayout) {
- _withdrawalAmountItemLayout = [[CHTCollectionViewWaterfallLayout alloc] init];
- _withdrawalAmountItemLayout.columnCount = 3;
- _withdrawalAmountItemLayout.sectionInset = UIEdgeInsetsMake(adapt(10), adapt(10), adapt(10), adapt(10));
- }
- return _withdrawalAmountItemLayout;
- }
- - (UICollectionView *)withdrawalAmountItemCollectionView{
- if (!_withdrawalAmountItemCollectionView) {
- _withdrawalAmountItemCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.withdrawalAmountItemLayout];
- _withdrawalAmountItemCollectionView.delegate = self;
- _withdrawalAmountItemCollectionView.dataSource = self;
- _withdrawalAmountItemCollectionView.showsVerticalScrollIndicator = NO;
- _withdrawalAmountItemCollectionView.showsHorizontalScrollIndicator = NO;
- _withdrawalAmountItemCollectionView.backgroundColor = UIColor.clearColor;
- [_withdrawalAmountItemCollectionView registerClass:[YMMyEarningsWithdrawalAmountCell class] forCellWithReuseIdentifier:NSStringFromClass([YMMyEarningsWithdrawalAmountCell class])];
- }
- return _withdrawalAmountItemCollectionView;
- }
- @end
|