RQExamProbabilyCell.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. //
  2. // RQExamProbabilyCell.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/7/29.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQExamProbabilyCell.h"
  9. @interface RQPopupContainerView : QMUIPopupContainerView
  10. @end
  11. @implementation RQPopupContainerView
  12. - (instancetype)initWithFrame:(CGRect)frame {
  13. self = [super initWithFrame:frame];
  14. if (self) {
  15. self.contentEdgeInsets = UIEdgeInsetsZero;
  16. // self.maskViewBackgroundColor = nil;
  17. // self.backgroundColor = nil;
  18. // self.borderWidth = 0;
  19. // self.cornerRadius = 4.f;
  20. // self.textLabel.textAlignment = NSTextAlignmentCenter;
  21. // self.arrowImage = [UIImageMake(@"popover_container_arrow") qmui_imageResizedInLimitedSize:CGSizeMake(RQ_FIT_HORIZONTAL(8.f), RQ_FIT_HORIZONTAL(4.f)) resizingMode:QMUIImageResizingModeScaleAspectFit];
  22. }
  23. return self;
  24. }
  25. //- (CGSize)sizeThatFitsInContentView:(CGSize)size {
  26. // return CGSizeMake(RQ_SCREEN_WIDTH - 32.f, RQ_FIT_HORIZONTAL(39.f));
  27. //}
  28. - (void)layoutSubviews {
  29. [super layoutSubviews];
  30. // 所有布局都参照 contentView
  31. }
  32. @end
  33. @interface RQPodDownContainerView : QMUIPopupContainerView
  34. @end
  35. @implementation RQPodDownContainerView
  36. - (instancetype)initWithFrame:(CGRect)frame {
  37. self = [super initWithFrame:frame];
  38. if (self) {
  39. self.contentEdgeInsets = UIEdgeInsetsZero;
  40. self.maskViewBackgroundColor = nil;
  41. self.backgroundColor = nil;
  42. self.borderWidth = 0;
  43. self.preferLayoutDirection = QMUIPopupContainerViewLayoutDirectionAbove;
  44. self.textLabel.text = @"目标值";
  45. self.textLabel.textAlignment = NSTextAlignmentCenter;
  46. self.cornerRadius = 4.f;
  47. self.textLabel.font = [UIFont systemFontOfSize:13];
  48. self.textLabel.textColor = UIColorWhite;
  49. self.backgroundView = ({
  50. [[UIImageView alloc] initWithImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  51. graColor.fromColor = [UIColor qmui_colorWithHexString:@"#01C18D"];
  52. graColor.toColor = [UIColor qmui_colorWithHexString:@"#3ED2AA"];
  53. graColor.type = QQGradualChangeTypeLeftToRight;
  54. } size:CGSizeMake(RQ_FIT_HORIZONTAL(50.f), RQ_FIT_HORIZONTAL(26.f)) cornerRadius:QQRadiusMakeSame(0.f)]];
  55. });
  56. self.arrowImage = [UIImageMake(@"popover_container_arrow") qmui_imageResizedInLimitedSize:CGSizeMake(RQ_FIT_HORIZONTAL(14.f), RQ_FIT_HORIZONTAL(8.f)) resizingMode:QMUIImageResizingModeScaleAspectFit];
  57. }
  58. return self;
  59. }
  60. - (CGSize)sizeThatFitsInContentView:(CGSize)size {
  61. return CGSizeMake(RQ_FIT_HORIZONTAL(50.f), RQ_FIT_HORIZONTAL(26.f));
  62. }
  63. - (void)layoutSubviews {
  64. [super layoutSubviews];
  65. // 所有布局都参照 contentView
  66. }
  67. @end
  68. @interface RQExamProbabilyCell ()
  69. @property (nonatomic, readwrite, strong) RQExamProbabilyItemViewModel *viewModel;
  70. @property (weak, nonatomic) IBOutlet UIView *probabilyView;
  71. @property (weak, nonatomic) IBOutlet UIView *bottomView;
  72. @property (nonatomic, readwrite, strong) RQPodDownContainerView *popupByAddTopSubview;
  73. @property (nonatomic, readwrite, strong) RQPopupContainerView *popupByAddBottomSubview;
  74. @property (weak, nonatomic) IBOutlet UIImageView *myHeadImageView;
  75. @property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
  76. @property (weak, nonatomic) IBOutlet UILabel *passRateDscLabel;
  77. @property (weak, nonatomic) IBOutlet UILabel *passRateTitleLabel;
  78. @property (weak, nonatomic) IBOutlet UIImageView *bgImageView;
  79. @end
  80. @implementation RQExamProbabilyCell
  81. #pragma mark - PublicMethods
  82. + (instancetype)cellWithTableView:(UITableView *)tableView {
  83. static NSString *ID = @"RQExamProbabilyCell";
  84. RQExamProbabilyCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  85. if (!cell) {
  86. cell = [self rq_viewFromXib];
  87. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  88. }
  89. return cell;
  90. }
  91. - (void)bindViewModel:(RQExamProbabilyItemViewModel *)viewModel {
  92. _viewModel = viewModel;
  93. @weakify(self)
  94. // self.passRateTitleLabel.text = viewModel.homePageSubjectType == RQHomePageSubjectType_SubjectOne? @"科目一考试预测通过率" : @"科目四考试预测通过率";
  95. [[RACObserve(RQ_USER_MANAGER.currentUser, photo) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(NSString *imageName) {
  96. @strongify(self);
  97. [self.myHeadImageView yy_setImageWithURL:[NSURL URLWithString:imageName] placeholder:RQWebAvatarImagePlaceholder() options:RQWebImageOptionAutomatic completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
  98. @strongify(self)
  99. if(image) {
  100. image = [image qmui_imageResizedInLimitedSize:CGSizeMake(RQ_FIT_HORIZONTAL(45.f), RQ_FIT_HORIZONTAL(45.f)) resizingMode:QMUIImageResizingModeScaleAspectFill];
  101. image = [image qmui_imageWithBorderColor:UIColor.whiteColor borderWidth:1 cornerRadius:RQ_FIT_HORIZONTAL(45.f) / 2.f];
  102. self.myHeadImageView.image = image;
  103. }
  104. }];
  105. }];
  106. RAC(_userNameLabel, text) = [RACObserve(RQ_USER_MANAGER.currentUser, nickName) takeUntil:self.rac_prepareForReuseSignal];
  107. NSArray *btnArr = @[_passRateBtn1,_passRateBtn2,_passRateBtn3,_passRateBtn4,_passRateBtn5,
  108. _passRateBtn6,_passRateBtn7,_passRateBtn8,_passRateBtn9,_passRateBtn10,
  109. _passRateBtn11,_passRateBtn12,_passRateBtn13,_passRateBtn14,_passRateBtn15,
  110. _passRateBtn16,_passRateBtn17,_passRateBtn18,_passRateBtn19,_passRateBtn20,
  111. _passRateBtn21,_passRateBtn22,_passRateBtn23,_passRateBtn24,_passRateBtn25,
  112. _passRateBtn26,_passRateBtn27,_passRateBtn28,_passRateBtn29,_passRateBtn30,];
  113. NSArray *btnHeightArr = @[_passRateBtnHeight1,_passRateBtnHeight2,_passRateBtnHeight3,_passRateBtnHeight4,_passRateBtnHeight5,_passRateBtnHeight6,_passRateBtnHeight7,_passRateBtnHeight8,_passRateBtnHeight9,_passRateBtnHeight10,_passRateBtnHeight11,_passRateBtnHeight12,_passRateBtnHeight13,_passRateBtnHeight14,_passRateBtnHeight15,_passRateBtnHeight16,_passRateBtnHeight17,_passRateBtnHeight18,_passRateBtnHeight19,_passRateBtnHeight20,_passRateBtnHeight21,_passRateBtnHeight22,_passRateBtnHeight23,_passRateBtnHeight24,_passRateBtnHeight25,_passRateBtnHeight26,_passRateBtnHeight27,_passRateBtnHeight28,_passRateBtnHeight29,_passRateBtnHeight30];
  114. _probabilyView.layer.cornerRadius = RQ_FIT_HORIZONTAL(30.f) / 2.f;
  115. CGFloat space = (RQ_SCREEN_WIDTH - 64.f - 20.f - (4 * 30)) / 29.f;
  116. [self.bottomView addSubview:self.popupByAddTopSubview];
  117. [self.popupByAddTopSubview mas_makeConstraints:^(MASConstraintMaker *make) {
  118. @strongify(self)
  119. make.left.mas_equalTo(self.probabilyView.mas_left).mas_offset(10.f + (4.f * 26) + (space * 26) + 2.f - (RQ_FIT_HORIZONTAL(47.f) / 2.f));
  120. make.bottom.mas_equalTo(self.probabilyView.mas_top).mas_offset(- 8.f);
  121. make.size.mas_equalTo(CGSizeMake(RQ_FIT_HORIZONTAL(47.f), RQ_FIT_HORIZONTAL(26.f)));
  122. self.popupByAddTopSubview.sourceRect = CGRectMake(10.f + (4.f * 26) + 2.f + (space * 26) - (RQ_FIT_HORIZONTAL(47.f)),
  123. self.probabilyView.frame.origin.y - 8.f - RQ_FIT_HORIZONTAL(26.f), RQ_FIT_HORIZONTAL(47.f), RQ_FIT_HORIZONTAL(26.f));
  124. }];
  125. [self.bottomView addSubview:self.popupByAddBottomSubview];
  126. [self.popupByAddBottomSubview mas_makeConstraints:^(MASConstraintMaker *make) {
  127. @strongify(self)
  128. make.left.mas_equalTo(self.probabilyView.mas_left).mas_offset(10.f + (4.f * 5) + (space * 4) + 2.f);
  129. make.top.mas_equalTo(self.probabilyView.mas_bottom).mas_offset(8.f);
  130. make.size.mas_equalTo(CGSizeMake(RQ_FIT_HORIZONTAL(120.f), RQ_FIT_HORIZONTAL(39.f)));
  131. [self.popupByAddBottomSubview sizeThatFitsInContentView:CGSizeMake(RQ_FIT_HORIZONTAL(120.f), RQ_FIT_HORIZONTAL(39.f))];
  132. self.popupByAddBottomSubview.sourceRect = CGRectMake(16.f + 16.f + 10.f + (4.f * 5) + 2.f + (space * 4) - (RQ_FIT_HORIZONTAL(120.f) / 2.f), self.probabilyView.frame.origin.y + self.probabilyView.frame.size.height + 8.f, RQ_FIT_HORIZONTAL(120.f), RQ_FIT_HORIZONTAL(39.f));
  133. }];
  134. NSInteger allCount = [RQ_YDTQuestion_Module getQuestionNumWithWithSubject:viewModel.homePageSubjectType exerciseType:RQExerciseType_Sequential];
  135. NSInteger wrongCount = [RQ_YDTQuestion_Module getQuestionNumWithWithSubject:viewModel.homePageSubjectType exerciseType:RQExerciseType_Wrong];
  136. NSInteger doCount = [RQ_YDTQuestion_Module getQuestionNumWithWithSubject:viewModel.homePageSubjectType exerciseType:RQExerciseType_Do];
  137. NSString *carTypeStr = [RQ_YDTQuestion_Module getCarTypeCNNameWithCarType:RQ_YDTQuestion_Module.carType];
  138. NSDictionary *params = @{
  139. @"carType":carTypeStr,
  140. @"kskm":[NSString stringWithFormat:@"%zd",viewModel.homePageSubjectType+1],
  141. @"practicedCount":@(doCount), //已做了
  142. @"totalQuestions":@(allCount), //总题数
  143. @"userId":RQ_USER_MANAGER.currentUser._id,
  144. @"wrongCount":@(wrongCount),//错题
  145. };
  146. [jiaPeiManager NYRequestAnythingDataWithURL:RQ_POST_CalculatePassRate contentType:@"application/json" parameters:params completion:^(NSDictionary *dict) {
  147. if([dict[@"code"] intValue]==200){
  148. UIColor *bgColor = RQColorFromHexString(@"#FF4D53");
  149. NSString *passRate = [NSString stringWithFormat:@"%0.2f",[dict[@"data"][@"passRate"] floatValue]];
  150. NSString *tip = dict[@"data"][@"tip"];
  151. NSInteger c = passRate.integerValue;
  152. self.passRateLabel.text = [NSString stringWithFormat:@"考试预测通过率%@%%,%@",passRate,tip];
  153. self.passRateBigLabel.text = [NSString stringWithFormat:@"%@%%",passRate];
  154. self.popupByAddBottomSubview.textLabel.text = tip;
  155. if (c >= 0 && c <= 10) {
  156. _passRateBtn1.selected = YES;
  157. _bgImageView.image = RQImageNamed(@"0%10%背景");
  158. } else if (c > 10 && c <= 20) {
  159. _bgImageView.image = RQImageNamed(@"0%10%背景");
  160. } else if (c > 20 && c <= 30) {
  161. _bgImageView.image = RQImageNamed(@"20%30%背景");
  162. } else if (c > 30 && c <= 40) {
  163. _bgImageView.image = RQImageNamed(@"20%30%背景");
  164. } else if (c > 40 && c <= 50) {
  165. _bgImageView.image = RQImageNamed(@"20%30%背景");
  166. } else if (c > 50 && c <= 60) {
  167. _bgImageView.image = RQImageNamed(@"20%30%背景");
  168. } else if (c > 60 && c <= 70) {
  169. _bgImageView.image = RQImageNamed(@"80%90%背景图");
  170. } else if (c > 70 && c <= 80) {
  171. _bgImageView.image = RQImageNamed(@"80%90%背景图");
  172. } else if (c > 80 && c <= 90) {
  173. _bgImageView.image = RQImageNamed(@"80%90%背景图");
  174. } else if (c > 90 && c <= 100) {
  175. _bgImageView.image = RQImageNamed(@"80%90%背景图");
  176. }
  177. [[[btnArr.rac_sequence.signal deliverOnMainThread] filter:^BOOL(QMUIButton *btn) {
  178. return btn.tag * 3 <= c;
  179. }] subscribeNext:^(QMUIButton *btn) {
  180. NSLayoutConstraint *layoutConstraint = btnHeightArr[btn.tag - 1];
  181. layoutConstraint.constant = 22.f;
  182. btn.backgroundColor = bgColor;
  183. }];
  184. // NSInteger length = 10 + self.popupByAddBottomSubview.textLabel.text.length;
  185. // [self.popupByAddBottomSubview mas_updateConstraints:^(MASConstraintMaker *make) {
  186. // @strongify(self)
  187. // make.size.mas_equalTo(CGSizeMake(RQ_FIT_HORIZONTAL(130.f), RQ_FIT_HORIZONTAL(40.f)));
  188. // [self.popupByAddBottomSubview sizeThatFitsInContentView:CGSizeMake(RQ_FIT_HORIZONTAL(130.f) + length, RQ_FIT_HORIZONTAL(40.f))];
  189. // self.popupByAddBottomSubview.sourceRect = CGRectMake(16.f + 16.f + 10.f + (4.f * 5) + 2.f + (space * 4) - ((RQ_FIT_HORIZONTAL(130.f) + length) / 2.f), self.probabilyView.frame.origin.y + self.probabilyView.frame.size.height + 8.f, RQ_FIT_HORIZONTAL(130.f) + length, RQ_FIT_HORIZONTAL(40.f));
  190. // }];
  191. }else{
  192. }
  193. }];
  194. // [[RQ_HTTP_Service getPassRateWithSubject:viewModel.homePageSubjectType carType:RQ_YDTQuestion_Module.carType] subscribeNext:^(NSString *str) {
  195. // @strongify(self)
  196. // if (RQStringIsNotEmpty(str)) {
  197. // self.passRateLabel.text = [NSString stringWithFormat:@"%@%%",str];
  198. // NSInteger c = str.integerValue;
  199. // UIColor *bgColor = RQColorFromHexString(@"#FF4D53");
  200. //
  201. // if (c >= 0 && c <= 10) {
  202. // self.popupByAddBottomSubview.textLabel.text = @"想啥呢?快开始学习吧!";
  203. // _passRateBtn1.selected = YES;
  204. // _bgImageView.image = RQImageNamed(@"0%10%背景");
  205. // } else if (c > 10 && c <= 20) {
  206. // self.popupByAddBottomSubview.textLabel.text = @"路遥知马力,加油!";
  207. // _bgImageView.image = RQImageNamed(@"0%10%背景");
  208. // } else if (c > 20 && c <= 30) {
  209. // self.popupByAddBottomSubview.textLabel.text = @"征服畏惧,建立自信。";
  210. // _bgImageView.image = RQImageNamed(@"20%30%背景");
  211. // } else if (c > 30 && c <= 40) {
  212. // self.popupByAddBottomSubview.textLabel.text = @"学习就像爬山,目的性强爬得就快。";
  213. // _bgImageView.image = RQImageNamed(@"20%30%背景");
  214. // } else if (c > 40 && c <= 50) {
  215. // self.popupByAddBottomSubview.textLabel.text = @"快到半山腰了哦!";
  216. // _bgImageView.image = RQImageNamed(@"20%30%背景");
  217. // } else if (c > 50 && c <= 60) {
  218. // self.popupByAddBottomSubview.textLabel.text = @"不错哦,五五开了呀。";
  219. // _bgImageView.image = RQImageNamed(@"20%30%背景");
  220. // } else if (c > 60 && c <= 70) {
  221. // self.popupByAddBottomSubview.textLabel.text = @"努努力,希望很大!";
  222. // _bgImageView.image = RQImageNamed(@"80%90%背景图");
  223. // } else if (c > 70 && c <= 80) {
  224. // self.popupByAddBottomSubview.textLabel.text = @"离成功不远了,加油!";
  225. // _bgImageView.image = RQImageNamed(@"80%90%背景图");
  226. // } else if (c > 80 && c <= 90) {
  227. // self.popupByAddBottomSubview.textLabel.text = @"上升空间挺大,继线努力!";
  228. // _bgImageView.image = RQImageNamed(@"80%90%背景图");
  229. // } else if (c > 90 && c <= 100) {
  230. // self.popupByAddBottomSubview.textLabel.text = @"十拿九稳了哦,还能审一审!";
  231. // _bgImageView.image = RQImageNamed(@"80%90%背景图");
  232. // }
  233. // self.passRateDscLabel.text = [NSString stringWithFormat:@"考试预测通过率%@%%,%@",str,self.popupByAddBottomSubview.textLabel.text];
  234. // NSInteger length = 10 + self.popupByAddBottomSubview.textLabel.text.length - [@"路遥知马力,加油!" length];
  235. // [self.popupByAddBottomSubview mas_updateConstraints:^(MASConstraintMaker *make) {
  236. // @strongify(self)
  237. // make.size.mas_equalTo(CGSizeMake(RQ_FIT_HORIZONTAL(120.f), RQ_FIT_HORIZONTAL(39.f)));
  238. // [self.popupByAddBottomSubview sizeThatFitsInContentView:CGSizeMake(RQ_FIT_HORIZONTAL(120.f) + length, RQ_FIT_HORIZONTAL(39.f))];
  239. // self.popupByAddBottomSubview.sourceRect = CGRectMake(16.f + 16.f + 10.f + (4.f * 5) + 2.f + (space * 4) - ((RQ_FIT_HORIZONTAL(120.f) + length) / 2.f), self.probabilyView.frame.origin.y + self.probabilyView.frame.size.height + 8.f, RQ_FIT_HORIZONTAL(120.f) + length, RQ_FIT_HORIZONTAL(39.f));
  240. // }];
  241. // [[[btnArr.rac_sequence.signal deliverOnMainThread] filter:^BOOL(QMUIButton *btn) {
  242. // return btn.tag * 3 <= c;
  243. // }] subscribeNext:^(QMUIButton *btn) {
  244. // NSLayoutConstraint *layoutConstraint = btnHeightArr[btn.tag - 1];
  245. // layoutConstraint.constant = 22.f;
  246. // btn.backgroundColor = bgColor;
  247. // }];
  248. // }
  249. // }];
  250. }
  251. - (void)awakeFromNib {
  252. [super awakeFromNib];
  253. self.myHeadImageView.layer.cornerRadius = RQ_FIT_HORIZONTAL(45.f) / 2.f;
  254. }
  255. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  256. [super setSelected:selected animated:animated];
  257. // Configure the view for the selected state
  258. }
  259. #pragma mark - LazyLoad
  260. - (RQPodDownContainerView *)popupByAddTopSubview {
  261. if (!_popupByAddTopSubview) {
  262. _popupByAddTopSubview = [[RQPodDownContainerView alloc] init];
  263. }
  264. return _popupByAddTopSubview;
  265. }
  266. - (RQPopupContainerView *)popupByAddBottomSubview {
  267. if (!_popupByAddBottomSubview) {
  268. _popupByAddBottomSubview = [[RQPopupContainerView alloc] init];
  269. _popupByAddBottomSubview.preferLayoutDirection = QMUIPopupContainerViewLayoutDirectionBelow;
  270. _popupByAddBottomSubview.textLabel.text = @"路遥知马力,加油!";
  271. _popupByAddBottomSubview.textLabel.textAlignment = NSTextAlignmentCenter;
  272. _popupByAddBottomSubview.cornerRadius = 4.f;
  273. _popupByAddBottomSubview.textLabel.font = [UIFont systemFontOfSize:12];
  274. _popupByAddBottomSubview.textLabel.textColor = RQ_MAIN_TEXT_COLOR_1;
  275. _popupByAddBottomSubview.backgroundView = ({
  276. [[UIImageView alloc] initWithImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  277. graColor.fromColor = UIColorWhite;
  278. graColor.toColor = UIColorWhite;
  279. graColor.type = QQGradualChangeTypeLeftToRight;
  280. } size:CGSizeMake(RQ_FIT_HORIZONTAL(120.f), RQ_FIT_HORIZONTAL(39.f)) cornerRadius:QQRadiusMakeSame(0.f)]];
  281. });
  282. _popupByAddBottomSubview.arrowImage = [UIImageMake(@"popover_container_arrow") qmui_imageResizedInLimitedSize:CGSizeMake(RQ_FIT_HORIZONTAL(14.f), RQ_FIT_HORIZONTAL(8.f)) resizingMode:QMUIImageResizingModeScaleAspectFit];
  283. }
  284. return _popupByAddBottomSubview;
  285. }
  286. - (IBAction)toUpBtnAction:(id)sender {
  287. [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full];
  288. }
  289. @end