NYComplaintPageViewController.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. //
  2. // NYComplaintPageViewController.m
  3. // jiaPei
  4. //
  5. // Created by Ning.ge on 2023/6/30.
  6. // Copyright © 2023 JCZ. All rights reserved.
  7. //
  8. #import "NYComplaintPageViewController.h"
  9. #import "TZImagePickerController.h"//第三方相册
  10. #import "CollectionViewCell.h"
  11. #import "NYComplaintPageViewModel.h"
  12. #define Kwidth [UIScreen mainScreen].bounds.size.width
  13. #define Kheight [UIScreen mainScreen].bounds.size.height
  14. @interface NYComplaintPageViewController ()<TZImagePickerControllerDelegate,UICollectionViewDelegate,UICollectionViewDataSource>{
  15. CGFloat _itemWH;
  16. CGFloat _margin;
  17. }
  18. //名称
  19. @property (weak, nonatomic) IBOutlet UILabel *objname_label;
  20. //照片 图片 - collectionView
  21. @property (weak, nonatomic) IBOutlet UIView *imageArrayView;
  22. @property (nonatomic,strong) NYComplaintPageViewModel *complaintPageViewModel;
  23. @end
  24. @implementation NYComplaintPageViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. // Do any additional setup after loading the view from its nib.
  28. [self setupUI];
  29. }
  30. - (void)dealloc {
  31. NSLog(@"投诉建议-NYComplaintPageViewController");
  32. }
  33. #pragma mark - PublicMethods
  34. #pragma mark - PrivateMethods
  35. - (void)setupUI {
  36. self.title = @"投诉建议";
  37. [self configureUI];
  38. }
  39. - (void)configureUI {
  40. self.phone_textfield.text = RQ_USER_MANAGER.currentUser.telphone;
  41. self.content_textview.maximumTextLength = 500;
  42. self.currentType_button = self.px_button;
  43. [self.collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
  44. [self.imageArrayView addSubview:self.collectionView];
  45. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.edges.mas_equalTo(self.imageArrayView);
  47. }];
  48. self.collectionView.backgroundColor = [UIColor colorWithHexString:@"#F2F3F5" alpha:1.0];
  49. //赋值
  50. self.objname_label.text = RQ_USER_MANAGER.currentUser.schoolName;
  51. [[self.submit_button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
  52. [self.complaintPageViewModel.submitCommand execute:nil];
  53. }];
  54. }
  55. #pragma mark - 事件
  56. //投诉类型
  57. - (IBAction)buttonTypeActiondo:(id)sender {
  58. self.currentType_button.selected = NO;
  59. self.currentType_button = sender;
  60. self.currentType_button.selected = YES;
  61. }
  62. #pragma mark - Lazy
  63. - (NYComplaintPageViewModel *)complaintPageViewModel
  64. {
  65. if(!_complaintPageViewModel){
  66. _complaintPageViewModel = [[NYComplaintPageViewModel alloc] init];
  67. _complaintPageViewModel.complaintPageViewVC = self;
  68. }
  69. return _complaintPageViewModel;
  70. }
  71. - (NSMutableArray *)image_idArray{
  72. if(!_image_idArray){
  73. _image_idArray = [NSMutableArray array];
  74. }
  75. return _image_idArray;
  76. }
  77. - (NSMutableArray *)photosArray{
  78. if (!_photosArray) {
  79. self.photosArray = [NSMutableArray array];
  80. }
  81. return _photosArray;
  82. }
  83. - (NSMutableArray *)assestArray{
  84. if (!_assestArray) {
  85. self.assestArray = [NSMutableArray array];
  86. }
  87. return _assestArray;
  88. }
  89. -(UICollectionView *)collectionView{
  90. if (!_collectionView) {
  91. UICollectionViewFlowLayout *flowLayOut = [[UICollectionViewFlowLayout alloc] init];
  92. flowLayOut.itemSize = CGSizeMake(50, 50);
  93. flowLayOut.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
  94. flowLayOut.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  95. self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayOut];
  96. self.collectionView.showsHorizontalScrollIndicator = NO;
  97. self.collectionView.delegate = self;
  98. self.collectionView.dataSource = self;
  99. // self.collectionView.scrollEnabled = NO;
  100. }
  101. return _collectionView;
  102. }
  103. #pragma mark -TZImagePickerController
  104. - (void)checkLocalPhoto{
  105. TZImagePickerController *imagePicker = [[TZImagePickerController alloc] initWithMaxImagesCount:9 delegate:self];
  106. [imagePicker setSortAscendingByModificationDate:NO];
  107. imagePicker.isSelectOriginalPhoto = _isSelectOriginalPhoto;
  108. imagePicker.selectedAssets = _assestArray;
  109. imagePicker.allowPickingVideo = NO;
  110. [self presentViewController:imagePicker animated:YES completion:nil];
  111. }
  112. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto{
  113. self.photosArray = [NSMutableArray arrayWithArray:photos];
  114. self.assestArray = [NSMutableArray arrayWithArray:assets];
  115. [self.complaintPageViewModel.uploadCommand execute:@(isSelectOriginalPhoto)];
  116. }
  117. #pragma mark UICollectionViewDelegate
  118. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  119. if (indexPath.row == _photosArray.count) {
  120. [self checkLocalPhoto];
  121. }else{
  122. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithSelectedAssets:_assestArray selectedPhotos:_photosArray index:indexPath.row];
  123. imagePickerVc.maxImagesCount = 9;//最大9
  124. imagePickerVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
  125. [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
  126. _photosArray = [NSMutableArray arrayWithArray:photos];
  127. _assestArray = [NSMutableArray arrayWithArray:assets];
  128. _isSelectOriginalPhoto = isSelectOriginalPhoto;
  129. [_collectionView reloadData];
  130. _collectionView.contentSize = CGSizeMake(0, ((_photosArray.count + 2) / 3 ) * (_margin + _itemWH));
  131. }];
  132. [self presentViewController:imagePickerVc animated:YES completion:nil];
  133. }
  134. }
  135. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  136. return _photosArray.count+1;
  137. }
  138. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  139. CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  140. if (indexPath.row == _photosArray.count) {
  141. cell.imagev.image = [UIImage imageNamed:@"comp_add"];
  142. // cell.imagev.backgroundColor = [UIColor redColor];
  143. cell.deleteButton.hidden = YES;
  144. }else{
  145. cell.imagev.image = _photosArray[indexPath.row];
  146. cell.deleteButton.hidden = NO;
  147. }
  148. cell.deleteButton.tag = 100 + indexPath.row;
  149. [cell.deleteButton addTarget:self action:@selector(deletePhotos:) forControlEvents:UIControlEventTouchUpInside];
  150. return cell;
  151. }
  152. - (void)deletePhotos:(UIButton *)sender{
  153. [_photosArray removeObjectAtIndex:sender.tag - 100];
  154. [_assestArray removeObjectAtIndex:sender.tag - 100];
  155. // [self deleteComplaintPicIndex:sender.tag - 100];
  156. [self.complaintPageViewModel.deleteCommand execute:@(sender.tag - 100)];
  157. [_collectionView performBatchUpdates:^{
  158. NSIndexPath *indexPath = [NSIndexPath indexPathForItem:sender.tag-100 inSection:0];
  159. [_collectionView deleteItemsAtIndexPaths:@[indexPath]];
  160. } completion:^(BOOL finished) {
  161. [_collectionView reloadData];
  162. }];
  163. }
  164. - (void)didReceiveMemoryWarning {
  165. [super didReceiveMemoryWarning];
  166. // Dispose of any resources that can be recreated.
  167. }
  168. @end