123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- //
- // 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 ()<TZImagePickerControllerDelegate>
- /// 举报备注最大上限
- @property (nonatomic, assign, readwrite) NSInteger reportRemarkMaxLength;
- /// 举报类型 1 个人详情页 2 视频 3 动态 4 IM
- @property (nonatomic, assign, readwrite) YMReportType reportType;
- /// 举报原因数据
- @property (nonatomic, strong, readwrite) NSArray <YMReportReasonCellViewModel*>*reportReasonDataArray;
- /// 是否显示添加Cell
- @property (nonatomic, assign, readwrite) BOOL isHideAddCell;
- /// 添加CellViewModel
- @property (nonatomic, strong, readwrite) YMReportEvidenceCellViewModel *addCellViewModel;
- /// 举报证据数据
- @property (nonatomic, strong, readwrite) NSArray <YMReportEvidenceCellViewModel*>*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 <UIImage*> * _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 <UIImage*> *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<NSString *> *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<NIMUser *> * _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<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
- // //1通过,0待审核,2,未通过
- // [LCCommonHttp uploadWithImages:photos Type:@"album" successBlock:^(NSArray<NSString *> *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<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)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
|