// // NYComplaintListViewModel.m // jiaPei // // Created by Ning.ge on 2023/7/4. // Copyright © 2023 JCZ. All rights reserved. // #import "NYComplaintListViewModel.h" #import "NYComplaintPageViewController.h" @implementation NYComplaintListViewModel - (instancetype)init { self = [super init]; if (self) { [self setupCommands]; } return self; } - (void)setupCommands { @weakify(self) self.addCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) { @strongify(self); NYComplaintPageViewController *complaintPageViewController = [[NYComplaintPageViewController alloc] init]; [RQControllerHelper.currentViewController.navigationController qmui_pushViewController:complaintPageViewController animated:YES completion:nil]; return [RACSignal empty]; }]; self.cancelCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) { @strongify(self); [self cancelHandledo:input]; return [RACSignal empty]; }]; self.imagesCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) { @strongify(self); int currentIndex = [input[1] intValue]; NSArray *images = input[0]; [RQ_SHARE_FUNCTION showPhotoBrowserWithDataSource:images currentIndex:currentIndex isCanSave:NO]; return [RACSignal empty]; }]; } - (void)getComplaintList{ _currentPage = 1; NSMutableArray *arr = [NSMutableArray array]; [arr addPro:@"stunum" Value:RQ_USER_MANAGER.currentUser.outId];///学员编号 [arr addPro:@"currentPage" Value:@(_currentPage)];///当前页 [arr addPro:@"pageSize" Value:@10]; [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];///地区编号 NSString *method = @"getComplaintList"; @weakify(self) [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) { @strongify(self); NSLog(@"%@",dict); int code = [dict[@"code"] intValue]; if(code == 0 ){ self.complaintDataModel = [ComplaintDataModel yy_modelWithDictionary:dict[@"body"]]; if(self.complaintDataModel.list.count>0&&self.complaintList.count!=self.complaintDataModel.list.count){ [self.complaintList removeAllObjects]; [self.complaintList addObjectsFromArray:self.complaintDataModel.list]; self.dataSource = self.complaintList; [self.vc.tableView reloadData]; } } }]; } //更多下一页 - (void)getComplaintListMore { int total = 10* _currentPage; if(self.complaintDataModel.total > total){ _currentPage +=1; NSMutableArray *arr = [NSMutableArray array]; [arr addPro:@"stunum" Value:RQ_USER_MANAGER.currentUser.outId];///学员编号 [arr addPro:@"currentPage" Value:@(_currentPage)];///当前页 [arr addPro:@"pageSize" Value:@10]; [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];///地区编号 NSString *method = @"getComplaintList"; @weakify(self) [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) { @strongify(self); NSLog(@"%@",dict); int code = [dict[@"code"] intValue]; if(code == 0 ){ self.complaintDataModel = [ComplaintDataModel yy_modelWithDictionary:dict[@"body"]]; if(self.complaintDataModel.list.count>0&&self.complaintList.count!=self.complaintDataModel.list.count){ [self.complaintList addObjectsFromArray:self.complaintDataModel.list]; self.dataSource = self.complaintList; [self.vc.tableView reloadData]; } } [self.vc.tableView.mj_footer endRefreshing]; }]; }else { [self.vc.tableView.mj_footer endRefreshing]; } } //撤销 - (void)cancelHandledo:(ComplaintInfoModel*)model { NSInteger compId = model.CI_ID;//减少开销 @weakify(self) [RQ_SHARE_FUNCTION showAlertWithTitle:@"提示" message:@"是否撤销投诉!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) { if (selectedOtherButtonIndex == 0) { NSMutableArray *arr = [NSMutableArray array]; [arr addPro:@"id" Value:@(compId)]; [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];///地区编号 NSString *method = @"delComplaint"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) { @strongify(self); NSLog(@"%@",dict); int code = [dict[@"code"] intValue]; if(code == 0 ){ model.AUDIT_STATUS = @4; [self.vc.tableView reloadData]; } }]; } }]; } #pragma mark - Lazy - (NSMutableArray *)complaintList { if(!_complaintList){ _complaintList = [NSMutableArray array]; } return _complaintList; } @end