123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- //
- // NYComplaintPageViewController.m
- // jiaPei
- //
- // Created by Ning.ge on 2023/6/30.
- // Copyright © 2023 JCZ. All rights reserved.
- //
- #import "NYComplaintPageViewController.h"
- #import "TZImagePickerController.h"//第三方相册
- #import "CollectionViewCell.h"
- #import "NYComplaintPageViewModel.h"
- #define Kwidth [UIScreen mainScreen].bounds.size.width
- #define Kheight [UIScreen mainScreen].bounds.size.height
- @interface NYComplaintPageViewController ()<TZImagePickerControllerDelegate,UICollectionViewDelegate,UICollectionViewDataSource>{
- CGFloat _itemWH;
- CGFloat _margin;
- }
- //名称
- @property (weak, nonatomic) IBOutlet UILabel *objname_label;
- //照片 图片 - collectionView
- @property (weak, nonatomic) IBOutlet UIView *imageArrayView;
- @property (nonatomic,strong) NYComplaintPageViewModel *complaintPageViewModel;
- @end
- @implementation NYComplaintPageViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
- [self setupUI];
- }
- - (void)dealloc {
-
- NSLog(@"投诉建议-NYComplaintPageViewController");
- }
- #pragma mark - PublicMethods
- #pragma mark - PrivateMethods
- - (void)setupUI {
- self.title = @"投诉建议";
- [self configureUI];
- }
- - (void)configureUI {
- self.phone_textfield.text = RQ_USER_MANAGER.currentUser.telphone;
- self.content_textview.maximumTextLength = 500;
- self.currentType_button = self.px_button;
- [self.collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
- [self.imageArrayView addSubview:self.collectionView];
- [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(self.imageArrayView);
- }];
- self.collectionView.backgroundColor = [UIColor colorWithHexString:@"#F2F3F5" alpha:1.0];
- //赋值
- self.objname_label.text = RQ_USER_MANAGER.currentUser.schoolName;
- [[self.submit_button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
- [self.complaintPageViewModel.submitCommand execute:nil];
- }];
- }
- #pragma mark - 事件
- //投诉类型
- - (IBAction)buttonTypeActiondo:(id)sender {
- self.currentType_button.selected = NO;
- self.currentType_button = sender;
- self.currentType_button.selected = YES;
- }
- #pragma mark - Lazy
- - (NYComplaintPageViewModel *)complaintPageViewModel
- {
- if(!_complaintPageViewModel){
- _complaintPageViewModel = [[NYComplaintPageViewModel alloc] init];
- _complaintPageViewModel.complaintPageViewVC = self;
- }
- return _complaintPageViewModel;
- }
- - (NSMutableArray *)image_idArray{
- if(!_image_idArray){
- _image_idArray = [NSMutableArray array];
- }
- return _image_idArray;
- }
- - (NSMutableArray *)photosArray{
- if (!_photosArray) {
- self.photosArray = [NSMutableArray array];
- }
- return _photosArray;
- }
- - (NSMutableArray *)assestArray{
- if (!_assestArray) {
- self.assestArray = [NSMutableArray array];
- }
- return _assestArray;
- }
- -(UICollectionView *)collectionView{
- if (!_collectionView) {
- UICollectionViewFlowLayout *flowLayOut = [[UICollectionViewFlowLayout alloc] init];
- flowLayOut.itemSize = CGSizeMake(50, 50);
- flowLayOut.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
- flowLayOut.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayOut];
- self.collectionView.showsHorizontalScrollIndicator = NO;
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
- // self.collectionView.scrollEnabled = NO;
- }
- return _collectionView;
- }
- #pragma mark -TZImagePickerController
- - (void)checkLocalPhoto{
-
- TZImagePickerController *imagePicker = [[TZImagePickerController alloc] initWithMaxImagesCount:9 delegate:self];
- [imagePicker setSortAscendingByModificationDate:NO];
- imagePicker.isSelectOriginalPhoto = _isSelectOriginalPhoto;
- imagePicker.selectedAssets = _assestArray;
- imagePicker.allowPickingVideo = NO;
- [self presentViewController:imagePicker animated:YES completion:nil];
-
- }
- - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto{
- self.photosArray = [NSMutableArray arrayWithArray:photos];
- self.assestArray = [NSMutableArray arrayWithArray:assets];
- [self.complaintPageViewModel.uploadCommand execute:@(isSelectOriginalPhoto)];
- }
- #pragma mark UICollectionViewDelegate
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- if (indexPath.row == _photosArray.count) {
- [self checkLocalPhoto];
- }else{
- TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithSelectedAssets:_assestArray selectedPhotos:_photosArray index:indexPath.row];
- imagePickerVc.maxImagesCount = 9;//最大9
- imagePickerVc.isSelectOriginalPhoto = _isSelectOriginalPhoto;
- [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
- _photosArray = [NSMutableArray arrayWithArray:photos];
- _assestArray = [NSMutableArray arrayWithArray:assets];
- _isSelectOriginalPhoto = isSelectOriginalPhoto;
- [_collectionView reloadData];
- _collectionView.contentSize = CGSizeMake(0, ((_photosArray.count + 2) / 3 ) * (_margin + _itemWH));
- }];
- [self presentViewController:imagePickerVc animated:YES completion:nil];
- }
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- return _photosArray.count+1;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
-
- if (indexPath.row == _photosArray.count) {
- cell.imagev.image = [UIImage imageNamed:@"comp_add"];
- // cell.imagev.backgroundColor = [UIColor redColor];
- cell.deleteButton.hidden = YES;
-
- }else{
- cell.imagev.image = _photosArray[indexPath.row];
- cell.deleteButton.hidden = NO;
- }
- cell.deleteButton.tag = 100 + indexPath.row;
- [cell.deleteButton addTarget:self action:@selector(deletePhotos:) forControlEvents:UIControlEventTouchUpInside];
- return cell;
-
- }
- - (void)deletePhotos:(UIButton *)sender{
- [_photosArray removeObjectAtIndex:sender.tag - 100];
- [_assestArray removeObjectAtIndex:sender.tag - 100];
- // [self deleteComplaintPicIndex:sender.tag - 100];
- [self.complaintPageViewModel.deleteCommand execute:@(sender.tag - 100)];
- [_collectionView performBatchUpdates:^{
- NSIndexPath *indexPath = [NSIndexPath indexPathForItem:sender.tag-100 inSection:0];
- [_collectionView deleteItemsAtIndexPaths:@[indexPath]];
- } completion:^(BOOL finished) {
- [_collectionView reloadData];
- }];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|