123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- //
- // RQExamHistoryCell.m
- // jiaPei
- //
- // Created by 张嵘 on 2022/8/2.
- // Copyright © 2022 JCZ. All rights reserved.
- //
- #import "RQExamHistoryCell.h"
- @interface RQExamHistoryCell ()
- @property (nonatomic, readwrite, strong) RQExamHistoryItemViewModel *viewModel;
- @property (weak, nonatomic) IBOutlet UIView *myContentView;
- @property (weak, nonatomic) IBOutlet QMUIButton *toTiFenBtn;
- @property (weak, nonatomic) IBOutlet QMUIButton *toDoExamBtn;
- @property (weak, nonatomic) IBOutlet UILabel *bottomLabel;
- @property (weak, nonatomic) IBOutlet UIStackView *historyListView;
- @end
- @implementation RQExamHistoryCell
- #pragma mark - PublicMethods
- + (instancetype)cellWithTableView:(UITableView *)tableView {
- static NSString *ID = @"RQExamHistoryCell";
- RQExamHistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
- if (!cell) {
- cell = [self rq_viewFromXib];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- return cell;
- }
- - (void)bindViewModel:(RQExamHistoryItemViewModel *)viewModel {
- @weakify(self)
- _viewModel = viewModel;
- if (viewModel.examResultArr.count > 0) {
- self.historyListView.hidden = NO;
- self.bottomLabel.text = [NSString stringWithFormat:@"-最近%ld次考试成绩-",(viewModel.examResultArr.count > 10? 10 : viewModel.examResultArr.count)];
- self.toDoExamBtn.hidden = YES;
-
- NSArray *honors = @[@"马路杀手",@"驾考标兵",@"驾考牛人",@"驾考神人",@"外星人",@"幸运儿"];
- [[[viewModel.examResultArr.rac_sequence.signal deliverOnMainThread] takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(RQExamResultModel *examResultModel) {
- @strongify(self)
- NSString *dateStr = examResultModel.crdate;
- if ([dateStr containsString:@" "]) {
- dateStr = [[dateStr componentsSeparatedByString:@" "] firstObject];
- }
- if (dateStr.length > 5) {
- dateStr = [dateStr substringFromIndex:5];
- }
-
- if ([dateStr containsString:@"-"]) {
- dateStr = [dateStr stringByReplacingOccurrencesOfString:@"-" withString:@"月"];
- dateStr = [NSString stringWithFormat:@"%@日",dateStr];
- }
-
-
- int timeS = [examResultModel.totalTime intValue];
- int min = timeS/60;
- int sec = timeS%60;
-
- NSString *minStr = [NSString stringWithFormat:@"%d",min];
- NSString *secStr = [NSString stringWithFormat:@"%d",sec];
-
- if (min < 10) {
- minStr = [NSString stringWithFormat:@"0%d",min];
- }
- if (sec < 10) {
- secStr = [NSString stringWithFormat:@"0%d",sec];
- }
-
-
- NSInteger score = [examResultModel.score integerValue];
-
- NSString *graHonorStr = @"";
- if (score < 60) {
- graHonorStr = honors[0];
- }else if (score < 90){
- graHonorStr = honors[1];
- }else if (score < 93){
- graHonorStr = honors[2];
- }else if (score < 96){
- graHonorStr = honors[3];
- }else if (score < 98){
- graHonorStr = honors[4];
- }else{
- graHonorStr = honors[5];
- }
-
- NSInteger index = [viewModel.examResultArr indexOfObject:examResultModel];
- NSInteger countTag = (index + 1) * 1000 + 1;
- UILabel *countLabel = [self viewWithTag:countTag];
- countLabel.text = [NSString stringWithFormat:@"%@分",examResultModel.score];
-
- NSInteger timeTag = (index + 1) * 1000 + 2;
- UILabel *timeLabel = [self viewWithTag:timeTag];
- timeLabel.text = [NSString stringWithFormat:@"%@分%@秒",minStr,secStr];
-
- NSInteger dateTag = (index + 1) * 1000 + 3;
- UILabel *dateLabel = [self viewWithTag:dateTag];
- dateLabel.text = [NSString stringWithFormat:@"%@",dateStr];
-
- NSInteger descTag = (index + 1) * 1000 + 4;
- UILabel *descLabel = [self viewWithTag:descTag];
- descLabel.textColor = [graHonorStr isEqualToString:@"马路杀手"]? RQ_MAIN_TEXT_COLOR_RED : RQ_MAIN_TEXT_COLOR_GREEN;
- descLabel.text = [NSString stringWithFormat:@"%@",graHonorStr];
-
- NSInteger tag = 1990 + index;
- UIStackView *currentHistoryItemView = [self viewWithTag:tag];
- currentHistoryItemView.hidden = NO;
- }];
- } else {
- self.historyListView.hidden = YES;
- self.bottomLabel.text = [NSString stringWithFormat:@"-您还没有考试过-"];
- self.toDoExamBtn.hidden = NO;
- }
- }
- - (void)awakeFromNib {
- [super awakeFromNib];
- _toTiFenBtn.imagePosition = QMUIButtonImagePositionRight;
- _myContentView.layer.shadowColor = RGBA_COLOR(124, 129, 136, 0.2).CGColor;
- _toDoExamBtn.layer.borderColor = RQColorFromHexString(@"#01C18D").CGColor;
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (IBAction)toExamAction:(id)sender {
- [RQ_APPDELEGATE.services popToRootViewModelAnimated:YES];
- }
- @end
|