// // DDMyInfoJuBaoViewController.m // DingDangApp // // Created by apple on 2023/6/1. // #import "DDMyInfoJuBaoViewController.h" #import #import "ZLPhotoActionSheet.h" #import "ZLPhotoManager.h" #import "FileToolsObject.h" #import "UITextView+Placeholder.h" @interface DDMyInfoJuBaoViewController () @property (nonatomic,strong) UIView * whiteBGV1; @property (nonatomic,strong) UIView * whiteBGV2; @property (nonatomic,strong) UIView * grayBGV1; @property (nonatomic,strong) UITextView * textView; @property (nonatomic,strong) UILabel * textCountLabel; @property (nonatomic,strong) UIButton * commitB; @property (nonatomic,strong) YYLabel * titleLabel1; @property (nonatomic,strong) YYLabel * titleLabel2; @property (nonatomic,strong) UIView * selectView; @property (nonatomic,strong) NSMutableArray * imagesArray; @property (nonatomic, copy) NSString *uploadType; @property (nonatomic, strong) ZLPhotoActionSheet * photoActionSheet; /* 视频本地地址 */ @property(nonatomic,copy)NSString *VideofileUrl; /* 视频地址 */ @property(nonatomic,copy)NSString *ReleaseVideoUrl; @end @implementation DDMyInfoJuBaoViewController -(ZLPhotoActionSheet *)photoActionSheet { if (!_photoActionSheet) { _photoActionSheet = [[ZLPhotoActionSheet alloc] init]; _photoActionSheet.configuration.allowSelectImage = YES; _photoActionSheet.configuration.allowSelectVideo = YES; _photoActionSheet.configuration.maxSelectCount = 3; _photoActionSheet.configuration.mutuallyExclusiveSelectInMix = YES; _photoActionSheet.configuration.bottomBtnsNormalBgColor = [UIColor jk_colorWithHexString:@"#333333"]; _photoActionSheet.configuration.bottomBtnsDisableBgColor = [UIColor jk_colorWithHexString:@"#333333"]; _photoActionSheet.configuration.indexLabelBgColor = [UIColor jk_colorWithHexString:@"#333333"]; _photoActionSheet.configuration.maxVideoDuration = 30.0f; _photoActionSheet.sender = self; _photoActionSheet.cancleBlock = ^{}; } return _photoActionSheet; } - (NSMutableArray *)imagesArray { if (!_imagesArray) { _imagesArray = [NSMutableArray array]; } return _imagesArray; } - (UIView *)whiteBGV1{ if (!_whiteBGV1){ _whiteBGV1 = [[UIView alloc] init]; _whiteBGV1.backgroundColor = UIColor.whiteColor; _whiteBGV1.layer.cornerRadius = 12; _whiteBGV1.layer.masksToBounds = YES; }return _whiteBGV1; } - (UIView *)whiteBGV2{ if (!_whiteBGV2){ _whiteBGV2 = [[UIView alloc] init]; _whiteBGV2.backgroundColor = UIColor.whiteColor; _whiteBGV2.layer.cornerRadius = 12; _whiteBGV2.layer.masksToBounds = YES; }return _whiteBGV2; } - (UIView *)grayBGV1{ if (!_grayBGV1){ _grayBGV1 = [[UIView alloc] init]; _grayBGV1.backgroundColor = [UIColor jk_colorWithHexString:@"#F6F6F6"]; _grayBGV1.layer.cornerRadius = 12; _grayBGV1.layer.masksToBounds = YES; }return _grayBGV1; } - (UIView *)selectView{ if (!_selectView){ _selectView = [[UIView alloc] init]; _selectView.userInteractionEnabled = YES; }return _selectView; } - (UITextView *)textView{ if (!_textView){ _textView = [[UITextView alloc] init]; _textView.textColor = [UIColor jk_colorWithHexString:@"#333333"]; _textView.placeholder = @"请描述带有对方昵称和事情的简要经过~"; _textView.placeholderColor = [UIColor jk_colorWithHexString:@"#999999"]; _textView.font = [UIFont systemFontOfSize:14]; _textView.delegate = self; }return _textView; } - (UILabel *)textCountLabel{ if (!_textCountLabel){ _textCountLabel = [[UILabel alloc] init]; _textCountLabel.textColor = [UIColor jk_colorWithHexString:@"#666666"]; _textCountLabel.font = [UIFont boldSystemFontOfSize:14]; _textCountLabel.text = @"0/100"; _textCountLabel.textAlignment = NSTextAlignmentRight; }return _textCountLabel; } - (YYLabel *)titleLabel1{ if (!_titleLabel1){ _titleLabel1 = [[YYLabel alloc] init]; _titleLabel1.attributedText = [self getTitleAttibute:@"举报描述" subTitle:@"(选填)"]; }return _titleLabel1; } - (YYLabel *)titleLabel2{ if (!_titleLabel2){ _titleLabel2 = [[YYLabel alloc] init]; _titleLabel2.attributedText = [self getTitleAttibute:@"凭证" subTitle:@"(选填,可添加3张图片证据或1个视频证据)"]; }return _titleLabel2; } - (UIButton *)commitB{ if (!_commitB){ _commitB = [UIButton buttonWithType:UIButtonTypeCustom]; [_commitB setImage:[UIImage imageNamed:@"myinfo_40"] forState:UIControlStateNormal]; [_commitB addTarget:self action:@selector(commitButtonClick) forControlEvents:UIControlEventTouchUpInside]; }return _commitB; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self defaultNavTitle:@"举报" hideLine:YES]; [self.view addSubview:self.whiteBGV1]; [self.whiteBGV1 mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(170); make.left.equalTo(self.view).offset(15); make.right.equalTo(self.view).inset(15); make.top.equalTo(self.view).offset(DDNavigationBarHeight()+20); }]; [self.whiteBGV1 addSubview:self.titleLabel1]; [self.titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(22); make.left.equalTo(self.whiteBGV1).offset(10); make.top.equalTo(self.whiteBGV1).offset(10); }]; [self.whiteBGV1 addSubview:self.grayBGV1]; [self.grayBGV1 mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.titleLabel1.mas_bottom).offset(15); make.left.equalTo(self.whiteBGV1).offset(25); make.right.equalTo(self.whiteBGV1).inset(25); make.bottom.equalTo(self.whiteBGV1).inset(15); }]; [self.grayBGV1 addSubview:self.textView]; [self.textView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.grayBGV1).inset(10); make.left.equalTo(self.grayBGV1).offset(10); make.top.equalTo(self.grayBGV1).offset(10); }]; [self.grayBGV1 addSubview:self.textCountLabel]; [self.textCountLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.grayBGV1); make.right.equalTo(self.grayBGV1).inset(10); make.left.equalTo(self.grayBGV1).offset(10); make.height.mas_equalTo(40); make.top.equalTo(self.textView.mas_bottom).offset(5); }]; [self.view addSubview:self.whiteBGV2]; [self.whiteBGV2 mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(170); make.top.equalTo(self.whiteBGV1.mas_bottom).offset(20); make.left.equalTo(self.view).offset(15); make.right.equalTo(self.view).inset(15); }]; [self.whiteBGV2 addSubview:self.titleLabel2]; [self.titleLabel2 mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(22); make.left.equalTo(self.whiteBGV2).offset(10); make.top.equalTo(self.whiteBGV2).offset(10); }]; [self.whiteBGV2 addSubview:self.selectView]; [self.selectView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.titleLabel2.mas_bottom).offset(15); make.height.mas_equalTo(84); make.right.equalTo(self.whiteBGV2).inset(10); // make.left.equalTo(self.whiteBGV2).offset(30); make.width.mas_equalTo(kWidth-40-30); }]; [self.selectView layoutIfNeeded]; [self reloadImagesViewUI]; [self.view addSubview:self.commitB]; [self.commitB mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(44); make.width.mas_equalTo(288); make.centerX.equalTo(self.view); make.top.equalTo(self.whiteBGV2.mas_bottom).offset(30); }]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [IQKeyboardManager sharedManager].enable = YES; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [IQKeyboardManager sharedManager].enable = NO; } - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { NSString *str = [NSString stringWithFormat:@"%@%@", textView.text, text]; if (str.length > 100) { return NO; } return YES; } - (void)textViewDidChange:(UITextView *)textView{ self.textCountLabel.text = [NSString stringWithFormat:@"%lu/100",[textView.text length]]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:YES]; } - (NSMutableAttributedString *)getTitleAttibute:(NSString *)title subTitle:(NSString *)subTitle{ NSMutableAttributedString *attributeString = [NSMutableAttributedString new]; [attributeString dd_appendImage:@"myinfo_41" size:CGSizeMake(4, 16)]; [attributeString dd_appendString:@" " font:[UIFont boldSystemFontOfSize:16] color:[UIColor jk_colorWithHexString:@"#333333"]]; [attributeString dd_appendString:title font:[UIFont boldSystemFontOfSize:16] color:[UIColor jk_colorWithHexString:@"#333333"]]; [attributeString dd_appendString:@" " font:[UIFont boldSystemFontOfSize:16] color:[UIColor jk_colorWithHexString:@"#333333"]]; [attributeString dd_appendString:subTitle font:[UIFont boldSystemFontOfSize:12] color:[UIColor jk_colorWithHexString:@"#999999"]]; return attributeString; } - (void)reloadImagesViewUI { if ([self.uploadType isEqualToString:@"img"]) { [self.selectView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; [[self mutableArrayValueForKey:@"imagesArray"] removeObject:[UIImage imageNamed:@"myinfo_43"]]; if (self.imagesArray.count < 3) { [[self mutableArrayValueForKey:@"imagesArray"] addObject:[UIImage imageNamed:@"myinfo_43"]]; } for (int a = 0; a < self.imagesArray.count; a ++) { UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15 + 84 * a + (self.selectView.width - 84 * 3 - 30)/2*a, 20, 84, 84)]; imageView.image = self.imagesArray[a]; [imageView roundCorners:UIRectCornerAllCorners radius:6]; [self.selectView addSubview:imageView]; if (self.imagesArray[a] == [UIImage imageNamed:@"myinfo_43"]) { WeakSelf(weakSelf) imageView.userInteractionEnabled = YES; [imageView jk_addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) { [weakSelf selectImage]; }]; continue; } UIButton * deleteButton = [UIButton buttonWithType:UIButtonTypeCustom]; [deleteButton setImage:[UIImage imageNamed:@"myinfo_42"] forState:UIControlStateNormal]; deleteButton.frame = CGRectMake(imageView.right - 22, 0, 44, 44); deleteButton.tag = a; [deleteButton addTarget:self action:@selector(deleteClick:) forControlEvents:UIControlEventTouchUpInside]; [self.selectView addSubview:deleteButton]; } }else{ dispatch_async(dispatch_get_main_queue(), ^{ [self.selectView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; [[self mutableArrayValueForKey:@"imagesArray"] removeObject:[UIImage imageNamed:@"myinfo_43"]]; if (self.imagesArray.count < 1) { [[self mutableArrayValueForKey:@"imagesArray"] addObject:[UIImage imageNamed:@"myinfo_43"]]; } for (int a = 0; a < self.imagesArray.count; a ++) { UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15 + 84 * a + (self.selectView.width - 84 * 3 - 30)/2*a, 20, 84, 84)]; imageView.image = self.imagesArray[a]; [imageView roundCorners:UIRectCornerAllCorners radius:6]; [self.selectView addSubview:imageView]; if (self.imagesArray[a] == [UIImage imageNamed:@"myinfo_43"]) { WeakSelf(weakSelf) imageView.userInteractionEnabled = YES; [imageView jk_addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) { [weakSelf selectImage]; }]; continue; } UIButton * playButton = [UIButton buttonWithType:UIButtonTypeCustom]; [playButton setImage:[UIImage imageNamed:@"DynamicData_12"] forState:UIControlStateNormal]; playButton.frame = CGRectMake(0, 0, 24, 24); playButton.center = imageView.center; // [[playButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) { // // }]; [self.selectView addSubview:playButton]; UIButton * deleteButton = [UIButton buttonWithType:UIButtonTypeCustom]; [deleteButton setImage:[UIImage imageNamed:@"myinfo_42"] forState:UIControlStateNormal]; deleteButton.frame = CGRectMake(imageView.right - 22, 0, 44, 44); deleteButton.tag = a; [deleteButton addTarget:self action:@selector(deleteClick:) forControlEvents:UIControlEventTouchUpInside]; [self.selectView addSubview:deleteButton]; } }); } } - (void)deleteClick:(UIButton *)button{ [[self mutableArrayValueForKey:@"imagesArray"] removeObjectAtIndex:button.tag]; [self reloadImagesViewUI]; } - (void)selectImage { if ([ToolsObject IsNullWithObject:self.uploadType]|| self.imagesArray[0] == [UIImage imageNamed:@"myinfo_43"]) { self.photoActionSheet.configuration.allowSelectImage = YES; self.photoActionSheet.configuration.allowSelectVideo = YES; self.photoActionSheet.configuration.maxSelectCount = 3; self.photoActionSheet.configuration.mutuallyExclusiveSelectInMix = YES; [self.photoActionSheet showPhotoLibrary]; }else{ if ([self.uploadType isEqualToString:@"img"]) { int count = 3 - (int)(self.imagesArray.count - 1); self.photoActionSheet.configuration.allowTakePhotoInLibrary = NO; self.photoActionSheet.configuration.maxSelectCount = count; self.photoActionSheet.configuration.allowSelectImage = YES; self.photoActionSheet.configuration.allowSelectVideo = NO; [self.photoActionSheet showPhotoLibrary]; }else{ self.photoActionSheet.configuration.allowTakePhotoInLibrary = NO; self.photoActionSheet.configuration.allowSelectImage = NO; self.photoActionSheet.configuration.allowSelectVideo = YES; self.photoActionSheet.configuration.maxVideoDuration = 30.0f; self.photoActionSheet.configuration.maxSelectCount = 1; [self.photoActionSheet showPhotoLibrary]; } } WeakSelf(weakSelf) [self.photoActionSheet setSelectImageBlock:^(NSArray * _Nonnull images, NSArray * _Nonnull assets, BOOL isOriginal) { [weakSelf uploadImg:assets andimage:images]; }]; } -(void)uploadImg:(NSArray *)image andimage:(NSArray *)imageArr{ PHAsset *asset = image[0]; if (asset.mediaType == PHAssetMediaTypeVideo) { self.uploadType = @"video"; if (imageArr.count != 0) { for (UIImage *images in imageArr) { [[self mutableArrayValueForKey:@"imagesArray"] removeObject:[UIImage imageNamed:@"myinfo_43"]]; [[self mutableArrayValueForKey:@"imagesArray"] addObjectsFromArray:@[images]]; } } PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init]; options.version = PHImageRequestOptionsVersionCurrent; options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic; WeakSelf(weakSelf) [ZLPhotoManager requestAssetFileUrl:asset complete:^(NSString * _Nonnull filePath) { NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey]; AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:filePath] options:opts]; NSString *path = [FileToolsObject libraryDir]; dispatch_async(dispatch_get_main_queue(), ^{ @autoreleasepool { [ToolsObject dd_movieFileMP4:urlAsset.URL completion:^(NSURL *Mp4FilePath) { NSString * thumbImagePath1 = [NSString stringWithFormat:@"source/report/video/%@.mp4",[ToolsObject dateChangeRealtimestamp]]; weakSelf.VideofileUrl = [path stringByAppendingPathComponent:thumbImagePath1]; [FileToolsObject createFileAtPath:weakSelf.VideofileUrl overwrite:YES]; NSData * mp4Data = [NSData dataWithContentsOfURL:urlAsset.URL]; [FileToolsObject writeFileAtPath:weakSelf.VideofileUrl content:mp4Data]; [weakSelf reloadImagesViewUI]; }]; } }); }]; }else if (asset.mediaType == PHAssetMediaTypeImage){ self.uploadType = @"img"; [[self mutableArrayValueForKey:@"imagesArray"] removeObject:[UIImage imageNamed:@"myinfo_43"]]; [[self mutableArrayValueForKey:@"imagesArray"] addObjectsFromArray:imageArr]; [self reloadImagesViewUI]; } } - (void)commitButtonClick { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [DDHUDManager dd_showErrorWithText:@"举报成功"]; [self.navigationController popViewControllerAnimated:YES]; }); return; [ToolsObject ShowSVProgressHUD:@""]; if ([ToolsObject IsNullWithObject:self.uploadType]|| self.imagesArray[0] == [UIImage imageNamed:@"myinfo_43"]) { [self commitDataWithImages:@""]; return; } if ([self.uploadType isEqualToString:@"img"]) { NSString *path = [FileToolsObject libraryDir]; NSMutableArray *arr = @[].mutableCopy; for (UIImage * image in self.imagesArray) { if (image == [UIImage imageNamed:@"myinfo_43"]) { continue; } NSString * imgUrl = [NSString stringWithFormat:@"source/report/image/%@.jpg",[ToolsObject dateChangeRealtimestamp]]; [FileToolsObject createFileAtPath:[path stringByAppendingPathComponent:imgUrl] overwrite:YES]; NSData *thumbImageData = [ToolsObject compressWithMaxLength:1024 WithImage:image]; [arr addObject:[path stringByAppendingPathComponent:imgUrl]]; [FileToolsObject writeFileAtPath:[path stringByAppendingPathComponent:imgUrl] content:thumbImageData]; } WeakSelf(weakSelf) [ToolsObject uploadImageWithArr:arr WithRecourseType:OSSUploadType_ReportImage completionHandler:^(NSMutableArray * _Nonnull urlArr) { if (urlArr.count > 0) { __block NSString * imagesStr = @""; [urlArr enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (idx == 0) { imagesStr = [NSString stringWithFormat:@"%@",obj]; return; } imagesStr = [NSString stringWithFormat:@"%@,%@",imagesStr,obj]; }]; dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf commitDataWithImages:imagesStr]; }); return; } [ToolsObject addPopVieToText:@"上传失败,请重试"]; }]; return; } if ([self.uploadType isEqualToString:@"video"]) { WeakSelf(weakSelf) [ToolsObject uploadVideoWithFileUrl:self.VideofileUrl WithRecourseType:(OSSUploadType_ReportVideo) completionHandler:^(id _Nonnull urlString) { weakSelf.ReleaseVideoUrl = urlString; [weakSelf commitDataWithImages:weakSelf.ReleaseVideoUrl]; return; }]; return; } } - (void)commitDataWithImages:(NSString *)images { NSMutableDictionary * requestDict = [NSMutableDictionary dictionaryWithCapacity:0]; [requestDict setValue:@(self.juBaoType) forKey:@"scene"]; [requestDict setValue:self.jubao_id forKey:@"params"]; [requestDict setValue:@"辱骂" forKey:@"report_type"];//(辱骂、涉黄等) [requestDict setValue:self.textView.text forKey:@"report_desc"];//举报内容 [requestDict setValue:images forKey:@"report_img"];//证据:图片地址,多个用豆号分开 WeakSelf(weakSelf) /// /room/report NSString *url = [DDEncryptManager dd_aesDecryptWithText:@"FsKVcXsP8WRb7QpBRRo2DA=="]; [NetworkRequest requestPOST:url parameters:requestDict block:^(BaseResponse * _Nonnull response) { [ToolsObject DismissSVProgressHUD]; if (response.code == 200){ [ToolsObject addPopVieToText:@"举报成功"]; [weakSelf.navigationController popViewControllerAnimated:YES]; } }]; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end