CourseViewController.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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. [KSNetworkingManager queryCourseForDay:KS_POST classDate:date success:^(NSDictionary * _Nonnull dic) {
  291. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  292. // 配置信息
  293. NSDictionary *config = [[dic ks_dictionaryValueForKey:@"data"] ks_dictionaryValueForKey:@"sysConfig"];
  294. self.vipStartTime = [config ks_integerValueForKey:@"vipStartTime"];
  295. self.vipEndTime = [config ks_integerValueForKey:@"vipEndTime"];
  296. self.practiceStartTime = [config ks_integerValueForKey:@"practiceStartTime"];
  297. self.practiceEndTime = [config ks_integerValueForKey:@"practiceEndTime"];
  298. self.liveStartTime = [config ks_integerValueForKey:@"liveStartTime"];
  299. self.liveEndTime = [config ks_integerValueForKey:@"liveEndTime"];
  300. self.pianoStartTime = [config ks_integerValueForKey:@"pianoStartTime"];
  301. self.pianoEndTime = [config ks_integerValueForKey:@"pianoEndTime"];
  302. NSArray *courseArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"studentList"];
  303. NSMutableArray *lessonArray = [NSMutableArray array];
  304. for (NSDictionary *parm in courseArray) {
  305. TableCourseModel *model = [[TableCourseModel alloc] initWithDictionary:parm];
  306. [lessonArray addObject:model];
  307. }
  308. self.dataArray = [lessonArray mutableCopy];
  309. }
  310. else {
  311. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  312. }
  313. [self.tableView reloadData];
  314. [self changePromptLabelState];
  315. } faliure:^(NSError * _Nonnull error) {
  316. }];
  317. }
  318. #pragma mark - <UIGestureRecognizerDelegate>
  319. // Whether scope gesture should begin
  320. - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
  321. {
  322. BOOL shouldBegin = self.tableView.contentOffset.y <= -self.tableView.contentInset.top;
  323. if (shouldBegin) {
  324. CGPoint velocity = [self.scopeGesture velocityInView:self.view];
  325. switch (self.calendar.scope) {
  326. case FSCalendarScopeMonth:
  327. return velocity.y < 0;
  328. case FSCalendarScopeWeek:
  329. return velocity.y > 0;
  330. }
  331. }
  332. return shouldBegin;
  333. }
  334. #pragma mark - KVO
  335. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
  336. {
  337. if (context == _KVOContext) {
  338. FSCalendarScope oldScope = [change[NSKeyValueChangeOldKey] unsignedIntegerValue];
  339. FSCalendarScope newScope = [change[NSKeyValueChangeNewKey] unsignedIntegerValue];
  340. NSLog(@"From %@ to %@",(oldScope==FSCalendarScopeWeek?@"week":@"month"),(newScope==FSCalendarScopeWeek?@"week":@"month"));
  341. NSString *imgName = newScope == FSCalendarScopeWeek ? @"arrow_down" : @"arrow_up";
  342. [self.calendarBottom.arrowImage setImage:[UIImage imageNamed:imgName]];
  343. } else {
  344. [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  345. }
  346. }
  347. #pragma mark --- table data source
  348. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  349. return 1;
  350. }
  351. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  352. return self.dataArray.count;
  353. }
  354. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  355. return 137.0f;
  356. }
  357. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  358. TableCourseModel *model = self.dataArray[indexPath.row];
  359. if ([model.courseType isEqualToString:@"PRACTICE"]) { // 趣纠课
  360. AccompanyCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyCourseCell"];
  361. MJWeakSelf;
  362. [cell configWithCourseMessage:model beforeTime:self.practiceStartTime actionCallback:^(ACCOMPANY_TYPE type, TableCourseModel * _Nonnull courseModel) {
  363. [weakSelf accompanyLessonAction:type source:courseModel];
  364. }];
  365. return cell;
  366. }
  367. else if ([model.courseType isEqualToString:@"VIP"]) { // 定制课
  368. VIPCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"VIPCourseCell"];
  369. MJWeakSelf;
  370. [cell configWithCourseMessage:model beforeTime:self.vipStartTime actionCallback:^(ACCOMPANY_TYPE type, TableCourseModel * _Nonnull courseModel) {
  371. [weakSelf vipLessionAction:type source:courseModel];
  372. }];
  373. return cell;
  374. }
  375. else if ([model.courseType isEqualToString:@"LIVE"]) { // 直播课
  376. CourseForLiveCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CourseForLiveCell"];
  377. MJWeakSelf;
  378. [cell configWithSource:model beforeTime:self.liveStartTime callback:^(LIVECOURSEACTION action, TableCourseModel *sourceModel) {
  379. [weakSelf liveCourseAction:action source:sourceModel];
  380. }];
  381. return cell;
  382. }
  383. else {
  384. MusicRoomCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MusicRoomCourseCell"];
  385. MJWeakSelf;
  386. [cell configWithSource:model beforeTime:self.pianoStartTime callback:^(NSString * _Nonnull targetId) {
  387. [weakSelf chatAction:targetId groupName:@"" isGroup:YES];
  388. }];
  389. return cell;
  390. }
  391. }
  392. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  393. TableCourseModel *model = self.dataArray[indexPath.row];
  394. if ([model.courseType isEqualToString:@"PRACTICE"]) { // 趣纠课
  395. [self showAccompanyDetailAction:model];
  396. }
  397. else if ([model.courseType isEqualToString:@"VIP"]) {
  398. [self showVipDetailAction:model];
  399. }
  400. else if ([model.courseType isEqualToString:@"LIVE"]) { // 直播课详情
  401. [self liveCourseDetail:model.courseId courseGroupId:model.courseGoupId];
  402. }
  403. else if ([model.courseType isEqualToString:@"PIANO_ROOM_CLASS"]) { // 琴房课详情
  404. [self showMusicRoomDetail:model];
  405. }
  406. else {
  407. [self showAccompanyDetailAction:model];
  408. }
  409. }
  410. - (void)accompanyLessonAction:(ACCOMPANY_TYPE)action source:(TableCourseModel *)source {
  411. switch (action) {
  412. case ACCOMPANY_TYPE_CHAT:
  413. {
  414. [self chatAction:source.imUserId groupName:source.name isGroup:NO];
  415. }
  416. break;
  417. case ACCOMPANY_DETAIL:
  418. {
  419. [self showAccompanyDetailAction:source];
  420. }
  421. break;
  422. default:
  423. break;
  424. }
  425. }
  426. - (void)vipLessionAction:(ACCOMPANY_TYPE)action source:(TableCourseModel *)source {
  427. switch (action) {
  428. case ACCOMPANY_TYPE_CHAT:
  429. {
  430. [self chatAction:source.imUserId groupName:source.name isGroup:NO];
  431. }
  432. break;
  433. case ACCOMPANY_DETAIL:
  434. {
  435. [self showVipDetailAction:source];
  436. }
  437. break;
  438. default:
  439. break;
  440. }
  441. }
  442. - (void)showAccompanyDetailAction:(TableCourseModel *)source {
  443. AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init];
  444. detailVC.courseId = source.courseId;
  445. detailVC.courseGroupId = source.courseGoupId;
  446. [self.navigationController pushViewController:detailVC animated:YES];
  447. }
  448. - (void)showVipDetailAction:(TableCourseModel *)source {
  449. VipCouseDetailViewController *detailVC = [[VipCouseDetailViewController alloc] init];
  450. detailVC.courseId = source.courseId;
  451. detailVC.courseGroupId = source.courseGoupId;
  452. [self.navigationController pushViewController:detailVC animated:YES];
  453. }
  454. - (void)showMusicRoomDetail:(TableCourseModel *)source {
  455. MusicRoomDetailViewController *detailVC = [[MusicRoomDetailViewController alloc] init];
  456. detailVC.courseId = source.courseId;
  457. detailVC.courseGroupId = source.courseGoupId;
  458. [self.navigationController pushViewController:detailVC animated:YES];
  459. }
  460. - (void)liveCourseAction:(LIVECOURSEACTION)action source:(TableCourseModel *)source {
  461. switch (action) {
  462. case LIVECOURSEACTION_CHAT: // 聊天
  463. {
  464. [self chatAction:source.imGroupId groupName:@"" isGroup:YES];
  465. }
  466. break;
  467. case LIVECOURSEACTION_LIVEROOM: // 直播课上课
  468. {
  469. [self liveCourseDetail:source.courseId courseGroupId:source.courseGoupId];
  470. }
  471. break;
  472. default:
  473. break;
  474. }
  475. }
  476. - (void)chatAction:(NSString *)targetId groupName:(NSString *)targetName isGroup:(BOOL)isGroup {
  477. if ([NSString isEmptyString:targetId] && isGroup) {
  478. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"报名未结束,暂无群组"];
  479. return;
  480. }
  481. if (isGroup) {
  482. TUIChatConversationModel *model = [[TUIChatConversationModel alloc] init];
  483. model.groupID = targetId;
  484. KSGroupConversationController *ctrl = [[KSGroupConversationController alloc] init];
  485. ctrl.conversation = model;
  486. [self.navigationController pushViewController:ctrl animated:YES];
  487. }
  488. else {
  489. TUIChatConversationModel *model = [[TUIChatConversationModel alloc] init];
  490. model.userID = targetId;
  491. KSChatConversationViewController *ctrl = [[KSChatConversationViewController alloc] init];
  492. ctrl.conversation = model;
  493. [self.navigationController pushViewController:ctrl animated:YES];
  494. }
  495. }
  496. - (void)liveCourseDetail:(NSString *)courseId courseGroupId:(NSString *)courseGroupId {
  497. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  498. NSString *url = [NSString stringWithFormat:@"%@/#/liveDetail?joinRoom=1&groupId=%@&classId=%@", WEBHOST, courseGroupId,courseId];
  499. ctrl.url = url;
  500. [self.navigationController pushViewController:ctrl animated:YES];
  501. }
  502. #pragma mark --- lazying
  503. - (CourseNavView *)navHeadView {
  504. if (!_navHeadView) {
  505. _navHeadView = [CourseNavView shareInstance];
  506. MJWeakSelf;
  507. [_navHeadView chooseNavCallback:^{
  508. [weakSelf displayMounthPicker];
  509. }];
  510. }
  511. return _navHeadView;
  512. }
  513. - (KSFullDatePicker *)datePicker {
  514. if (!_datePicker) {
  515. _datePicker = [[KSFullDatePicker alloc] initWithTitle:@"" date:[NSDate date] pickMode:KSDATEPICKER_MODE_YEAR_MONTH sureButtonColor:CLIENT_THEMECOLOR selectDateBlock:^(NSString *date) {
  516. self.navHeadView.navTitle.text = [self getTimeDisplay:date];
  517. self.chooseMonth = date;
  518. [self resetPickerStatus];
  519. [self scrollCalendarToChooseMonth];
  520. } cancleBlock:^{
  521. [self resetPickerStatus];
  522. }];
  523. }
  524. return _datePicker;
  525. }
  526. - (void)scrollCalendarToChooseMonth {
  527. self.isPickerChoose = YES;
  528. NSDateFormatter *formatter = [NSObject getDateformatter];
  529. [formatter setDateFormat:@"yyyy-MM"];
  530. NSDate *chooseDate = [formatter dateFromString:self.chooseMonth];
  531. [formatter setDateFormat:@"yyyy-MM-dd"];
  532. self.chooseDay = [NSString stringWithFormat:@"%@ 00:00:00", [formatter stringFromDate:chooseDate]];
  533. [self.calendar setCurrentPage:chooseDate animated:YES];
  534. [self loadMonthCourse:self.chooseMonth];
  535. if (![NSString isEmptyString:self.chooseDay]) {
  536. [self.calendar selectDate:chooseDate];
  537. [self getCourseByDate:self.chooseDay];
  538. }
  539. }
  540. - (NSString *)getTimeDisplay:(NSString *)chooseMonth {
  541. [self.dateFormatter setDateFormat:@"yyyy-MM"];
  542. NSDate *chooseDate = [self.dateFormatter dateFromString:chooseMonth];
  543. [self.dateFormatter setDateFormat:@"yyyy年MM月"];
  544. NSString *displayTime = [self.dateFormatter stringFromDate:chooseDate];
  545. return displayTime;
  546. }
  547. - (void)resetPickerStatus {
  548. self.navHeadView.arrowUp = NO;
  549. }
  550. - (void)displayMounthPicker {
  551. [self.datePicker show];
  552. }
  553. - (NSDateFormatter *)dateFormatter {
  554. if (!_dateFormatter) {
  555. _dateFormatter = [NSObject getDateformatter];
  556. _dateFormatter.dateFormat = @"yyyy年MM月";
  557. }
  558. return _dateFormatter;
  559. }
  560. - (UITableView *)tableView {
  561. if (!_tableView) {
  562. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  563. _tableView.delegate = self;
  564. _tableView.dataSource = self;
  565. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  566. _tableView.backgroundColor = [UIColor clearColor];
  567. _tableView.showsVerticalScrollIndicator = NO;
  568. _tableView.showsHorizontalScrollIndicator = NO;
  569. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyCourseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyCourseCell"];
  570. [_tableView registerNib:[UINib nibWithNibName:@"CourseForLiveCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CourseForLiveCell"];
  571. [_tableView registerNib:[UINib nibWithNibName:@"MusicRoomCourseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MusicRoomCourseCell"];
  572. [_tableView registerNib:[UINib nibWithNibName:@"VIPCourseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"VIPCourseCell"];
  573. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 15)];
  574. bottomView.backgroundColor = [UIColor clearColor];
  575. _tableView.tableFooterView = bottomView;
  576. }
  577. return _tableView;
  578. }
  579. /*
  580. #pragma mark - Navigation
  581. // In a storyboard-based application, you will often want to do a little preparation before navigation
  582. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  583. // Get the new view controller using [segue destinationViewController].
  584. // Pass the selected object to the new view controller.
  585. }
  586. */
  587. @end