YMReportEvidenceView.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. //
  2. // YMReportEvidenceView.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/5.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMReportEvidenceView.h"
  9. #import "YMReportViewModel.h"
  10. #import "YMReportEvidenceCell.h"
  11. #import "CHTCollectionViewWaterfallLayout.h"
  12. @interface YMReportEvidenceView ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout,CHTCollectionViewDelegateWaterfallLayout,TZImagePickerControllerDelegate,YBImageBrowserDelegate>
  13. /// 举报VM
  14. @property (nonatomic, strong) YMReportViewModel *viewModel;
  15. /// 举报描述标题标签
  16. @property (nonatomic, strong) UILabel *reportDescTitleLb;
  17. /// 举报描述详情标签
  18. @property (nonatomic, strong) UILabel *reportDescDetailLb;
  19. /// 举报证据排版
  20. @property (nonatomic, strong) CHTCollectionViewWaterfallLayout *reportEvidenceLayout;
  21. /// 举报证据容器列表
  22. @property (nonatomic, strong) UICollectionView *reportEvidenceCollectionView;
  23. @end
  24. @implementation YMReportEvidenceView
  25. - (void)ym_setupViews{
  26. [self addSubview:self.reportDescTitleLb];
  27. [self addSubview:self.reportDescDetailLb];
  28. [self addSubview:self.reportEvidenceCollectionView];
  29. [self setNeedsUpdateConstraints];
  30. [self updateConstraintsIfNeeded];
  31. }
  32. - (void)updateConstraints{
  33. [self.reportDescTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.top.equalTo(self).offset(adapt(10));
  35. make.left.equalTo(self).offset(adapt(15));
  36. }];
  37. [self.reportDescDetailLb mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.centerY.equalTo(self.reportDescTitleLb.mas_centerY);
  39. make.left.equalTo(self.reportDescTitleLb.mas_right).offset(adapt(5));
  40. }];
  41. [self.reportEvidenceCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.top.equalTo(self.reportDescTitleLb.mas_bottom).offset(adapt(10));
  43. make.left.equalTo(self);
  44. make.right.equalTo(self);
  45. make.bottom.equalTo(self);
  46. }];
  47. [super updateConstraints];
  48. }
  49. - (void)ym_bindViewModel:(YMReportViewModel *)viewModel{
  50. if (!viewModel) {
  51. return;
  52. }
  53. _viewModel = viewModel;
  54. @weakify(self)
  55. [[self.viewModel.refreshReportEvidenceSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
  56. @strongify(self)
  57. [self.reportEvidenceCollectionView reloadData];
  58. [self.reportEvidenceCollectionView layoutIfNeeded];
  59. //刷新高度
  60. CGFloat collectionViewHeight = self.reportEvidenceCollectionView.collectionViewLayout.collectionViewContentSize.height;
  61. [self.reportEvidenceCollectionView mas_updateConstraints:^(MASConstraintMaker *make) {
  62. make.height.mas_equalTo(collectionViewHeight);
  63. }];
  64. }];
  65. }
  66. #pragma mark - UICollectionViewDataSource
  67. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  68. return 1;
  69. }
  70. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  71. return !self.viewModel.isHideAddCell ? self.viewModel.reportEvidenceDataArray.count + 1: self.viewModel.reportEvidenceDataArray.count;
  72. }
  73. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  74. if (!self.viewModel.isHideAddCell) {
  75. if (self.viewModel.reportEvidenceDataArray.count == indexPath.item) {
  76. YMReportEvidenceCell *addCell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YMReportEvidenceCell class]) forIndexPath:indexPath];
  77. [addCell ym_bindViewModel:self.viewModel.addCellViewModel];
  78. return addCell;
  79. }
  80. }
  81. YMReportEvidenceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YMReportEvidenceCell class]) forIndexPath:indexPath];
  82. YMReportEvidenceCellViewModel *cellVM = self.viewModel.reportEvidenceDataArray[indexPath.item];
  83. WS(weakSelf)
  84. cellVM.removeReportEvidenceBlock = ^{
  85. [weakSelf.viewModel.deleteReportEvidenceSubject sendNext:@(indexPath.item)];
  86. };
  87. [cell ym_bindViewModel:cellVM];
  88. return cell;
  89. }
  90. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  91. UICollectionReusableView *reusableView = nil;
  92. reusableView.backgroundColor = [UIColor clearColor];
  93. return reusableView;
  94. }
  95. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  96. return CGSizeZero;
  97. }
  98. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
  99. return CGSizeZero;
  100. }
  101. #pragma mark - UICollectionViewDelegate
  102. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  103. if (!self.viewModel.isHideAddCell && self.viewModel.reportEvidenceDataArray.count == indexPath.item) {
  104. [self.viewModel openEvidencePickerPopupView];
  105. }else{
  106. NSMutableArray *tempArr = [NSMutableArray array];
  107. for (YMReportEvidenceCellViewModel *model in self.viewModel.reportEvidenceDataArray) {
  108. YBIBImageData *data = [YBIBImageData new];
  109. data.image = ^UIImage * _Nullable{
  110. return model.localAlbum;
  111. };
  112. data.projectiveView = [collectionView cellForItemAtIndexPath:indexPath];
  113. [tempArr addObject:data];
  114. }
  115. YBImageBrowser *browser = [YBImageBrowser new];
  116. browser.delegate = self;
  117. browser.dataSourceArray = tempArr;
  118. browser.currentPage = indexPath.item;
  119. [browser show];
  120. }
  121. }
  122. #pragma mark - CHTCollectionViewDelegateWaterfallLayout
  123. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  124. return CGSizeMake(adapt(100), adapt(100));
  125. }
  126. - (UILabel *)reportDescTitleLb{
  127. if (!_reportDescTitleLb) {
  128. _reportDescTitleLb = [[UILabel alloc]init];
  129. _reportDescTitleLb.font = LCBoldFont(14);
  130. _reportDescTitleLb.textColor = HexColorFromRGB(0x333333);
  131. _reportDescTitleLb.textAlignment = NSTextAlignmentLeft;
  132. _reportDescTitleLb.text = @"举报描述";
  133. }
  134. return _reportDescTitleLb;
  135. }
  136. - (UILabel *)reportDescDetailLb{
  137. if (!_reportDescDetailLb) {
  138. _reportDescDetailLb = [[UILabel alloc]init];
  139. _reportDescDetailLb.font = LCFont(11);
  140. _reportDescDetailLb.textColor = HexColorFromRGB(0x737373);
  141. _reportDescDetailLb.textAlignment = NSTextAlignmentLeft;
  142. _reportDescDetailLb.text = @"(选填)";
  143. }
  144. return _reportDescDetailLb;
  145. }
  146. - (CHTCollectionViewWaterfallLayout *)reportEvidenceLayout{
  147. if (!_reportEvidenceLayout) {
  148. _reportEvidenceLayout = [[CHTCollectionViewWaterfallLayout alloc] init];
  149. _reportEvidenceLayout.columnCount = 3;
  150. _reportEvidenceLayout.sectionInset = UIEdgeInsetsMake(adapt(10), adapt(15), adapt(10), adapt(15));
  151. }
  152. return _reportEvidenceLayout;
  153. }
  154. - (UICollectionView *)reportEvidenceCollectionView{
  155. if (!_reportEvidenceCollectionView) {
  156. _reportEvidenceCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.reportEvidenceLayout];
  157. _reportEvidenceCollectionView.delegate = self;
  158. _reportEvidenceCollectionView.dataSource = self;
  159. _reportEvidenceCollectionView.showsVerticalScrollIndicator = NO;
  160. _reportEvidenceCollectionView.showsHorizontalScrollIndicator = NO;
  161. _reportEvidenceCollectionView.backgroundColor = UIColor.whiteColor;
  162. [_reportEvidenceCollectionView registerClass:[YMReportEvidenceCell class] forCellWithReuseIdentifier:NSStringFromClass([YMReportEvidenceCell class])];
  163. }
  164. return _reportEvidenceCollectionView;
  165. }
  166. @end