|
@@ -11,7 +11,12 @@
|
|
|
#import "LTSCalendarBottomView.h"
|
|
|
#import "KSFullDatePicker.h"
|
|
|
#import "AccompanyCourseCell.h"
|
|
|
-#import "LiveCourseCell.h"
|
|
|
+#import "CourseForLiveCell.h"
|
|
|
+#import "TableCourseModel.h"
|
|
|
+#import "KSChatConversationViewController.h"
|
|
|
+#import "KSEnterLiveroomManager.h"
|
|
|
+#import "KSBaseWKWebViewController.h"
|
|
|
+#import "AccompanyDetailViewController.h"
|
|
|
|
|
|
@interface CourseViewController ()<UITableViewDataSource,UITableViewDelegate,FSCalendarDataSource,FSCalendarDelegate,UIGestureRecognizerDelegate>
|
|
|
{
|
|
@@ -37,6 +42,18 @@
|
|
|
|
|
|
@property (nonatomic, assign) BOOL cancleRequest;
|
|
|
|
|
|
+@property (nonatomic, strong) KSFullDatePicker *datePicker;
|
|
|
+
|
|
|
+@property (nonatomic, assign) BOOL isPickerChoose; // 是否选择的月份
|
|
|
+
|
|
|
+@property (nonatomic, assign) NSInteger practiceStartTime; // 陪练课开课前可进入时间配置(分钟)
|
|
|
+
|
|
|
+@property (nonatomic, assign) NSInteger practiceEndTime; // 陪练课结束后退出时间配置(分钟)
|
|
|
+
|
|
|
+@property (nonatomic, assign) NSInteger liveStartTime; // 直播课开课前可进入时间配置(分钟)
|
|
|
+
|
|
|
+@property (nonatomic, assign) NSInteger liveEndTime; // 直播课结束后退出时间配置(分钟)
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation CourseViewController
|
|
@@ -54,8 +71,14 @@
|
|
|
[formatter setDateFormat:@"yyyy-MM"];
|
|
|
NSDate *date = [NSDate date];
|
|
|
self.chooseMonth = [formatter stringFromDate:date];
|
|
|
+ [formatter setDateFormat:@"yyyy-MM-dd"];
|
|
|
self.chooseDay = [NSString stringWithFormat:@"%@ 00:00:00", [formatter stringFromDate:date]];
|
|
|
[self.calendar selectDate:date];
|
|
|
+
|
|
|
+ // title 显示
|
|
|
+ [formatter setDateFormat:@"yyyy年MM月"];
|
|
|
+ [self.navHeadView.navTitle setText:[formatter stringFromDate:date]];
|
|
|
+
|
|
|
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
|
|
|
[self loadMonthCourse:self.chooseMonth];
|
|
|
if (![NSString isEmptyString:self.chooseDay]) {
|
|
@@ -146,16 +169,12 @@
|
|
|
|
|
|
#pragma mark ---- calender action
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// 收起或展开日历
|
|
|
- (void)changeDisplay {
|
|
|
FSCalendarScope selectedScope = self.calendar.scope == FSCalendarScopeMonth ? FSCalendarScopeWeek : FSCalendarScopeMonth;
|
|
|
[self.calendar setScope:selectedScope animated:YES];
|
|
|
NSString *imgName = selectedScope == FSCalendarScopeWeek ? @"arrow_down" : @"arrow_up";
|
|
|
[self.calendarBottom.arrowImage setImage:[UIImage imageNamed:imgName]];
|
|
|
-#warning ---- 测试有课日期
|
|
|
- self.calendar.highlightDates = [NSMutableArray arrayWithArray:@[@"2022-04-12 00:00:00",@"2022-04-15 00:00:00"]];
|
|
|
[self.calendar reloadData];
|
|
|
}
|
|
|
|
|
@@ -183,7 +202,7 @@
|
|
|
self.calendar.appearance.subtitleSelectionColor = [UIColor whiteColor];
|
|
|
self.calendar.dataSource = self;
|
|
|
self.calendar.delegate = self;
|
|
|
-// self.calendar.firstWeekday = 2;
|
|
|
+ // self.calendar.firstWeekday = 2;
|
|
|
self.calendar.appearance.caseOptions = FSCalendarCaseOptionsWeekdayUsesSingleUpperCase|FSCalendarCaseOptionsHeaderUsesUpperCase;
|
|
|
self.calendar.calendarHeaderView.hidden = YES;
|
|
|
self.calendar.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];
|
|
@@ -238,8 +257,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
-- (void)calendarCurrentPageDidChange:(FSCalendar *)calendar
|
|
|
-{
|
|
|
+- (void)calendarCurrentPageDidChange:(FSCalendar *)calendar {
|
|
|
+ if (_isPickerChoose) {
|
|
|
+ _isPickerChoose = NO;
|
|
|
+ return;
|
|
|
+ }
|
|
|
self.navHeadView.navTitle.text = [self.dateFormatter stringFromDate:calendar.currentPage];
|
|
|
NSLog(@"%s %@", __FUNCTION__, [self.dateFormatter stringFromDate:calendar.currentPage]);
|
|
|
// 获取当前月份信息
|
|
@@ -261,12 +283,54 @@
|
|
|
|
|
|
#pragma mark --- 获取当前月份有课日期
|
|
|
- (void)loadMonthCourse:(NSString *)month {
|
|
|
-
|
|
|
+ [KSNetworkingManager queryCourseSchedule:KS_POST classMonth:month success:^(NSDictionary * _Nonnull dic) {
|
|
|
+ [self endRefresh];
|
|
|
+ if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
|
|
|
+ NSArray *courseArray = [dic arrayValueForKey:@"data"];
|
|
|
+ NSMutableArray *courseDateArray = [NSMutableArray array];
|
|
|
+ for (NSString *dateString in courseArray) {
|
|
|
+ NSString *dateStr = [NSString stringWithFormat:@"%@ %@", dateString, @"00:00:00"];
|
|
|
+ [courseDateArray addObject:dateStr];
|
|
|
+ }
|
|
|
+ self.calendar.highlightDates = courseDateArray;
|
|
|
+ [self.calendar reloadData];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [self MBPShow:MESSAGEKEY];
|
|
|
+ }
|
|
|
+ } faliure:^(NSError * _Nonnull error) {
|
|
|
+ [self endRefresh];
|
|
|
+ }];
|
|
|
}
|
|
|
|
|
|
#pragma mark --- 获取当日课程
|
|
|
- (void)getCourseByDate:(NSString *)date {
|
|
|
-
|
|
|
+ [self showhud];
|
|
|
+ [KSNetworkingManager queryCourseForDay:KS_POST classDate:date success:^(NSDictionary * _Nonnull dic) {
|
|
|
+ [self removehub];
|
|
|
+ if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
|
|
|
+ // 配置信息
|
|
|
+ NSDictionary *config = [[dic dictionaryValueForKey:@"data"] dictionaryValueForKey:@"sysConfig"];
|
|
|
+ self.practiceStartTime = [config integerValueForKey:@"practiceStartTime"];
|
|
|
+ self.practiceEndTime = [config integerValueForKey:@"practiceEndTime"];
|
|
|
+ self.liveStartTime = [config integerValueForKey:@"liveStartTime"];
|
|
|
+ self.liveEndTime = [config integerValueForKey:@"liveEndTime"];
|
|
|
+
|
|
|
+ NSArray *courseArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"studentList"];
|
|
|
+ NSMutableArray *lessonArray = [NSMutableArray array];
|
|
|
+ for (NSDictionary *parm in courseArray) {
|
|
|
+ TableCourseModel *model = [[TableCourseModel alloc] initWithDictionary:parm];
|
|
|
+ [lessonArray addObject:model];
|
|
|
+ }
|
|
|
+ self.dataArray = [lessonArray mutableCopy];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [self MBPShow:MESSAGEKEY];
|
|
|
+ }
|
|
|
+ [self.tableView reloadData];
|
|
|
+ } faliure:^(NSError * _Nonnull error) {
|
|
|
+ [self removehub];
|
|
|
+ }];
|
|
|
}
|
|
|
|
|
|
#pragma mark - <UIGestureRecognizerDelegate>
|
|
@@ -309,12 +373,105 @@
|
|
|
}
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
- AccompanyCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyCourseCell"];
|
|
|
- return cell;
|
|
|
+ TableCourseModel *model = self.dataArray[indexPath.row];
|
|
|
+ if ([model.courseType isEqualToString:@"PRACTICE"]) { // 陪练课
|
|
|
+ AccompanyCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyCourseCell"];
|
|
|
+ MJWeakSelf;
|
|
|
+ [cell configWithCourseMessage:model beforeTime:self.practiceStartTime actionCallback:^(ACCOMPANY_TYPE type, TableCourseModel * _Nonnull courseModel) {
|
|
|
+ [weakSelf accompanyLessonAction:type source:courseModel];
|
|
|
+ }];
|
|
|
+ return cell;
|
|
|
+ }
|
|
|
+ else { // 直播课
|
|
|
+ CourseForLiveCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CourseForLiveCell"];
|
|
|
+ MJWeakSelf;
|
|
|
+ [cell configWithSource:model beforeTime:self.liveStartTime callback:^(LIVECOURSEACTION action, TableCourseModel *sourceModel) {
|
|
|
+ [weakSelf liveCourseAction:action source:sourceModel];
|
|
|
+ }];
|
|
|
+ return cell;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-#pragma mark --- lazying
|
|
|
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ TableCourseModel *model = self.dataArray[indexPath.row];
|
|
|
+ if ([model.courseType isEqualToString:@"PRACTICE"]) { // 陪练课
|
|
|
+ [self showAccompanyDetailAction:model];
|
|
|
+ }
|
|
|
+ else { // 直播课详情
|
|
|
+ [self liveCourseDetail:model.courseId courseGroupId:model.courseGoupId];
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+- (void)accompanyLessonAction:(ACCOMPANY_TYPE)action source:(TableCourseModel *)source {
|
|
|
+ switch (action) {
|
|
|
+ case ACCOMPANY_TYPE_CHAT:
|
|
|
+ {
|
|
|
+ [self chatAction:source.userId groupName:source.name isGroup:NO];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ACCOMPANY_TYPE_ADJUST:
|
|
|
+ {
|
|
|
+ [self adjustCourseAction:source];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ACCOMPANY_DETAIL:
|
|
|
+ {
|
|
|
+ [self showAccompanyDetailAction:source];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)adjustCourseAction:(TableCourseModel *)source {
|
|
|
+ KSFullDatePicker *adjustPicker = [[KSFullDatePicker alloc] initWithTitle:@"课程调整" date:[NSDate date] pickMode:KSDATEPICKER_MODE_DAY_TIME selectDateBlock:^(NSString *date) {
|
|
|
+
|
|
|
+ } cancleBlock:^{
|
|
|
+
|
|
|
+ }];
|
|
|
+ [adjustPicker show];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)showAccompanyDetailAction:(TableCourseModel *)source {
|
|
|
+ AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init];
|
|
|
+ detailVC.courseId = source.courseId;
|
|
|
+// detailVC.cour
|
|
|
+ [self.navigationController pushViewController:detailVC animated:YES];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)liveCourseAction:(LIVECOURSEACTION)action source:(TableCourseModel *)source {
|
|
|
+ switch (action) {
|
|
|
+ case LIVECOURSEACTION_CHAT: // 聊天
|
|
|
+ {
|
|
|
+ [self chatAction:source.courseGoupId groupName:source.name isGroup:YES];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case LIVECOURSEACTION_LIVEROOM: // 直播课上课
|
|
|
+ {
|
|
|
+ [self liveCourseDetail:source.courseId courseGroupId:source.courseGoupId];
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)chatAction:(NSString *)targetId groupName:(NSString *)targetName isGroup:(BOOL)isGroup {
|
|
|
+ KSChatConversationViewController *conversationVC = [[KSChatConversationViewController alloc] init];
|
|
|
+ conversationVC.targetId = targetId;
|
|
|
+ conversationVC.title = targetName;
|
|
|
+ conversationVC.conversationType = isGroup ? ConversationType_GROUP : ConversationType_PRIVATE;
|
|
|
+ [self.navigationController pushViewController:conversationVC animated:YES];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)liveCourseDetail:(NSString *)courseId courseGroupId:(NSString *)courseGroupId {
|
|
|
+ KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
|
|
|
+ ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/openLive"];
|
|
|
+ [self.navigationController pushViewController:ctrl animated:YES];
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark --- lazying
|
|
|
- (CourseNavView *)navHeadView {
|
|
|
if (!_navHeadView) {
|
|
|
_navHeadView = [CourseNavView shareInstance];
|
|
@@ -327,12 +484,55 @@
|
|
|
return _navHeadView;
|
|
|
}
|
|
|
|
|
|
+- (KSFullDatePicker *)datePicker {
|
|
|
+ if (!_datePicker) {
|
|
|
+ _datePicker = [[KSFullDatePicker alloc] initWithTitle:@"" date:[NSDate date] pickMode:KSDATEPICKER_MODE_YEAR_MONTH selectDateBlock:^(NSString *date) {
|
|
|
+ self.navHeadView.navTitle.text = [self getTimeDisplay:date];
|
|
|
+ self.chooseMonth = date;
|
|
|
+ [self resetPickerStatus];
|
|
|
+ [self scrollCalendarToChooseMonth];
|
|
|
+
|
|
|
+ } cancleBlock:^{
|
|
|
+ [self resetPickerStatus];
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ return _datePicker;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)scrollCalendarToChooseMonth {
|
|
|
+ self.isPickerChoose = YES;
|
|
|
+ NSDateFormatter *formatter = [NSObject getDateformatter];
|
|
|
+ [formatter setDateFormat:@"yyyy-MM"];
|
|
|
+ NSDate *chooseDate = [formatter dateFromString:self.chooseMonth];
|
|
|
+ [formatter setDateFormat:@"yyyy-MM-dd"];
|
|
|
+ self.chooseDay = [NSString stringWithFormat:@"%@ 00:00:00", [formatter stringFromDate:chooseDate]];
|
|
|
+ [self.calendar setCurrentPage:chooseDate animated:YES];
|
|
|
+ [self loadMonthCourse:self.chooseMonth];
|
|
|
+ if (![NSString isEmptyString:self.chooseDay]) {
|
|
|
+ [self.calendar selectDate:chooseDate];
|
|
|
+ [self getCourseByDate:self.chooseDay];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (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.navHeadView.arrowUp = NO;
|
|
|
+}
|
|
|
+
|
|
|
- (void)displayMounthPicker {
|
|
|
-
|
|
|
+ [self.datePicker show];
|
|
|
}
|
|
|
+
|
|
|
- (NSDateFormatter *)dateFormatter {
|
|
|
if (!_dateFormatter) {
|
|
|
- _dateFormatter = [NSObject getDateformatter];
|
|
|
+ _dateFormatter = [NSObject getDateformatter];
|
|
|
_dateFormatter.dateFormat = @"yyyy年MM月";
|
|
|
}
|
|
|
return _dateFormatter;
|
|
@@ -346,10 +546,10 @@
|
|
|
_tableView.backgroundColor = [UIColor clearColor];
|
|
|
_tableView.showsVerticalScrollIndicator = NO;
|
|
|
_tableView.showsHorizontalScrollIndicator = NO;
|
|
|
- _tableView.rowHeight = UITableViewAutomaticDimension;
|
|
|
- _tableView.estimatedRowHeight = 130;
|
|
|
+// _tableView.rowHeight = UITableViewAutomaticDimension;
|
|
|
+ _tableView.rowHeight = 127.0f;
|
|
|
[_tableView registerNib:[UINib nibWithNibName:@"AccompanyCourseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyCourseCell"];
|
|
|
- [_tableView registerNib:[UINib nibWithNibName:@"LiveCourseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"LiveCourseCell"];
|
|
|
+ [_tableView registerNib:[UINib nibWithNibName:@"CourseForLiveCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CourseForLiveCell"];
|
|
|
UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 15)];
|
|
|
bottomView.backgroundColor = [UIColor clearColor];
|
|
|
_tableView.tableFooterView = bottomView;
|
|
@@ -359,13 +559,13 @@
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
-#pragma mark - Navigation
|
|
|
-
|
|
|
-// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
|
-- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
- // Get the new view controller using [segue destinationViewController].
|
|
|
- // Pass the selected object to the new view controller.
|
|
|
-}
|
|
|
-*/
|
|
|
+ #pragma mark - Navigation
|
|
|
+
|
|
|
+ // In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
|
+ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
+ // Get the new view controller using [segue destinationViewController].
|
|
|
+ // Pass the selected object to the new view controller.
|
|
|
+ }
|
|
|
+ */
|
|
|
|
|
|
@end
|