|
@@ -0,0 +1,586 @@
|
|
|
+//
|
|
|
+// ProgramCourseGroupBodyView.m
|
|
|
+// KulexiuForTeacher
|
|
|
+//
|
|
|
+// Created by 王智 on 2024/11/22.
|
|
|
+//
|
|
|
+
|
|
|
+#import "ProgramCourseGroupBodyView.h"
|
|
|
+#import "GroupCourseSortView.h"
|
|
|
+#import "StateView.h"
|
|
|
+#import "Reachability.h"
|
|
|
+#import "ProgramCourseListCell.h"
|
|
|
+#import "MusicRoomCourseListCell.h"
|
|
|
+#import "AccompanyDetailViewController.h"
|
|
|
+#import "VipCouseDetailViewController.h"
|
|
|
+#import "MusicRoomDetailViewController.h"
|
|
|
+#import "GroupCourseListModel.h"
|
|
|
+#import "OnlineClassManager.h"
|
|
|
+#import "KSPremissionAlert.h"
|
|
|
+#import "RecordCheckManager.h"
|
|
|
+#import <KSChoosePicker.h>
|
|
|
+#import <KSFullDatePicker.h>
|
|
|
+
|
|
|
+@interface ProgramCourseGroupBodyView ()<UITableViewDelegate,UITableViewDataSource>
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSDateFormatter *dateFormatter;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSMutableArray *dataArray;
|
|
|
+
|
|
|
+@property (nonatomic, strong) StateView *promptView;
|
|
|
+@property (nonatomic, strong) UIView *promptPlaceView;
|
|
|
+
|
|
|
+@property (nonatomic, assign) BOOL networkAvaiable; // 网络是否可用
|
|
|
+
|
|
|
+@property (nonatomic, strong) GroupCourseSortView *sortView;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSString *classDate;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSString *attendanceStatus;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSString *courseStatus;
|
|
|
+
|
|
|
+@property (nonatomic, strong) OnlineClassManager *classManager;
|
|
|
+
|
|
|
+@property (nonatomic, assign) NSInteger secondChooseIndex;
|
|
|
+
|
|
|
+@property (nonatomic, assign) NSInteger thirdChooseIndex;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSMutableArray *statusArray;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSMutableArray *attendenceStatusArray;
|
|
|
+
|
|
|
+@property (nonatomic, assign) NSInteger joinRoomBeforeTime; // 上课开始时间
|
|
|
+
|
|
|
+@property (nonatomic, assign) NSInteger quitRomeEndTime; // 下课截止时间
|
|
|
+
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation ProgramCourseGroupBodyView
|
|
|
+
|
|
|
+- (instancetype)initWithFrame:(CGRect)frame {
|
|
|
+ self = [super initWithFrame:frame];
|
|
|
+ if (self) {
|
|
|
+ self.backgroundColor = [UIColor clearColor];
|
|
|
+ self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) style:UITableViewStylePlain];
|
|
|
+ self.tableView.backgroundColor = [UIColor clearColor];
|
|
|
+ self.tableView.showsVerticalScrollIndicator = NO;
|
|
|
+
|
|
|
+ self.tableView.dataSource = self;
|
|
|
+ self.tableView.delegate = self;
|
|
|
+ self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
|
+ [self addSubview:self.tableView];
|
|
|
+ self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
|
+ [self.tableView registerNib:[UINib nibWithNibName:@"ProgramCourseListCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"ProgramCourseListCell"];
|
|
|
+ [self.tableView registerNib:[UINib nibWithNibName:@"MusicRoomCourseListCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MusicRoomCourseListCell"];
|
|
|
+
|
|
|
+ UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, iPhoneXSafeBottomMargin)];
|
|
|
+ bottomView.backgroundColor = [UIColor clearColor];
|
|
|
+ self.tableView.tableFooterView = bottomView;
|
|
|
+ [self configDefault];
|
|
|
+
|
|
|
+ MJWeakSelf;
|
|
|
+ self.tableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
|
|
|
+ [weakSelf resetParamenter];
|
|
|
+ [weakSelf requestData];
|
|
|
+ }];
|
|
|
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forceScroll) name:@"UITextViewScroll" object:nil];
|
|
|
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enableScroll) name:@"UITextViewEndScroll" object:nil];
|
|
|
+ }
|
|
|
+ return self;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)configDefault {
|
|
|
+ [self.dateFormatter setDateFormat:@"yyyy-MM"];
|
|
|
+ NSDate *currentDate = [NSDate date];
|
|
|
+ self.classDate = [self.dateFormatter stringFromDate:currentDate];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)forceScroll {
|
|
|
+ self.tableView.scrollEnabled = NO;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)enableScroll {
|
|
|
+ self.tableView.scrollEnabled = YES;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)refreshAndRequestData {
|
|
|
+ [self resetParamenter];
|
|
|
+ [self requestData];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)resetParamenter {
|
|
|
+
|
|
|
+ self.dataArray = [NSMutableArray array];
|
|
|
+ [self.tableView.mj_footer resetNoMoreData];
|
|
|
+ [self setPromptString:@"暂无内容" imageName:@"empty_course" inView:self.tableView];
|
|
|
+ [self.tableView reloadData];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)endRefresh {
|
|
|
+ @weakObj(self);
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ @strongObj(self);
|
|
|
+ [self.tableView.mj_header endRefreshing];
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+- (void)requestRoomConfig {
|
|
|
+ [KSNetworkingManager selectRoomConfigRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
|
|
|
+ if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
|
|
|
+ NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
|
|
|
+ self.joinRoomBeforeTime = [result ks_integerValueForKey:@"practiceStartTime"];
|
|
|
+ self.quitRomeEndTime = [result ks_integerValueForKey:@"practiceEndTime"];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
|
|
|
+ }
|
|
|
+ } faliure:^(NSError * _Nonnull error) {
|
|
|
+
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)requestData {
|
|
|
+ [KSNetworkingManager courseScheduleListRequest:KS_POST courseGroupId:self.courseGroupId classMonth:self.classDate attendanceStatus:self.attendanceStatus courseStatus:self.courseStatus success:^(NSDictionary * _Nonnull dic) {
|
|
|
+ [self endRefresh];
|
|
|
+ if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
|
|
|
+ NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
|
|
|
+ for (NSDictionary *parm in sourceArray) {
|
|
|
+ GroupCourseListModel *model = [[GroupCourseListModel alloc] initWithDictionary:parm];
|
|
|
+ [self.dataArray addObject:model];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
|
|
|
+ }
|
|
|
+ [self.tableView reloadData];
|
|
|
+ [self changePromptLabelStateWithArray:self.dataArray];
|
|
|
+ } faliure:^(NSError * _Nonnull error) {
|
|
|
+ [self endRefresh];
|
|
|
+ if (self.networkAvaiable == NO) {
|
|
|
+ [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.tableView];
|
|
|
+ }
|
|
|
+ [self.dataArray removeAllObjects];
|
|
|
+ [self.tableView reloadData];
|
|
|
+ [self changePromptLabelStateWithArray:self.dataArray];
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)beginRefreshImmediately {
|
|
|
+ [self.tableView.mj_header beginRefreshing];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)beginFirstRefresh {
|
|
|
+ if (!self.isHeaderRefreshed) {
|
|
|
+ [self beginRefreshImmediately];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)selectCellAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+
|
|
|
+ if (self.lastSelectedIndexPath == indexPath) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (self.lastSelectedIndexPath != nil) {
|
|
|
+ UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:self.lastSelectedIndexPath];
|
|
|
+ [cell setSelected:NO animated:NO];
|
|
|
+ }
|
|
|
+ UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
|
|
|
+ [cell setSelected:YES animated:NO];
|
|
|
+ self.lastSelectedIndexPath = indexPath;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)layoutSubviews {
|
|
|
+ [super layoutSubviews];
|
|
|
+ CGFloat sortViewHeight = [GroupCourseSortView getViewHeight];
|
|
|
+
|
|
|
+ if (![self.subviews containsObject:self.sortView]) {
|
|
|
+ [self addSubview:self.sortView];
|
|
|
+ [self.sortView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.right.top.mas_equalTo(self);
|
|
|
+ make.height.mas_equalTo(sortViewHeight);
|
|
|
+ }];
|
|
|
+ [self.dateFormatter setDateFormat:@"yyyy年MM月"];
|
|
|
+ NSDate *currentDate = [NSDate date];
|
|
|
+ [self.sortView.firstLabel setText:[self.dateFormatter stringFromDate:currentDate]];
|
|
|
+ }
|
|
|
+
|
|
|
+ [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.right.bottom.mas_equalTo(self);
|
|
|
+ make.top.mas_equalTo(self.sortView.mas_bottom);
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - UITableViewDataSource
|
|
|
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
+ return self.dataArray.count;
|
|
|
+}
|
|
|
+
|
|
|
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ return 123.0f;
|
|
|
+}
|
|
|
+
|
|
|
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ GroupCourseListModel *model = self.dataArray[indexPath.row];
|
|
|
+ if (self.courseType == COURSE_GROUP_TYPE_VIP || self.courseType == COURSE_GROUP_TYPE_ACCOMPANY) {
|
|
|
+ ProgramCourseListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ProgramCourseListCell"];
|
|
|
+ MJWeakSelf;
|
|
|
+ [cell configWithSource:model beforeTime:self.enterStartTime callback:^(GroupCourseListModel * _Nonnull model) {
|
|
|
+ [weakSelf enterClassRoom:model];
|
|
|
+ }];
|
|
|
+ return cell;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ MusicRoomCourseListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MusicRoomCourseListCell"];
|
|
|
+ MJWeakSelf;
|
|
|
+ [cell configWithSource:model beforeTime:self.enterStartTime callback:^(GroupCourseListModel * _Nonnull model) {
|
|
|
+ [weakSelf enterClassRoom:model];
|
|
|
+ }];
|
|
|
+ return cell;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)enterClassRoom:(GroupCourseListModel *)model {
|
|
|
+
|
|
|
+ NSDateFormatter *dateFormatter = [NSObject getDateformatter];
|
|
|
+ [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
|
|
|
+ NSDate *beginDate = [dateFormatter dateFromString:model.startTime];
|
|
|
+ NSDate *endDate = [dateFormatter dateFromString:model.endTime];
|
|
|
+ NSDate *currentDate = [NSDate date];
|
|
|
+ NSTimeInterval beginTimeInterval = [beginDate timeIntervalSinceDate:currentDate];
|
|
|
+ NSTimeInterval endTimeInterval = [currentDate timeIntervalSinceDate:endDate];
|
|
|
+ if (beginTimeInterval <= self.joinRoomBeforeTime * 60 && endTimeInterval < 0) {
|
|
|
+ [self joinClassRoom:model];
|
|
|
+ }
|
|
|
+ else if (endTimeInterval > 0) {
|
|
|
+ [LOADING_MANAGER MBShowAUTOHidingInWindow:@"该课程已结束"];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ NSString *tipsString = [NSString stringWithFormat:@"课程还未开始,请在上课前%zd分钟进入", self.joinRoomBeforeTime];
|
|
|
+ [LOADING_MANAGER MBShowAUTOHidingInWindow:tipsString];
|
|
|
+ }
|
|
|
+
|
|
|
+ [self joinClassRoom:model];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ // 课程详情
|
|
|
+ GroupCourseListModel *courseModel = self.dataArray[indexPath.row];
|
|
|
+ if (self.courseType == COURSE_GROUP_TYPE_VIP) {
|
|
|
+ VipCouseDetailViewController *detailVC = [[VipCouseDetailViewController alloc] init];
|
|
|
+ detailVC.courseId = courseModel.courseId;
|
|
|
+ detailVC.courseGroupId = courseModel.courseGoupId;
|
|
|
+ [self.naviController pushViewController:detailVC animated:YES];
|
|
|
+ }
|
|
|
+ else if (self.courseType == COURSE_GROUP_TYPE_ACCOMPANY) {
|
|
|
+ AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init];
|
|
|
+ detailVC.courseId = courseModel.courseId;
|
|
|
+ detailVC.courseGroupId = courseModel.courseGoupId;
|
|
|
+ [self.naviController pushViewController:detailVC animated:YES];
|
|
|
+ }
|
|
|
+ else if (self.courseType == COURSE_GROUP_TYPE_MUSICROOM) {
|
|
|
+ MusicRoomDetailViewController *ctrl = [[MusicRoomDetailViewController alloc] init];
|
|
|
+ ctrl.courseId = courseModel.courseId;
|
|
|
+ ctrl.courseGroupId = courseModel.courseGoupId;
|
|
|
+ [self.naviController pushViewController:ctrl animated:YES];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark ---- lazying
|
|
|
+- (GroupCourseSortView *)sortView {
|
|
|
+ if (!_sortView) {
|
|
|
+ _sortView = [GroupCourseSortView sharedInstance];
|
|
|
+ MJWeakSelf;
|
|
|
+ [_sortView sortAction:^(SORT_TYPE type) {
|
|
|
+ [weakSelf sortWithType:type];
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ return _sortView;
|
|
|
+}
|
|
|
+
|
|
|
+- (NSMutableArray *)statusArray {
|
|
|
+ if (!_statusArray) {
|
|
|
+ _statusArray = [NSMutableArray arrayWithObject:@[]];
|
|
|
+ }
|
|
|
+ return _statusArray;
|
|
|
+}
|
|
|
+
|
|
|
+- (OnlineClassManager *)classManager {
|
|
|
+ if (!_classManager) {
|
|
|
+ _classManager = [[OnlineClassManager alloc] init];
|
|
|
+ }
|
|
|
+ return _classManager;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// 加入房间
|
|
|
+- (void)joinClassRoom:(GroupCourseListModel *)model {
|
|
|
+
|
|
|
+ // 加入房间前判断摄像头和麦克风逻辑
|
|
|
+ [RecordCheckManager checkCameraPremissionAvaiableCallback:^(PREMISSIONTYPE type) {
|
|
|
+ [self afterCheckCameraCheckMic:type source:model];
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)afterCheckCameraCheckMic:(PREMISSIONTYPE)cameraType source:(GroupCourseListModel *)model {
|
|
|
+ [RecordCheckManager checkMicPermissionAvaiableCallback:^(PREMISSIONTYPE type) {
|
|
|
+ if (type == PREMISSIONTYPE_YES && cameraType == PREMISSIONTYPE_YES) {
|
|
|
+ // 判断是否进行课前检测
|
|
|
+ [self.classManager joinRoomWithId:model.courseId subjectName:model.subjectName classEndTime:model.endTime inViewController:(KSBaseViewController *)self.naviController.visibleViewController];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ NSString *content = @"";
|
|
|
+ CHECKDEVICETYPE checkType = CHECKDEVICETYPE_BOTH;
|
|
|
+ if (cameraType == PREMISSIONTYPE_NO && type == PREMISSIONTYPE_NO) {
|
|
|
+ content = @"请开启相机和麦克风访问权限";
|
|
|
+ checkType = CHECKDEVICETYPE_BOTH;
|
|
|
+ }
|
|
|
+ else if (cameraType == PREMISSIONTYPE_NO && type == PREMISSIONTYPE_YES) {
|
|
|
+ content = @"请开启相机访问权限";
|
|
|
+ checkType = CHECKDEVICETYPE_CAMREA;
|
|
|
+ }
|
|
|
+ else if (cameraType == PREMISSIONTYPE_YES && type == PREMISSIONTYPE_NO) {
|
|
|
+ content = @"请开启麦克风访问权限";
|
|
|
+ checkType = CHECKDEVICETYPE_MIC;
|
|
|
+ }
|
|
|
+ [self showAlertWithMessage:content type:checkType];
|
|
|
+ }
|
|
|
+ }];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
|
|
|
+ [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:[NSObject getKeyWindow] cancel:^{
|
|
|
+
|
|
|
+ } confirm:^{
|
|
|
+ [self openSettingView];
|
|
|
+ }];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (void)openSettingView {
|
|
|
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
|
|
|
+}
|
|
|
+/**
|
|
|
+ 设置没有数据时的显示
|
|
|
+
|
|
|
+ @param promptString 提示语
|
|
|
+ @param imgName 图片名称
|
|
|
+ @param view 显示在什么地方
|
|
|
+ */
|
|
|
+- (void)setPromptString:(NSString *)promptString imageName:(NSString *)imgName inView:(UIView *)view {
|
|
|
+ if (self.promptView != nil) {
|
|
|
+ [self.promptView removeFromSuperview];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ self.promptView = [[StateView alloc]init];
|
|
|
+ self.promptView.frame = CGRectMake(0, 0, KPortraitWidth, KPortraitHeight - 300);
|
|
|
+ }
|
|
|
+ _promptPlaceView = view;
|
|
|
+ //当请求不到数据时 ,自定义提示view 将会出现;
|
|
|
+ self.promptView.imageName = imgName;
|
|
|
+ self.promptView.alpha = 0.0f;
|
|
|
+ [self.promptView setText:promptString];
|
|
|
+ [view addSubview:self.promptView];
|
|
|
+}
|
|
|
+
|
|
|
+// 结束刷新后调用方法
|
|
|
+- (void)changePromptLabelStateWithArray:(NSMutableArray *)array {
|
|
|
+ NSInteger count;
|
|
|
+ if (array.count) {
|
|
|
+ count = array.count;
|
|
|
+ } else {
|
|
|
+ count = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ [UIView animateWithDuration:0.1 animations:^{
|
|
|
+ [[self promptView] setAlpha:count ? 0.0f :1.0f ] ;
|
|
|
+ }] ;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)networkAvaiable {
|
|
|
+ return [self checkNetworkAvaiable];
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)checkNetworkAvaiable {
|
|
|
+ BOOL isExistenceNetwork = YES;
|
|
|
+ Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
|
|
|
+ switch ([reach currentReachabilityStatus]) {
|
|
|
+ case NotReachable:
|
|
|
+ isExistenceNetwork = NO;
|
|
|
+ //NSLog(@"notReachable");
|
|
|
+ break;
|
|
|
+ case ReachableViaWiFi:
|
|
|
+ isExistenceNetwork = YES;
|
|
|
+ //NSLog(@"WIFI");
|
|
|
+ break;
|
|
|
+ case ReachableViaWWAN:
|
|
|
+ isExistenceNetwork = YES;
|
|
|
+ //NSLog(@"3G");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return isExistenceNetwork;
|
|
|
+}
|
|
|
+- (void)dealloc {
|
|
|
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (NSDateFormatter *)dateFormatter {
|
|
|
+ if (!_dateFormatter) {
|
|
|
+ _dateFormatter = [NSObject getDateformatter];
|
|
|
+ }
|
|
|
+ return _dateFormatter;
|
|
|
+}
|
|
|
+- (void)sortWithType:(SORT_TYPE)type {
|
|
|
+
|
|
|
+ if (type == SORT_TYPE_TIME) { // time
|
|
|
+ [self showPickerView];
|
|
|
+ }
|
|
|
+ else if (type == SORT_TYPE_STATUS) { // 状态
|
|
|
+ MJWeakSelf;
|
|
|
+ KSChoosePicker *picker = [[KSChoosePicker alloc] initWithTitle:@"课程状态" sourceData:@[@"全部",@"未开始",@"进行中",@"已结束"] lastChooseIndex:self.secondChooseIndex sureButtonColor:THEMECOLOR chooseReturnWithBlock:^(NSString * _Nonnull returnValue, NSInteger chooseIndex) {
|
|
|
+ weakSelf.secondChooseIndex = chooseIndex;
|
|
|
+ if (chooseIndex == 0) {
|
|
|
+ [weakSelf.sortView.secondLabel setText:@"全部状态"];
|
|
|
+ weakSelf.courseStatus = nil;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [weakSelf.sortView.secondLabel setText:returnValue];
|
|
|
+ [weakSelf evaluateStatusWithIndex:chooseIndex isCourseStatus:YES];
|
|
|
+ }
|
|
|
+ self.sortView.secondArrowUp = NO;
|
|
|
+ [weakSelf refreshAndRequestData];
|
|
|
+ } cancel:^{
|
|
|
+ self.sortView.secondArrowUp = NO;
|
|
|
+ }];
|
|
|
+ [picker showPicker];
|
|
|
+ }
|
|
|
+ else if (type == SORT_TYPE_ATTENDENCE) {
|
|
|
+
|
|
|
+ MJWeakSelf;
|
|
|
+ KSChoosePicker *picker = [[KSChoosePicker alloc] initWithTitle:@"考勤" sourceData:@[@"全部",@"到课",@"旷课"] lastChooseIndex:self.secondChooseIndex sureButtonColor:THEMECOLOR chooseReturnWithBlock:^(NSString * _Nonnull returnValue, NSInteger chooseIndex) {
|
|
|
+ weakSelf.thirdChooseIndex = chooseIndex;
|
|
|
+ if (chooseIndex == 0) {
|
|
|
+ [weakSelf.sortView.thirdLabel setText:@"全部考勤"];
|
|
|
+ weakSelf.attendanceStatus = nil;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [weakSelf.sortView.thirdLabel setText:returnValue];
|
|
|
+ [weakSelf evaluateStatusWithIndex:chooseIndex isCourseStatus:NO];
|
|
|
+ }
|
|
|
+ self.sortView.thirdArrowUp = NO;
|
|
|
+ [weakSelf refreshAndRequestData];
|
|
|
+ } cancel:^{
|
|
|
+ self.sortView.thirdArrowUp = NO;
|
|
|
+ }];
|
|
|
+ [picker showPicker];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [self hiddenPopView];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)evaluateStatusWithIndex:(NSInteger)chooseIndex isCourseStatus:(BOOL)isCourseStatus {
|
|
|
+ if (isCourseStatus) {
|
|
|
+ switch (chooseIndex) {
|
|
|
+ case 0:
|
|
|
+ {
|
|
|
+ self.courseStatus = nil;
|
|
|
+ [self.sortView.secondLabel setText:@"全部状态"];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ {
|
|
|
+ self.courseStatus = @"NOT_START";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ {
|
|
|
+ self.courseStatus = @"ING";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ {
|
|
|
+ self.courseStatus = @"COMPLETE";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ switch (chooseIndex) {
|
|
|
+ case 0:
|
|
|
+ {
|
|
|
+ self.attendanceStatus = nil;
|
|
|
+ [self.sortView.thirdLabel setText:@"全部考勤"];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ {
|
|
|
+ self.attendanceStatus = @"1";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ {
|
|
|
+ self.attendanceStatus = @"0";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)showPickerView {
|
|
|
+ [self.dateFormatter setDateFormat:@"yyyy-MM"];
|
|
|
+ NSDate *preDate = [NSDate date];
|
|
|
+ if (![NSString isEmptyString:self.classDate]) {
|
|
|
+ preDate = [self.dateFormatter dateFromString:self.classDate];
|
|
|
+ }
|
|
|
+
|
|
|
+ KSFullDatePicker *picker = [[KSFullDatePicker alloc] initWithTitle:@"" date:preDate pickMode:KSDATEPICKER_MODE_YEAR_MONTH sureButtonColor:THEMECOLOR selectDateBlock:^(NSString *date) {
|
|
|
+
|
|
|
+ self.classDate = date;
|
|
|
+ NSString *displayTime = [self getTimeDisplay:date];
|
|
|
+ [self.sortView.firstLabel setText:displayTime];
|
|
|
+ [self resetPickerStatus];
|
|
|
+ // 请求数据
|
|
|
+ [self refreshAndRequestData];
|
|
|
+ } cancleBlock:^{
|
|
|
+ [self resetPickerStatus];
|
|
|
+ }];
|
|
|
+ [picker show];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)hiddenPopView {
|
|
|
+ self.sortView.firstArrowUp = NO;
|
|
|
+ self.sortView.secondArrowUp = NO;
|
|
|
+ self.sortView.thirdArrowUp = NO;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (NSString *)getTimeDisplay:(NSString *)chooseMonth {
|
|
|
+ [self.dateFormatter setDateFormat:@"yyyy-MM"];
|
|
|
+ NSDate *chooseDate = [self.dateFormatter dateFromString:chooseMonth];
|
|
|
+ [self.dateFormatter setDateFormat:@"yyyy年MM月"];
|
|
|
+ NSString *displayTime = [self.dateFormatter stringFromDate:chooseDate];
|
|
|
+ return displayTime;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)resetPickerStatus {
|
|
|
+ self.sortView.firstArrowUp = NO;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+// Only override drawRect: if you perform custom drawing.
|
|
|
+// An empty implementation adversely affects performance during animation.
|
|
|
+- (void)drawRect:(CGRect)rect {
|
|
|
+ // Drawing code
|
|
|
+}
|
|
|
+*/
|
|
|
+
|
|
|
+@end
|