MyLiveCourseBodyView.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. //
  2. // MyLiveCourseBodyView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/4/6.
  6. //
  7. #import "MyLiveCourseBodyView.h"
  8. #import "LiveCourseCell.h"
  9. #import "LiveCourseModel.h"
  10. #import "KSBaseWKWebViewController.h"
  11. #import "AuthDisplayView.h"
  12. @interface MyLiveCourseBodyView ()<UITableViewDelegate,UITableViewDataSource>
  13. @property (nonatomic, strong) NSMutableArray *dataArray;
  14. @property (nonatomic, strong) KSButtonStatusView *promptView;
  15. @property (nonatomic, strong) UIView *promptPlaceView;
  16. @property (nonatomic, assign) BOOL networkAvaiable; // 网络是否可用
  17. @property (nonatomic, assign) BOOL isLoadMore;
  18. @property (nonatomic, assign) NSInteger rows;
  19. @property (nonatomic, assign) NSInteger pages;
  20. @property (nonatomic, strong) NSString *groupStatus;
  21. @property (nonatomic, strong) AuthDisplayView *authView;
  22. @property (nonatomic, assign) BOOL teacherAuthPass; // 是否通过老师审核
  23. @end
  24. @implementation MyLiveCourseBodyView
  25. - (instancetype)initWithFrame:(CGRect)frame {
  26. self = [super initWithFrame:frame];
  27. if (self) {
  28. self.backgroundColor = HexRGB(0xf6f8f9);
  29. self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  30. self.tableView.backgroundColor = HexRGB(0xf6f8f9);
  31. self.tableView.showsVerticalScrollIndicator = NO;
  32. self.tableView.rowHeight = 150.0f;
  33. self.tableView.dataSource = self;
  34. self.tableView.delegate = self;
  35. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  36. [self addSubview:self.tableView];
  37. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.left.right.bottom.top.mas_equalTo(self);
  39. }];
  40. UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
  41. headView.backgroundColor = HexRGB(0xf6f8f9);
  42. self.tableView.tableHeaderView = headView;
  43. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
  44. bottomView.backgroundColor = HexRGB(0xf6f8f9);
  45. self.tableView.tableFooterView = bottomView;
  46. [self.tableView registerNib:[UINib nibWithNibName:@"LiveCourseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"LiveCourseCell"];
  47. MJWeakSelf;
  48. self.tableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
  49. [weakSelf resetParamenter];
  50. [weakSelf requestData];
  51. }];
  52. self.tableView.mj_footer = [KSGifRefreshFooter footerWithRefreshingBlock:^{
  53. if (weakSelf.isLoadMore) {
  54. weakSelf.pages += 1;
  55. [weakSelf requestData];
  56. }
  57. else {
  58. [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
  59. }
  60. }];
  61. }
  62. return self;
  63. }
  64. - (void)configRequestStatus {
  65. if (self.selectIndex == 0) {
  66. self.groupStatus = @"ING";
  67. }
  68. else if (self.selectIndex == 1) {
  69. self.groupStatus = @"NOT_SALE";
  70. }
  71. else if (self.selectIndex == 2) {
  72. self.groupStatus = @"APPLY";
  73. }
  74. else if (self.selectIndex == 3) {
  75. self.groupStatus = @"COMPLETE";
  76. }
  77. else {
  78. self.groupStatus = @"CANCEL";
  79. }
  80. }
  81. - (void)endRefresh {
  82. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  83. [self.tableView.mj_header endRefreshing];
  84. [self.tableView.mj_footer endRefreshing];
  85. });
  86. }
  87. - (void)refreshAndRequestData {
  88. [self resetParamenter];
  89. [self requestData];
  90. }
  91. - (void)resetParamenter {
  92. self.isLoadMore = YES;
  93. self.pages = 1;
  94. self.rows = 10;
  95. [self configRequestStatus];
  96. self.dataArray = [NSMutableArray array];
  97. [self.tableView.mj_footer resetNoMoreData];
  98. [self setPromptString:[self getEmptyMessage] imageName:@"authTeacher_Live" buttonTitle:@"立即创建" inView:self.tableView];
  99. [self.tableView reloadData];
  100. }
  101. - (NSString *)getEmptyMessage {
  102. if (self.selectIndex == 0) {
  103. return @"暂无进行中直播课程";
  104. }
  105. else if (self.selectIndex == 1) {
  106. return @"暂无未上架直播课程";
  107. }
  108. else if (self.selectIndex == 2) {
  109. return @"暂无销售中直播课程";
  110. }
  111. else if (self.selectIndex == 3) {
  112. return @"暂无已完成直播课程";
  113. }
  114. else {
  115. return @"暂无已取消直播课程";
  116. }
  117. }
  118. - (void)requestData {
  119. [KSNetworkingManager LiveCourseGroupRequest:KS_POST groupStatus:self.groupStatus page:self.pages rows: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:@"rows"];
  123. for (NSDictionary *parm in sourceArray) {
  124. LiveCourseModel *model = [[LiveCourseModel 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" buttonTitle:@"" inView:self.tableView];
  140. }
  141. [self.dataArray removeAllObjects];
  142. [self.tableView reloadData];
  143. [self changePromptLabelStateWithArray:self.dataArray];
  144. }];
  145. }
  146. - (void)beginRefreshImmediately {
  147. [self.tableView.mj_header beginRefreshing];
  148. }
  149. - (void)beginFirstRefresh {
  150. if (!self.isHeaderRefreshed) {
  151. [self beginRefreshImmediately];
  152. }
  153. }
  154. - (void)selectCellAtIndexPath:(NSIndexPath *)indexPath {
  155. if (self.lastSelectedIndexPath == indexPath) {
  156. return;
  157. }
  158. if (self.lastSelectedIndexPath != nil) {
  159. UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:self.lastSelectedIndexPath];
  160. [cell setSelected:NO animated:NO];
  161. }
  162. UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  163. [cell setSelected:YES animated:NO];
  164. self.lastSelectedIndexPath = indexPath;
  165. }
  166. - (void)layoutSubviews {
  167. [super layoutSubviews];
  168. if (self.teacherAuthPass == NO) {
  169. [self showAuthView];
  170. }
  171. else {
  172. [self hideAuthView];
  173. }
  174. }
  175. #pragma mark - UITableViewDataSource
  176. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  177. return self.dataArray.count;
  178. }
  179. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  180. LiveCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LiveCourseCell"];
  181. LiveCourseModel *model = self.dataArray[indexPath.row];
  182. BOOL hiddenInfo = self.selectIndex == 1 ? YES : NO;
  183. [cell configCellWithSource:model hideStudentInfo:hiddenInfo];
  184. return cell;
  185. }
  186. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  187. // 直播课程组详情
  188. LiveCourseModel *model = self.dataArray[indexPath.row];
  189. [self displayLiveCourseDetailWithGroupId:[NSString stringWithFormat:@"%.0f",model.courseGroupId]];
  190. }
  191. - (void)displayLiveCourseDetailWithGroupId:(NSString *)groupId {
  192. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  193. NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/liveDetail?groupId=",groupId];
  194. ctrl.url = url;
  195. [self.naviController pushViewController:ctrl animated:YES];
  196. }
  197. /**
  198. 设置没有数据时的显示
  199. @param promptString 提示语
  200. @param imgName 图片名称
  201. @param view 显示在什么地方
  202. */
  203. - (void)setPromptString:(NSString *)promptString imageName:(NSString *)imgName buttonTitle:(NSString *)buttonTitle inView:(UIView *)view {
  204. if (self.promptView != nil) {
  205. [self.promptView removeFromSuperview];
  206. }
  207. else {
  208. self.promptView = [[KSButtonStatusView alloc] init];
  209. }
  210. _promptPlaceView = view;
  211. //当请求不到数据时 ,自定义提示view 将会出现;
  212. self.promptView.imageName = imgName;
  213. self.promptView.alpha = 0.0f;
  214. [self.promptView setText:promptString];
  215. [self.promptView setButtonTitle:buttonTitle];
  216. MJWeakSelf;
  217. [self.promptView buttonClickCallback:^{
  218. [weakSelf emptyButtonAction];
  219. }];
  220. [view addSubview:self.promptView];
  221. [self.promptView mas_makeConstraints:^(MASConstraintMaker *make) {
  222. make.left.right.top.bottom.mas_equalTo(self);
  223. }];
  224. }
  225. - (void)emptyButtonAction {
  226. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  227. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/liveCreate"];
  228. [self.naviController pushViewController:webCtrl animated:YES];
  229. }
  230. // 结束刷新后调用方法
  231. - (void)changePromptLabelStateWithArray:(NSMutableArray *)array {
  232. NSInteger count;
  233. if (array.count) {
  234. count = array.count;
  235. } else {
  236. count = 0;
  237. }
  238. [UIView animateWithDuration:0.1 animations:^{
  239. [[self promptView] setAlpha:count ? 0.0f :1.0f ] ;
  240. }] ;
  241. }
  242. - (BOOL)networkAvaiable {
  243. return [self checkNetworkAvaiable];
  244. }
  245. - (BOOL)checkNetworkAvaiable {
  246. BOOL isExistenceNetwork = YES;
  247. Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
  248. switch ([reach currentReachabilityStatus]) {
  249. case NotReachable:
  250. isExistenceNetwork = NO;
  251. //NSLog(@"notReachable");
  252. break;
  253. case ReachableViaWiFi:
  254. isExistenceNetwork = YES;
  255. //NSLog(@"WIFI");
  256. break;
  257. case ReachableViaWWAN:
  258. isExistenceNetwork = YES;
  259. //NSLog(@"3G");
  260. break;
  261. }
  262. return isExistenceNetwork;
  263. }
  264. #pragma mark ---- lazying
  265. - (NSMutableArray *)dataArray {
  266. if (!_dataArray) {
  267. _dataArray = [NSMutableArray array];
  268. }
  269. return _dataArray;
  270. }
  271. - (void)setTeaherStatus:(NSString *)teaherStatus {
  272. _teaherStatus = teaherStatus;
  273. if ([teaherStatus isEqualToString:@"UNPAALY"]) { // 未申请
  274. self.teacherAuthPass = NO;
  275. }
  276. else if ([teaherStatus isEqualToString:@"DOING"]) { // 审核中
  277. self.teacherAuthPass = NO;
  278. }
  279. else if ([teaherStatus isEqualToString:@"UNPASS"]) { // 不通过
  280. self.teacherAuthPass = NO;
  281. }
  282. else {
  283. self.teacherAuthPass = YES;
  284. }
  285. if (self.liveFlag == NO) { // 无直播权限直接改成未通过
  286. self.teacherAuthPass = NO;
  287. }
  288. if (self.teacherAuthPass == NO) {
  289. [self showAuthView];
  290. }
  291. else {
  292. [self hideAuthView];
  293. }
  294. }
  295. - (void)configAuthDisplay {
  296. [self.authView configDisplayMessage:[self getAuthDisplayMessage]];
  297. if ([self.teaherStatus isEqualToString:@"DOING"]) {
  298. self.authView.sureButton.userInteractionEnabled = NO;
  299. self.authView.sureButton.hidden = YES;
  300. }
  301. else {
  302. if ([self.teaherStatus isEqual:@"PASS"] && self.liveFlag == NO) {
  303. [self.authView.sureButton setTitle:@"立即开通" forState:UIControlStateNormal];
  304. }
  305. else {
  306. [self.authView.sureButton setTitle:@"去认证" forState:UIControlStateNormal];
  307. }
  308. self.authView.sureButton.userInteractionEnabled = YES;
  309. self.authView.sureButton.hidden = NO;
  310. }
  311. }
  312. - (void)showAuthView {
  313. [self configAuthDisplay];
  314. if ([self.subviews containsObject:self.authView]) {
  315. [self bringSubviewToFront:self.authView];
  316. }
  317. else {
  318. [self addSubview:self.authView];
  319. [self.authView mas_makeConstraints:^(MASConstraintMaker *make) {
  320. make.left.top.bottom.right.mas_equalTo(self);
  321. }];
  322. }
  323. }
  324. - (void)hideAuthView {
  325. if ([self.subviews containsObject:self.authView]) {
  326. [self.authView removeFromSuperview];
  327. self.authView = nil;
  328. }
  329. }
  330. - (AuthDisplayView *)authView {
  331. if (!_authView) {
  332. _authView = [AuthDisplayView shareInstance];
  333. [_authView.imageView setImage:[UIImage imageNamed:[self getAuthDisplayImage]]];
  334. MJWeakSelf;
  335. [_authView sureCallback:^{
  336. [weakSelf authAction];
  337. }];
  338. }
  339. return _authView;
  340. }
  341. - (NSString *)getAuthDisplayImage {
  342. return @"authTeacher_accompany";
  343. }
  344. - (NSString *)getAuthDisplayMessage {
  345. if ([self.teaherStatus isEqualToString:@"DOING"]) { // 审核中
  346. return @"您已提交认证申请,请耐心等待审核结果~";
  347. }
  348. else {
  349. if ([self.teaherStatus isEqualToString:@"PASS"] && self.liveFlag == NO) { // 如果达人认证通过
  350. return @"您尚未开通直播服务,开通后即可创建直播课程~";
  351. }
  352. return @"您还没有完成达人认证,认证后才可创建直播课哦~";
  353. }
  354. }
  355. - (void)authAction {
  356. if ([self.teaherStatus isEqual:@"PASS"] && self.liveFlag == NO) { // 开通直播
  357. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  358. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/openLive"];
  359. [self.naviController pushViewController:webCtrl animated:YES];
  360. }
  361. else {
  362. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  363. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherCert"];
  364. [self.naviController pushViewController:webCtrl animated:YES];
  365. }
  366. }
  367. /*
  368. // Only override drawRect: if you perform custom drawing.
  369. // An empty implementation adversely affects performance during animation.
  370. - (void)drawRect:(CGRect)rect {
  371. // Drawing code
  372. }
  373. */
  374. @end