|
@@ -0,0 +1,338 @@
|
|
|
+//
|
|
|
+// MyCourseRankSortView.m
|
|
|
+// KulexiuForTeacher
|
|
|
+//
|
|
|
+// Created by 王智 on 2024/11/21.
|
|
|
+//
|
|
|
+
|
|
|
+#import "MyCourseRankSortView.h"
|
|
|
+#import "MyCourseSearchView.h"
|
|
|
+
|
|
|
+@interface MyCourseRankSortView ()<UIScrollViewDelegate,UIGestureRecognizerDelegate>
|
|
|
+
|
|
|
+@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topSpace;
|
|
|
+
|
|
|
+@property (nonatomic, strong) UITapGestureRecognizer *tapGesture;
|
|
|
+
|
|
|
+@property (weak, nonatomic) IBOutlet UIView *containerView;
|
|
|
+
|
|
|
+@property (weak, nonatomic) IBOutlet UIView *sortButtonContainer;
|
|
|
+
|
|
|
+@property (weak, nonatomic) IBOutlet NSLayoutConstraint *sortContainerHeight;
|
|
|
+
|
|
|
+@property (nonatomic, copy) MyCourseSortTypeCallback callback;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSMutableArray *statusArray;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSMutableArray *subjectArray;
|
|
|
+
|
|
|
+@property (nonatomic, strong) UIScrollView *scrollView;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSString *status;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSString *subjectId;
|
|
|
+
|
|
|
+@property (nonatomic, assign) NSInteger statusChooseIndex; // 状态
|
|
|
+
|
|
|
+@property (nonatomic, assign) NSInteger subjectChooseIndex; // 声部id
|
|
|
+
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation MyCourseRankSortView
|
|
|
+
|
|
|
+- (void)awakeFromNib {
|
|
|
+ [super awakeFromNib];
|
|
|
+ self.containerView.layer.cornerRadius = 20.0f;
|
|
|
+ self.containerView.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
|
|
|
+ [self.sortButtonContainer addSubview:self.scrollView];
|
|
|
+ [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.bottom.left.right.mas_equalTo(self.sortButtonContainer);
|
|
|
+ }];
|
|
|
+ self.statusChooseIndex = 1000;
|
|
|
+ self.subjectChooseIndex = 2000;
|
|
|
+ self.tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
|
|
|
+ [self addGestureRecognizer:self.tapGesture];
|
|
|
+ self.tapGesture.delegate = self;
|
|
|
+ self.topSpace.constant = kNaviBarHeight + 44 + [MyCourseSearchView getViewHeight];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
++ (instancetype)sharedInstance {
|
|
|
+ MyCourseRankSortView *view = [[[NSBundle mainBundle] loadNibNamed:@"MyCourseRankSortView" owner:nil options:nil] firstObject];
|
|
|
+ return view;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)configWithStatusArray:(NSMutableArray *)statusArray subjectArray:(NSMutableArray *)subjectArray {
|
|
|
+ self.statusArray = [statusArray mutableCopy];
|
|
|
+ self.subjectArray = [subjectArray mutableCopy];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)refreshUI:(NSInteger)statusIndex subjectId:(NSInteger)subjectIndex {
|
|
|
+ self.statusChooseIndex = statusIndex;
|
|
|
+ self.subjectChooseIndex = subjectIndex;
|
|
|
+
|
|
|
+ if (statusIndex == 0) {
|
|
|
+ self.statusChooseIndex = 1000;
|
|
|
+ }
|
|
|
+ if (subjectIndex == 0) {
|
|
|
+ self.subjectChooseIndex = 2000;
|
|
|
+ }
|
|
|
+
|
|
|
+ [self configUI];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)configUI {
|
|
|
+ [self.scrollView removeAllSubViews];
|
|
|
+ CGFloat topHeight = 0.0f;
|
|
|
+
|
|
|
+ CGFloat midSpace = 9.0f;
|
|
|
+ CGFloat leftSpace = 14.0f;
|
|
|
+ CGFloat topSpace = 9.0f;
|
|
|
+ CGFloat buttonHeight = 32.0f;
|
|
|
+
|
|
|
+ // 添加课程状态数据
|
|
|
+ if (self.statusArray.count) {
|
|
|
+ topHeight += 24.0f;
|
|
|
+ UIView *statusLineView = [[UIView alloc] init];
|
|
|
+ [self.scrollView addSubview:statusLineView];
|
|
|
+ statusLineView.backgroundColor = THEMECOLOR;
|
|
|
+ statusLineView.layer.cornerRadius = 2.0f;
|
|
|
+ [statusLineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(self.sortButtonContainer.mas_left).offset(16);
|
|
|
+ make.top.mas_equalTo(self.scrollView.mas_top).offset(topHeight);
|
|
|
+ make.width.mas_equalTo(4);
|
|
|
+ make.height.mas_equalTo(11);
|
|
|
+ }];
|
|
|
+ UILabel *statusLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
|
|
+ statusLabel.textColor = HexRGB(0x333333);
|
|
|
+ statusLabel.text = @"课程状态";
|
|
|
+ statusLabel.font = [UIFont systemFontOfSize:16.0f weight:UIFontWeightMedium];
|
|
|
+ [self.scrollView addSubview:statusLabel];
|
|
|
+ [statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(statusLineView.mas_right).offset(6);
|
|
|
+ make.height.mas_equalTo(22);
|
|
|
+ make.centerY.mas_equalTo(statusLineView.mas_centerY);
|
|
|
+ }];
|
|
|
+ topHeight += 16.0f;
|
|
|
+
|
|
|
+
|
|
|
+ CGFloat buttonWidth = (KPortraitWidth - leftSpace * 2 - midSpace * 3) / 4.0f;
|
|
|
+
|
|
|
+ for (NSInteger index = 0; index < self.statusArray.count; index++) {
|
|
|
+ CGFloat xSpace = leftSpace + (buttonWidth + midSpace) * (index % 4);
|
|
|
+ CGFloat ySpace = topSpace + (buttonHeight + topSpace) * (index / 4);
|
|
|
+
|
|
|
+ NSDictionary *parm = self.statusArray[index];
|
|
|
+ NSString *title = [parm ks_stringValueForKey:@"name"];
|
|
|
+ UIButton *button = [self createButton:1000+index buttonTitle:title];
|
|
|
+ [self.scrollView addSubview:button];
|
|
|
+ if (self.statusChooseIndex == 1000 + index) {
|
|
|
+ [self modifyButtonStatus:YES buttonIndex:1000+index];
|
|
|
+ self.status = [parm ks_stringValueForKey:@"id"];
|
|
|
+ }
|
|
|
+ [button mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(self.sortButtonContainer.mas_left).offset(xSpace);
|
|
|
+ make.width.mas_equalTo(buttonWidth);
|
|
|
+ make.height.mas_equalTo(buttonHeight);
|
|
|
+ make.top.mas_equalTo(statusLabel.mas_bottom).offset(ySpace);
|
|
|
+ }];
|
|
|
+ // 增加行高
|
|
|
+ if (index % 4 == 0) {
|
|
|
+ topHeight += (buttonHeight + topSpace);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (self.subjectArray) {
|
|
|
+ topHeight += 24.0;
|
|
|
+ UIView *lineView = [[UIView alloc] init];
|
|
|
+ [self.scrollView addSubview:lineView];
|
|
|
+ lineView.backgroundColor = THEMECOLOR;
|
|
|
+ lineView.layer.cornerRadius = 2.0f;
|
|
|
+ [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(self.sortButtonContainer.mas_left).offset(16);
|
|
|
+ make.top.mas_equalTo(self.scrollView.mas_top).offset(topHeight);
|
|
|
+ make.width.mas_equalTo(4);
|
|
|
+ make.height.mas_equalTo(11);
|
|
|
+ }];
|
|
|
+ UILabel *subjectLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
|
|
+ subjectLabel.textColor = HexRGB(0x333333);
|
|
|
+ subjectLabel.text = @"声部";
|
|
|
+ subjectLabel.font = [UIFont systemFontOfSize:16.0f weight:UIFontWeightMedium];
|
|
|
+ [self.scrollView addSubview:subjectLabel];
|
|
|
+ [subjectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(lineView.mas_right).offset(6);
|
|
|
+ make.height.mas_equalTo(22);
|
|
|
+ make.centerY.mas_equalTo(lineView.mas_centerY);
|
|
|
+ }];
|
|
|
+ topHeight += 16.0f;
|
|
|
+
|
|
|
+ CGFloat buttonWidth = (KPortraitWidth - leftSpace * 2 - midSpace * 2) / 3.0f;
|
|
|
+
|
|
|
+ for (NSInteger index = 0; index < self.subjectArray.count; index++) {
|
|
|
+ CGFloat xSpace = leftSpace + (buttonWidth + midSpace) * (index % 3);
|
|
|
+ CGFloat ySpace = topSpace + (buttonHeight + topSpace) * (index / 3);
|
|
|
+
|
|
|
+ NSDictionary *parm = self.subjectArray[index];
|
|
|
+ NSString *title = [parm ks_stringValueForKey:@"name"];
|
|
|
+ UIButton *button = [self createButton:2000+index buttonTitle:title];
|
|
|
+ [self.scrollView addSubview:button];
|
|
|
+ if (self.subjectChooseIndex == 2000 + index) {
|
|
|
+ [self modifyButtonStatus:YES buttonIndex:2000+index];
|
|
|
+ self.subjectId = [parm ks_stringValueForKey:@"id"];
|
|
|
+ }
|
|
|
+ [button mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(self.sortButtonContainer.mas_left).offset(xSpace);
|
|
|
+ make.width.mas_equalTo(buttonWidth);
|
|
|
+ make.height.mas_equalTo(buttonHeight);
|
|
|
+ make.top.mas_equalTo(subjectLabel.mas_bottom).offset(ySpace);
|
|
|
+ }];
|
|
|
+ // 增加行高
|
|
|
+ if (index % 3 == 0) {
|
|
|
+ topHeight += (buttonHeight + topSpace);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ topHeight += 18; // 底部区域
|
|
|
+ }
|
|
|
+ if (topHeight > 303) {
|
|
|
+ topHeight = 303.0f;
|
|
|
+ }
|
|
|
+ self.sortContainerHeight.constant = topHeight;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)sortActionCallback:(MyCourseSortTypeCallback)callback {
|
|
|
+ if (callback) {
|
|
|
+ self.callback = callback;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (void)showInView:(UIView *)displayView {
|
|
|
+ if (![displayView.subviews containsObject:self]) {
|
|
|
+ [displayView addSubview:self];
|
|
|
+ [self mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.right.top.bottom.mas_equalTo(displayView);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)resetAllChoose {
|
|
|
+ if (self.statusChooseIndex != 0) {
|
|
|
+ [self modifyButtonStatus:NO buttonIndex:self.statusChooseIndex];
|
|
|
+ self.statusChooseIndex = 1000;
|
|
|
+ [self modifyButtonStatus:YES buttonIndex:self.statusChooseIndex];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (self.subjectChooseIndex != 0) {
|
|
|
+ [self modifyButtonStatus:NO buttonIndex:self.subjectChooseIndex];
|
|
|
+ self.subjectChooseIndex = 2000;
|
|
|
+ [self modifyButtonStatus:YES buttonIndex:self.subjectChooseIndex];
|
|
|
+ }
|
|
|
+ self.status = nil;
|
|
|
+ self.subjectId = nil;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)hideView {
|
|
|
+ [self removeFromSuperview];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)tapAction:(id)sender {
|
|
|
+ [self hideView];
|
|
|
+ if (self.callback) {
|
|
|
+ self.callback(MY_COURSE_SORTTYPE_HIDE, self.status, self.subjectId,self.statusChooseIndex , self.subjectChooseIndex);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (IBAction)resetAction:(id)sender {
|
|
|
+ [self resetAllChoose];
|
|
|
+}
|
|
|
+
|
|
|
+- (IBAction)sureAction:(id)sender {
|
|
|
+ [self hideView];
|
|
|
+ if (self.callback) {
|
|
|
+ self.callback(MY_COURSE_SORTTYPE_SORT, self.status, self.subjectId, self.statusChooseIndex, self.subjectChooseIndex);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+#pragma mark ----- lazying
|
|
|
+- (UIScrollView *)scrollView {
|
|
|
+ if (!_scrollView) {
|
|
|
+ _scrollView = [[UIScrollView alloc] init];
|
|
|
+ _scrollView.delegate = self;
|
|
|
+ _scrollView.pagingEnabled = YES;
|
|
|
+ _scrollView.bounces = NO;
|
|
|
+ _scrollView.backgroundColor = [UIColor clearColor];
|
|
|
+ _scrollView.showsHorizontalScrollIndicator = NO;
|
|
|
+ _scrollView.showsVerticalScrollIndicator = NO;
|
|
|
+ }
|
|
|
+ return _scrollView;
|
|
|
+}
|
|
|
+
|
|
|
+- (UIButton *)createButton:(NSInteger)tag buttonTitle:(NSString *)buttonTitle {
|
|
|
+ UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ button.tag = tag;
|
|
|
+ button.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 5);
|
|
|
+ [button setTitle:buttonTitle forState:UIControlStateNormal];
|
|
|
+ [button.titleLabel setFont:[UIFont systemFontOfSize:12.0f weight:UIFontWeightRegular]];
|
|
|
+ button.titleLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
|
|
|
+ [button setTitleColor:HexRGB(0x999999) forState:UIControlStateNormal];
|
|
|
+ [button addTarget:self action:@selector(buttonClickAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ button.layer.cornerRadius = 4.0f;
|
|
|
+ button.backgroundColor = HexRGB(0xF8F8F8);
|
|
|
+ button.layer.borderWidth = 1.0f;
|
|
|
+ button.layer.borderColor = [UIColor clearColor].CGColor;
|
|
|
+ return button;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)buttonClickAction:(UIButton *)sender {
|
|
|
+ if (sender.tag >= 1000 && sender.tag < 2000) { // 状态
|
|
|
+
|
|
|
+ if (self.statusChooseIndex != sender.tag) {
|
|
|
+ [self modifyButtonStatus:NO buttonIndex:self.statusChooseIndex];
|
|
|
+ [self modifyButtonStatus:YES buttonIndex:sender.tag];
|
|
|
+ self.statusChooseIndex = sender.tag;
|
|
|
+ NSDictionary *parm = self.statusArray[self.statusChooseIndex-1000];
|
|
|
+ self.status = [parm ks_stringValueForKey:@"id"];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (sender.tag >= 2000 && sender.tag < 3000) { // 声部
|
|
|
+ if (self.subjectChooseIndex != sender.tag) {
|
|
|
+ [self modifyButtonStatus:NO buttonIndex:self.subjectChooseIndex];
|
|
|
+ [self modifyButtonStatus:YES buttonIndex:sender.tag];
|
|
|
+ self.subjectChooseIndex = sender.tag;
|
|
|
+ NSDictionary *parm = self.subjectArray[self.subjectChooseIndex-2000];
|
|
|
+ self.subjectId = [parm ks_stringValueForKey:@"id"];
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)modifyButtonStatus:(BOOL)isChoose buttonIndex:(NSInteger)buttonIndex {
|
|
|
+ UIButton *button = (UIButton *)[self.scrollView viewWithTag:buttonIndex];
|
|
|
+ if (isChoose) {
|
|
|
+ [button setBackgroundColor:HexRGB(0xE9FFF8)];
|
|
|
+ [button setTitleColor:HexRGB(0x2DC7AA) forState:UIControlStateNormal];
|
|
|
+ button.layer.borderColor = HexRGB(0x2DC7AA).CGColor;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [button setBackgroundColor:HexRGB(0xF8F8F8)];
|
|
|
+ [button setTitleColor:HexRGB(0x999999) forState:UIControlStateNormal];
|
|
|
+ button.layer.borderColor = [UIColor clearColor].CGColor;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
|
|
|
+ if ([touch.view isDescendantOfView:self.containerView]) {
|
|
|
+ return NO;
|
|
|
+ }
|
|
|
+ return YES;
|
|
|
+}
|
|
|
+/*
|
|
|
+// Only override drawRect: if you perform custom drawing.
|
|
|
+// An empty implementation adversely affects performance during animation.
|
|
|
+- (void)drawRect:(CGRect)rect {
|
|
|
+ // Drawing code
|
|
|
+}
|
|
|
+*/
|
|
|
+
|
|
|
+@end
|