YMReportViewModel.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. //
  2. // YMReportViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/5.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMReportViewModel.h"
  9. #import "YMReportReasonModel.h"
  10. #import "YOUPAILCIMSessionVC.h"
  11. @interface YMReportViewModel ()<TZImagePickerControllerDelegate>
  12. /// 举报备注最大上限
  13. @property (nonatomic, assign, readwrite) NSInteger reportRemarkMaxLength;
  14. /// 举报类型 1 个人详情页 2 视频 3 动态 4 IM
  15. @property (nonatomic, assign, readwrite) YMReportType reportType;
  16. /// 举报原因数据
  17. @property (nonatomic, strong, readwrite) NSArray <YMReportReasonCellViewModel*>*reportReasonDataArray;
  18. /// 是否显示添加Cell
  19. @property (nonatomic, assign, readwrite) BOOL isHideAddCell;
  20. /// 添加CellViewModel
  21. @property (nonatomic, strong, readwrite) YMReportEvidenceCellViewModel *addCellViewModel;
  22. /// 举报证据数据
  23. @property (nonatomic, strong, readwrite) NSArray <YMReportEvidenceCellViewModel*>*reportEvidenceDataArray;
  24. /// 刷新举报原因
  25. @property (nonatomic, strong, readwrite) RACSubject *refreshReportReasonSubject;
  26. /// 刷新举报证据
  27. @property (nonatomic, strong, readwrite) RACSubject *refreshReportEvidenceSubject;
  28. /// 获取举报原因Id
  29. @property (nonatomic, strong, readwrite) RACSubject *getReportReasonIdSubject;
  30. /// 新增证据
  31. @property (nonatomic, strong, readwrite) RACSubject *addReportEvidenceSubject;
  32. /// 删除证据
  33. @property (nonatomic, strong, readwrite) RACSubject *deleteReportEvidenceSubject;
  34. /// 获取举报文本
  35. @property (nonatomic, strong, readwrite) RACSubject *getReportTextSubject;
  36. /// 举报Id
  37. @property (nonatomic, assign) NSInteger reportId;
  38. /// 举报原因Id
  39. @property (nonatomic, assign) NSInteger reportReasonId;
  40. /// 举报证据图片链接
  41. @property (nonatomic, copy) NSString *reportEvidenceImagesUrl;
  42. /// 举报文本
  43. @property (nonatomic, copy) NSString *reportText;
  44. @end
  45. @implementation YMReportViewModel
  46. - (void)ym_initialize{
  47. [super ym_initialize];
  48. self.customNavTitle = @"举报";
  49. self.reportRemarkMaxLength = 100;
  50. self.reportType = [self.params integerValueForKey:ParamsCategoryType defaultValue:YMReportTypePersonalPage];
  51. self.reportId = [self.params integerValueForKey:ParamsId defaultValue:0];
  52. self.addCellViewModel = [[YMReportEvidenceCellViewModel alloc]initWithParams:@{
  53. @"isAddCell":@(YES),
  54. @"isHideDeleteButton":@(YES),
  55. }];
  56. @weakify(self)
  57. [[self.getReportReasonIdSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * _Nullable value) {
  58. @strongify(self)
  59. self.reportReasonId = [value intValue];
  60. }];
  61. [[self.addReportEvidenceSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSArray <UIImage*> * _Nullable photos) {
  62. @strongify(self)
  63. NSMutableArray *tempArr = [NSMutableArray arrayWithArray:self.reportEvidenceDataArray];
  64. NSArray *viewModelArr = [photos.rac_sequence map:^id _Nullable(UIImage * _Nullable value) {
  65. YMReportEvidenceCellViewModel *viewModel = [[YMReportEvidenceCellViewModel alloc]initWithParams:@{
  66. @"isAddCell":@(NO),
  67. @"localAlbum":value,
  68. @"isHideDeleteButton":@(NO)
  69. }];
  70. return viewModel;
  71. }].array;
  72. [tempArr addObjectsFromArray:viewModelArr];
  73. self.reportEvidenceDataArray = tempArr.mutableCopy;
  74. self.isHideAddCell = self.reportEvidenceDataArray.count < 9 ? NO : YES;
  75. [self.refreshReportEvidenceSubject sendNext:@(YMRefreshUI)];
  76. }];
  77. [[self.deleteReportEvidenceSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNumber * _Nullable index) {
  78. @strongify(self)
  79. NSMutableArray *tempArr = [NSMutableArray arrayWithArray:self.reportEvidenceDataArray];
  80. [tempArr removeObjectAtIndex:[index intValue]];
  81. self.reportEvidenceDataArray = tempArr.mutableCopy;
  82. self.isHideAddCell = self.reportEvidenceDataArray.count < 9 ? NO : YES;
  83. [self.refreshReportEvidenceSubject sendNext:@(YMRefreshUI)];
  84. }];
  85. [[self.getReportTextSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSString * _Nullable value) {
  86. @strongify(self)
  87. self.reportText = value;
  88. }];
  89. }
  90. - (void)getReportReasonListData{
  91. @weakify(self)
  92. [ZCHUDHelper showWithStatus:@"加载中..."];
  93. [LCHttpHelper requestWithURLString:ReportInit parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  94. @strongify(self)
  95. NSDictionary* dict = (NSDictionary*)responseObject;
  96. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  97. if (code == 0) {
  98. [ZCHUDHelper dismiss];
  99. self.reportReasonDataArray = [[NSArray yy_modelArrayWithClass:[YMReportReasonModel class] json:[dict arrayValueForKey:@"data" defaultValue:@[]]].rac_sequence map:^(YMReportReasonModel * _Nullable model) {
  100. YMReportReasonCellViewModel *viewModel = [[YMReportReasonCellViewModel alloc]initWithParams:@{
  101. ParamsModel:model
  102. }];
  103. return viewModel;
  104. }].array;
  105. [self.refreshReportReasonSubject sendNext:@(YMRefreshUI)];
  106. [self.refreshReportEvidenceSubject sendNext:@(YMRefreshUI)];
  107. }else{
  108. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  109. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  110. [self.refreshReportReasonSubject sendNext:@(YMRefreshError)];
  111. [self.refreshReportEvidenceSubject sendNext:@(YMRefreshError)];
  112. });
  113. }
  114. } failure:^(NSError *error) {
  115. [ZCHUDHelper showTitle:error.localizedDescription];
  116. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  117. [self.refreshReportReasonSubject sendNext:@(YMRefreshError)];
  118. [self.refreshReportEvidenceSubject sendNext:@(YMRefreshError)];
  119. });
  120. }];
  121. }
  122. - (void)uploadReportEvidenceData{
  123. if (self.reportReasonId == 0) {
  124. [ZCHUDHelper showTitle:@"选择举报类型"];
  125. return;
  126. }
  127. NSArray <UIImage*> *photos = [self.reportEvidenceDataArray.rac_sequence map:^id _Nullable(YMReportEvidenceCellViewModel * _Nullable viewModel) {
  128. return viewModel.localAlbum;
  129. }].array;
  130. if (photos.count > 0) {
  131. [ZCHUDHelper showWithStatus:@"正在上传证据..."];
  132. [LCCommonHttp uploadWithImages:photos Type:@"album" successBlock:^(NSArray<NSString *> *ossImagePaths) {
  133. [ZCHUDHelper dismiss];
  134. self.reportEvidenceImagesUrl = [ossImagePaths componentsJoinedByString:@","];
  135. [self submitReportInfoData];
  136. }];
  137. }else{
  138. [self submitReportInfoData];
  139. }
  140. }
  141. - (void)submitReportInfoData{
  142. [ZCHUDHelper showWithStatus:@"正在提交证据..."];
  143. [LCHttpHelper requestWithURLString:ReportUpload parameters:@{
  144. @"type":@(self.reportType),
  145. @"report_uid":@(self.reportId),
  146. @"cate_id":@(self.reportReasonId),
  147. @"images":self.reportEvidenceImagesUrl?:@"",
  148. @"content":self.reportText?:@""
  149. } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  150. NSDictionary* dict = (NSDictionary*)responseObject;
  151. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  152. if (code == 0) {
  153. [ZCHUDHelper dismiss];
  154. YMTipsPopupView *customView = [[YMTipsPopupView alloc]init];
  155. customView.titleText = @"举报成功";
  156. customView.cancelTitle = @"需紧急处理";
  157. customView.confirmTitle = @"确定";
  158. [customView configutationWithTips:@"我们已接收到您的举报内容,非常重视您的举报。每一条举报都会被认真核实,并依据国家法律法规及本平台条款积极处理,感谢您的配合。" TipsAlignment:NSTextAlignmentLeft IsHideTitle:NO IsHideSingleButton:YES];
  159. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
  160. popupView.priority = 999;
  161. popupView.cornerRadius = adapt(10);
  162. popupView.rectCorners = UIRectCornerAllCorners;
  163. popupView.positionStyle = YMPositionStyleCenter;
  164. popupView.isHideBg = NO;
  165. popupView.bgAlpha = 0.3;
  166. @weakify(popupView)
  167. customView.buttonBlock = ^(BOOL isConfirm) {
  168. @strongify(popupView)
  169. if (isConfirm) {
  170. [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES];
  171. }else{
  172. NIMSession *session = [NIMSession session:@"4" type:NIMSessionTypeP2P];
  173. [ZCHUDHelper show];
  174. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  175. [ZCHUDHelper dismiss];
  176. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
  177. [[YMGlobalUtils getCurrentVC].navigationController pushViewController:vc animated:YES];
  178. }];
  179. }
  180. [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
  181. };
  182. [popupView pop];
  183. }else{
  184. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  185. }
  186. } failure:^(NSError *error) {
  187. [ZCHUDHelper showTitle:error.localizedDescription];
  188. }];
  189. }
  190. - (void)openEvidencePickerPopupView{
  191. TZImagePickerController *imagePickerVC = [[TZImagePickerController alloc] initWithMaxImagesCount:9 columnNumber:4 delegate:self];
  192. [LCTZImageConfigHelper setDefaultTZImageConfig:imagePickerVC];
  193. imagePickerVC.allowTakePicture = NO;
  194. imagePickerVC.allowTakeVideo = NO;
  195. imagePickerVC.allowPickingVideo = NO;
  196. imagePickerVC.allowPickingImage = YES;
  197. imagePickerVC.showSelectBtn = YES;
  198. imagePickerVC.allowPickingOriginalPhoto = YES;
  199. imagePickerVC.showSelectedIndex = YES;
  200. imagePickerVC.sortAscendingByModificationDate = YES;
  201. [imagePickerVC setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
  202. // //1通过,0待审核,2,未通过
  203. // [LCCommonHttp uploadWithImages:photos Type:@"album" successBlock:^(NSArray<NSString *> *ossImagePaths) {
  204. // NSString *uploadImage = ossImagePaths.firstObject;
  205. // self.userAvatar = uploadImage;
  206. // }];
  207. }];
  208. imagePickerVC.modalPresentationStyle = UIModalPresentationFullScreen;
  209. [[YMGlobalUtils getCurrentVC] presentViewController:imagePickerVC animated:YES completion:nil];
  210. }
  211. #pragma mark - TZImagePickerControllerDelegate
  212. - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)infos{
  213. [self.addReportEvidenceSubject sendNext:photos];
  214. }
  215. - (RACSubject *)refreshReportReasonSubject{
  216. if (!_refreshReportReasonSubject) {
  217. _refreshReportReasonSubject = [RACSubject subject];
  218. }
  219. return _refreshReportReasonSubject;
  220. }
  221. - (RACSubject *)refreshReportEvidenceSubject{
  222. if (!_refreshReportEvidenceSubject) {
  223. _refreshReportEvidenceSubject = [RACSubject subject];
  224. }
  225. return _refreshReportEvidenceSubject;
  226. }
  227. - (RACSubject *)getReportReasonIdSubject{
  228. if (!_getReportReasonIdSubject) {
  229. _getReportReasonIdSubject = [RACSubject subject];
  230. }
  231. return _getReportReasonIdSubject;
  232. }
  233. - (RACSubject *)addReportEvidenceSubject{
  234. if (!_addReportEvidenceSubject) {
  235. _addReportEvidenceSubject = [RACSubject subject];
  236. }
  237. return _addReportEvidenceSubject;
  238. }
  239. - (RACSubject *)deleteReportEvidenceSubject{
  240. if (!_deleteReportEvidenceSubject) {
  241. _deleteReportEvidenceSubject = [RACSubject subject];
  242. }
  243. return _deleteReportEvidenceSubject;
  244. }
  245. - (RACSubject *)getReportTextSubject{
  246. if (!_getReportTextSubject) {
  247. _getReportTextSubject = [RACSubject subject];
  248. }
  249. return _getReportTextSubject;
  250. }
  251. @end