AccompanyDetailViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. //
  2. // AccompanyDetailViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/4/6.
  6. //
  7. #import "AccompanyDetailViewController.h"
  8. #import "AccompanyNavView.h"
  9. #import "AccompanyAlertView.h"
  10. #import "AccompanyCourseInfoCell.h"
  11. #import "AccompanyEvaluateCell.h"
  12. #import "AccompanyStudentEvaCell.h"
  13. #import "AccompanyArrangeCell.h"
  14. #import "AccompanyHomeworkCell.h"
  15. #import "AccompanyRemarkCell.h"
  16. #import "HomeworkDetailModel.h"
  17. #import "EvaluateDetailModel.h"
  18. #import "AccompanyDetailBottomView.h"
  19. #import "KSChatConversationViewController.h"
  20. #import "WMPlayer.h"
  21. @interface AccompanyDetailViewController ()<UITableViewDelegate,UITableViewDataSource,WMPlayerDelegate>
  22. {
  23. WMPlayer *_wmPlayer;
  24. CGRect _playerFrame;
  25. }
  26. @property (nonatomic, strong) UIView *bgView;
  27. @property (nonatomic, assign) BOOL isRatation;
  28. @property (nonatomic, strong) AccompanyNavView *navView;
  29. @property (nonatomic, strong) UITableView *tableView;
  30. @property (nonatomic, strong) HomeworkDetailModel *homeworkModel;
  31. @property (nonatomic, strong) EvaluateDetailModel *evaluateModel;
  32. @property (nonatomic, strong) AccompanyDetailBottomView *bottomView;
  33. @property (nonatomic, strong) AccompanyAlertView *alertView;
  34. @property (nonatomic, strong) NSMutableArray *fileArray;
  35. @end
  36. @implementation AccompanyDetailViewController
  37. - (void)viewDidLoad {
  38. [super viewDidLoad];
  39. // Do any additional setup after loading the view.
  40. self.ks_prefersNavigationBarHidden = YES;
  41. [self configUI];
  42. [self requestCourseInfoMessage];
  43. }
  44. - (void)requestCourseInfoMessage {
  45. [self requestHomeworkMessage];
  46. [self requestEvaluateMessage];
  47. }
  48. - (void)requestHomeworkMessage {
  49. [KSNetworkingManager homeworkDetailRequest:KS_GET courseId:self.courseId success:^(NSDictionary * _Nonnull dic) {
  50. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  51. self.homeworkModel = [[HomeworkDetailModel alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
  52. if (self.homeworkModel.submitHomework == 1) {
  53. if (![NSString isEmptyString:self.homeworkModel.studentAttachments]) {
  54. self.fileArray = [NSMutableArray arrayWithArray:[self.homeworkModel.studentAttachments componentsSeparatedByString:@","]];
  55. }
  56. else {
  57. self.fileArray = [NSMutableArray array];
  58. }
  59. }
  60. else {
  61. self.fileArray = [NSMutableArray array];
  62. }
  63. }
  64. else {
  65. [self MBPShow:MESSAGEKEY];
  66. }
  67. [self.tableView reloadData];
  68. } faliure:^(NSError * _Nonnull error) {
  69. }];
  70. }
  71. - (void)requestEvaluateMessage {
  72. [KSNetworkingManager selectRepliedRequest:KS_POST courseGroupId:self.courseId courseScheduleId:self.courseGroupId studentId:self.studentId success:^(NSDictionary * _Nonnull dic) {
  73. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  74. self.evaluateModel = [[EvaluateDetailModel alloc] initWithDictionary:[dic dictionaryValueForKey:@"data"]];
  75. }
  76. else {
  77. [self MBPShow:MESSAGEKEY];
  78. }
  79. [self.tableView reloadData];
  80. } faliure:^(NSError * _Nonnull error) {
  81. }];
  82. }
  83. - (void)configUI {
  84. [self.scrollView removeFromSuperview];
  85. [self.view addSubview:self.navView];
  86. CGFloat height = [self.navView getViewHeight];
  87. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.right.top.mas_equalTo(self.view);
  89. make.height.mas_equalTo(height);
  90. }];
  91. [self.view addSubview:self.tableView];
  92. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.left.right.mas_equalTo(self.view);
  94. make.top.mas_equalTo(self.view.mas_top).offset(kNaviBarHeight);
  95. make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
  96. }];
  97. }
  98. #pragma mark --- table data source
  99. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  100. return 6;
  101. }
  102. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  103. if (indexPath.row == 0) {
  104. AccompanyCourseInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyCourseInfoCell"];
  105. [cell configWithStartTime:self.homeworkModel.startTime endTime:self.homeworkModel.endTime studentAvatar:self.homeworkModel.studentAvatar studentName:self.homeworkModel.studentName studentId:self.homeworkModel.studentId studentSubject:self.homeworkModel.subjectName];
  106. cell.hideChatButton = NO;
  107. MJWeakSelf;
  108. [cell chatCalkback:^{
  109. [weakSelf chatAction];
  110. }];
  111. return cell;
  112. }
  113. else if (indexPath.row == 1) {
  114. AccompanyEvaluateCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyEvaluateCell"];
  115. NSString *message = self.evaluateModel.teacherReplied;
  116. BOOL hasEvaluate = [NSString isEmptyString:self.evaluateModel.teacherReplied] ? NO : YES;
  117. MJWeakSelf;
  118. [cell configWithEvaluateMessage:message hasEvaluate:hasEvaluate callback:^{
  119. [weakSelf evaluateCourse];
  120. }];
  121. return cell;
  122. }
  123. else if (indexPath.row == 2) {
  124. AccompanyStudentEvaCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyStudentEvaCell"];
  125. NSString *message = self.evaluateModel.studentReplied;
  126. BOOL hasEvaluate = [NSString isEmptyString:self.evaluateModel.studentReplied] ? NO : YES;
  127. [cell configWithEvaluateMessage:message starNum:self.evaluateModel.score hasEvaluate:hasEvaluate];
  128. return cell;
  129. }
  130. else if (indexPath.row == 3) {
  131. AccompanyArrangeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyArrangeCell"];
  132. BOOL hasArrange = self.homeworkModel.decorateHomework == 1 ? YES : NO;
  133. MJWeakSelf;
  134. [cell configWithHomeworkContent:self.homeworkModel.content hasArrangeHomework:hasArrange callback:^{
  135. [weakSelf arrangeHomework];
  136. }];
  137. return cell;
  138. }
  139. else if (indexPath.row == 4) {
  140. BOOL hasSubmitHomework = self.homeworkModel.submitHomework == 1 ? YES : NO;
  141. AccompanyHomeworkCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyHomeworkCell"];
  142. MJWeakSelf;
  143. [cell configWithAttachmentArray:self.fileArray hasSubmit:hasSubmitHomework callback:^(NSInteger viewIndex) {
  144. [weakSelf playVideoIndex:viewIndex];
  145. }];
  146. return cell;
  147. }
  148. else {
  149. AccompanyRemarkCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyRemarkCell"];
  150. BOOL hasEvaluate = self.homeworkModel.reviewHomework == 1? YES : NO;
  151. MJWeakSelf;
  152. [cell configWithRemarkMessage:self.homeworkModel.teacherReplied hasEvaluate:hasEvaluate callback:^{
  153. [weakSelf evaluateHomework];
  154. }];
  155. return cell;
  156. }
  157. }
  158. - (void)chatAction {
  159. if (self.homeworkModel && ![NSString isEmptyString:self.homeworkModel.studentId]) {
  160. KSChatConversationViewController *conversationVC = [[KSChatConversationViewController alloc] init];
  161. conversationVC.targetId = self.homeworkModel.studentId;
  162. conversationVC.title = self.homeworkModel.studentName;
  163. conversationVC.conversationType = ConversationType_PRIVATE;
  164. [self.navigationController pushViewController:conversationVC animated:YES];
  165. }
  166. }
  167. - (void)evaluateCourse {
  168. self.alertView = [AccompanyAlertView shareInstance];
  169. self.alertView.alertTitle.text = @"评价学员";
  170. self.alertView.tipsLabel.text = @"请输入您对本次课程学员表现的评价";
  171. self.alertView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
  172. [self.alertView showInView:[UIApplication sharedApplication].keyWindow showStarView:NO];
  173. MJWeakSelf;
  174. [self.alertView sureCallback:^(NSString * _Nonnull content, NSInteger starNum) {
  175. [weakSelf evaluateAction:content];
  176. }];
  177. }
  178. - (void)evaluateAction:(NSString *)content {
  179. if ([NSString isEmptyString:content]) {
  180. [self MBPShow:@"请输入评价内容"];
  181. return;
  182. }
  183. [self showhud];
  184. [KSNetworkingManager teacherCourseRepliedRequest:KS_POST courseScheduleId:self.courseId courseGroupId:self.courseGroupId studentId:self.studentId teacherReplied:content success:^(NSDictionary * _Nonnull dic) {
  185. [self removehub];
  186. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  187. [self MBPShow:@"评价成功"];
  188. [self requestCourseInfoMessage];
  189. }
  190. else {
  191. [self MBPShow:MESSAGEKEY];
  192. }
  193. } faliure:^(NSError * _Nonnull error) {
  194. [self removehub];
  195. }];
  196. }
  197. - (void)arrangeHomework {
  198. self.alertView = [AccompanyAlertView shareInstance];
  199. self.alertView.alertTitle.text = @"布置作业";
  200. self.alertView.tipsLabel.text = @"请输入本次课程作业内容";
  201. self.alertView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
  202. [self.alertView showInView:[UIApplication sharedApplication].keyWindow showStarView:NO];
  203. MJWeakSelf;
  204. [self.alertView sureCallback:^(NSString * _Nonnull content, NSInteger starNum) {
  205. [weakSelf arrangeAction:content];
  206. }];
  207. }
  208. - (void)arrangeAction:(NSString *)homeworkContent {
  209. [self showhud];
  210. [KSNetworkingManager homeworkDecorateRequest:KS_POST content:homeworkContent courseScheduleId:self.courseId success:^(NSDictionary * _Nonnull dic) {
  211. [self removehub];
  212. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  213. [self MBPShow:@"布置成功"];
  214. [self requestCourseInfoMessage];
  215. }
  216. else {
  217. [self MBPShow:MESSAGEKEY];
  218. }
  219. } faliure:^(NSError * _Nonnull error) {
  220. [self removehub];
  221. }];
  222. }
  223. // 评价作业
  224. - (void)evaluateHomework {
  225. self.alertView = [AccompanyAlertView shareInstance];
  226. self.alertView.alertTitle.text = @"作业点评";
  227. self.alertView.tipsLabel.text = @"请输入您对本次作业的点评";
  228. self.alertView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
  229. [self.alertView showInView:[UIApplication sharedApplication].keyWindow showStarView:NO];
  230. MJWeakSelf;
  231. [self.alertView sureCallback:^(NSString * _Nonnull content, NSInteger starNum) {
  232. [weakSelf commentAction:content];
  233. }];
  234. }
  235. - (void)commentAction:(NSString *)commentMessage {
  236. [self showhud];
  237. [KSNetworkingManager homeworkReviewRequest:KS_POST courseScheduleId:self.courseId review:commentMessage success:^(NSDictionary * _Nonnull dic) {
  238. [self removehub];
  239. if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
  240. [self MBPShow:@"点评成功"];
  241. [self requestCourseInfoMessage];
  242. }
  243. else {
  244. [self MBPShow:MESSAGEKEY];
  245. }
  246. } faliure:^(NSError * _Nonnull error) {
  247. [self removehub];
  248. }];
  249. }
  250. - (void)playVideoIndex:(NSInteger)index {
  251. if (self.fileArray.count > index) {
  252. NSString *fileUrl = self.fileArray[index];
  253. [self playVideoWithUrl:fileUrl];
  254. }
  255. }
  256. #pragma mark ------ WMPlayer
  257. - (void)playVideoWithUrl:(NSString *)fileUrl {
  258. fileUrl = [fileUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  259. _playerFrame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  260. _wmPlayer = [[WMPlayer alloc] initWithFrame:_playerFrame];
  261. WMPlayerModel *playModel = [[WMPlayerModel alloc] init];
  262. playModel.videoURL = [NSURL URLWithString:fileUrl];
  263. _wmPlayer.playerModel = playModel;
  264. _wmPlayer.delegate = self;
  265. _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
  266. _bgView.backgroundColor = [UIColor blackColor];
  267. [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
  268. [[UIApplication sharedApplication].keyWindow addSubview:_wmPlayer];
  269. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:_wmPlayer];
  270. [_wmPlayer play];
  271. }
  272. - (void)wmplayer:(WMPlayer *)wmplayer clickedCloseButton:(UIButton *)backBtn {
  273. [wmplayer removePlayer];
  274. [_bgView removeFromSuperview];
  275. [self setNeedsStatusBarAppearanceUpdate];
  276. }
  277. - (void)wmplayer:(WMPlayer *)wmplayer clickedFullScreenButton:(UIButton *)fullScreenBtn {
  278. self.isRatation = !self.isRatation;
  279. if (self.isRatation) {
  280. [wmplayer removeFromSuperview];
  281. [UIView animateWithDuration:1.0f animations:^{
  282. wmplayer.transform = CGAffineTransformMakeRotation(M_PI_2);
  283. } completion:^(BOOL finished) {
  284. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  285. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  286. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  287. }];
  288. }
  289. else {
  290. [wmplayer removeFromSuperview];
  291. [UIView animateWithDuration:1.0f animations:^{
  292. // 复原
  293. wmplayer.transform = CGAffineTransformIdentity;
  294. } completion:^(BOOL finished) {
  295. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  296. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  297. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  298. }];
  299. }
  300. }
  301. #pragma mark --- lazying
  302. - (UITableView *)tableView {
  303. if (!_tableView) {
  304. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  305. _tableView.delegate = self;
  306. _tableView.dataSource = self;
  307. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  308. _tableView.showsVerticalScrollIndicator = NO;
  309. _tableView.showsHorizontalScrollIndicator = NO;
  310. _tableView.backgroundColor = [UIColor clearColor];
  311. _tableView.rowHeight = UITableViewAutomaticDimension;
  312. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyCourseInfoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyCourseInfoCell"];
  313. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyEvaluateCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyEvaluateCell"];
  314. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyStudentEvaCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyStudentEvaCell"];
  315. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyArrangeCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyArrangeCell"];
  316. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyHomeworkCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyHomeworkCell"];
  317. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyRemarkCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyRemarkCell"];
  318. _tableView.estimatedRowHeight = 136.0f;
  319. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
  320. bottomView.backgroundColor = [UIColor clearColor];
  321. _tableView.tableFooterView = bottomView;
  322. }
  323. return _tableView;
  324. }
  325. - (AccompanyNavView *)navView {
  326. if (!_navView) {
  327. _navView = [AccompanyNavView shareInstance];
  328. MJWeakSelf;
  329. [_navView navCallback:^{
  330. [weakSelf backAction];
  331. }];
  332. }
  333. return _navView;
  334. }
  335. - (AccompanyDetailBottomView *)bottomView {
  336. if (!_bottomView) {
  337. _bottomView = [AccompanyDetailBottomView shareInstance];
  338. MJWeakSelf;
  339. [_bottomView joinroomCallback:^{
  340. [weakSelf joinRoomAction];
  341. }];
  342. }
  343. return _bottomView;
  344. }
  345. - (void)joinRoomAction {
  346. }
  347. /*
  348. #pragma mark - Navigation
  349. // In a storyboard-based application, you will often want to do a little preparation before navigation
  350. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  351. // Get the new view controller using [segue destinationViewController].
  352. // Pass the selected object to the new view controller.
  353. }
  354. */
  355. @end