RQExamHistoryCell.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // RQExamHistoryCell.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/8/2.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQExamHistoryCell.h"
  9. @interface RQExamHistoryCell ()
  10. @property (nonatomic, readwrite, strong) RQExamHistoryItemViewModel *viewModel;
  11. @property (weak, nonatomic) IBOutlet UIView *myContentView;
  12. @property (weak, nonatomic) IBOutlet QMUIButton *toTiFenBtn;
  13. @property (weak, nonatomic) IBOutlet QMUIButton *toDoExamBtn;
  14. @property (weak, nonatomic) IBOutlet UILabel *bottomLabel;
  15. @property (weak, nonatomic) IBOutlet UIStackView *historyListView;
  16. @end
  17. @implementation RQExamHistoryCell
  18. #pragma mark - PublicMethods
  19. + (instancetype)cellWithTableView:(UITableView *)tableView {
  20. static NSString *ID = @"RQExamHistoryCell";
  21. RQExamHistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  22. if (!cell) {
  23. cell = [self rq_viewFromXib];
  24. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  25. }
  26. return cell;
  27. }
  28. - (void)bindViewModel:(RQExamHistoryItemViewModel *)viewModel {
  29. @weakify(self)
  30. _viewModel = viewModel;
  31. if (viewModel.examResultArr.count > 0) {
  32. self.historyListView.hidden = NO;
  33. self.bottomLabel.text = [NSString stringWithFormat:@"-最近%ld次考试成绩-",(viewModel.examResultArr.count > 10? 10 : viewModel.examResultArr.count)];
  34. self.toDoExamBtn.hidden = YES;
  35. NSArray *honors = @[@"马路杀手",@"驾考标兵",@"驾考牛人",@"驾考神人",@"外星人",@"幸运儿"];
  36. [[[viewModel.examResultArr.rac_sequence.signal deliverOnMainThread] takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(RQExamResultModel *examResultModel) {
  37. @strongify(self)
  38. NSString *dateStr = examResultModel.crdate;
  39. if ([dateStr containsString:@" "]) {
  40. dateStr = [[dateStr componentsSeparatedByString:@" "] firstObject];
  41. }
  42. if (dateStr.length > 5) {
  43. dateStr = [dateStr substringFromIndex:5];
  44. }
  45. if ([dateStr containsString:@"-"]) {
  46. dateStr = [dateStr stringByReplacingOccurrencesOfString:@"-" withString:@"月"];
  47. dateStr = [NSString stringWithFormat:@"%@日",dateStr];
  48. }
  49. int timeS = [examResultModel.totalTime intValue];
  50. int min = timeS/60;
  51. int sec = timeS%60;
  52. NSString *minStr = [NSString stringWithFormat:@"%d",min];
  53. NSString *secStr = [NSString stringWithFormat:@"%d",sec];
  54. if (min < 10) {
  55. minStr = [NSString stringWithFormat:@"0%d",min];
  56. }
  57. if (sec < 10) {
  58. secStr = [NSString stringWithFormat:@"0%d",sec];
  59. }
  60. NSInteger score = [examResultModel.score integerValue];
  61. NSString *graHonorStr = @"";
  62. if (score < 60) {
  63. graHonorStr = honors[0];
  64. }else if (score < 90){
  65. graHonorStr = honors[1];
  66. }else if (score < 93){
  67. graHonorStr = honors[2];
  68. }else if (score < 96){
  69. graHonorStr = honors[3];
  70. }else if (score < 98){
  71. graHonorStr = honors[4];
  72. }else{
  73. graHonorStr = honors[5];
  74. }
  75. NSInteger index = [viewModel.examResultArr indexOfObject:examResultModel];
  76. NSInteger countTag = (index + 1) * 1000 + 1;
  77. UILabel *countLabel = [self viewWithTag:countTag];
  78. countLabel.text = [NSString stringWithFormat:@"%@分",examResultModel.score];
  79. NSInteger timeTag = (index + 1) * 1000 + 2;
  80. UILabel *timeLabel = [self viewWithTag:timeTag];
  81. timeLabel.text = [NSString stringWithFormat:@"%@分%@秒",minStr,secStr];
  82. NSInteger dateTag = (index + 1) * 1000 + 3;
  83. UILabel *dateLabel = [self viewWithTag:dateTag];
  84. dateLabel.text = [NSString stringWithFormat:@"%@",dateStr];
  85. NSInteger descTag = (index + 1) * 1000 + 4;
  86. UILabel *descLabel = [self viewWithTag:descTag];
  87. descLabel.textColor = [graHonorStr isEqualToString:@"马路杀手"]? RQ_MAIN_TEXT_COLOR_RED : RQ_MAIN_TEXT_COLOR_GREEN;
  88. descLabel.text = [NSString stringWithFormat:@"%@",graHonorStr];
  89. NSInteger tag = 1990 + index;
  90. UIStackView *currentHistoryItemView = [self viewWithTag:tag];
  91. currentHistoryItemView.hidden = NO;
  92. }];
  93. } else {
  94. self.historyListView.hidden = YES;
  95. self.bottomLabel.text = [NSString stringWithFormat:@"-您还没有考试过-"];
  96. self.toDoExamBtn.hidden = NO;
  97. }
  98. }
  99. - (void)awakeFromNib {
  100. [super awakeFromNib];
  101. _toTiFenBtn.imagePosition = QMUIButtonImagePositionRight;
  102. _myContentView.layer.shadowColor = RGBA_COLOR(124, 129, 136, 0.2).CGColor;
  103. _toDoExamBtn.layer.borderColor = RQColorFromHexString(@"#01C18D").CGColor;
  104. }
  105. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  106. [super setSelected:selected animated:animated];
  107. // Configure the view for the selected state
  108. }
  109. - (IBAction)toExamAction:(id)sender {
  110. [RQ_APPDELEGATE.services popToRootViewModelAnimated:YES];
  111. }
  112. @end