RQExamProbabilyCell.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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(47.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(47.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. [[RQ_HTTP_Service getPassRateWithSubject:viewModel.homePageSubjectType carType:RQ_YDTQuestion_Module.carType] subscribeNext:^(NSString *str) {
  135. @strongify(self)
  136. if (RQStringIsNotEmpty(str)) {
  137. self.passRateLabel.text = [NSString stringWithFormat:@"%@%%",str];
  138. NSInteger c = str.integerValue;
  139. UIColor *bgColor = RQColorFromHexString(@"#FF4D53");
  140. if (c >= 0 && c <= 10) {
  141. self.popupByAddBottomSubview.textLabel.text = @"想啥呢?快开始学习吧!";
  142. _passRateBtn1.selected = YES;
  143. _bgImageView.image = RQImageNamed(@"0%10%背景");
  144. } else if (c > 10 && c <= 20) {
  145. self.popupByAddBottomSubview.textLabel.text = @"路遥知马力,加油!";
  146. _bgImageView.image = RQImageNamed(@"0%10%背景");
  147. } else if (c > 20 && c <= 30) {
  148. self.popupByAddBottomSubview.textLabel.text = @"征服畏惧,建立自信。";
  149. _bgImageView.image = RQImageNamed(@"20%30%背景");
  150. } else if (c > 30 && c <= 40) {
  151. self.popupByAddBottomSubview.textLabel.text = @"学习就像爬山,目的性强爬得就快。";
  152. _bgImageView.image = RQImageNamed(@"20%30%背景");
  153. } else if (c > 40 && c <= 50) {
  154. self.popupByAddBottomSubview.textLabel.text = @"快到半山腰了哦!";
  155. _bgImageView.image = RQImageNamed(@"20%30%背景");
  156. } else if (c > 50 && c <= 60) {
  157. self.popupByAddBottomSubview.textLabel.text = @"不错哦,五五开了呀。";
  158. _bgImageView.image = RQImageNamed(@"20%30%背景");
  159. } else if (c > 60 && c <= 70) {
  160. self.popupByAddBottomSubview.textLabel.text = @"努努力,希望很大!";
  161. _bgImageView.image = RQImageNamed(@"80%90%背景图");
  162. } else if (c > 70 && c <= 80) {
  163. self.popupByAddBottomSubview.textLabel.text = @"离成功不远了,加油!";
  164. _bgImageView.image = RQImageNamed(@"80%90%背景图");
  165. } else if (c > 80 && c <= 90) {
  166. self.popupByAddBottomSubview.textLabel.text = @"上升空间挺大,继线努力!";
  167. _bgImageView.image = RQImageNamed(@"80%90%背景图");
  168. } else if (c > 90 && c <= 100) {
  169. self.popupByAddBottomSubview.textLabel.text = @"十拿九稳了哦,还能审一审!";
  170. _bgImageView.image = RQImageNamed(@"80%90%背景图");
  171. }
  172. self.passRateDscLabel.text = [NSString stringWithFormat:@"考试预测通过率%@%%,%@",str,self.popupByAddBottomSubview.textLabel.text];
  173. NSInteger length = 10 + self.popupByAddBottomSubview.textLabel.text.length - [@"路遥知马力,加油!" length];
  174. [self.popupByAddBottomSubview mas_updateConstraints:^(MASConstraintMaker *make) {
  175. @strongify(self)
  176. make.size.mas_equalTo(CGSizeMake(RQ_FIT_HORIZONTAL(120.f), RQ_FIT_HORIZONTAL(39.f)));
  177. [self.popupByAddBottomSubview sizeThatFitsInContentView:CGSizeMake(RQ_FIT_HORIZONTAL(120.f) + length, RQ_FIT_HORIZONTAL(39.f))];
  178. 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));
  179. }];
  180. [[[btnArr.rac_sequence.signal deliverOnMainThread] filter:^BOOL(QMUIButton *btn) {
  181. return btn.tag * 3 <= c;
  182. }] subscribeNext:^(QMUIButton *btn) {
  183. NSLayoutConstraint *layoutConstraint = btnHeightArr[btn.tag - 1];
  184. layoutConstraint.constant = 22.f;
  185. btn.backgroundColor = bgColor;
  186. }];
  187. }
  188. }];
  189. }
  190. - (void)awakeFromNib {
  191. [super awakeFromNib];
  192. self.myHeadImageView.layer.cornerRadius = RQ_FIT_HORIZONTAL(45.f) / 2.f;
  193. }
  194. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  195. [super setSelected:selected animated:animated];
  196. // Configure the view for the selected state
  197. }
  198. #pragma mark - LazyLoad
  199. - (RQPodDownContainerView *)popupByAddTopSubview {
  200. if (!_popupByAddTopSubview) {
  201. _popupByAddTopSubview = [[RQPodDownContainerView alloc] init];
  202. }
  203. return _popupByAddTopSubview;
  204. }
  205. - (RQPopupContainerView *)popupByAddBottomSubview {
  206. if (!_popupByAddBottomSubview) {
  207. _popupByAddBottomSubview = [[RQPopupContainerView alloc] init];
  208. _popupByAddBottomSubview.preferLayoutDirection = QMUIPopupContainerViewLayoutDirectionBelow;
  209. _popupByAddBottomSubview.textLabel.text = @"路遥知马力,加油!";
  210. _popupByAddBottomSubview.textLabel.textAlignment = NSTextAlignmentCenter;
  211. _popupByAddBottomSubview.cornerRadius = 4.f;
  212. _popupByAddBottomSubview.textLabel.font = [UIFont systemFontOfSize:13];
  213. _popupByAddBottomSubview.textLabel.textColor = RQ_MAIN_TEXT_COLOR_1;
  214. _popupByAddBottomSubview.backgroundView = ({
  215. [[UIImageView alloc] initWithImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  216. graColor.fromColor = UIColorWhite;
  217. graColor.toColor = UIColorWhite;
  218. graColor.type = QQGradualChangeTypeLeftToRight;
  219. } size:CGSizeMake(RQ_FIT_HORIZONTAL(120.f), RQ_FIT_HORIZONTAL(39.f)) cornerRadius:QQRadiusMakeSame(0.f)]];
  220. });
  221. _popupByAddBottomSubview.arrowImage = [UIImageMake(@"popover_container_arrow") qmui_imageResizedInLimitedSize:CGSizeMake(RQ_FIT_HORIZONTAL(14.f), RQ_FIT_HORIZONTAL(8.f)) resizingMode:QMUIImageResizingModeScaleAspectFit];
  222. }
  223. return _popupByAddBottomSubview;
  224. }
  225. - (IBAction)toUpBtnAction:(id)sender {
  226. [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full];
  227. }
  228. @end