NYComplaintPageViewModel.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // NYComplaintPageViewModel.m
  3. // jiaPei
  4. //
  5. // Created by Ning.ge on 2023/6/30.
  6. // Copyright © 2023 JCZ. All rights reserved.
  7. //
  8. #import "NYComplaintPageViewModel.h"
  9. @implementation NYComplaintPageViewModel
  10. - (instancetype)init {
  11. self = [super init];
  12. if (self) {
  13. [self setupCommands];
  14. }
  15. return self;
  16. }
  17. - (void)setupCommands {
  18. @weakify(self)
  19. self.uploadCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) {
  20. @strongify(self);
  21. [NYSerialQueueManager.sharedInstance clear];
  22. //上传照片-记录ID
  23. for (UIImage *image in self.complaintPageViewVC.photosArray) {
  24. [NYSerialQueueManager.sharedInstance addTask:^{
  25. [self uploadComplaintPicImage:image];
  26. } completion:nil];
  27. }
  28. [MBProgressHUD rq_showProgressHUD:@"上传照片..."];
  29. [NYSerialQueueManager.sharedInstance startCompletion:^{
  30. self.complaintPageViewVC.isSelectOriginalPhoto = (BOOL)input;
  31. [self.complaintPageViewVC.collectionView reloadData];
  32. [MBProgressHUD rq_hideHUD];
  33. }];
  34. return [RACSignal empty];
  35. }];
  36. self.deleteCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) {
  37. @strongify(self);
  38. [self deleteComplaintPicIndex:[input intValue]];
  39. return [RACSignal empty];
  40. }];
  41. self.submitCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) {
  42. @strongify(self);
  43. [self submitComplaintdo];
  44. return [RACSignal empty];
  45. }];
  46. }
  47. //上传图片
  48. - (void)uploadComplaintPicImage:(UIImage *)image{
  49. __block NSMutableArray *arr = [NSMutableArray array];
  50. [RQ_CHECKBODY_MANAGER getImageStrWithImage:image completeBlock:^(NSString *backString) {
  51. [arr property:backString forKey:@"pic"];
  52. }];
  53. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  54. NSString* method = @"uploadComplaintPic";
  55. @weakify(self)
  56. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  57. NSLog(@"%@",dict);
  58. int code = [dict[@"code"] intValue];
  59. if(code == 0 ){
  60. [self.complaintPageViewVC.image_idArray addObject:dict[@"body"]];
  61. }
  62. }];
  63. }
  64. //删除照片
  65. - (void)deleteComplaintPicIndex:(int )index{
  66. NSMutableArray *arr = [NSMutableArray array];
  67. [arr property:RQ_USER_MANAGER.currentUser.city forKey:@"dqbh"];
  68. [arr property:self.complaintPageViewVC.image_idArray[index] forKey:@"id"];
  69. [self.complaintPageViewVC.image_idArray removeObjectAtIndex:index];
  70. NSString* method = @"delComplaintPic";
  71. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  72. NSLog(@"%@",dict);
  73. int code = [dict[@"code"] intValue];
  74. if(code == 0 ){
  75. NSLog(@"删除成功");
  76. }
  77. }];
  78. }
  79. //提交投诉
  80. - (void)submitComplaintdo{
  81. NSMutableString *picids = [NSMutableString string];
  82. if(self.complaintPageViewVC.image_idArray.count>0){
  83. for (id item in self.complaintPageViewVC.image_idArray) {
  84. [picids appendFormat:@"%@,",item];
  85. }
  86. NSRange range = NSMakeRange(picids.length - 1, 1);
  87. [picids deleteCharactersInRange:range];
  88. }
  89. NSString *content = self.complaintPageViewVC.content_textview.text;
  90. NSMutableArray *arr = [NSMutableArray array];
  91. [arr addPro:@"stunum" Value:RQ_USER_MANAGER.currentUser.outId];///学员编号
  92. [arr addPro:@"type" Value:@2];///驾校
  93. [arr addPro:@"content" Value:content];///投诉内容
  94. [arr addPro:@"phone" Value:RQ_USER_MANAGER.currentUser.telphone];///学员电话
  95. [arr addPro:@"picids" Value:picids];///照片ID ,,
  96. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];///地区编号
  97. [MBProgressHUD rq_showProgressHUD:@"提交投诉..."];
  98. [jiaPeiManager requestAnythingWithURL:@"uploadComplaint" array:arr data:nil completion:^(NSDictionary * root) {
  99. NSString *body = root[@"body"];
  100. [MBProgressHUD rq_hideHUD];
  101. [RQ_SHARE_FUNCTION showAlertWithMessage:body completion:nil];
  102. [RQControllerHelper.currentViewController.navigationController popViewControllerAnimated:YES];
  103. return;
  104. }];
  105. }
  106. @end