// // YMReportViewModel.m // MSYOUPAI // // Created by YoMi on 2024/3/5. // Copyright © 2024 MS. All rights reserved. // #import "YMReportViewModel.h" #import "YMReportReasonModel.h" #import "YOUPAILCIMSessionVC.h" @interface YMReportViewModel () /// 举报备注最大上限 @property (nonatomic, assign, readwrite) NSInteger reportRemarkMaxLength; /// 举报类型 1 个人详情页 2 视频 3 动态 4 IM @property (nonatomic, assign, readwrite) YMReportType reportType; /// 举报原因数据 @property (nonatomic, strong, readwrite) NSArray *reportReasonDataArray; /// 是否显示添加Cell @property (nonatomic, assign, readwrite) BOOL isHideAddCell; /// 添加CellViewModel @property (nonatomic, strong, readwrite) YMReportEvidenceCellViewModel *addCellViewModel; /// 举报证据数据 @property (nonatomic, strong, readwrite) NSArray *reportEvidenceDataArray; /// 刷新举报原因 @property (nonatomic, strong, readwrite) RACSubject *refreshReportReasonSubject; /// 刷新举报证据 @property (nonatomic, strong, readwrite) RACSubject *refreshReportEvidenceSubject; /// 获取举报原因Id @property (nonatomic, strong, readwrite) RACSubject *getReportReasonIdSubject; /// 新增证据 @property (nonatomic, strong, readwrite) RACSubject *addReportEvidenceSubject; /// 删除证据 @property (nonatomic, strong, readwrite) RACSubject *deleteReportEvidenceSubject; /// 获取举报文本 @property (nonatomic, strong, readwrite) RACSubject *getReportTextSubject; /// 举报Id @property (nonatomic, assign) NSInteger reportId; /// 举报原因Id @property (nonatomic, assign) NSInteger reportReasonId; /// 举报证据图片链接 @property (nonatomic, copy) NSString *reportEvidenceImagesUrl; /// 举报文本 @property (nonatomic, copy) NSString *reportText; @end @implementation YMReportViewModel - (void)ym_initialize{ [super ym_initialize]; self.customNavTitle = @"举报"; self.reportRemarkMaxLength = 100; self.reportType = [self.params integerValueForKey:ParamsCategoryType defaultValue:YMReportTypePersonalPage]; self.reportId = [self.params integerValueForKey:ParamsId defaultValue:0]; self.addCellViewModel = [[YMReportEvidenceCellViewModel alloc]initWithParams:@{ @"isAddCell":@(YES), @"isHideDeleteButton":@(YES), }]; @weakify(self) [[self.getReportReasonIdSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * _Nullable value) { @strongify(self) self.reportReasonId = [value intValue]; }]; [[self.addReportEvidenceSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSArray * _Nullable photos) { @strongify(self) NSMutableArray *tempArr = [NSMutableArray arrayWithArray:self.reportEvidenceDataArray]; NSArray *viewModelArr = [photos.rac_sequence map:^id _Nullable(UIImage * _Nullable value) { YMReportEvidenceCellViewModel *viewModel = [[YMReportEvidenceCellViewModel alloc]initWithParams:@{ @"isAddCell":@(NO), @"localAlbum":value, @"isHideDeleteButton":@(NO) }]; return viewModel; }].array; [tempArr addObjectsFromArray:viewModelArr]; self.reportEvidenceDataArray = tempArr.mutableCopy; self.isHideAddCell = self.reportEvidenceDataArray.count < 9 ? NO : YES; [self.refreshReportEvidenceSubject sendNext:@(YMRefreshUI)]; }]; [[self.deleteReportEvidenceSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * _Nullable index) { @strongify(self) NSMutableArray *tempArr = [NSMutableArray arrayWithArray:self.reportEvidenceDataArray]; [tempArr removeObjectAtIndex:[index intValue]]; self.reportEvidenceDataArray = tempArr.mutableCopy; self.isHideAddCell = self.reportEvidenceDataArray.count < 9 ? NO : YES; [self.refreshReportEvidenceSubject sendNext:@(YMRefreshUI)]; }]; [[self.getReportTextSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * _Nullable value) { @strongify(self) self.reportText = value; }]; } - (void)getReportReasonListData{ @weakify(self) [ZCHUDHelper showWithStatus:@"加载中..."]; [LCHttpHelper requestWithURLString:ReportInit parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self) NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [ZCHUDHelper dismiss]; self.reportReasonDataArray = [[NSArray yy_modelArrayWithClass:[YMReportReasonModel class] json:[dict arrayValueForKey:@"data" defaultValue:@[]]].rac_sequence map:^(YMReportReasonModel * _Nullable model) { YMReportReasonCellViewModel *viewModel = [[YMReportReasonCellViewModel alloc]initWithParams:@{ ParamsModel:model }]; return viewModel; }].array; [self.refreshReportReasonSubject sendNext:@(YMRefreshUI)]; [self.refreshReportEvidenceSubject sendNext:@(YMRefreshUI)]; }else{ [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.refreshReportReasonSubject sendNext:@(YMRefreshError)]; [self.refreshReportEvidenceSubject sendNext:@(YMRefreshError)]; }); } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.refreshReportReasonSubject sendNext:@(YMRefreshError)]; [self.refreshReportEvidenceSubject sendNext:@(YMRefreshError)]; }); }]; } - (void)uploadReportEvidenceData{ if (self.reportReasonId == 0) { [ZCHUDHelper showTitle:@"选择举报类型"]; return; } NSArray *photos = [self.reportEvidenceDataArray.rac_sequence map:^id _Nullable(YMReportEvidenceCellViewModel * _Nullable viewModel) { return viewModel.localAlbum; }].array; if (photos.count > 0) { [ZCHUDHelper showWithStatus:@"正在上传证据..."]; [LCCommonHttp uploadWithImages:photos Type:@"album" successBlock:^(NSArray *ossImagePaths) { [ZCHUDHelper dismiss]; self.reportEvidenceImagesUrl = [ossImagePaths componentsJoinedByString:@","]; [self submitReportInfoData]; }]; }else{ [self submitReportInfoData]; } } - (void)submitReportInfoData{ [ZCHUDHelper showWithStatus:@"正在提交证据..."]; [LCHttpHelper requestWithURLString:ReportUpload parameters:@{ @"type":@(self.reportType), @"report_uid":@(self.reportId), @"cate_id":@(self.reportReasonId), @"images":self.reportEvidenceImagesUrl?:@"", @"content":self.reportText?:@"" } needToken:YES type:HttpRequestTypePost success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [ZCHUDHelper dismiss]; YMTipsPopupView *customView = [[YMTipsPopupView alloc]init]; customView.titleText = @"举报成功"; customView.cancelTitle = @"需紧急处理"; customView.confirmTitle = @"确定"; [customView configutationWithTips:@"我们已接收到您的举报内容,非常重视您的举报。每一条举报都会被认真核实,并依据国家法律法规及本平台条款积极处理,感谢您的配合。" TipsAlignment:NSTextAlignmentLeft IsHideTitle:NO IsHideSingleButton:YES]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerAllCorners; popupView.positionStyle = YMPositionStyleCenter; popupView.isHideBg = NO; popupView.bgAlpha = 0.3; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm) { @strongify(popupView) if (isConfirm) { [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES]; }else{ NIMSession *session = [NIMSession session:@"4" type:NIMSessionTypeP2P]; [ZCHUDHelper show]; [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray * _Nullable users, NSError * _Nullable error) { [ZCHUDHelper dismiss]; YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session]; [[YMGlobalUtils getCurrentVC].navigationController pushViewController:vc animated:YES]; }]; } [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; [popupView pop]; }else{ [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)openEvidencePickerPopupView{ TZImagePickerController *imagePickerVC = [[TZImagePickerController alloc] initWithMaxImagesCount:9 columnNumber:4 delegate:self]; [LCTZImageConfigHelper setDefaultTZImageConfig:imagePickerVC]; imagePickerVC.allowTakePicture = NO; imagePickerVC.allowTakeVideo = NO; imagePickerVC.allowPickingVideo = NO; imagePickerVC.allowPickingImage = YES; imagePickerVC.showSelectBtn = YES; imagePickerVC.allowPickingOriginalPhoto = YES; imagePickerVC.showSelectedIndex = YES; imagePickerVC.sortAscendingByModificationDate = YES; [imagePickerVC setDidFinishPickingPhotosHandle:^(NSArray *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { // //1通过,0待审核,2,未通过 // [LCCommonHttp uploadWithImages:photos Type:@"album" successBlock:^(NSArray *ossImagePaths) { // NSString *uploadImage = ossImagePaths.firstObject; // self.userAvatar = uploadImage; // }]; }]; imagePickerVC.modalPresentationStyle = UIModalPresentationFullScreen; [[YMGlobalUtils getCurrentVC] presentViewController:imagePickerVC animated:YES completion:nil]; } #pragma mark - TZImagePickerControllerDelegate - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray *)infos{ [self.addReportEvidenceSubject sendNext:photos]; } - (RACSubject *)refreshReportReasonSubject{ if (!_refreshReportReasonSubject) { _refreshReportReasonSubject = [RACSubject subject]; } return _refreshReportReasonSubject; } - (RACSubject *)refreshReportEvidenceSubject{ if (!_refreshReportEvidenceSubject) { _refreshReportEvidenceSubject = [RACSubject subject]; } return _refreshReportEvidenceSubject; } - (RACSubject *)getReportReasonIdSubject{ if (!_getReportReasonIdSubject) { _getReportReasonIdSubject = [RACSubject subject]; } return _getReportReasonIdSubject; } - (RACSubject *)addReportEvidenceSubject{ if (!_addReportEvidenceSubject) { _addReportEvidenceSubject = [RACSubject subject]; } return _addReportEvidenceSubject; } - (RACSubject *)deleteReportEvidenceSubject{ if (!_deleteReportEvidenceSubject) { _deleteReportEvidenceSubject = [RACSubject subject]; } return _deleteReportEvidenceSubject; } - (RACSubject *)getReportTextSubject{ if (!_getReportTextSubject) { _getReportTextSubject = [RACSubject subject]; } return _getReportTextSubject; } @end