CourseViewController.m 27 KB

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