RQErrorViewController.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // RQErrorViewController.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/8/3.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQErrorViewController.h"
  9. @interface RQErrorViewController ()
  10. /// viewModel
  11. @property (nonatomic, readonly, strong) RQErrorViewModel *viewModel;
  12. @property (nonatomic, readwrite, strong) RQErrorAndCollectHeaderView *errorHeaderView;
  13. @end
  14. @implementation RQErrorViewController
  15. @dynamic viewModel;
  16. #pragma mark - SystemMethod
  17. - (void)viewDidLoad {
  18. @weakify(self)
  19. [super viewDidLoad];
  20. self.tableView.tableHeaderView = self.errorHeaderView;
  21. self.tableView.backgroundColor = UIColor.clearColor;
  22. [[RACObserve(self.viewModel, dataSource) deliverOnMainThread] subscribeNext:^(NSArray *dataSource) {
  23. @strongify(self)
  24. NSUInteger count = dataSource.count;
  25. if (count == 0) {
  26. // [self showEmptyViewWithImage:RQImageNamed(@"暂无错题") text:@"暂无错题,继续保持~" detailText:nil buttonTitle:nil buttonAction:nil];
  27. [self.emptyView setImage:RQImageNamed(@"暂无错题")];
  28. [self.emptyView setLoadingViewHidden:YES];
  29. [self.emptyView setTextLabelText:@"暂无错题,继续保持~"];
  30. [self.tableView addSubview:self.emptyView];
  31. [self.tableView sendSubviewToBack:self.emptyView];
  32. CGFloat a = 8.f + RQ_FIT_HORIZONTAL(214.f) + 4.f + RQ_FIT_HORIZONTAL(40.f) + 20.f + 10.f + ((10.f + ((RQ_SCREEN_WIDTH - 32.f) * (74.f / 345.f)) + 10.f) + (RQ_FIT_HORIZONTAL(56.f)) + (RQ_FIT_HORIZONTAL(49.f)));
  33. self.emptyView.frame = CGRectMake(0, a / 2.f + 50.f, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT);
  34. self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);
  35. } else {
  36. [self hideEmptyView];
  37. self.tableView.contentInset = UIEdgeInsetsMake((RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT), 0, 0, 0);
  38. }
  39. }];
  40. [[[RQNotificationCenter rac_addObserverForName:RQCancelWrongNotification object:nil] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification * _Nullable x) {
  41. @strongify(self);
  42. self.errorHeaderView.allNumLabel.text = [NSString qmui_stringWithNSInteger:[RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count];
  43. }];
  44. }
  45. - (void)viewDidLayoutSubviews {
  46. [super viewDidLayoutSubviews];
  47. self.tableView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - RQ_APPLICATION_STATUS_BAR_HEIGHT - RQ_APPLICATION_NAV_BAR_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
  48. self.errorHeaderView.size = CGSizeMake(RQ_SCREEN_WIDTH, 8.f + RQ_FIT_HORIZONTAL(214.f) + 4.f + RQ_FIT_HORIZONTAL(40.f) + 20.f + 10.f + ((10.f + ((RQ_SCREEN_WIDTH - 32.f) * (74.f / 345.f)) + 10.f) + (RQ_FIT_HORIZONTAL(56.f)) + (RQ_FIT_HORIZONTAL(49.f))));
  49. }
  50. #pragma mark - OverrideMethods
  51. - (UITableViewCell *)tableView:(UITableView *)tableView dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath {
  52. RQCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
  53. RQCommonCollectionItemViewModel *itemViewModel = groupViewModel.itemViewModels[indexPath.row];
  54. return [NSClassFromString(itemViewModel.itemClassName) cellWithTableView:tableView];
  55. }
  56. - (void)configureCell:(RQCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object {
  57. [cell bindViewModel:object];
  58. }
  59. #pragma mark - JXPagerSmoothViewListViewDelegate
  60. - (UIView *)listView {
  61. return self.view;
  62. }
  63. - (UIScrollView *)listScrollView {
  64. return self.tableView;
  65. }
  66. #pragma mark - LazyLoad
  67. - (RQErrorAndCollectHeaderView *)errorHeaderView {
  68. if (!_errorHeaderView) {
  69. _errorHeaderView = [RQErrorAndCollectHeaderView errorAndCollectHeaderView];
  70. _errorHeaderView.size = CGSizeMake(RQ_SCREEN_WIDTH, 8.f + RQ_FIT_HORIZONTAL(214.f) + 4.f + RQ_FIT_HORIZONTAL(40.f) + 20.f + 10.f + ((10.f + ((RQ_SCREEN_WIDTH - 32.f) * (74.f / 345.f)) + 10.f) + (RQ_FIT_HORIZONTAL(56.f)) + (RQ_FIT_HORIZONTAL(49.f))));
  71. _errorHeaderView.bottomView.hidden = NO;
  72. [_errorHeaderView.todayErrorBtn setTitleNormal:@"今日错题"];
  73. [_errorHeaderView.allErrorBtn setTitleNormal:@"全部错题"];
  74. _errorHeaderView.titleLabel.text = @"错题数";
  75. _errorHeaderView.allNumLabel.text = [NSString qmui_stringWithNSInteger:[RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count];
  76. [_errorHeaderView.todayErrorBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  77. NSArray *todayArr = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong];
  78. NSArray *arr = [todayArr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) {
  79. return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel];
  80. }].toArray;
  81. RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  82. RQHomePageCarTypeKey : @(RQ_YDTQuestion_Module.carType),
  83. RQHomePageSubjectTypeKey : @(RQ_YDTQuestion_Module.subject),
  84. RQHomeSubPageTypeKey : @(RQHomeSubPageType_WrongTopicAndCollection),
  85. RQViewModelIDKey : @"今日错题",
  86. RQExerciseTypeKey : @(RQExerciseType_Wrong),
  87. RQViewModelUtilKey : arr,
  88. }];
  89. [RQ_APPDELEGATE.services pushViewModel:exerciseViewModel animated:YES];
  90. }];
  91. [_errorHeaderView.allErrorBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  92. NSArray *allArr = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong];
  93. NSArray *arr = [allArr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) {
  94. return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel];
  95. }].toArray;
  96. RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  97. RQHomePageCarTypeKey : @(RQ_YDTQuestion_Module.carType),
  98. RQHomePageSubjectTypeKey : @(RQ_YDTQuestion_Module.subject),
  99. RQHomeSubPageTypeKey : @(RQHomeSubPageType_WrongTopicAndCollection),
  100. RQViewModelIDKey : @"全部错题",
  101. RQExerciseTypeKey : @(RQExerciseType_Wrong),
  102. RQViewModelUtilKey : arr,
  103. }];
  104. [RQ_APPDELEGATE.services pushViewModel:exerciseViewModel animated:YES];
  105. }];
  106. }
  107. return _errorHeaderView;
  108. }
  109. @end