|
@@ -0,0 +1,267 @@
|
|
|
+//
|
|
|
+// MyLiveCourseBodyView.m
|
|
|
+// KulexiuForTeacher
|
|
|
+//
|
|
|
+// Created by 王智 on 2022/4/6.
|
|
|
+//
|
|
|
+
|
|
|
+#import "MyLiveCourseBodyView.h"
|
|
|
+#import "LiveCourseCell.h"
|
|
|
+#import "LiveCourseModel.h"
|
|
|
+
|
|
|
+@interface MyLiveCourseBodyView ()<UITableViewDelegate,UITableViewDataSource>
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSMutableArray *dataArray;
|
|
|
+
|
|
|
+@property (nonatomic, strong) StateView *promptView;
|
|
|
+@property (nonatomic, strong) UIView *promptPlaceView;
|
|
|
+
|
|
|
+@property (nonatomic, assign) BOOL networkAvaiable; // 网络是否可用
|
|
|
+
|
|
|
+@property (nonatomic, assign) BOOL isLoadMore;
|
|
|
+@property (nonatomic, assign) NSInteger rows;
|
|
|
+@property (nonatomic, assign) NSInteger pages;
|
|
|
+
|
|
|
+@property (nonatomic, strong) NSString *groupStatus;
|
|
|
+
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation MyLiveCourseBodyView
|
|
|
+
|
|
|
+- (instancetype)initWithFrame:(CGRect)frame {
|
|
|
+ self = [super initWithFrame:frame];
|
|
|
+ if (self) {
|
|
|
+ self.backgroundColor = HexRGB(0xf6f8f9);
|
|
|
+ self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) style:UITableViewStylePlain];
|
|
|
+ self.tableView.backgroundColor = HexRGB(0xf6f8f9);
|
|
|
+ self.tableView.showsVerticalScrollIndicator = NO;
|
|
|
+ self.tableView.rowHeight = 110.0f;
|
|
|
+ self.tableView.dataSource = self;
|
|
|
+ self.tableView.delegate = self;
|
|
|
+ self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
|
+ [self addSubview:self.tableView];
|
|
|
+
|
|
|
+
|
|
|
+ UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
|
|
|
+ headView.backgroundColor = HexRGB(0xf6f8f9);
|
|
|
+ self.tableView.tableHeaderView = headView;
|
|
|
+
|
|
|
+ UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
|
|
|
+ bottomView.backgroundColor = HexRGB(0xf6f8f9);
|
|
|
+ self.tableView.tableFooterView = bottomView;
|
|
|
+ [self.tableView registerNib:[UINib nibWithNibName:@"LiveCourseCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"LiveCourseCell"];
|
|
|
+
|
|
|
+ MJWeakSelf;
|
|
|
+ self.tableView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
|
|
|
+ [weakSelf resetParamenter];
|
|
|
+ [weakSelf requestData];
|
|
|
+ }];
|
|
|
+ self.tableView.mj_footer = [KSGifRefreshFooter footerWithRefreshingBlock:^{
|
|
|
+ if (weakSelf.isLoadMore) {
|
|
|
+ weakSelf.pages += 1;
|
|
|
+ [weakSelf requestData];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
|
|
|
+ }
|
|
|
+ }];
|
|
|
+ [self configRequestStatus];
|
|
|
+ }
|
|
|
+ return self;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)configRequestStatus {
|
|
|
+ if (self.selectIndex == 0) {
|
|
|
+ self.groupStatus = @"ING";
|
|
|
+ }
|
|
|
+ else if (self.selectIndex == 1) {
|
|
|
+ self.groupStatus = @"NOT_SALE";
|
|
|
+ }
|
|
|
+ else if (self.selectIndex == 2) {
|
|
|
+ self.groupStatus = @"APPLY";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ self.groupStatus = @"COMPLETE";
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)endRefresh {
|
|
|
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+ [self.tableView.mj_header endRefreshing];
|
|
|
+ [self.tableView.mj_footer endRefreshing];
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+- (void)refreshAndRequestData {
|
|
|
+ [self resetParamenter];
|
|
|
+ [self requestData];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)resetParamenter {
|
|
|
+ self.isLoadMore = YES;
|
|
|
+ self.pages = 1;
|
|
|
+ self.rows = 10;
|
|
|
+
|
|
|
+ self.dataArray = [NSMutableArray array];
|
|
|
+ [self.tableView.mj_footer resetNoMoreData];
|
|
|
+ [self setPromptString:@"暂无内容" imageName:@"wd_img_zwsj" inView:self.tableView];
|
|
|
+ [self.tableView reloadData];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)requestData {
|
|
|
+ [KSNetworkingManager LiveCourseGroupRequest:KS_POST groupStatus:self.groupStatus page:self.pages rows:self.rows success:^(NSDictionary * _Nonnull dic) {
|
|
|
+ [self endRefresh];
|
|
|
+ if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
|
|
|
+ NSArray *sourceArray = [[dic dictionaryValueForKey:@"data"] arrayValueForKey:@"rows"];
|
|
|
+ for (NSDictionary *parm in sourceArray) {
|
|
|
+ LiveCourseModel *model = [[LiveCourseModel alloc] initWithDictionary:parm];
|
|
|
+ [self.dataArray addObject:model];
|
|
|
+ }
|
|
|
+// for (NSInteger i = 0; i < 5; i++) {
|
|
|
+// LiveCourseModel *model = [[LiveCourseModel alloc] init];
|
|
|
+// model.courseStartTime = @"2021-09-17 14:00:00";
|
|
|
+// model.courseNum = 5;
|
|
|
+// model.studentCount = 10;
|
|
|
+// model.teacherName = @"zahgns";
|
|
|
+// model.coursePrice = 125;
|
|
|
+// model.courseGroupName = @"nihao ssss";
|
|
|
+// [self.dataArray addObject:model];
|
|
|
+// }
|
|
|
+
|
|
|
+ if (sourceArray.count < self.rows) {
|
|
|
+ self.isLoadMore = NO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [self MBPShow:MESSAGEKEY];
|
|
|
+ }
|
|
|
+ [self.tableView reloadData];
|
|
|
+ [self changePromptLabelStateWithArray:self.dataArray];
|
|
|
+ } faliure:^(NSError * _Nonnull error) {
|
|
|
+ [self endRefresh];
|
|
|
+ if (self.networkAvaiable == NO) {
|
|
|
+ [self setPromptString:@"暂无网络" imageName:@"no_networking" inView:self.tableView];
|
|
|
+ }
|
|
|
+ [self.dataArray removeAllObjects];
|
|
|
+ [self.tableView reloadData];
|
|
|
+ [self changePromptLabelStateWithArray:self.dataArray];
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)beginRefreshImmediately {
|
|
|
+ [self.tableView.mj_header beginRefreshing];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)beginFirstRefresh {
|
|
|
+ if (!self.isHeaderRefreshed) {
|
|
|
+ [self beginRefreshImmediately];
|
|
|
+ }
|
|
|
+}
|
|
|
+- (void)selectCellAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+
|
|
|
+ if (self.lastSelectedIndexPath == indexPath) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (self.lastSelectedIndexPath != nil) {
|
|
|
+ UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:self.lastSelectedIndexPath];
|
|
|
+ [cell setSelected:NO animated:NO];
|
|
|
+ }
|
|
|
+ UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
|
|
|
+ [cell setSelected:YES animated:NO];
|
|
|
+ self.lastSelectedIndexPath = indexPath;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)layoutSubviews {
|
|
|
+ [super layoutSubviews];
|
|
|
+ self.tableView.frame = self.bounds;
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark - UITableViewDataSource
|
|
|
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
+ return self.dataArray.count;
|
|
|
+}
|
|
|
+
|
|
|
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ LiveCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LiveCourseCell"];
|
|
|
+ LiveCourseModel *model = self.dataArray[indexPath.row];
|
|
|
+ BOOL hiddenInfo = self.selectIndex == 1 ? YES : NO;
|
|
|
+ [cell configCellWithSource:model hideStudentInfo:hiddenInfo];
|
|
|
+ return cell;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ // 直播课程组详情
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ 设置没有数据时的显示
|
|
|
+
|
|
|
+ @param promptString 提示语
|
|
|
+ @param imgName 图片名称
|
|
|
+ @param view 显示在什么地方
|
|
|
+ */
|
|
|
+- (void)setPromptString:(NSString *)promptString imageName:(NSString *)imgName inView:(UIView *)view {
|
|
|
+ if (self.promptView != nil) {
|
|
|
+ [self.promptView removeFromSuperview];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ self.promptView = [[StateView alloc]init];
|
|
|
+ self.promptView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - 300);
|
|
|
+ }
|
|
|
+ _promptPlaceView = view;
|
|
|
+ //当请求不到数据时 ,自定义提示view 将会出现;
|
|
|
+ self.promptView.imageName = imgName;
|
|
|
+ self.promptView.alpha = 0.0f;
|
|
|
+ [self.promptView setText:promptString];
|
|
|
+ [view addSubview:self.promptView];
|
|
|
+}
|
|
|
+
|
|
|
+// 结束刷新后调用方法
|
|
|
+- (void)changePromptLabelStateWithArray:(NSMutableArray *)array {
|
|
|
+ NSInteger count;
|
|
|
+ if (array.count) {
|
|
|
+ count = array.count;
|
|
|
+ } else {
|
|
|
+ count = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ [UIView animateWithDuration:0.1 animations:^{
|
|
|
+ [[self promptView] setAlpha:count ? 0.0f :1.0f ] ;
|
|
|
+ }] ;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)networkAvaiable {
|
|
|
+ return [self checkNetworkAvaiable];
|
|
|
+}
|
|
|
+
|
|
|
+- (BOOL)checkNetworkAvaiable {
|
|
|
+ BOOL isExistenceNetwork = YES;
|
|
|
+ Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
|
|
|
+ switch ([reach currentReachabilityStatus]) {
|
|
|
+ case NotReachable:
|
|
|
+ isExistenceNetwork = NO;
|
|
|
+ //NSLog(@"notReachable");
|
|
|
+ break;
|
|
|
+ case ReachableViaWiFi:
|
|
|
+ isExistenceNetwork = YES;
|
|
|
+ //NSLog(@"WIFI");
|
|
|
+ break;
|
|
|
+ case ReachableViaWWAN:
|
|
|
+ isExistenceNetwork = YES;
|
|
|
+ //NSLog(@"3G");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return isExistenceNetwork;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+// Only override drawRect: if you perform custom drawing.
|
|
|
+// An empty implementation adversely affects performance during animation.
|
|
|
+- (void)drawRect:(CGRect)rect {
|
|
|
+ // Drawing code
|
|
|
+}
|
|
|
+*/
|
|
|
+
|
|
|
+@end
|