CourseViewController.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. //
  2. // CourseViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/17.
  6. //
  7. #import "CourseViewController.h"
  8. #import "FSCalendar.h"
  9. #import "CourseNavView.h"
  10. #import "LTSCalendarBottomView.h"
  11. #import "KSFullDatePicker.h"
  12. #import "AccompanyCourseCell.h"
  13. #import "CourseForLiveCell.h"
  14. #import "TableCourseModel.h"
  15. #import "KSChatConversationViewController.h"
  16. #import "KSEnterLiveroomManager.h"
  17. #import "KSBaseWKWebViewController.h"
  18. #import "AccompanyDetailViewController.h"
  19. #import "NSDate+Transform.h"
  20. #import "MusicRoomCourseCell.h"
  21. #import "MusicRoomViewController.h"
  22. @interface CourseViewController ()<UITableViewDataSource,UITableViewDelegate,FSCalendarDataSource,FSCalendarDelegate,UIGestureRecognizerDelegate>
  23. {
  24. void * _KVOContext;
  25. }
  26. @property (nonatomic, strong) CourseNavView *navHeadView;
  27. @property (nonatomic, strong) NSString *chooseMonth;
  28. @property (nonatomic, strong) NSString *chooseDay;
  29. @property (nonatomic,strong) FSCalendar *calendar;
  30. @property (strong, nonatomic) NSCalendar *gregorian;
  31. @property (nonatomic, strong) UITableView *tableView;
  32. @property (strong, nonatomic) UIPanGestureRecognizer *scopeGesture;
  33. @property (strong, nonatomic) NSDateFormatter *dateFormatter;
  34. @property (nonatomic, strong) LTSCalendarBottomView *calendarBottom;
  35. @property (nonatomic, assign) BOOL cancleRequest;
  36. @property (nonatomic, strong) KSFullDatePicker *datePicker;
  37. @property (nonatomic, assign) BOOL isPickerChoose; // 是否选择的月份
  38. @property (nonatomic, assign) NSInteger practiceStartTime; // 陪练课开课前可进入时间配置(分钟)
  39. @property (nonatomic, assign) NSInteger practiceEndTime; // 陪练课结束后退出时间配置(分钟)
  40. @property (nonatomic, assign) NSInteger liveStartTime; // 直播课开课前可进入时间配置(分钟)
  41. @property (nonatomic, assign) NSInteger liveEndTime; // 直播课结束后退出时间配置(分钟)
  42. @property (nonatomic, strong) NSString *adjustBeginTime; // 可调整开始时间
  43. @property (nonatomic, strong) NSString *adjustEndTime; // 可调整结束时间
  44. @end
  45. @implementation CourseViewController
  46. - (void)viewDidLoad {
  47. [super viewDidLoad];
  48. // Do any additional setup after loading the view.
  49. self.ks_prefersNavigationBarHidden = YES;
  50. [self configUI];
  51. [self loadCalendarInfo];
  52. }
  53. - (void)loadCalendarInfo {
  54. NSDateFormatter *formatter = [NSObject getDateformatter];
  55. [formatter setDateFormat:@"yyyy-MM"];
  56. NSDate *date = [NSDate date];
  57. self.chooseMonth = [formatter stringFromDate:date];
  58. [formatter setDateFormat:@"yyyy-MM-dd"];
  59. self.chooseDay = [NSString stringWithFormat:@"%@ 00:00:00", [formatter stringFromDate:date]];
  60. [self.calendar selectDate:date];
  61. // title 显示
  62. [formatter setDateFormat:@"yyyy年MM月"];
  63. [self.navHeadView.navTitle setText:[formatter stringFromDate:date]];
  64. [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  65. }
  66. - (void)viewWillAppear:(BOOL)animated {
  67. [super viewWillAppear:animated];
  68. [self loadMonthCourse:self.chooseMonth];
  69. if (![NSString isEmptyString:self.chooseDay]) {
  70. [self getCourseByDate:self.chooseDay];
  71. }
  72. [self requestAdjustConfig];
  73. }
  74. - (void)requestAdjustConfig {
  75. [KSNetworkingManager queryCourseAdjustTimeLimit:KS_GET success:^(NSDictionary * _Nonnull dic) {
  76. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  77. NSArray *result = [dic arrayValueForKey:@"data"];
  78. for (NSDictionary *parm in result) {
  79. if ([[parm stringValueForKey:@"paramName"] isEqualToString:@"course_start_setting"]) { // 开始时间
  80. NSString *begTime = [parm stringValueForKey:@"paramValue"];
  81. if (![NSString isEmptyString:begTime]) {
  82. self.adjustBeginTime = [NSString stringWithFormat:@"%@",begTime];
  83. }
  84. }
  85. else if ([[parm stringValueForKey:@"paramName"] isEqualToString:@"course_end_setting"]) { // 结束时间
  86. NSString *endTime = [parm stringValueForKey:@"paramValue"];
  87. if (![NSString isEmptyString:endTime]) {
  88. self.adjustEndTime = [NSString stringWithFormat:@"%@",endTime];
  89. }
  90. }
  91. }
  92. }
  93. else {
  94. }
  95. } faliure:^(NSError * _Nonnull error) {
  96. }];
  97. }
  98. - (void)configEmptyView {
  99. [self setPromptString:@"暂无课程~" imageName:@"empty_course" inView:self.tableView];
  100. }
  101. - (void)configUI {
  102. [self.view addSubview:self.navHeadView];
  103. [self.navHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.left.right.top.mas_equalTo(self.view);
  105. make.height.mas_equalTo(kNaviBarHeight);
  106. }];
  107. [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
  108. make.left.right.mas_equalTo(self.view);
  109. make.top.mas_equalTo(self.navHeadView.mas_bottom);
  110. make.bottom.mas_equalTo(self.view.mas_bottom);
  111. }];
  112. UIView *containerView = [[UIView alloc] initWithFrame:CGRectZero];
  113. containerView.backgroundColor = [UIColor clearColor];
  114. [self.scrollView addSubview:containerView];
  115. [containerView mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.edges.mas_equalTo(self.scrollView);
  117. make.width.mas_equalTo(self.scrollView);
  118. }];
  119. self.calendar = [[FSCalendar alloc] init];
  120. [self configCalendar];
  121. [containerView addSubview:self.calendar];
  122. [self.calendar mas_makeConstraints:^(MASConstraintMaker *make) {
  123. make.left.right.mas_equalTo(containerView);
  124. make.top.mas_equalTo(containerView.mas_top);
  125. make.height.mas_equalTo(300);
  126. }];
  127. self.calendarBottom = [LTSCalendarBottomView shareInstance];
  128. MJWeakSelf;
  129. [self.calendarBottom changeDisplay:^{
  130. [weakSelf changeDisplay];
  131. }];
  132. [containerView addSubview:self.calendarBottom];
  133. [self.calendarBottom mas_makeConstraints:^(MASConstraintMaker *make) {
  134. make.left.right.mas_equalTo(containerView);
  135. make.top.mas_equalTo(self.calendar.mas_bottom);
  136. make.height.mas_equalTo(40);
  137. }];
  138. [containerView addSubview:self.tableView];
  139. CGFloat tableHeight = kScreenHeight - kNaviBarHeight - kTabBarHeight - 300 - 40;
  140. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  141. make.left.right.mas_equalTo(self.view);
  142. make.top.mas_equalTo(self.calendarBottom.mas_bottom);
  143. make.height.mas_equalTo(tableHeight);
  144. }];
  145. [containerView mas_makeConstraints:^(MASConstraintMaker *make) {
  146. make.bottom.mas_equalTo(self.tableView.mas_bottom);
  147. }];
  148. UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self.calendar action:@selector(handleScopeGesture:)];
  149. panGesture.delegate = self;
  150. panGesture.minimumNumberOfTouches = 1;
  151. panGesture.maximumNumberOfTouches = 2;
  152. [self.scrollView addGestureRecognizer:panGesture];
  153. self.scopeGesture = panGesture;
  154. [self.tableView.panGestureRecognizer requireGestureRecognizerToFail:panGesture];
  155. self.scrollView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
  156. [weakSelf.calendar setToday:[NSDate date]];
  157. [weakSelf loadMonthCourse:weakSelf.chooseMonth];
  158. if (![NSString isEmptyString:weakSelf.chooseDay]) {
  159. [weakSelf getCourseByDate:weakSelf.chooseDay];
  160. }
  161. }];
  162. if (@available(iOS 11.0, *)) {
  163. self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  164. } else {
  165. // Fallback on earlier versions
  166. self.automaticallyAdjustsScrollViewInsets = NO;
  167. }
  168. [self configEmptyView];
  169. }
  170. - (void)endRefresh {
  171. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  172. [self.scrollView.mj_header endRefreshing];
  173. });
  174. }
  175. #pragma mark ---- calender action
  176. // 收起或展开日历
  177. - (void)changeDisplay {
  178. FSCalendarScope selectedScope = self.calendar.scope == FSCalendarScopeMonth ? FSCalendarScopeWeek : FSCalendarScopeMonth;
  179. [self.calendar setScope:selectedScope animated:YES];
  180. NSString *imgName = selectedScope == FSCalendarScopeWeek ? @"arrow_down" : @"arrow_up";
  181. [self.calendarBottom.arrowImage setImage:[UIImage imageNamed:imgName]];
  182. [self.calendar reloadData];
  183. }
  184. - (void)configCalendar {
  185. self.calendar.backgroundColor = [UIColor whiteColor];
  186. self.calendar.appearance.titleFont = [UIFont systemFontOfSize:14.0f weight:UIFontWeightMedium];
  187. self.calendar.appearance.titleDefaultColor = HexRGB(0x444444);
  188. self.calendar.appearance.titleTodayColor = HexRGB(0x444444);
  189. self.calendar.appearance.titleSelectionColor = [UIColor whiteColor];
  190. self.calendar.appearance.selectionColor = THEMECOLOR;
  191. self.calendar.appearance.weekdayFont = [UIFont systemFontOfSize:14.0f];
  192. self.calendar.appearance.weekdayTextColor = HexRGB(0x777777);
  193. self.calendar.appearance.titleWeekendColor = THEMECOLOR;
  194. self.calendar.appearance.todaySelectionColor = THEMECOLOR;
  195. self.calendar.appearance.todayColor = [UIColor whiteColor];
  196. self.calendar.appearance.todayBorderColor = [UIColor whiteColor];
  197. self.calendar.appearance.borderRadius = 0.2f;
  198. self.calendar.appearance.borderDefaultColor = [UIColor whiteColor];
  199. self.calendar.appearance.titleHightlightColor = HexRGB(0x444444);
  200. self.calendar.appearance.backgoundHightlightColor = HexRGBAlpha(0xffd7a6, 0.21);
  201. self.calendar.appearance.subtitleFont = [UIFont systemFontOfSize:10.0f];
  202. self.calendar.appearance.subtitleOffset = CGPointMake(0, 3);
  203. self.calendar.appearance.subtitleTodayColor = HexRGB(0xff6363);
  204. self.calendar.appearance.subtitleDefaultColor = HexRGB(0xff6363);
  205. self.calendar.appearance.subtitleSelectionColor = [UIColor whiteColor];
  206. self.calendar.dataSource = self;
  207. self.calendar.delegate = self;
  208. // self.calendar.firstWeekday = 2;
  209. self.calendar.appearance.caseOptions = FSCalendarCaseOptionsWeekdayUsesSingleUpperCase|FSCalendarCaseOptionsHeaderUsesUpperCase;
  210. self.calendar.calendarHeaderView.hidden = YES;
  211. self.calendar.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];
  212. [self.calendar addObserver:self forKeyPath:@"scope" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:_KVOContext];
  213. self.calendar.placeholderType = FSCalendarPlaceholderTypeNone;
  214. self.calendar.scope = FSCalendarScopeMonth;
  215. [self.calendar selectDate:[NSDate date] scrollToDate:YES];
  216. }
  217. #pragma mark - FSCalendarDataSource
  218. - (NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date {
  219. // 判断有课的日期显示subtitle
  220. if ([calendar.highlightDates containsObject:date]) {
  221. return @"有课";
  222. }
  223. return nil;
  224. }
  225. #pragma mark - FSCalendarDelegate
  226. - (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
  227. {
  228. [calendar mas_updateConstraints:^(MASConstraintMaker *make) {
  229. make.height.mas_equalTo(bounds.size.height);
  230. // Do other updates
  231. }];
  232. [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
  233. make.height.mas_equalTo(kScreenHeight - kTabBarHeight - bounds.size.height - kNaviBarHeight - 40);
  234. }];
  235. [self.view layoutIfNeeded];
  236. }
  237. - (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition
  238. {
  239. NSLog(@"did select date %@",[self.dateFormatter stringFromDate:date]);
  240. NSMutableArray *selectedDates = [NSMutableArray arrayWithCapacity:calendar.selectedDates.count];
  241. [calendar.selectedDates enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  242. [selectedDates addObject:[self.dateFormatter stringFromDate:obj]];
  243. }];
  244. self.navHeadView.navTitle.text = [self.dateFormatter stringFromDate:date];
  245. NSLog(@"selected dates is %@",selectedDates);
  246. if (monthPosition == FSCalendarMonthPositionNext || monthPosition == FSCalendarMonthPositionPrevious) {
  247. [calendar setCurrentPage:date animated:YES];
  248. }
  249. NSDateFormatter *formatter = [NSObject getDateformatter];
  250. [formatter setDateFormat:@"yyyy-MM-dd"];
  251. NSString *dateStr = [formatter stringFromDate:date];
  252. dateStr = [NSString stringWithFormat:@"%@ 00:00:00", dateStr];
  253. self.chooseDay = dateStr;
  254. [self getCourseByDate:dateStr];
  255. }
  256. - (void)calendarCurrentPageDidChange:(FSCalendar *)calendar {
  257. if (_isPickerChoose) {
  258. _isPickerChoose = NO;
  259. return;
  260. }
  261. self.navHeadView.navTitle.text = [self.dateFormatter stringFromDate:calendar.currentPage];
  262. NSLog(@"%s %@", __FUNCTION__, [self.dateFormatter stringFromDate:calendar.currentPage]);
  263. // 获取当前月份信息
  264. NSDateFormatter *formatter = [NSObject getDateformatter];
  265. [formatter setDateFormat:@"yyyy-MM"];
  266. NSString *month = [formatter stringFromDate:calendar.currentPage];
  267. if (![_chooseMonth isEqualToString:month]) {
  268. _chooseMonth = month;
  269. [self loadMonthCourse:month];
  270. }
  271. [formatter setDateFormat:@"yyyy-MM-dd"];
  272. NSString *chooseDay = [formatter stringFromDate:calendar.currentPage];
  273. self.chooseDay = chooseDay;
  274. [self.calendar selectDate:calendar.currentPage];
  275. [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  276. NSString *currentDate = [formatter stringFromDate:calendar.currentPage];
  277. [self getCourseByDate:currentDate];
  278. }
  279. #pragma mark --- 获取当前月份有课日期
  280. - (void)loadMonthCourse:(NSString *)month {
  281. [KSNetworkingManager queryCourseSchedule:KS_POST classMonth:month success:^(NSDictionary * _Nonnull dic) {
  282. [self endRefresh];
  283. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  284. NSArray *courseArray = [dic arrayValueForKey:@"data"];
  285. NSMutableArray *courseDateArray = [NSMutableArray array];
  286. for (NSString *dateString in courseArray) {
  287. NSString *dateStr = [NSString stringWithFormat:@"%@ %@", dateString, @"00:00:00"];
  288. [courseDateArray addObject:dateStr];
  289. }
  290. self.calendar.highlightDates = courseDateArray;
  291. [self.calendar reloadData];
  292. }
  293. else {
  294. [self MBPShow:MESSAGEKEY];
  295. }
  296. } faliure:^(NSError * _Nonnull error) {
  297. [self endRefresh];
  298. }];
  299. }
  300. #pragma mark --- 获取当日课程
  301. - (void)getCourseByDate:(NSString *)date {
  302. [self showhud];
  303. [KSNetworkingManager queryCourseForDay:KS_POST classDate:date success:^(NSDictionary * _Nonnull dic) {
  304. [self removehub];
  305. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  306. // 配置信息
  307. NSDictionary *config = [[dic dictionaryValueForKey:@"data"] dictionaryValueForKey:@"sysConfig"];
  308. self.practiceStartTime = [config integerValueForKey:@"practiceStartTime"];
  309. self.practiceEndTime = [config integerValueForKey:@"practiceEndTime"];
  310. self.liveStartTime = [config integerValueForKey:@"liveStartTime"];
  311. self.liveEndTime = [config integerValueForKey:@"liveEndTime"];
  312. NSArray *courseArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"studentList"];
  313. NSMutableArray *lessonArray = [NSMutableArray array];
  314. for (NSDictionary *parm in courseArray) {
  315. TableCourseModel *model = [[TableCourseModel alloc] initWithDictionary:parm];
  316. [lessonArray addObject:model];
  317. }
  318. self.dataArray = [lessonArray mutableCopy];
  319. }
  320. else {
  321. [self MBPShow:MESSAGEKEY];
  322. }
  323. [self.tableView reloadData];
  324. [self changePromptLabelState];
  325. } faliure:^(NSError * _Nonnull error) {
  326. [self removehub];
  327. }];
  328. }
  329. #pragma mark - <UIGestureRecognizerDelegate>
  330. // Whether scope gesture should begin
  331. - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
  332. {
  333. BOOL shouldBegin = self.tableView.contentOffset.y <= -self.tableView.contentInset.top;
  334. if (shouldBegin) {
  335. CGPoint velocity = [self.scopeGesture velocityInView:self.view];
  336. switch (self.calendar.scope) {
  337. case FSCalendarScopeMonth:
  338. return velocity.y < 0;
  339. case FSCalendarScopeWeek:
  340. return velocity.y > 0;
  341. }
  342. }
  343. return shouldBegin;
  344. }
  345. #pragma mark - KVO
  346. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
  347. {
  348. if (context == _KVOContext) {
  349. FSCalendarScope oldScope = [change[NSKeyValueChangeOldKey] unsignedIntegerValue];
  350. FSCalendarScope newScope = [change[NSKeyValueChangeNewKey] unsignedIntegerValue];
  351. NSLog(@"From %@ to %@",(oldScope==FSCalendarScopeWeek?@"week":@"month"),(newScope==FSCalendarScopeWeek?@"week":@"month"));
  352. } else {
  353. [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  354. }
  355. }
  356. #pragma mark --- table data source
  357. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  358. return 1;
  359. }
  360. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  361. return self.dataArray.count;
  362. }
  363. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  364. TableCourseModel *model = self.dataArray[indexPath.row];
  365. if ([model.courseType isEqualToString:@"PIANO_ROOM_CLASS"]) {
  366. return 127.0f;
  367. }
  368. return 147.0f;
  369. }
  370. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  371. TableCourseModel *model = self.dataArray[indexPath.row];
  372. if ([model.courseType isEqualToString:@"PRACTICE"]) { // 陪练课
  373. AccompanyCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyCourseCell"];
  374. MJWeakSelf;
  375. [cell configWithCourseMessage:model beforeTime:self.practiceStartTime actionCallback:^(ACCOMPANY_TYPE type, TableCourseModel * _Nonnull courseModel) {
  376. [weakSelf accompanyLessonAction:type source:courseModel];
  377. }];
  378. return cell;
  379. }
  380. else if ([model.courseType isEqualToString:@"LIVE"]) { // 直播课
  381. CourseForLiveCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CourseForLiveCell"];
  382. MJWeakSelf;
  383. [cell configWithSource:model beforeTime:self.liveStartTime callback:^(LIVECOURSEACTION action, TableCourseModel *sourceModel) {
  384. [weakSelf liveCourseAction:action source:sourceModel];
  385. }];
  386. return cell;
  387. }
  388. else { // 琴房课 PIANO_ROOM_CLASS
  389. MusicRoomCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MusicRoomCourseCell"];
  390. MJWeakSelf;
  391. [cell configWithSource:model callback:^(NSString * _Nonnull targetId) {
  392. [weakSelf chatAction:targetId groupName:@"" isGroup:YES];
  393. }];
  394. return cell;
  395. }
  396. }
  397. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  398. TableCourseModel *model = self.dataArray[indexPath.row];
  399. if ([model.courseType isEqualToString:@"PRACTICE"]) { // 陪练课
  400. [self showAccompanyDetailAction:model];
  401. }
  402. else if ([model.courseType isEqualToString:@"LIVE"]) { // 直播课详情
  403. [self liveCourseDetail:model.courseId courseGroupId:model.courseGoupId];
  404. }
  405. else {
  406. MusicRoomViewController *ctrl = [[MusicRoomViewController alloc] init];
  407. ctrl.courseId = model.courseId;
  408. ctrl.courseGroupId = model.courseGoupId;
  409. [self.navigationController pushViewController:ctrl animated:YES];
  410. }
  411. }
  412. - (void)accompanyLessonAction:(ACCOMPANY_TYPE)action source:(TableCourseModel *)source {
  413. switch (action) {
  414. case ACCOMPANY_TYPE_CHAT:
  415. {
  416. [self chatAction:source.userId groupName:source.name isGroup:NO];
  417. }
  418. break;
  419. case ACCOMPANY_TYPE_ADJUST:
  420. {
  421. [self adjustCourseAction:source];
  422. }
  423. break;
  424. case ACCOMPANY_DETAIL:
  425. {
  426. [self showAccompanyDetailAction:source];
  427. }
  428. break;
  429. default:
  430. break;
  431. }
  432. }
  433. - (void)adjustCourseAction:(TableCourseModel *)source {
  434. KSFullDatePicker *adjustPicker = [[KSFullDatePicker alloc] initWithTitle:@"课程调整" date:[NSDate date] pickMode:KSDATEPICKER_MODE_DAY_TIME selectDateBlock:^(NSString *date) {
  435. NSString *timeString = [NSString stringWithFormat:@"%@:00", date];
  436. [self adjustCourseWithSource:source time:timeString];
  437. } cancleBlock:^{
  438. }];
  439. [adjustPicker show];
  440. }
  441. - (void)adjustCourseWithSource:(TableCourseModel *)model time:(NSString *)chooseTime {
  442. NSString *formatString = @"yyyy-MM-dd HH:mm:ss";
  443. NSTimeInterval courseDuration = [NSDate countTimesTampWithBeginTime:model.startTime endTime:model.endTime format:formatString];
  444. NSDate *endDate = [NSDate dateWithTimeInterval:courseDuration sinceDate:[NSDate dateFromString:chooseTime format:formatString]];
  445. NSString *endTime = [endDate stringDateWithFormat:formatString];
  446. NSString *classDay = [[chooseTime componentsSeparatedByString:@" "] firstObject];
  447. NSString *classDate = [NSString stringWithFormat:@"%@ 00:00:00", classDay];
  448. // 判断是否能在规定的时间内
  449. if (![NSString isEmptyString:self.adjustBeginTime] && ![NSString isEmptyString:self.adjustEndTime]) {
  450. NSString *limitBegin = [NSString stringWithFormat:@"%@ %@:00",classDay,self.adjustBeginTime];
  451. NSString *limitEnd = [NSString stringWithFormat:@"%@ %@:00",classDay,self.adjustEndTime];
  452. NSTimeInterval beginDuration = [NSDate countTimesTampWithBeginTime:limitBegin endTime:chooseTime format:formatString];
  453. NSTimeInterval endDuration = [NSDate countTimesTampWithBeginTime:endTime endTime:limitEnd format:formatString];
  454. if (beginDuration < 0) {
  455. [self MBPShow:[NSString stringWithFormat:@"课程开始时间不可早于%@",self.adjustBeginTime]];
  456. return;
  457. }
  458. else if (endDuration < 0) {
  459. [self MBPShow:[NSString stringWithFormat:@"课程结束时间不可晚于%@",self.adjustEndTime]];
  460. return;
  461. }
  462. }
  463. [self showhud];
  464. [KSNetworkingManager courseAdjustRequst:KS_POST courseId:model.courseId classDate:classDate startTime:chooseTime endTime:endTime success:^(NSDictionary * _Nonnull dic) {
  465. [self removehub];
  466. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  467. MJWeakSelf;
  468. [self KSShowMsg:@"调整成功" promptCompletion:^{
  469. [weakSelf loadMonthCourse:weakSelf.chooseMonth];
  470. if (![NSString isEmptyString:weakSelf.chooseDay]) {
  471. [weakSelf getCourseByDate:weakSelf.chooseDay];
  472. }
  473. }];
  474. }
  475. else {
  476. [self MBPShow:MESSAGEKEY];
  477. }
  478. } faliure:^(NSError * _Nonnull error) {
  479. [self removehub];
  480. }];
  481. }
  482. - (void)showAccompanyDetailAction:(TableCourseModel *)source {
  483. AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init];
  484. detailVC.courseId = source.courseId;
  485. detailVC.courseGroupId = source.courseGoupId;
  486. detailVC.studentId = source.userId;
  487. [self.navigationController pushViewController:detailVC animated:YES];
  488. }
  489. - (void)liveCourseAction:(LIVECOURSEACTION)action source:(TableCourseModel *)source {
  490. switch (action) {
  491. case LIVECOURSEACTION_CHAT: // 聊天
  492. {
  493. if ([NSString isEmptyString:source.imGroupId]) {
  494. return;
  495. }
  496. [self chatAction:source.imGroupId groupName:source.name isGroup:YES];
  497. }
  498. break;
  499. case LIVECOURSEACTION_LIVEROOM: // 直播课上课
  500. {
  501. [self liveCourseDetail:source.courseId courseGroupId:source.courseGoupId];
  502. }
  503. break;
  504. default:
  505. break;
  506. }
  507. }
  508. - (void)chatAction:(NSString *)targetId groupName:(NSString *)targetName isGroup:(BOOL)isGroup {
  509. KSChatConversationViewController *conversationVC = [[KSChatConversationViewController alloc] init];
  510. conversationVC.targetId = targetId;
  511. conversationVC.title = targetName;
  512. conversationVC.conversationType = isGroup ? ConversationType_GROUP : ConversationType_PRIVATE;
  513. [self.navigationController pushViewController:conversationVC animated:YES];
  514. }
  515. - (void)liveCourseDetail:(NSString *)courseId courseGroupId:(NSString *)courseGroupId {
  516. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  517. ctrl.url = [NSString stringWithFormat:@"%@/#/liveDetail?groupId=%@&classId=%@", WEBHOST, courseGroupId,courseId];
  518. [self.navigationController pushViewController:ctrl animated:YES];
  519. }
  520. #pragma mark --- lazying
  521. - (CourseNavView *)navHeadView {
  522. if (!_navHeadView) {
  523. _navHeadView = [CourseNavView shareInstance];
  524. MJWeakSelf;
  525. [_navHeadView chooseNavCallback:^{
  526. [weakSelf displayMounthPicker];
  527. }];
  528. }
  529. return _navHeadView;
  530. }
  531. - (KSFullDatePicker *)datePicker {
  532. if (!_datePicker) {
  533. _datePicker = [[KSFullDatePicker alloc] initWithTitle:@"" date:[NSDate date] pickMode:KSDATEPICKER_MODE_YEAR_MONTH selectDateBlock:^(NSString *date) {
  534. self.navHeadView.navTitle.text = [self getTimeDisplay:date];
  535. self.chooseMonth = date;
  536. [self resetPickerStatus];
  537. [self scrollCalendarToChooseMonth];
  538. } cancleBlock:^{
  539. [self resetPickerStatus];
  540. }];
  541. }
  542. return _datePicker;
  543. }
  544. - (void)scrollCalendarToChooseMonth {
  545. self.isPickerChoose = YES;
  546. NSDateFormatter *formatter = [NSObject getDateformatter];
  547. [formatter setDateFormat:@"yyyy-MM"];
  548. NSDate *chooseDate = [formatter dateFromString:self.chooseMonth];
  549. [formatter setDateFormat:@"yyyy-MM-dd"];
  550. self.chooseDay = [NSString stringWithFormat:@"%@ 00:00:00", [formatter stringFromDate:chooseDate]];
  551. [self.calendar setCurrentPage:chooseDate animated:YES];
  552. [self loadMonthCourse:self.chooseMonth];
  553. if (![NSString isEmptyString:self.chooseDay]) {
  554. [self.calendar selectDate:chooseDate];
  555. [self getCourseByDate:self.chooseDay];
  556. }
  557. }
  558. - (NSString *)getTimeDisplay:(NSString *)chooseMonth {
  559. [self.dateFormatter setDateFormat:@"yyyy-MM"];
  560. NSDate *chooseDate = [self.dateFormatter dateFromString:chooseMonth];
  561. [self.dateFormatter setDateFormat:@"yyyy年MM月"];
  562. NSString *displayTime = [self.dateFormatter stringFromDate:chooseDate];
  563. return displayTime;
  564. }
  565. - (void)resetPickerStatus {
  566. self.navHeadView.arrowUp = NO;
  567. }
  568. - (void)displayMounthPicker {
  569. [self.datePicker show];
  570. }
  571. - (NSDateFormatter *)dateFormatter {
  572. if (!_dateFormatter) {
  573. _dateFormatter = [NSObject getDateformatter];
  574. _dateFormatter.dateFormat = @"yyyy年MM月";
  575. }
  576. return _dateFormatter;
  577. }
  578. - (UITableView *)tableView {
  579. if (!_tableView) {
  580. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  581. _tableView.delegate = self;
  582. _tableView.dataSource = self;
  583. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  584. _tableView.backgroundColor = [UIColor clearColor];
  585. _tableView.showsVerticalScrollIndicator = NO;
  586. _tableView.showsHorizontalScrollIndicator = NO;
  587. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyCourseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyCourseCell"];
  588. [_tableView registerNib:[UINib nibWithNibName:@"CourseForLiveCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CourseForLiveCell"];
  589. [_tableView registerNib:[UINib nibWithNibName:@"MusicRoomCourseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MusicRoomCourseCell"];
  590. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 15)];
  591. bottomView.backgroundColor = [UIColor clearColor];
  592. _tableView.tableFooterView = bottomView;
  593. }
  594. return _tableView;
  595. }
  596. /*
  597. #pragma mark - Navigation
  598. // In a storyboard-based application, you will often want to do a little preparation before navigation
  599. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  600. // Get the new view controller using [segue destinationViewController].
  601. // Pass the selected object to the new view controller.
  602. }
  603. */
  604. @end