VIPCourseGroupViewController.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. //
  2. // VIPCourseGroupViewController.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2024/11/13.
  6. //
  7. #import "VIPCourseGroupViewController.h"
  8. #import "CourseGroupNavView.h"
  9. #import "JXCategoryView.h"
  10. #import "JXPagerListRefreshView.h"
  11. #import "ProgramCourseInfoView.h"
  12. #import "ProgramCourseGroupBodyView.h"
  13. #import "StudentCourseGroupDetailModel.h"
  14. @interface VIPCourseGroupViewController ()<JXPagerViewDelegate,JXCategoryViewDelegate>
  15. @property (nonatomic, strong) NSMutableArray *listViewArray;
  16. @property (nonatomic, strong) CourseGroupNavView *navView;
  17. @property (nonatomic, assign) NSInteger headHeight;
  18. @property (nonatomic, assign) NSInteger topViewHeight;
  19. @property (nonatomic, strong) ProgramCourseInfoView *infoView;
  20. @property (nonatomic, assign) BOOL isFirstLoad;
  21. @property (nonatomic, strong) StudentCourseGroupDetailModel *detailModel;
  22. @property (nonatomic, assign) NSInteger enterStartTime; // 开课前可进入时间配置(分钟)
  23. @property (nonatomic, assign) NSInteger quitEndTime; // 结束后退出时间配置(分钟)
  24. @property (nonatomic, strong) UIImageView *bgImageView;
  25. @end
  26. @implementation VIPCourseGroupViewController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view.
  30. self.ks_prefersNavigationBarHidden = YES;
  31. [self configUI];
  32. self.isFirstLoad = YES;
  33. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(forceScroll) name:@"UITextViewScroll" object:nil];
  34. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enableScroll) name:@"UITextViewEndScroll" object:nil];
  35. }
  36. - (void)forceScroll {
  37. self.pagerView.mainTableView.scrollEnabled = NO;
  38. }
  39. - (void)enableScroll {
  40. self.pagerView.mainTableView.scrollEnabled = YES;
  41. }
  42. - (void)configUI {
  43. [self.scrollView removeFromSuperview];
  44. UIImage *bgImage = [UIImage imageNamed:@"courseDetail_bg"];
  45. NSInteger height = (NSInteger)(bgImage.size.height / bgImage.size.width * KPortraitWidth);
  46. self.bgImageView = [[UIImageView alloc] initWithImage:bgImage];
  47. self.bgImageView.frame = CGRectMake(0, 0, KPortraitWidth, height);
  48. [self.view addSubview:self.bgImageView];
  49. [self.view addSubview:self.navView];
  50. CGFloat navHeight = [CourseGroupNavView getViewHeight];
  51. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.left.right.top.mas_equalTo(self.view);
  53. make.height.mas_equalTo(navHeight);
  54. }];
  55. self.headHeight = CGFLOAT_MIN;
  56. self.titles = @[@""];
  57. [self configCategoryView:navHeight];
  58. }
  59. - (void)requestCourseInfo {
  60. [KSNetworkingManager getCourseGroupDetailRequest:KS_POST courseGroupId:self.courseGroupId success:^(NSDictionary * _Nonnull dic) {
  61. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  62. NSDictionary *parm = [dic ks_dictionaryValueForKey:@"data"];
  63. self.detailModel = [[StudentCourseGroupDetailModel alloc] initWithDictionary:parm];
  64. // 配置信息
  65. NSDictionary *config = [[dic ks_dictionaryValueForKey:@"data"] ks_dictionaryValueForKey:@"sysConfig"];
  66. self.enterStartTime = [config ks_integerValueForKey:@"vipStartTime"];
  67. self.quitEndTime = [config ks_integerValueForKey:@"vipEndTime"];
  68. }
  69. else {
  70. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  71. }
  72. [self refreshHeadView];
  73. } faliure:^(NSError * _Nonnull error) {
  74. [self refreshHeadView];
  75. }];
  76. }
  77. - (void)refreshHeadView {
  78. [self refreshListPage];
  79. self.topViewHeight = [ProgramCourseInfoView getViewHeightWithPlanString:self.detailModel.coursePlan];
  80. [self.infoView configWithSource:self.detailModel];
  81. [self.pagerView resizeTableHeaderViewHeightWithAnimatable:NO duration:0.3f curve:UIViewAnimationCurveEaseInOut];
  82. }
  83. - (void)configCategoryView:(NSInteger)topHeight {
  84. _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, topHeight, KPortraitWidth, self.headHeight)];
  85. self.categoryView.titles = self.titles;
  86. self.categoryView.delegate = self;
  87. self.categoryView.titleFont = [UIFont systemFontOfSize:16.0f];
  88. self.categoryView.titleSelectedFont = [UIFont systemFontOfSize:16.0f weight:UIFontWeightSemibold];
  89. self.categoryView.titleSelectedColor = HexRGB(0x333333);
  90. self.categoryView.titleColor = HexRGB(0x666666);
  91. self.categoryView.titleColorGradientEnabled = YES;
  92. _pagerView = [self preferredPagingView];
  93. self.pagerView.frame = CGRectMake(0, topHeight, KPortraitWidth, KPortraitHeight - topHeight);
  94. self.pagerView.backgroundColor = [UIColor clearColor];
  95. self.pagerView.mainTableView.backgroundColor = [UIColor clearColor];
  96. self.pagerView.listContainerView.backgroundColor = [UIColor clearColor];
  97. // self.pagerView.mainTableView.gestureDelegate = self;
  98. self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  99. self.pagerView.listContainerView.listCellBackgroundColor = [UIColor clearColor];
  100. [self.view addSubview:self.pagerView];
  101. }
  102. - (void)viewDidAppear:(BOOL)animated {
  103. [super viewDidAppear:animated];
  104. self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
  105. }
  106. - (void)viewWillAppear:(BOOL)animated {
  107. [super viewWillAppear:animated];
  108. self.navigationController.interactivePopGestureRecognizer.enabled = YES;
  109. // 刷新课程详情
  110. [self requestCourseInfo];
  111. if (self.isFirstLoad == NO) {
  112. [self refreshListPage];
  113. }
  114. self.isFirstLoad = NO;
  115. }
  116. - (void)refreshListPage {
  117. id value = self.listViewArray[0];
  118. if ([value isKindOfClass:[ProgramCourseGroupBodyView class]]) {
  119. ProgramCourseGroupBodyView *listView = (ProgramCourseGroupBodyView *)value;
  120. listView.enterStartTime = self.enterStartTime;
  121. listView.quitEndTime = self.quitEndTime;
  122. [listView beginFirstRefresh];
  123. }
  124. }
  125. - (JXPagerView *)preferredPagingView {
  126. return [[JXPagerListRefreshView alloc] initWithDelegate:self];
  127. }
  128. #pragma mark - JXPagerViewDelegate
  129. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  130. return self.infoView;
  131. }
  132. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  133. return self.topViewHeight;
  134. }
  135. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  136. return self.headHeight;
  137. }
  138. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  139. return self.categoryView;
  140. }
  141. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  142. //和categoryView的item数量一致
  143. return self.titles.count;
  144. }
  145. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  146. ProgramCourseGroupBodyView *listView = [[ProgramCourseGroupBodyView alloc] init];
  147. listView.naviController = self.navigationController;
  148. listView.selectIndex = index;
  149. listView.courseGroupId = self.courseGroupId;
  150. listView.courseType = COURSE_GROUP_TYPE_VIP;
  151. [self.listViewArray replaceObjectAtIndex:index withObject:listView];
  152. self.listViewArray[index] = listView;
  153. [listView beginFirstRefresh];
  154. return listView;
  155. }
  156. - (void)pagerView:(JXPagerView *)pagerView mainTableViewDidScroll:(UIScrollView *)scrollView {
  157. NSLog(@"sscroll content offset y %f", scrollView.contentOffset.y);
  158. CGFloat height = self.topViewHeight;
  159. CGFloat space = scrollView.contentOffset.y;
  160. if (space > 100) {
  161. CGFloat rate = (space - 100) / (height - 100);
  162. NSLog(@"rate ---------%f",rate);
  163. self.navView.backgroundColor = HexRGBAlpha(0xffffff, rate);
  164. if (rate == 1) {
  165. self.bgImageView.hidden = YES;
  166. }
  167. else {
  168. self.bgImageView.hidden = NO;
  169. }
  170. }
  171. else {
  172. self.navView.backgroundColor = [UIColor clearColor];
  173. self.bgImageView.hidden = NO;
  174. }
  175. }
  176. - (void)dealloc {
  177. [[NSNotificationCenter defaultCenter] removeObserver:self];
  178. }
  179. #pragma mark ----- lazying
  180. - (CourseGroupNavView *)navView {
  181. if (!_navView) {
  182. _navView = [CourseGroupNavView sharedInstance];
  183. MJWeakSelf;
  184. [_navView configWithNavTitle:@"课程组详情" callback:^{
  185. [weakSelf backAction];
  186. }];
  187. }
  188. return _navView;
  189. }
  190. - (NSMutableArray *)listViewArray {
  191. if (!_listViewArray) {
  192. _listViewArray = [NSMutableArray arrayWithArray:@[@""]];
  193. }
  194. return _listViewArray;
  195. }
  196. - (ProgramCourseInfoView *)infoView {
  197. if (!_infoView) {
  198. _infoView =[ProgramCourseInfoView sharedInstance];
  199. }
  200. return _infoView;
  201. }
  202. /*
  203. #pragma mark - Navigation
  204. // In a storyboard-based application, you will often want to do a little preparation before navigation
  205. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  206. // Get the new view controller using [segue destinationViewController].
  207. // Pass the selected object to the new view controller.
  208. }
  209. */
  210. @end