// // YMReportEvidenceView.m // MSYOUPAI // // Created by YoMi on 2024/3/5. // Copyright © 2024 MS. All rights reserved. // #import "YMReportEvidenceView.h" #import "YMReportViewModel.h" #import "YMReportEvidenceCell.h" #import "CHTCollectionViewWaterfallLayout.h" @interface YMReportEvidenceView () /// 举报VM @property (nonatomic, strong) YMReportViewModel *viewModel; /// 举报描述标题标签 @property (nonatomic, strong) UILabel *reportDescTitleLb; /// 举报描述详情标签 @property (nonatomic, strong) UILabel *reportDescDetailLb; /// 举报证据排版 @property (nonatomic, strong) CHTCollectionViewWaterfallLayout *reportEvidenceLayout; /// 举报证据容器列表 @property (nonatomic, strong) UICollectionView *reportEvidenceCollectionView; @end @implementation YMReportEvidenceView - (void)ym_setupViews{ [self addSubview:self.reportDescTitleLb]; [self addSubview:self.reportDescDetailLb]; [self addSubview:self.reportEvidenceCollectionView]; [self setNeedsUpdateConstraints]; [self updateConstraintsIfNeeded]; } - (void)updateConstraints{ [self.reportDescTitleLb mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self).offset(adapt(10)); make.left.equalTo(self).offset(adapt(15)); }]; [self.reportDescDetailLb mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.reportDescTitleLb.mas_centerY); make.left.equalTo(self.reportDescTitleLb.mas_right).offset(adapt(5)); }]; [self.reportEvidenceCollectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.reportDescTitleLb.mas_bottom).offset(adapt(10)); make.left.equalTo(self); make.right.equalTo(self); make.bottom.equalTo(self); }]; [super updateConstraints]; } - (void)ym_bindViewModel:(YMReportViewModel *)viewModel{ if (!viewModel) { return; } _viewModel = viewModel; @weakify(self) [[self.viewModel.refreshReportEvidenceSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) { @strongify(self) [self.reportEvidenceCollectionView reloadData]; [self.reportEvidenceCollectionView layoutIfNeeded]; //刷新高度 CGFloat collectionViewHeight = self.reportEvidenceCollectionView.collectionViewLayout.collectionViewContentSize.height; [self.reportEvidenceCollectionView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(collectionViewHeight); }]; }]; } #pragma mark - UICollectionViewDataSource - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return !self.viewModel.isHideAddCell ? self.viewModel.reportEvidenceDataArray.count + 1: self.viewModel.reportEvidenceDataArray.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { if (!self.viewModel.isHideAddCell) { if (self.viewModel.reportEvidenceDataArray.count == indexPath.item) { YMReportEvidenceCell *addCell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YMReportEvidenceCell class]) forIndexPath:indexPath]; [addCell ym_bindViewModel:self.viewModel.addCellViewModel]; return addCell; } } YMReportEvidenceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YMReportEvidenceCell class]) forIndexPath:indexPath]; YMReportEvidenceCellViewModel *cellVM = self.viewModel.reportEvidenceDataArray[indexPath.item]; WS(weakSelf) cellVM.removeReportEvidenceBlock = ^{ [weakSelf.viewModel.deleteReportEvidenceSubject sendNext:@(indexPath.item)]; }; [cell ym_bindViewModel:cellVM]; 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 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if (!self.viewModel.isHideAddCell && self.viewModel.reportEvidenceDataArray.count == indexPath.item) { [self.viewModel openEvidencePickerPopupView]; }else{ NSMutableArray *tempArr = [NSMutableArray array]; for (YMReportEvidenceCellViewModel *model in self.viewModel.reportEvidenceDataArray) { YBIBImageData *data = [YBIBImageData new]; data.image = ^UIImage * _Nullable{ return model.localAlbum; }; data.projectiveView = [collectionView cellForItemAtIndexPath:indexPath]; [tempArr addObject:data]; } YBImageBrowser *browser = [YBImageBrowser new]; browser.delegate = self; browser.dataSourceArray = tempArr; browser.currentPage = indexPath.item; [browser show]; } } #pragma mark - CHTCollectionViewDelegateWaterfallLayout - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(adapt(100), adapt(100)); } - (UILabel *)reportDescTitleLb{ if (!_reportDescTitleLb) { _reportDescTitleLb = [[UILabel alloc]init]; _reportDescTitleLb.font = LCBoldFont(14); _reportDescTitleLb.textColor = HexColorFromRGB(0x333333); _reportDescTitleLb.textAlignment = NSTextAlignmentLeft; _reportDescTitleLb.text = @"举报描述"; } return _reportDescTitleLb; } - (UILabel *)reportDescDetailLb{ if (!_reportDescDetailLb) { _reportDescDetailLb = [[UILabel alloc]init]; _reportDescDetailLb.font = LCFont(11); _reportDescDetailLb.textColor = HexColorFromRGB(0x737373); _reportDescDetailLb.textAlignment = NSTextAlignmentLeft; _reportDescDetailLb.text = @"(选填)"; } return _reportDescDetailLb; } - (CHTCollectionViewWaterfallLayout *)reportEvidenceLayout{ if (!_reportEvidenceLayout) { _reportEvidenceLayout = [[CHTCollectionViewWaterfallLayout alloc] init]; _reportEvidenceLayout.columnCount = 3; _reportEvidenceLayout.sectionInset = UIEdgeInsetsMake(adapt(10), adapt(15), adapt(10), adapt(15)); } return _reportEvidenceLayout; } - (UICollectionView *)reportEvidenceCollectionView{ if (!_reportEvidenceCollectionView) { _reportEvidenceCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.reportEvidenceLayout]; _reportEvidenceCollectionView.delegate = self; _reportEvidenceCollectionView.dataSource = self; _reportEvidenceCollectionView.showsVerticalScrollIndicator = NO; _reportEvidenceCollectionView.showsHorizontalScrollIndicator = NO; _reportEvidenceCollectionView.backgroundColor = UIColor.whiteColor; [_reportEvidenceCollectionView registerClass:[YMReportEvidenceCell class] forCellWithReuseIdentifier:NSStringFromClass([YMReportEvidenceCell class])]; } return _reportEvidenceCollectionView; } @end