NYComplaintListViewModel.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // NYComplaintListViewModel.m
  3. // jiaPei
  4. //
  5. // Created by Ning.ge on 2023/7/4.
  6. // Copyright © 2023 JCZ. All rights reserved.
  7. //
  8. #import "NYComplaintListViewModel.h"
  9. #import "NYComplaintPageViewController.h"
  10. @implementation NYComplaintListViewModel
  11. - (instancetype)init {
  12. self = [super init];
  13. if (self) {
  14. [self setupCommands];
  15. }
  16. return self;
  17. }
  18. - (void)setupCommands {
  19. @weakify(self)
  20. self.addCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) {
  21. @strongify(self);
  22. NYComplaintPageViewController *complaintPageViewController = [[NYComplaintPageViewController alloc] init];
  23. [RQControllerHelper.currentViewController.navigationController qmui_pushViewController:complaintPageViewController animated:YES completion:nil];
  24. return [RACSignal empty];
  25. }];
  26. self.cancelCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) {
  27. @strongify(self);
  28. [self cancelHandledo:input];
  29. return [RACSignal empty];
  30. }];
  31. self.imagesCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) {
  32. @strongify(self);
  33. int currentIndex = [input[1] intValue];
  34. NSArray *images = input[0];
  35. [RQ_SHARE_FUNCTION showPhotoBrowserWithDataSource:images currentIndex:currentIndex isCanSave:NO];
  36. return [RACSignal empty];
  37. }];
  38. }
  39. - (void)getComplaintList{
  40. _currentPage = 1;
  41. NSMutableArray *arr = [NSMutableArray array];
  42. [arr addPro:@"stunum" Value:RQ_USER_MANAGER.currentUser.outId];///学员编号
  43. [arr addPro:@"currentPage" Value:@(_currentPage)];///当前页
  44. [arr addPro:@"pageSize" Value:@10];
  45. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];///地区编号
  46. NSString *method = @"getComplaintList";
  47. @weakify(self)
  48. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  49. @strongify(self);
  50. NSLog(@"%@",dict);
  51. int code = [dict[@"code"] intValue];
  52. if(code == 0 ){
  53. self.complaintDataModel = [ComplaintDataModel yy_modelWithDictionary:dict[@"body"]];
  54. if(self.complaintDataModel.list.count>0&&self.complaintList.count!=self.complaintDataModel.list.count){
  55. [self.complaintList removeAllObjects];
  56. [self.complaintList addObjectsFromArray:self.complaintDataModel.list];
  57. self.dataSource = self.complaintList;
  58. [self.vc.tableView reloadData];
  59. }
  60. }
  61. }];
  62. }
  63. //更多下一页
  64. - (void)getComplaintListMore {
  65. int total = 10* _currentPage;
  66. if(self.complaintDataModel.total > total){
  67. _currentPage +=1;
  68. NSMutableArray *arr = [NSMutableArray array];
  69. [arr addPro:@"stunum" Value:RQ_USER_MANAGER.currentUser.outId];///学员编号
  70. [arr addPro:@"currentPage" Value:@(_currentPage)];///当前页
  71. [arr addPro:@"pageSize" Value:@10];
  72. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];///地区编号
  73. NSString *method = @"getComplaintList";
  74. @weakify(self)
  75. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  76. @strongify(self);
  77. NSLog(@"%@",dict);
  78. int code = [dict[@"code"] intValue];
  79. if(code == 0 ){
  80. self.complaintDataModel = [ComplaintDataModel yy_modelWithDictionary:dict[@"body"]];
  81. if(self.complaintDataModel.list.count>0&&self.complaintList.count!=self.complaintDataModel.list.count){
  82. [self.complaintList addObjectsFromArray:self.complaintDataModel.list];
  83. self.dataSource = self.complaintList;
  84. [self.vc.tableView reloadData];
  85. }
  86. }
  87. [self.vc.tableView.mj_footer endRefreshing];
  88. }];
  89. }else {
  90. [self.vc.tableView.mj_footer endRefreshing];
  91. }
  92. }
  93. //撤销
  94. - (void)cancelHandledo:(ComplaintInfoModel*)model {
  95. NSInteger compId = model.CI_ID;//减少开销
  96. @weakify(self)
  97. [RQ_SHARE_FUNCTION showAlertWithTitle:@"提示" message:@"是否撤销投诉!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  98. if (selectedOtherButtonIndex == 0) {
  99. NSMutableArray *arr = [NSMutableArray array];
  100. [arr addPro:@"id" Value:@(compId)];
  101. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];///地区编号
  102. NSString *method = @"delComplaint";
  103. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  104. @strongify(self);
  105. NSLog(@"%@",dict);
  106. int code = [dict[@"code"] intValue];
  107. if(code == 0 ){
  108. model.AUDIT_STATUS = @4;
  109. [self.vc.tableView reloadData];
  110. }
  111. }];
  112. }
  113. }];
  114. }
  115. #pragma mark - Lazy
  116. - (NSMutableArray *)complaintList
  117. {
  118. if(!_complaintList){
  119. _complaintList = [NSMutableArray array];
  120. }
  121. return _complaintList;
  122. }
  123. @end