AccompanyCourseGroupViewController.m 9.9 KB

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