MyLessonBodyView.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. //
  2. // MyLessonBodyView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/4/12.
  6. //
  7. #import "MyLessonBodyView.h"
  8. #import "KSBaseWKWebViewController.h"
  9. #import "AuthDisplayView.h"
  10. #import "MyLiveCourseCell.h"
  11. #import "AccompanyCourseCell.h"
  12. #import "LiveLessonModel.h"
  13. #import "AccompanyLessonModel.h"
  14. #import "KSChatConversationViewController.h"
  15. #import "MyLessonSearchView.h"
  16. #import "NewClassPopView.h"
  17. #import "KSFullDatePicker.h"
  18. #import "AccompanyDetailViewController.h"
  19. #import "KSChoosePicker.h"
  20. @interface MyLessonBodyView ()<UITableViewDelegate,UITableViewDataSource>
  21. @property (nonatomic, strong) NSDateFormatter *dateFormatter;
  22. @property (nonatomic, copy) MyLessonSearchView *sortView;
  23. @property (nonatomic, strong) NewClassPopView *popView;
  24. @property (nonatomic, strong) NSMutableArray *dataArray;
  25. @property (nonatomic, strong) StateView *promptView;
  26. @property (nonatomic, strong) UIView *promptPlaceView;
  27. @property (nonatomic, assign) BOOL networkAvaiable; // 网络是否可用
  28. @property (nonatomic, assign) BOOL isLoadMore;
  29. @property (nonatomic, assign) NSInteger rows;
  30. @property (nonatomic, assign) NSInteger pages;
  31. @property (nonatomic, strong) AuthDisplayView *authView;
  32. @property (nonatomic, assign) NSInteger secondChooseIndex;
  33. @property (nonatomic, assign) NSInteger thirdChooseIndex;
  34. @property (nonatomic, strong) NSString *classDate;
  35. @property (nonatomic, strong) NSString *status;
  36. @property (nonatomic, strong) NSString *subjectId;
  37. @property (nonatomic, strong) NSMutableArray *subjectMessageArray;
  38. @property (nonatomic, assign) BOOL teacherAuthPass; // 是否通过老师审核
  39. @end
  40. @implementation MyLessonBodyView
  41. - (instancetype)initWithFrame:(CGRect)frame {
  42. self = [super initWithFrame:frame];
  43. if (self) {
  44. self.backgroundColor = HexRGB(0xf6f8f9);
  45. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) style:UITableViewStylePlain];
  46. self.tableView.backgroundColor = HexRGB(0xf6f8f9);
  47. self.tableView.showsVerticalScrollIndicator = NO;
  48. self.tableView.dataSource = self;
  49. self.tableView.delegate = self;
  50. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  51. [self addSubview:self.tableView];
  52. UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
  53. headView.backgroundColor = HexRGB(0xf6f8f9);
  54. self.tableView.tableHeaderView = headView;
  55. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
  56. bottomView.backgroundColor = HexRGB(0xf6f8f9);
  57. self.tableView.tableFooterView = bottomView;
  58. [self.tableView registerNib:[UINib nibWithNibName:@"AccompanyCourseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyCourseCell"];
  59. [self.tableView registerNib:[UINib nibWithNibName:@"MyLiveCourseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MyLiveCourseCell"];
  60. [self.dateFormatter setDateFormat:@"yyyy-MM"];
  61. NSDate *currentDate = [NSDate date];
  62. self.classDate = [self.dateFormatter stringFromDate:currentDate];
  63. MJWeakSelf;
  64. self.tableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
  65. [weakSelf resetParamenter];
  66. [weakSelf requestData];
  67. }];
  68. self.tableView.mj_footer = [KSGifRefreshFooter footerWithRefreshingBlock:^{
  69. if (weakSelf.isLoadMore) {
  70. weakSelf.pages += 1;
  71. [weakSelf requestData];
  72. }
  73. else {
  74. [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
  75. }
  76. }];
  77. }
  78. return self;
  79. }
  80. - (void)endRefresh {
  81. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  82. [self.tableView.mj_header endRefreshing];
  83. [self.tableView.mj_footer endRefreshing];
  84. });
  85. }
  86. - (void)refreshAndRequestData {
  87. [self resetParamenter];
  88. [self requestData];
  89. }
  90. - (void)resetParamenter {
  91. self.isLoadMore = YES;
  92. self.pages = 1;
  93. self.rows = 10;
  94. self.dataArray = [NSMutableArray array];
  95. [self.tableView.mj_footer resetNoMoreData];
  96. [self setPromptString:@"暂无课程~" imageName:@"empty_course" inView:self.tableView];
  97. [self.tableView reloadData];
  98. }
  99. - (void)requestData {
  100. if (self.selectIndex == 0) { // 陪练课
  101. [KSNetworkingManager accompanyCourseRequest:KS_POST classMonth:self.classDate status:self.status subjectId:self.subjectId page:self.pages rows:self.rows success:^(NSDictionary * _Nonnull dic) {
  102. [self endRefresh];
  103. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  104. NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
  105. for (NSDictionary *parm in sourceArray) {
  106. AccompanyLessonModel *model = [[AccompanyLessonModel alloc] initWithDictionary:parm];
  107. [self.dataArray addObject:model];
  108. }
  109. if (sourceArray.count < self.rows) {
  110. self.isLoadMore = NO;
  111. }
  112. }
  113. else {
  114. [self MBPShow:MESSAGEKEY];
  115. }
  116. [self.tableView reloadData];
  117. [self changePromptLabelStateWithArray:self.dataArray];
  118. } faliure:^(NSError * _Nonnull error) {
  119. [self endRefresh];
  120. if (self.networkAvaiable == NO) {
  121. [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.tableView];
  122. }
  123. [self.dataArray removeAllObjects];
  124. [self.tableView reloadData];
  125. [self changePromptLabelStateWithArray:self.dataArray];
  126. }];
  127. }
  128. else { // 直播课
  129. [KSNetworkingManager queryTeacherLiveCourse:KS_POST classDate:self.classDate status:self.status subjectId:self.subjectId page:self.pages rows:self.rows success:^(NSDictionary * _Nonnull dic) {
  130. [self endRefresh];
  131. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  132. NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
  133. for (NSDictionary *parm in sourceArray) {
  134. LiveLessonModel *model = [[LiveLessonModel alloc] initWithDictionary:parm];
  135. [self.dataArray addObject:model];
  136. }
  137. if (sourceArray.count < self.rows) {
  138. self.isLoadMore = NO;
  139. }
  140. }
  141. else {
  142. [self MBPShow:MESSAGEKEY];
  143. }
  144. [self.tableView reloadData];
  145. [self changePromptLabelStateWithArray:self.dataArray];
  146. } faliure:^(NSError * _Nonnull error) {
  147. [self endRefresh];
  148. if (self.networkAvaiable == NO) {
  149. [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.tableView];
  150. }
  151. [self.dataArray removeAllObjects];
  152. [self.tableView reloadData];
  153. [self changePromptLabelStateWithArray:self.dataArray];
  154. }];
  155. }
  156. }
  157. - (void)beginRefreshImmediately {
  158. [self.tableView.mj_header beginRefreshing];
  159. }
  160. - (void)beginFirstRefresh {
  161. if (!self.isHeaderRefreshed) {
  162. [self beginRefreshImmediately];
  163. }
  164. }
  165. - (void)selectCellAtIndexPath:(NSIndexPath *)indexPath {
  166. if (self.lastSelectedIndexPath == indexPath) {
  167. return;
  168. }
  169. if (self.lastSelectedIndexPath != nil) {
  170. UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:self.lastSelectedIndexPath];
  171. [cell setSelected:NO animated:NO];
  172. }
  173. UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  174. [cell setSelected:YES animated:NO];
  175. self.lastSelectedIndexPath = indexPath;
  176. }
  177. - (void)layoutSubviews {
  178. [super layoutSubviews];
  179. self.tableView.frame = self.bounds;
  180. CGFloat topHeight = 55.0f;
  181. self.tableView.frame = CGRectMake(0, topHeight, self.bounds.size.width, self.bounds.size.height - topHeight);
  182. if (!_sortView) {
  183. _sortView = [MyLessonSearchView shareInstance];
  184. _sortView.frame = CGRectMake(0, 0, kScreenWidth, 55);
  185. MJWeakSelf;
  186. [_sortView sortAction:^(SORT_TYPE type) {
  187. [weakSelf sortWithType:type];
  188. }];
  189. [self.dateFormatter setDateFormat:@"yyyy年M月"];
  190. NSDate *currentDate = [NSDate date];
  191. [self.sortView.firstButton setTitle:[self.dateFormatter stringFromDate:currentDate] forState:UIControlStateNormal];
  192. [self addSubview:self.sortView];
  193. }
  194. if (self.teacherAuthPass == NO) {
  195. [self showAuthView];
  196. }
  197. else {
  198. [self hideAuthView];
  199. }
  200. }
  201. - (void)sortWithType:(SORT_TYPE)type {
  202. if (type == SORT_TYPE_TIME) { // time
  203. [self showPickerView];
  204. }
  205. else if (type == SORT_TYPE_STATUS) { // 状态
  206. [self.popView refreshWithSourceArray:@[@"全部",@"未开始",@"进行中",@"已结束"] preChooseIndex:_secondChooseIndex inView:self actionItem:1];
  207. }
  208. else if (type == SORT_TYPE_SUBJECT) {
  209. if (self.subjectList.count) {
  210. NSMutableArray *nameArray = [NSMutableArray array];
  211. [nameArray addObject:@"全部"];
  212. for (NSDictionary *parm in self.subjectList) {
  213. [nameArray addObject:[parm stringValueForKey:@"subjectName"]];
  214. }
  215. MJWeakSelf;
  216. KSChoosePicker *picker = [[KSChoosePicker alloc] initWithTitle:@"声部筛选" sourceData:nameArray chooseReturnWithBlock:^(NSString * _Nonnull returnValue, NSInteger chooseIndex) {
  217. if (chooseIndex == 0) {
  218. [weakSelf.sortView.thirdButton setTitle:@"全部声部" forState:UIControlStateNormal];
  219. weakSelf.subjectId = nil;
  220. }
  221. else {
  222. [weakSelf.sortView.thirdButton setTitle:returnValue forState:UIControlStateNormal];
  223. NSDictionary *parm = self.subjectList[chooseIndex-1];
  224. weakSelf.subjectId = [parm stringValueForKey:@"subjectId"];
  225. }
  226. self.sortView.thirdArrowUp = NO;
  227. [weakSelf refreshAndRequestData];
  228. } cancel:^{
  229. self.sortView.thirdArrowUp = NO;
  230. }];
  231. [picker showPicker];
  232. }
  233. else {
  234. [self MBPShow:@"无声部信息"];
  235. self.sortView.thirdArrowUp = NO;
  236. }
  237. }
  238. else {
  239. [self hiddenPopView];
  240. }
  241. }
  242. - (void)showPickerView {
  243. KSFullDatePicker *picker = [[KSFullDatePicker alloc] initWithTitle:@"" date:[NSDate date] pickMode:KSDATEPICKER_MODE_YEAR_MONTH selectDateBlock:^(NSString *date) {
  244. self.classDate = date;
  245. NSString *displayTime = [self getTimeDisplay:date];
  246. [self.sortView.firstButton setTitle:displayTime forState:UIControlStateNormal];
  247. [self resetPickerStatus];
  248. // 请求数据
  249. [self refreshAndRequestData];
  250. } cancleBlock:^{
  251. [self resetPickerStatus];
  252. }];
  253. [picker show];
  254. }
  255. - (NSString *)getTimeDisplay:(NSString *)chooseMonth {
  256. [self.dateFormatter setDateFormat:@"yyyy-MM"];
  257. NSDate *chooseDate = [self.dateFormatter dateFromString:chooseMonth];
  258. [self.dateFormatter setDateFormat:@"yyyy年M月"];
  259. NSString *displayTime = [self.dateFormatter stringFromDate:chooseDate];
  260. return displayTime;
  261. }
  262. - (void)resetPickerStatus {
  263. self.sortView.firstArrowUp = NO;
  264. }
  265. - (NewClassPopView *)popView {
  266. if (!_popView) {
  267. MJWeakSelf;
  268. _popView = [[NewClassPopView alloc] initWithFrame:CGRectMake(0, 55, kScreenWidth, kScreenHeight - 55 - kNaviBarHeight - iPhoneXSafeBottomMargin) tableColor:HexRGB(0xf6f8f9) chooseCallback:^(NSString * _Nonnull sortStr, NSInteger chooseIndex, NSInteger item) {
  269. if (chooseIndex != 0) {
  270. // 回调
  271. [weakSelf sortWithChooseIndex:chooseIndex item:item title:sortStr];
  272. }
  273. [weakSelf hiddenPopView];
  274. }];
  275. }
  276. return _popView;
  277. }
  278. - (void)sortWithChooseIndex:(NSInteger)chooseIndex item:(NSInteger)item title:(NSString *)title {
  279. if (item == 0) { //
  280. }
  281. else if (item == 1) { // 课程状态
  282. self.secondChooseIndex = chooseIndex;
  283. self.thirdChooseIndex = 0;
  284. [self.sortView.secondButton setTitle:title forState:UIControlStateNormal];
  285. switch (chooseIndex) {
  286. case 1:
  287. {
  288. self.status = nil;
  289. [self.sortView.secondButton setTitle:@"课程状态" forState:UIControlStateNormal];
  290. }
  291. break;
  292. case 2:
  293. {
  294. self.status = @"NOT_START";
  295. }
  296. break;
  297. case 3:
  298. {
  299. self.status = @"ING";
  300. }
  301. break;
  302. case 4:
  303. {
  304. self.status = @"COMPLETE";
  305. }
  306. break;
  307. default:
  308. break;
  309. }
  310. }
  311. else if (item == 2) { // 声部筛选
  312. self.thirdChooseIndex = chooseIndex;
  313. [self.sortView.thirdButton setTitle:title forState:UIControlStateNormal];
  314. if (chooseIndex == 1) {
  315. self.subjectId = nil;
  316. [self.sortView.thirdButton setTitle:@"全部声部" forState:UIControlStateNormal];
  317. }
  318. else {
  319. NSDictionary *parm = self.subjectMessageArray[chooseIndex-1];
  320. self.subjectId = [parm stringValueForKey:@"subjectId"];
  321. }
  322. }
  323. [self resetParamenter];
  324. [self requestData];
  325. }
  326. - (void)hiddenPopView {
  327. self.sortView.firstArrowUp = NO;
  328. self.sortView.secondArrowUp = NO;
  329. self.sortView.thirdArrowUp = NO;
  330. [self.popView hiddenView];
  331. }
  332. #pragma mark - UITableViewDataSource
  333. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  334. return self.dataArray.count;
  335. }
  336. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  337. if (self.selectIndex == 0) {
  338. return 127.0f;
  339. }
  340. else {
  341. return 164.0f;
  342. }
  343. }
  344. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  345. if (self.selectIndex == 0) {
  346. AccompanyLessonModel *model = self.dataArray[indexPath.row];
  347. AccompanyCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyCourseCell"];
  348. MJWeakSelf;
  349. [cell configWithSource:model actionCallback:^(ACCOMPANY_TYPE type, AccompanyLessonModel * _Nonnull source) {
  350. [weakSelf courseOperation:type sourceModel:source];
  351. }];
  352. return cell;
  353. }
  354. else {
  355. LiveLessonModel *model = self.dataArray[indexPath.row];
  356. MyLiveCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyLiveCourseCell"];
  357. MJWeakSelf;
  358. [cell configCellWithSource:model callback:^(NSString *targetId) {
  359. [weakSelf chatAction:targetId];
  360. }];
  361. return cell;
  362. }
  363. }
  364. - (void)courseOperation:(ACCOMPANY_TYPE)type sourceModel:(AccompanyLessonModel *)model {
  365. switch (type) {
  366. case ACCOMPANY_TYPE_CHAT: // 聊天
  367. {
  368. KSChatConversationViewController *conversationVC = [[KSChatConversationViewController alloc] init];
  369. conversationVC.targetId = model.imUserId;
  370. conversationVC.conversationType = ConversationType_PRIVATE;
  371. [self.naviController pushViewController:conversationVC animated:YES];
  372. }
  373. break;
  374. case ACCOMPANY_TYPE_ADJUST: // 调整
  375. {
  376. [self showAdjustPicker:model];
  377. }
  378. break;
  379. case ACCOMPANY_DETAIL: // 陪练课详情
  380. {
  381. [self showAccompanyDetail:model];
  382. }
  383. break;
  384. default:
  385. break;
  386. }
  387. }
  388. - (void)showAccompanyDetail:(AccompanyLessonModel *)model {
  389. AccompanyDetailViewController *detailVC = [[AccompanyDetailViewController alloc] init];
  390. detailVC.courseId = model.courseId;
  391. detailVC.courseGroupId = model.courseGoupId;
  392. detailVC.studentId = model.userId;
  393. [self.naviController pushViewController:detailVC animated:YES];
  394. }
  395. - (void)showAdjustPicker:(AccompanyLessonModel *)model {
  396. KSFullDatePicker *picker = [[KSFullDatePicker alloc] initWithTitle:@"课时调整" date:[NSDate date] pickMode:KSDATEPICKER_MODE_DAY_TIME selectDateBlock:^(NSString *date) {
  397. [self courseAdjustAction:model];
  398. } cancleBlock:^{
  399. }];
  400. [picker show];
  401. }
  402. - (void)courseAdjustAction:(AccompanyLessonModel *)model {
  403. }
  404. - (void)chatAction:(NSString *)targetId {
  405. if ([NSString isEmptyString:targetId]) {
  406. [self MBPShow:@"报名未结束,暂无群组"];
  407. return;
  408. }
  409. KSChatConversationViewController *conversationVC = [[KSChatConversationViewController alloc] init];
  410. conversationVC.targetId = targetId;
  411. conversationVC.conversationType = ConversationType_GROUP;
  412. [self.naviController pushViewController:conversationVC animated:YES];
  413. }
  414. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  415. if (self.selectIndex == 0) { // 进入陪练课详情
  416. AccompanyLessonModel *model = self.dataArray[indexPath.row];
  417. [self showAccompanyDetail:model];
  418. }
  419. else { // 直播课程组详情
  420. LiveLessonModel *model = self.dataArray[indexPath.row];
  421. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  422. NSString *url = [NSString stringWithFormat:@"%@/#/liveDetail?joinRoom=1&groupId=%@&classId=%@", WEBHOST, model.courseGroupId,model.courseId];
  423. ctrl.url = url;
  424. [self.naviController pushViewController:ctrl animated:YES];
  425. }
  426. }
  427. /**
  428. 设置没有数据时的显示
  429. @param promptString 提示语
  430. @param imgName 图片名称
  431. @param view 显示在什么地方
  432. */
  433. - (void)setPromptString:(NSString *)promptString imageName:(NSString *)imgName inView:(UIView *)view {
  434. if (self.promptView != nil) {
  435. [self.promptView removeFromSuperview];
  436. }
  437. else {
  438. self.promptView = [[StateView alloc]init];
  439. self.promptView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - 300);
  440. }
  441. _promptPlaceView = view;
  442. //当请求不到数据时 ,自定义提示view 将会出现;
  443. self.promptView.imageName = imgName;
  444. self.promptView.alpha = 0.0f;
  445. [self.promptView setText:promptString];
  446. [view addSubview:self.promptView];
  447. }
  448. // 结束刷新后调用方法
  449. - (void)changePromptLabelStateWithArray:(NSMutableArray *)array {
  450. NSInteger count;
  451. if (array.count) {
  452. count = array.count;
  453. } else {
  454. count = 0;
  455. }
  456. [UIView animateWithDuration:0.1 animations:^{
  457. [[self promptView] setAlpha:count ? 0.0f :1.0f ] ;
  458. }] ;
  459. }
  460. - (BOOL)networkAvaiable {
  461. return [self checkNetworkAvaiable];
  462. }
  463. - (BOOL)checkNetworkAvaiable {
  464. BOOL isExistenceNetwork = YES;
  465. Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
  466. switch ([reach currentReachabilityStatus]) {
  467. case NotReachable:
  468. isExistenceNetwork = NO;
  469. //NSLog(@"notReachable");
  470. break;
  471. case ReachableViaWiFi:
  472. isExistenceNetwork = YES;
  473. //NSLog(@"WIFI");
  474. break;
  475. case ReachableViaWWAN:
  476. isExistenceNetwork = YES;
  477. //NSLog(@"3G");
  478. break;
  479. }
  480. return isExistenceNetwork;
  481. }
  482. #pragma mark ----- lazying
  483. - (NSDateFormatter *)dateFormatter {
  484. if (!_dateFormatter) {
  485. _dateFormatter = [NSObject getDateformatter];
  486. }
  487. return _dateFormatter;
  488. }
  489. - (void)setTeaherStatus:(NSString *)teaherStatus {
  490. _teaherStatus = teaherStatus;
  491. if ([teaherStatus isEqualToString:@"UNPAALY"]) { // 未申请
  492. self.teacherAuthPass = NO;
  493. }
  494. else if ([teaherStatus isEqualToString:@"DOING"]) { // 审核中
  495. self.teacherAuthPass = NO;
  496. }
  497. else if ([teaherStatus isEqualToString:@"UNPASS"]) { // 不通过
  498. self.teacherAuthPass = NO;
  499. }
  500. else {
  501. self.teacherAuthPass = YES;
  502. }
  503. // 如果
  504. if (self.selectIndex == 1) { // 直播课
  505. if (self.liveFlag == NO) { // 无直播权限直接改成未通过
  506. self.teacherAuthPass = NO;
  507. }
  508. }
  509. if (self.teacherAuthPass == NO) {
  510. [self showAuthView];
  511. }
  512. else {
  513. [self hideAuthView];
  514. }
  515. }
  516. - (void)configAuthDisplay {
  517. [self.authView configDisplayMessage:[self getAuthDisplayMessage]];
  518. if (self.selectIndex == 0) { // 陪练课
  519. if ([self.teaherStatus isEqualToString:@"DOING"]) {
  520. self.authView.sureButton.userInteractionEnabled = NO;
  521. self.authView.sureButton.hidden = YES;
  522. }
  523. else {
  524. self.authView.sureButton.userInteractionEnabled = YES;
  525. self.authView.sureButton.hidden = NO;
  526. }
  527. }
  528. else { // 直播课
  529. if ([self.teaherStatus isEqualToString:@"DOING"]) {
  530. self.authView.sureButton.userInteractionEnabled = NO;
  531. self.authView.sureButton.hidden = YES;
  532. }
  533. else {
  534. if ([self.teaherStatus isEqual:@"PASS"] && self.liveFlag == NO) {
  535. [self.authView.sureButton setTitle:@"立即开通" forState:UIControlStateNormal];
  536. }
  537. else {
  538. [self.authView.sureButton setTitle:@"去认证" forState:UIControlStateNormal];
  539. }
  540. self.authView.sureButton.userInteractionEnabled = YES;
  541. self.authView.sureButton.hidden = NO;
  542. }
  543. }
  544. }
  545. - (void)showAuthView {
  546. [self configAuthDisplay];
  547. if ([self.subviews containsObject:self.authView]) {
  548. [self bringSubviewToFront:self.authView];
  549. }
  550. else {
  551. [self addSubview:self.authView];
  552. [self.authView mas_makeConstraints:^(MASConstraintMaker *make) {
  553. make.left.top.bottom.right.mas_equalTo(self);
  554. }];
  555. }
  556. }
  557. - (void)hideAuthView {
  558. if ([self.subviews containsObject:self.authView]) {
  559. [self.authView removeFromSuperview];
  560. self.authView = nil;
  561. }
  562. }
  563. - (AuthDisplayView *)authView {
  564. if (!_authView) {
  565. _authView = [AuthDisplayView shareInstance];
  566. [_authView.imageView setImage:[UIImage imageNamed:[self getAuthDisplayImage]]];
  567. [_authView configDisplayMessage:[self getAuthDisplayMessage]];
  568. MJWeakSelf;
  569. [_authView sureCallback:^{
  570. [weakSelf authAction];
  571. }];
  572. }
  573. return _authView;
  574. }
  575. - (NSString *)getAuthDisplayImage {
  576. if (self.selectIndex == 0) {
  577. return @"authTeacher_accompany";
  578. }
  579. else {
  580. return @"authTeacher_Live";
  581. }
  582. }
  583. - (NSString *)getAuthDisplayMessage {
  584. if (self.selectIndex == 0) { // 陪练课
  585. if ([self.teaherStatus isEqualToString:@"DOING"]) { // 审核中
  586. return @"您已提交认证申请,请耐心等待审核结果~";
  587. }
  588. else {
  589. return @"您还没有完成达人认证,认证后才可设置陪练课哦~";
  590. }
  591. }
  592. else { // 直播课
  593. if ([self.teaherStatus isEqualToString:@"DOING"]) { // 审核中
  594. return @"您已提交认证申请,请耐心等待审核结果~";
  595. }
  596. else {
  597. if ([self.teaherStatus isEqualToString:@"PASS"] && self.liveFlag == NO) { // 如果达人认证通过
  598. return @"您尚未开通直播服务,开通后即可创建直播课程~";
  599. }
  600. return @"您还没有完成达人认证,认证后才可创建直播课哦~";
  601. }
  602. }
  603. }
  604. - (void)authAction {
  605. if (self.selectIndex == 0) {
  606. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  607. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherCert"];
  608. [self.naviController pushViewController:webCtrl animated:YES];
  609. }
  610. else {
  611. if ([self.teaherStatus isEqual:@"PASS"] && self.liveFlag == NO) { // 开通直播
  612. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  613. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/openLive"];
  614. [self.naviController pushViewController:webCtrl animated:YES];
  615. }
  616. else {
  617. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  618. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherCert"];
  619. [self.naviController pushViewController:webCtrl animated:YES];
  620. }
  621. }
  622. }
  623. - (void)setSubjectList:(NSMutableArray *)subjectList {
  624. _subjectList = subjectList;
  625. self.thirdChooseIndex = 0;
  626. }
  627. /*
  628. // Only override drawRect: if you perform custom drawing.
  629. // An empty implementation adversely affects performance during animation.
  630. - (void)drawRect:(CGRect)rect {
  631. // Drawing code
  632. }
  633. */
  634. @end