WaitExamViewController.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // WaitExamViewController.m
  3. // MusicGradeExam
  4. //
  5. // Created by Kyle on 2020/7/15.
  6. // Copyright © 2020 DayaMusic. All rights reserved.
  7. //
  8. #import "WaitExamViewController.h"
  9. #import "WaitExamBodyView.h"
  10. #import "TicketDetailModel.h"
  11. #import "OnlineRoomManager.h"
  12. @interface WaitExamViewController ()
  13. @property (nonatomic, strong) WaitExamBodyView *bodyView;
  14. @property (nonatomic, strong) TicketDetailModel *sourceModel;
  15. @property (nonatomic, strong) OnlineRoomManager *classManager;
  16. @property (nonatomic, assign) BOOL cancleRequest;
  17. @end
  18. @implementation WaitExamViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. [self allocTitle:@"待考"];
  23. self.view.backgroundColor = HexRGB(0xf3f4f8);
  24. [self configUI];
  25. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backLoginView) name:@"backLoginView" object:nil];
  26. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshWaitList) name:RefreshWaitListNotification object:nil];
  27. }
  28. - (void)refreshWaitList {
  29. [self requestDataWithHub:NO];
  30. }
  31. // 试听课被挤掉
  32. - (void)backLoginView {
  33. _cancleRequest = YES;
  34. }
  35. - (void)viewWillAppear:(BOOL)animated {
  36. [super viewWillAppear:animated];
  37. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
  38. if(@available(iOS 13.0, *)){
  39. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
  40. }
  41. if (_cancleRequest) {
  42. _cancleRequest = NO;
  43. [KSRequestManager logoutAction];
  44. return;
  45. }
  46. [self requestDataWithHub:YES];
  47. }
  48. - (void)requestDataWithHub:(BOOL)needHub {
  49. if (needHub) {
  50. [self showhud];
  51. }
  52. [KSRequestManager needCheckingDetailRequest:KS_GET examRegistrationId:self.examRegistrationId success:^(NSDictionary * _Nonnull dic) {
  53. if (needHub) {
  54. [self removehub];
  55. }
  56. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  57. self.sourceModel = [[TicketDetailModel alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
  58. [self.bodyView configMessageSource:self.sourceModel];
  59. }
  60. else {
  61. [self MBPShow:MESSAGEKEY];
  62. }
  63. } faliure:^(NSError * _Nonnull error) {
  64. if (needHub) {
  65. [self removehub];
  66. }
  67. }];
  68. }
  69. - (void)configUI {
  70. self.scrollView.backgroundColor = HexRGB(0xf3f4f8);
  71. self.scrollView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kTabBarHeight - iPhoneXSafeBottomMargin);
  72. _bodyView = [WaitExamBodyView shareInstance];
  73. CGFloat viewHeight = 206 + 200 + 19 + 204 + 50 + 21 + 9 + 50 + 27;
  74. viewHeight = viewHeight > kScreenHeight - kTabBarHeight - iPhoneXSafeBottomMargin ? viewHeight : kScreenHeight - kTabBarHeight - iPhoneXSafeBottomMargin;
  75. _bodyView.frame = CGRectMake(0, 0, kScreenWidth, viewHeight);
  76. MJWeakSelf;
  77. [_bodyView operationCallback:^(JOINROOMACTION action, TicketDetailModel * _Nullable source) {
  78. [weakSelf opreationAction:action source:source];
  79. }];
  80. [self.scrollView addSubview:_bodyView];
  81. [self.scrollView setContentSize:CGSizeMake(kScreenWidth, viewHeight)];
  82. }
  83. - (void)opreationAction:(JOINROOMACTION)action source:(TicketDetailModel *)source {
  84. switch (action) {
  85. case JOINROOMACTION_SIGN: // 签到
  86. {
  87. [self signAction];
  88. }
  89. break;
  90. case JOINROOMACTION_GUIDE: // 引导页
  91. {
  92. }
  93. break;
  94. case JOINROOMACTION_JOIN: // 加入房间
  95. {
  96. NSString *roomId = [NSString stringWithFormat:@"%.0f", source.examRegistrationId];
  97. [self joinRoomAction:roomId];
  98. }
  99. break;
  100. default:
  101. break;
  102. }
  103. }
  104. #pragma mark ----- 签到
  105. - (void)signAction {
  106. [self showhud];
  107. [KSRequestManager signInRequest:KS_POST examRegistrationId:self.examRegistrationId success:^(NSDictionary * _Nonnull dic) {
  108. [self removehub];
  109. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  110. self.bodyView.isSign = YES;
  111. }
  112. else {
  113. [self MBPShow:MESSAGEKEY];
  114. }
  115. } faliure:^(NSError * _Nonnull error) {
  116. [self removehub];
  117. }];
  118. }
  119. #pragma mark ----- 加入房间
  120. - (void)joinRoomAction:(NSString *)roomId {
  121. [self.classManager joinRoomWithId:roomId inViewController:self];
  122. }
  123. - (OnlineRoomManager *)classManager {
  124. if (!_classManager) {
  125. _classManager = [[OnlineRoomManager alloc] init];
  126. }
  127. return _classManager;
  128. }
  129. - (void)dealloc {
  130. [[NSNotificationCenter defaultCenter] removeObserver:self];
  131. }
  132. /*
  133. #pragma mark - Navigation
  134. // In a storyboard-based application, you will often want to do a little preparation before navigation
  135. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  136. // Get the new view controller using [segue destinationViewController].
  137. // Pass the selected object to the new view controller.
  138. }
  139. */
  140. @end