HomeArrangeRankView.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //
  2. // HomeArrangeRankView.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2024/11/19.
  6. //
  7. #import "HomeArrangeRankView.h"
  8. #import "ArrangeRecentRankButtonView.h"
  9. #import "HomeArrangeRankButtonView.h"
  10. typedef NS_ENUM(NSInteger, RANK_BUTTON_TYPE) {
  11. RANK_BUTTON_TYPE_FINISH,
  12. RANK_BUTTON_TYPE_PRICE,
  13. RANK_BUTTON_TYPE_SCORE,
  14. };
  15. #define ARR_LEFT_SPACE (14)
  16. #define ARR_BUTTON_SPACE (10)
  17. @interface HomeArrangeRankView ()
  18. @property (weak, nonatomic) IBOutlet UIView *buttonContainer;
  19. @property (nonatomic, strong) ArrangeRecentRankButtonView *recentButton;
  20. @property (nonatomic, strong) HomeArrangeRankButtonView *finishButton;
  21. @property (nonatomic, strong) HomeArrangeRankButtonView *priceButton;
  22. @property (nonatomic, strong) HomeArrangeRankButtonView *scoreButton;
  23. @property (nonatomic, copy) ArrangeRankCallback callback;
  24. @property (nonatomic, strong) NSString *sortField;
  25. @property (nonatomic, strong) NSString *sortRule;
  26. @property (nonatomic, assign) BOOL isRecentFree;
  27. @end
  28. @implementation HomeArrangeRankView
  29. + (instancetype)sharedInstance {
  30. HomeArrangeRankView *view = [[[NSBundle mainBundle] loadNibNamed:@"HomeArrangeRankView" owner:nil options:nil] firstObject];
  31. return view;
  32. }
  33. - (void)configUI {
  34. // CGFloat phoneSpace = (KPortraitWidth - 111 - 74 * 2 - 58 - ARR_LEFT_SPACE * 2) / 3.0f;
  35. // CGFloat space = IS_IPAD ? ARR_BUTTON_SPACE : phoneSpace;
  36. CGFloat space = ARR_BUTTON_SPACE;
  37. [self.buttonContainer addSubview:self.recentButton];
  38. [self.recentButton mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.left.mas_equalTo(self.buttonContainer.mas_left).offset(ARR_LEFT_SPACE);
  40. make.top.bottom.mas_equalTo(self.buttonContainer);
  41. make.width.mas_equalTo(111.0f);
  42. }];
  43. [self.buttonContainer addSubview:self.finishButton];
  44. [self.finishButton mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.left.mas_equalTo(self.recentButton.mas_right).offset(space);
  46. make.top.bottom.mas_equalTo(self.buttonContainer);
  47. make.width.mas_equalTo(74.0f);
  48. }];
  49. if (self.hidePriceSort == NO) {
  50. [self.buttonContainer addSubview:self.priceButton];
  51. [self.priceButton mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.left.mas_equalTo(self.finishButton.mas_right).offset(space);
  53. make.top.bottom.mas_equalTo(self.buttonContainer);
  54. make.width.mas_equalTo(74.0f);
  55. }];
  56. [self.buttonContainer addSubview:self.scoreButton];
  57. [self.scoreButton mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.mas_equalTo(self.priceButton.mas_right).offset(space);
  59. make.top.bottom.mas_equalTo(self.buttonContainer);
  60. make.width.mas_equalTo(58.0f);
  61. }];
  62. }
  63. else {
  64. [self.buttonContainer addSubview:self.scoreButton];
  65. [self.scoreButton mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.left.mas_equalTo(self.finishButton.mas_right).offset(space);
  67. make.top.bottom.mas_equalTo(self.buttonContainer);
  68. make.width.mas_equalTo(58.0f);
  69. }];
  70. }
  71. }
  72. - (void)sortAction:(ArrangeRankCallback)callback {
  73. if (callback) {
  74. self.callback = callback;
  75. }
  76. }
  77. + (CGFloat)getViewHeight {
  78. return 40.0f;
  79. }
  80. - (ArrangeRecentRankButtonView *)recentButton {
  81. if (!_recentButton) {
  82. _recentButton = [ArrangeRecentRankButtonView sharedInstance];
  83. MJWeakSelf;
  84. [_recentButton settingCallback:^(BOOL isChoose) {
  85. [weakSelf recentButtonAction:isChoose];
  86. }];
  87. }
  88. return _recentButton;
  89. }
  90. - (HomeArrangeRankButtonView *)finishButton {
  91. if (!_finishButton) {
  92. _finishButton = [HomeArrangeRankButtonView sharedInstance];
  93. MJWeakSelf;
  94. [_finishButton configWithTitle:@"已上课时" callback:^(RANKTYPE type) {
  95. [weakSelf rankAction:type buttonType:RANK_BUTTON_TYPE_FINISH];
  96. }];
  97. }
  98. return _finishButton;
  99. }
  100. - (HomeArrangeRankButtonView *)priceButton {
  101. if (!_priceButton) {
  102. _priceButton = [HomeArrangeRankButtonView sharedInstance];
  103. MJWeakSelf;
  104. [_priceButton configWithTitle:@"课时单价" callback:^(RANKTYPE type) {
  105. [weakSelf rankAction:type buttonType:RANK_BUTTON_TYPE_PRICE];
  106. }];
  107. }
  108. return _priceButton;
  109. }
  110. - (HomeArrangeRankButtonView *)scoreButton {
  111. if (!_scoreButton) {
  112. _scoreButton = [HomeArrangeRankButtonView sharedInstance];
  113. MJWeakSelf;
  114. [_scoreButton configWithTitle:@"评分" callback:^(RANKTYPE type) {
  115. [weakSelf rankAction:type buttonType:RANK_BUTTON_TYPE_SCORE];
  116. }];
  117. }
  118. return _scoreButton;
  119. }
  120. - (void)rankAction:(RANKTYPE)type buttonType:(RANK_BUTTON_TYPE)buttonType {
  121. switch (buttonType) {
  122. case RANK_BUTTON_TYPE_FINISH:
  123. {
  124. self.priceButton.status = RANKTYPE_NONE;
  125. self.scoreButton.status = RANKTYPE_NONE;
  126. if (type == RANKTYPE_NONE) {
  127. self.sortRule = nil;
  128. self.sortField = nil;
  129. }
  130. else if (type == RANKTYPE_UP) {
  131. self.sortRule = @"ASC";
  132. self.sortField = @"expTime";
  133. }
  134. else {
  135. self.sortRule = @"DESC";
  136. self.sortField = @"expTime";
  137. }
  138. }
  139. break;
  140. case RANK_BUTTON_TYPE_PRICE:
  141. {
  142. self.finishButton.status = RANKTYPE_NONE;
  143. self.scoreButton.status = RANKTYPE_NONE;
  144. if (type == RANKTYPE_NONE) {
  145. self.sortRule = nil;
  146. self.sortField = nil;
  147. }
  148. else if (type == RANKTYPE_UP) {
  149. self.sortRule = @"ASC";
  150. self.sortField = @"subjectPrice";
  151. }
  152. else {
  153. self.sortRule = @"DESC";
  154. self.sortField = @"subjectPrice";
  155. }
  156. }
  157. break;
  158. case RANK_BUTTON_TYPE_SCORE:
  159. {
  160. self.finishButton.status = RANKTYPE_NONE;
  161. self.priceButton.status = RANKTYPE_NONE;
  162. if (type == RANKTYPE_NONE) {
  163. self.sortRule = nil;
  164. self.sortField = nil;
  165. }
  166. else if (type == RANKTYPE_UP) {
  167. self.sortRule = @"ASC";
  168. self.sortField = @"starGrade";
  169. }
  170. else {
  171. self.sortRule = @"DESC";
  172. self.sortField = @"starGrade";
  173. }
  174. }
  175. break;
  176. default:
  177. break;
  178. }
  179. if (self.callback) {
  180. self.callback(self.isRecentFree, self.sortField, self.sortRule);
  181. }
  182. }
  183. - (void)recentButtonAction:(BOOL)isChoose {
  184. self.isRecentFree = !self.isRecentFree;
  185. if (self.callback) {
  186. self.callback(self.isRecentFree, self.sortField, self.sortRule);
  187. }
  188. }
  189. /*
  190. // Only override drawRect: if you perform custom drawing.
  191. // An empty implementation adversely affects performance during animation.
  192. - (void)drawRect:(CGRect)rect {
  193. // Drawing code
  194. }
  195. */
  196. @end