MinePageCourseView.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. //
  2. // MinePageCourseView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/30.
  6. //
  7. #import "MinePageCourseView.h"
  8. #import "MinePageSubmitView.h"
  9. #import "KSBaseWKWebViewController.h"
  10. #import "MusicMessageModel.h"
  11. #import "AccompanyCourseCell.h"
  12. #import "LiveCourseCell.h"
  13. #import "MinePageMusicCell.h"
  14. #import "AuthDisplayView.h"
  15. #import "AccompanyLessonModel.h"
  16. @interface MinePageCourseView ()<UITableViewDelegate,UITableViewDataSource>
  17. @property (nonatomic, strong) NSMutableArray *dataArray;
  18. @property (nonatomic, strong) StateView *promptView;
  19. @property (nonatomic, strong) UIView *promptPlaceView;
  20. @property (nonatomic, assign) BOOL networkAvaiable; // 网络是否可用
  21. @property (nonatomic, assign) BOOL isLoadMore;
  22. @property (nonatomic, assign) NSInteger rows;
  23. @property (nonatomic, assign) NSInteger pages;
  24. @property (nonatomic, strong) AuthDisplayView *authView;
  25. @property (nonatomic, strong) MinePageSubmitView *uploadView;
  26. @end
  27. @implementation MinePageCourseView
  28. - (instancetype)initWithFrame:(CGRect)frame {
  29. self = [super initWithFrame:frame];
  30. if (self) {
  31. self.backgroundColor = HexRGB(0xf6f8f9);
  32. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) style:UITableViewStylePlain];
  33. self.tableView.backgroundColor = HexRGB(0xf6f8f9);
  34. self.tableView.showsVerticalScrollIndicator = NO;
  35. self.tableView.dataSource = self;
  36. self.tableView.delegate = self;
  37. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  38. [self addSubview:self.tableView];
  39. UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
  40. headView.backgroundColor = HexRGB(0xf6f8f9);
  41. self.tableView.tableHeaderView = headView;
  42. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
  43. bottomView.backgroundColor = HexRGB(0xf6f8f9);
  44. self.tableView.tableFooterView = bottomView;
  45. [self.tableView registerNib:[UINib nibWithNibName:@"AccompanyCourseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyCourseCell"];
  46. [self.tableView registerNib:[UINib nibWithNibName:@"LiveCourseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"LiveCourseCell"];
  47. [self.tableView registerNib:[UINib nibWithNibName:@"MinePageMusicCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MinePageMusicCell"];
  48. MJWeakSelf;
  49. self.tableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
  50. [weakSelf resetParamenter];
  51. [weakSelf requestData];
  52. }];
  53. self.tableView.mj_footer = [KSGifRefreshFooter footerWithRefreshingBlock:^{
  54. if (weakSelf.isLoadMore) {
  55. weakSelf.pages += 1;
  56. [weakSelf requestData];
  57. }
  58. else {
  59. [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
  60. }
  61. }];
  62. }
  63. return self;
  64. }
  65. - (void)endRefresh {
  66. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  67. [self.tableView.mj_header endRefreshing];
  68. [self.tableView.mj_footer endRefreshing];
  69. });
  70. }
  71. - (void)refreshAndRequestData {
  72. [self resetParamenter];
  73. [self requestData];
  74. }
  75. - (void)resetParamenter {
  76. self.isLoadMore = YES;
  77. self.pages = 1;
  78. self.rows = 10;
  79. self.dataArray = [NSMutableArray array];
  80. [self.tableView.mj_footer resetNoMoreData];
  81. [self setPromptString:@"暂无内容" imageName:@"wd_img_zwsj" inView:self.tableView];
  82. [self.tableView reloadData];
  83. }
  84. - (void)requestData {
  85. if (self.selectIndex == 1) { // 陪练课
  86. [KSNetworkingManager accompanyCourseRequest:KS_POST classMonth:nil status:nil subjectId:nil page:self.pages rows:self.rows success:^(NSDictionary * _Nonnull dic) {
  87. } faliure:^(NSError * _Nonnull error) {
  88. }];
  89. }
  90. else if (self.selectIndex == 2) { // 直播课
  91. [KSNetworkingManager LiveCourseGroupRequest:KS_POST groupStatus:@"APPLY" page:self.pages rows:self.rows success:^(NSDictionary * _Nonnull dic) {
  92. [self endRefresh];
  93. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  94. NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
  95. for (NSDictionary *parm in sourceArray) {
  96. LiveCourseModel *model = [[LiveCourseModel alloc] initWithDictionary:parm];
  97. [self.dataArray addObject:model];
  98. }
  99. if (sourceArray.count < self.rows) {
  100. self.isLoadMore = NO;
  101. }
  102. }
  103. else {
  104. [self MBPShow:MESSAGEKEY];
  105. }
  106. [self.tableView reloadData];
  107. [self changePromptLabelStateWithArray:self.dataArray];
  108. } faliure:^(NSError * _Nonnull error) {
  109. [self endRefresh];
  110. if (self.networkAvaiable == NO) {
  111. [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.tableView];
  112. }
  113. [self.dataArray removeAllObjects];
  114. [self.tableView reloadData];
  115. [self changePromptLabelStateWithArray:self.dataArray];
  116. }];
  117. }
  118. else if (self.selectIndex == 4) { // 乐谱
  119. [KSNetworkingManager musicListRequest:KS_POST auditStatus:@"1" pageNo:self.pages pageSize:self.rows success:^(NSDictionary * _Nonnull dic) {
  120. [self endRefresh];
  121. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  122. NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"records"];
  123. for (NSDictionary *parm in sourceArray) {
  124. MusicMessageModel *model = [[MusicMessageModel alloc] initWithDictionary:parm];
  125. [self.dataArray addObject:model];
  126. }
  127. if (sourceArray.count < self.rows) {
  128. self.isLoadMore = NO;
  129. }
  130. }
  131. else {
  132. [self MBPShow:MESSAGEKEY];
  133. }
  134. [self.tableView reloadData];
  135. [self changePromptLabelStateWithArray:self.dataArray];
  136. } faliure:^(NSError * _Nonnull error) {
  137. [self endRefresh];
  138. if (self.networkAvaiable == NO) {
  139. [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.tableView];
  140. }
  141. [self.dataArray removeAllObjects];
  142. [self.tableView reloadData];
  143. [self changePromptLabelStateWithArray:self.dataArray];
  144. }];
  145. }
  146. }
  147. - (void)beginRefreshImmediately {
  148. [self.tableView.mj_header beginRefreshing];
  149. }
  150. - (void)beginFirstRefresh {
  151. if (!self.isHeaderRefreshed) {
  152. [self beginRefreshImmediately];
  153. }
  154. }
  155. - (void)selectCellAtIndexPath:(NSIndexPath *)indexPath {
  156. if (self.lastSelectedIndexPath == indexPath) {
  157. return;
  158. }
  159. if (self.lastSelectedIndexPath != nil) {
  160. UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:self.lastSelectedIndexPath];
  161. [cell setSelected:NO animated:NO];
  162. }
  163. UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  164. [cell setSelected:YES animated:NO];
  165. self.lastSelectedIndexPath = indexPath;
  166. }
  167. - (void)layoutSubviews {
  168. [super layoutSubviews];
  169. CGFloat topHeight = 60.0f;
  170. self.tableView.frame = CGRectMake(0, topHeight, self.bounds.size.width, self.bounds.size.height - topHeight);
  171. if (![self.subviews containsObject:self.uploadView]) {
  172. [self addSubview:self.uploadView];
  173. if (self.teaherAuth == NO) {
  174. [self showAuthView];
  175. }
  176. else {
  177. [self hideAuthView];
  178. }
  179. }
  180. }
  181. #pragma mark - UITableViewDataSource
  182. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  183. return self.dataArray.count;
  184. }
  185. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  186. if (self.selectIndex == 1) {
  187. return 100;
  188. }
  189. else if (self.selectIndex == 2) {
  190. return 100;
  191. }
  192. else {
  193. return 110.0f;;
  194. }
  195. }
  196. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  197. if (self.selectIndex == 1) {
  198. AccompanyCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyCourseCell"];
  199. return cell;
  200. }
  201. else if (self.selectIndex == 2) {
  202. LiveCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LiveCourseCell"];
  203. LiveCourseModel *model = self.dataArray[indexPath.row];
  204. BOOL hiddenInfo = NO;
  205. [cell configCellWithSource:model hideStudentInfo:hiddenInfo];
  206. return cell;
  207. }
  208. else {
  209. MusicMessageModel *model = self.dataArray[indexPath.row];
  210. MinePageMusicCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MinePageMusicCell"];
  211. [cell configWithMessage:model];
  212. return cell;
  213. }
  214. }
  215. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  216. if (self.selectIndex == 2) { // 直播课详情
  217. }
  218. else if (self.selectIndex == 4) { // 曲谱详情
  219. }
  220. }
  221. /**
  222. 设置没有数据时的显示
  223. @param promptString 提示语
  224. @param imgName 图片名称
  225. @param view 显示在什么地方
  226. */
  227. - (void)setPromptString:(NSString *)promptString imageName:(NSString *)imgName inView:(UIView *)view {
  228. if (self.promptView != nil) {
  229. [self.promptView removeFromSuperview];
  230. }
  231. else {
  232. self.promptView = [[StateView alloc]init];
  233. self.promptView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - 300);
  234. }
  235. _promptPlaceView = view;
  236. //当请求不到数据时 ,自定义提示view 将会出现;
  237. self.promptView.imageName = imgName;
  238. self.promptView.alpha = 0.0f;
  239. [self.promptView setText:promptString];
  240. [view addSubview:self.promptView];
  241. }
  242. // 结束刷新后调用方法
  243. - (void)changePromptLabelStateWithArray:(NSMutableArray *)array {
  244. NSInteger count;
  245. if (array.count) {
  246. count = array.count;
  247. } else {
  248. count = 0;
  249. }
  250. [UIView animateWithDuration:0.1 animations:^{
  251. [[self promptView] setAlpha:count ? 0.0f :1.0f ] ;
  252. }] ;
  253. }
  254. - (BOOL)networkAvaiable {
  255. return [self checkNetworkAvaiable];
  256. }
  257. - (BOOL)checkNetworkAvaiable {
  258. BOOL isExistenceNetwork = YES;
  259. Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
  260. switch ([reach currentReachabilityStatus]) {
  261. case NotReachable:
  262. isExistenceNetwork = NO;
  263. //NSLog(@"notReachable");
  264. break;
  265. case ReachableViaWiFi:
  266. isExistenceNetwork = YES;
  267. //NSLog(@"WIFI");
  268. break;
  269. case ReachableViaWWAN:
  270. isExistenceNetwork = YES;
  271. //NSLog(@"3G");
  272. break;
  273. }
  274. return isExistenceNetwork;
  275. }
  276. #pragma mark ----- lazying
  277. - (void)setTeaherAuth:(BOOL)teaherAuth {
  278. _teaherAuth = teaherAuth;
  279. if (self.selectIndex == 1) {
  280. self.uploadView.type = MINEPAGETYPE_ACCOMPANY;
  281. }
  282. else if (self.selectIndex == 2) {
  283. self.uploadView.type =MINEPAGETYPE_LIVE;
  284. }
  285. if (teaherAuth == NO) {
  286. [self showAuthView];
  287. }
  288. else {
  289. [self hideAuthView];
  290. }
  291. }
  292. - (void)showAuthView {
  293. if ([self.subviews containsObject:self.authView]) {
  294. [self bringSubviewToFront:self.authView];
  295. }
  296. else {
  297. [self addSubview:self.authView];
  298. [self.authView mas_makeConstraints:^(MASConstraintMaker *make) {
  299. make.left.top.bottom.right.mas_equalTo(self);
  300. }];
  301. }
  302. }
  303. - (void)hideAuthView {
  304. if ([self.subviews containsObject:self.authView]) {
  305. [self.authView removeFromSuperview];
  306. self.authView = nil;
  307. }
  308. }
  309. - (void)setMusicianAuthStatus:(BOOL)musicianAuthStatus {
  310. _musicianAuthStatus = musicianAuthStatus;
  311. if (self.selectIndex == 4) {
  312. self.uploadView.type = MINEPAGETYPE_MUSIC;
  313. }
  314. }
  315. - (MinePageSubmitView *)uploadView {
  316. if (!_uploadView) {
  317. _uploadView = [MinePageSubmitView shareInstance];
  318. CGFloat topHeight = 60.0f;
  319. _uploadView.frame = CGRectMake(0, 0, kScreenWidth, topHeight);
  320. MJWeakSelf;
  321. [_uploadView opreationCallback:^(MINEPAGETYPE type) {
  322. [weakSelf uploadAciton:type];
  323. }];
  324. }
  325. return _uploadView;
  326. }
  327. - (void)uploadAciton:(MINEPAGETYPE)type {
  328. switch (type) {
  329. case MINEPAGETYPE_ACCOMPANY: // 陪练课设置
  330. {
  331. }
  332. break;
  333. case MINEPAGETYPE_LIVE: // 直播课设置
  334. {
  335. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  336. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/liveCreate"];
  337. [self.naviController pushViewController:webCtrl animated:YES];
  338. }
  339. break;
  340. case MINEPAGETYPE_MUSIC: // 上传曲谱
  341. {
  342. }
  343. break;
  344. default:
  345. break;
  346. }
  347. }
  348. - (AuthDisplayView *)authView {
  349. if (!_authView) {
  350. _authView = [AuthDisplayView shareInstance];
  351. [_authView configDisplayMessage:[self getAuthDisplayMessage]];
  352. MJWeakSelf;
  353. [_authView sureCallback:^{
  354. [weakSelf authAction];
  355. }];
  356. }
  357. return _authView;
  358. }
  359. - (NSString *)getAuthDisplayMessage {
  360. if (self.selectIndex == 1) {
  361. return @"您还没有完成老师认证,认证后才可设置陪练课哦~";
  362. }
  363. else if (self.selectIndex == 2) {
  364. return @"您还没有完成老师认证,认证后才可创建直播课哦~";
  365. }
  366. else {
  367. return @"您还没有完成音乐人认证,认证后才可上传曲谱哦~";
  368. }
  369. }
  370. - (void)authAction {
  371. if (self.selectIndex == 1 || self.selectIndex == 2) {
  372. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  373. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherCert"];
  374. [self.naviController pushViewController:webCtrl animated:YES];
  375. }
  376. else {
  377. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  378. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/musicCert"];
  379. [self.naviController pushViewController:webCtrl animated:YES];
  380. }
  381. }
  382. /*
  383. // Only override drawRect: if you perform custom drawing.
  384. // An empty implementation adversely affects performance during animation.
  385. - (void)drawRect:(CGRect)rect {
  386. // Drawing code
  387. }
  388. */
  389. @end