123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481 |
- //
- // MyLiveCourseBodyView.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/4/6.
- //
- #import "MyLiveCourseBodyView.h"
- #import "MineLiveCourseGroupCell.h"
- #import "LiveCourseModel.h"
- #import "KSBaseWKWebViewController.h"
- #import "AuthDisplayView.h"
- @interface MyLiveCourseBodyView ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
- @property (nonatomic, strong) NSMutableArray *dataArray;
- @property (nonatomic, strong) KSButtonStatusView *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;
- @property (nonatomic, strong) AuthDisplayView *authView;
- @property (nonatomic, assign) BOOL teacherAuthPass; // 是否通过老师审核
- @end
- @implementation MyLiveCourseBodyView
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- self.backgroundColor = HexRGB(0xf8f9fc);
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.sectionInset = UIEdgeInsetsMake(12, 14, 12, 14);
-
- self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) collectionViewLayout:layout];
- self.collectionView.backgroundColor = HexRGB(0xf8f9fc);
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
- self.collectionView.showsVerticalScrollIndicator = NO;
- self.collectionView.showsHorizontalScrollIndicator = NO;
- [self.collectionView registerNib:[UINib nibWithNibName:@"MineLiveCourseGroupCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"MineLiveCourseGroupCell"];
- [self addSubview:self.collectionView];
- self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- MJWeakSelf;
- self.collectionView.mj_header = [KSGifRefreshHeader headerWithRefreshingBlock:^{
- [weakSelf resetParamenter];
- [weakSelf requestData];
- }];
- self.collectionView.mj_footer = [KSGifRefreshFooter footerWithRefreshingBlock:^{
- if (weakSelf.isLoadMore) {
- weakSelf.pages += 1;
- [weakSelf requestData];
- }
- else {
- [weakSelf.collectionView.mj_footer endRefreshingWithNoMoreData];
- }
- }];
- }
- 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 if (self.selectIndex == 3) {
- self.groupStatus = @"COMPLETE";
- }
- else if (self.selectIndex == 4) {
- self.groupStatus = @"CANCEL";
- }
- else {
- self.groupStatus = @"OUT_SALE";
- }
- }
- - (void)endRefresh {
- @weakObj(self);
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- @strongObj(self);
- [self.collectionView.mj_header endRefreshing];
- [self.collectionView.mj_footer endRefreshing];
- });
- }
- - (void)refreshAndRequestData {
- [self resetParamenter];
- [self requestData];
- }
- - (void)resetParamenter {
- self.isLoadMore = YES;
- self.pages = 1;
- self.rows = 10;
- [self configRequestStatus];
- self.dataArray = [NSMutableArray array];
- [self.collectionView.mj_footer resetNoMoreData];
- [self setPromptString:[self getEmptyMessage] imageName:@"authTeacher_Live" buttonTitle:@"立即创建" inView:self.collectionView];
-
- [self.collectionView reloadData];
- }
- - (NSString *)getEmptyMessage {
- if (self.selectIndex == 0) {
- return @"暂无进行中直播课程";
- }
- else if (self.selectIndex == 1) {
- return @"暂无未上架直播课程";
- }
- else if (self.selectIndex == 2) {
- return @"暂无销售中直播课程";
- }
- else if (self.selectIndex == 3) {
- return @"暂无已完成直播课程";
- }
- else if (self.selectIndex == 4) {
- return @"暂无已取消直播课程";
- }
- else {
- return @"暂无已下架直播课程";
- }
- }
- - (void)requestData {
- [KSNetworkingManager LiveCourseGroupRequest:KS_POST groupStatus:self.groupStatus page:self.pages rows:self.rows success:^(NSDictionary * _Nonnull dic) {
- [self endRefresh];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *sourceArray = [[dic ks_dictionaryValueForKey:@"data"] ks_arrayValueForKey:@"rows"];
- for (NSDictionary *parm in sourceArray) {
- LiveCourseModel *model = [[LiveCourseModel alloc] initWithDictionary:parm];
- [self.dataArray addObject:model];
- }
-
- if (sourceArray.count < self.rows) {
- self.isLoadMore = NO;
- }
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- [self.collectionView reloadData];
- [self changePromptLabelStateWithArray:self.dataArray];
- } faliure:^(NSError * _Nonnull error) {
- [self endRefresh];
- if (self.networkAvaiable == NO) {
- [self setPromptString:@"暂无网络" imageName:@"no_networking" buttonTitle:@"" inView:self.collectionView];
- }
- [self.dataArray removeAllObjects];
- [self.collectionView reloadData];
- [self changePromptLabelStateWithArray:self.dataArray];
- }];
- }
- - (void)beginRefreshImmediately {
- [self.collectionView.mj_header beginRefreshing];
- }
- - (void)beginFirstRefresh {
- if (!self.isHeaderRefreshed) {
- [self beginRefreshImmediately];
- }
- }
- - (void)selectCellAtIndexPath:(NSIndexPath *)indexPath {
-
- if (self.lastSelectedIndexPath == indexPath) {
- return;
- }
- if (self.lastSelectedIndexPath != nil) {
- UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:self.lastSelectedIndexPath];
- [cell setSelected:NO];
- }
- UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
- [cell setSelected:YES];
- self.lastSelectedIndexPath = indexPath;
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
- [self.collectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.mas_equalTo(self);
- }];
- if (self.teacherAuthPass == NO) {
- [self showAuthView];
- }
- else {
- [self hideAuthView];
- }
- }
- #pragma mark ----- collection view
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.dataArray.count;
- }
- - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- MineLiveCourseGroupCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MineLiveCourseGroupCell" forIndexPath:indexPath];
-
- LiveCourseModel *model = [self.dataArray objectAtIndex:indexPath.row];
- COURSERSTATUS status = [self getCourseStatus:self.selectIndex];
- [cell configCellWithSource:model groupStatus:status hideStatusView:NO];
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- // 直播课程组详情
- LiveCourseModel *model = self.dataArray[indexPath.item];
- if (self.selectIndex == 5) {
- [self editLiveCourseWithGroupId:[NSString stringWithFormat:@"%.0f",model.courseGroupId]];
-
- }
- else {
- [self displayLiveCourseDetailWithGroupId:[NSString stringWithFormat:@"%.0f",model.courseGroupId]];
- }
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- CGFloat width = KPortraitWidth - 28;
- if (IS_IPAD) {
- width = (KPortraitWidth - 28 - 12 * 2 - 12) / 2.0f;
- }
- CGFloat height = (width - 12 * 2) / 16 * 9 + 143;
- return CGSizeMake(width, height);
- }
- - (COURSERSTATUS)getCourseStatus:(NSInteger)index {
- COURSERSTATUS status;
- if (index == 0) {
- status = COURSERSTATUS_ING;
- }
- else if (index == 1) {
- status = COURSERSTATUS_NOTSALE;
- }
- else if (index == 2) {
- status = COURSERSTATUS_APPLY;
- }
- else if (index == 3) {
- status = COURSERSTATUS_COMPLETE;
- }
- else if (index == 4) {
- status = COURSERSTATUS_CANCLE;
- }
- else {
- status = COURSERSTATUS_OUTSALE;
- }
- return status;
- }
- - (void)editLiveCourseWithGroupId:(NSString *)groupId {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/liveCreate?groupId=",groupId];
- ctrl.url = url;
- [self.naviController pushViewController:ctrl animated:YES];
- }
- - (void)displayLiveCourseDetailWithGroupId:(NSString *)groupId {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- NSString *url = [NSString stringWithFormat:@"%@%@%@", WEBHOST, @"/#/liveDetail?groupId=",groupId];
- ctrl.url = url;
- [self.naviController pushViewController:ctrl animated:YES];
- }
- /**
- 设置没有数据时的显示
-
- @param promptString 提示语
- @param imgName 图片名称
- @param view 显示在什么地方
- */
- - (void)setPromptString:(NSString *)promptString imageName:(NSString *)imgName buttonTitle:(NSString *)buttonTitle inView:(UIView *)view {
- if (self.promptView != nil) {
- [self.promptView removeFromSuperview];
- }
- else {
- self.promptView = [[KSButtonStatusView alloc] init];
- }
- _promptPlaceView = view;
- //当请求不到数据时 ,自定义提示view 将会出现;
- self.promptView.imageName = imgName;
- self.promptView.alpha = 0.0f;
- [self.promptView setText:promptString];
- [self.promptView setButtonTitle:buttonTitle];
- MJWeakSelf;
- [self.promptView buttonClickCallback:^{
- [weakSelf emptyButtonAction];
- }];
- [view addSubview:self.promptView];
- [self.promptView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self);
- make.top.mas_equalTo(self.collectionView);
- make.height.mas_equalTo(self);
- }];
- }
- - (void)emptyButtonAction {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/liveCreate"];
- [self.naviController pushViewController:webCtrl animated:YES];
- }
- // 结束刷新后调用方法
- - (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;
- }
- #pragma mark ---- lazying
- - (NSMutableArray *)dataArray {
- if (!_dataArray) {
- _dataArray = [NSMutableArray array];
- }
- return _dataArray;
- }
- - (void)setTeaherStatus:(NSString *)teaherStatus {
- _teaherStatus = teaherStatus;
- if ([teaherStatus isEqualToString:@"UNPAALY"]) { // 未申请
- self.teacherAuthPass = NO;
- }
- else if ([teaherStatus isEqualToString:@"DOING"]) { // 审核中
- self.teacherAuthPass = NO;
- }
- else if ([teaherStatus isEqualToString:@"UNPASS"]) { // 不通过
- self.teacherAuthPass = NO;
- }
- else {
- self.teacherAuthPass = YES;
- }
- if (self.liveFlag == NO) { // 无直播权限直接改成未通过
- self.teacherAuthPass = NO;
- }
- if (self.teacherAuthPass == NO) {
- [self showAuthView];
- }
- else {
- [self hideAuthView];
- }
- }
- - (void)configAuthDisplay {
- [self.authView configDisplayMessage:[self getAuthDisplayMessage]];
- if ([self.teaherStatus isEqualToString:@"DOING"]) {
- self.authView.sureButton.userInteractionEnabled = NO;
- self.authView.sureButton.hidden = YES;
- }
- else {
- if ([self.teaherStatus isEqual:@"PASS"] && self.liveFlag == NO) {
- [self.authView.sureButton setTitle:@"立即开通" forState:UIControlStateNormal];
- }
- else {
- [self.authView.sureButton setTitle:@"去认证" forState:UIControlStateNormal];
- }
- self.authView.sureButton.userInteractionEnabled = YES;
- self.authView.sureButton.hidden = NO;
- }
- }
- - (void)showAuthView {
- [self configAuthDisplay];
- if ([self.subviews containsObject:self.authView]) {
- [self bringSubviewToFront:self.authView];
- }
- else {
- [self addSubview:self.authView];
- [self.authView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.bottom.right.mas_equalTo(self);
- }];
- }
- }
- - (void)hideAuthView {
- if ([self.subviews containsObject:self.authView]) {
- [self.authView removeFromSuperview];
- self.authView = nil;
- }
- }
- - (AuthDisplayView *)authView {
- if (!_authView) {
- _authView = [AuthDisplayView shareInstance];
- [_authView.imageView setImage:[UIImage imageNamed:[self getAuthDisplayImage]]];
- MJWeakSelf;
- [_authView sureCallback:^{
- [weakSelf authAction];
- }];
- }
- return _authView;
- }
- - (NSString *)getAuthDisplayImage {
- return @"authTeacher_accompany";
- }
- - (NSString *)getAuthDisplayMessage {
- if ([self.teaherStatus isEqualToString:@"DOING"]) { // 审核中
- return @"您已提交认证申请,请耐心等待审核结果~";
- }
- else {
- if ([self.teaherStatus isEqualToString:@"PASS"] && self.liveFlag == NO) { // 如果达人认证通过
- return @"您尚未开通直播服务,开通后即可创建直播课程~";
- }
- return @"您还没有完成达人认证,认证后才可创建直播课哦~";
- }
- }
- - (void)authAction {
- if ([self.teaherStatus isEqual:@"PASS"] && self.liveFlag == NO) { // 开通直播
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/openLive"];
- [self.naviController pushViewController:webCtrl animated:YES];
- }
- else {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherCert"];
- [self.naviController pushViewController:webCtrl animated:YES];
- }
-
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|