// // NYComplaintPageViewModel.m // jiaPei // // Created by Ning.ge on 2023/6/30. // Copyright © 2023 JCZ. All rights reserved. // #import "NYComplaintPageViewModel.h" @implementation NYComplaintPageViewModel - (instancetype)init { self = [super init]; if (self) { [self setupCommands]; } return self; } - (void)setupCommands { @weakify(self) self.uploadCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) { @strongify(self); [NYSerialQueueManager.sharedInstance clear]; //上传照片-记录ID for (UIImage *image in self.complaintPageViewVC.photosArray) { [NYSerialQueueManager.sharedInstance addTask:^{ [self uploadComplaintPicImage:image]; } completion:nil]; } [MBProgressHUD rq_showProgressHUD:@"上传照片..."]; [NYSerialQueueManager.sharedInstance startCompletion:^{ self.complaintPageViewVC.isSelectOriginalPhoto = (BOOL)input; [self.complaintPageViewVC.collectionView reloadData]; [MBProgressHUD rq_hideHUD]; }]; return [RACSignal empty]; }]; self.deleteCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) { @strongify(self); [self deleteComplaintPicIndex:[input intValue]]; return [RACSignal empty]; }]; self.submitCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) { @strongify(self); [self submitComplaintdo]; return [RACSignal empty]; }]; } //上传图片 - (void)uploadComplaintPicImage:(UIImage *)image{ __block NSMutableArray *arr = [NSMutableArray array]; [RQ_CHECKBODY_MANAGER getImageStrWithImage:image completeBlock:^(NSString *backString) { [arr property:backString forKey:@"pic"]; }]; [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"]; NSString* method = @"uploadComplaintPic"; @weakify(self) [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) { NSLog(@"%@",dict); int code = [dict[@"code"] intValue]; if(code == 0 ){ [self.complaintPageViewVC.image_idArray addObject:dict[@"body"]]; } }]; } //删除照片 - (void)deleteComplaintPicIndex:(int )index{ NSMutableArray *arr = [NSMutableArray array]; [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"]; [arr property:self.complaintPageViewVC.image_idArray[index] forKey:@"id"]; [self.complaintPageViewVC.image_idArray removeObjectAtIndex:index]; NSString* method = @"delComplaintPic"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) { NSLog(@"%@",dict); int code = [dict[@"code"] intValue]; if(code == 0 ){ NSLog(@"删除成功"); } }]; } //提交投诉 - (void)submitComplaintdo{ NSMutableString *picids = [NSMutableString string]; if(self.complaintPageViewVC.image_idArray.count>0){ for (id item in self.complaintPageViewVC.image_idArray) { [picids appendFormat:@"%@,",item]; } NSRange range = NSMakeRange(picids.length - 1, 1); [picids deleteCharactersInRange:range]; } NSString *content = self.complaintPageViewVC.content_textview.text; NSMutableArray *arr = [NSMutableArray array]; [arr addPro:@"stunum" Value:RQ_USER_MANAGER.currentUser.outId];///学员编号 [arr addPro:@"type" Value:@2];///驾校 [arr addPro:@"content" Value:content];///投诉内容 [arr addPro:@"phone" Value:RQ_USER_MANAGER.currentUser.telphone];///学员电话 [arr addPro:@"picids" Value:picids];///照片ID ,, [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];///地区编号 [MBProgressHUD rq_showProgressHUD:@"提交投诉..."]; [jiaPeiManager requestAnythingWithURL:@"uploadComplaint" array:arr data:nil completion:^(NSDictionary * root) { NSString *body = root[@"body"]; [MBProgressHUD rq_hideHUD]; [RQ_SHARE_FUNCTION showAlertWithMessage:body completion:nil]; [RQControllerHelper.currentViewController.navigationController popViewControllerAnimated:YES]; return; }]; } @end