AccompanyCourseCell.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. //
  2. // AccompanyCourseCell.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/4/2.
  6. //
  7. #import "AccompanyCourseCell.h"
  8. @interface AccompanyCourseCell ()
  9. @property (weak, nonatomic) IBOutlet UILabel *courseTime;
  10. @property (weak, nonatomic) IBOutlet UILabel *courseStatus;
  11. @property (weak, nonatomic) IBOutlet UIImageView *studentAvatar;
  12. @property (weak, nonatomic) IBOutlet UILabel *studentName;
  13. @property (weak, nonatomic) IBOutlet UILabel *studentSubject;
  14. @property (weak, nonatomic) IBOutlet UIButton *opreationButton;
  15. @property (nonatomic, copy) AccompanyCourseCallback callback;
  16. @property (nonatomic, strong) AccompanyLessonModel *sourceModel;
  17. @property (nonatomic, assign) ACCOMPANY_TYPE type;
  18. /// 课表使用
  19. @property (nonatomic, copy) AccompanyLessonCallback lessonCallback;
  20. @property (nonatomic, strong) TableCourseModel *lessonModel;
  21. @end
  22. @interface AccompanyCourseCell ()
  23. @end
  24. @implementation AccompanyCourseCell
  25. - (void)awakeFromNib {
  26. [super awakeFromNib];
  27. // Initialization code
  28. self.selectionStyle = UITableViewCellSelectionStyleNone;
  29. }
  30. - (void)configWithSource:(AccompanyLessonModel *)model actionCallback:(AccompanyCourseCallback)callback {
  31. if (callback) {
  32. self.callback = callback;
  33. }
  34. self.sourceModel = model;
  35. [self.studentAvatar sd_setImageWithURL:[NSURL URLWithString:[model.avatar getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
  36. self.studentName.text = [NSString returnNoNullStringWithString:model.userName];
  37. self.studentSubject.text = [NSString returnNoNullStringWithString:model.subjectName];
  38. // time
  39. [self evaluateTimeLabelWithBeginTime:model.startTime endTime:model.endTime];
  40. if ([model.status isEqualToString:@"NOT_START"]) { // 未开始
  41. self.courseStatus.text = @"未开始";
  42. self.courseStatus.textColor = HexRGB(0xff802C);
  43. // 判断按钮显示调课还是进入教室
  44. BOOL canChange = NO;
  45. if (canChange) {
  46. self.type = ACCOMPANY_TYPE_ADJUST;
  47. self.opreationButton.userInteractionEnabled = YES;
  48. [self.opreationButton setTitle:@"调课" forState:UIControlStateNormal];
  49. [self.opreationButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
  50. [self.opreationButton setBackgroundColor:HexRGB(0xffffff)];
  51. }
  52. else {
  53. self.type = ACCOMPANY_DETAIL;
  54. self.opreationButton.userInteractionEnabled = YES;
  55. [self.opreationButton setTitle:@"进入教室" forState:UIControlStateNormal];
  56. [self.opreationButton setTitleColor:HexRGB(0xffffff) forState:UIControlStateNormal];
  57. [self.opreationButton setBackgroundColor:THEMECOLOR];
  58. }
  59. }
  60. else if ([model.status isEqualToString:@"ING"]) { // 进行中
  61. self.courseStatus.text = @"进行中";
  62. self.courseStatus.textColor = THEMECOLOR;
  63. self.type = ACCOMPANY_DETAIL;
  64. self.opreationButton.userInteractionEnabled = YES;
  65. [self.opreationButton setTitle:@"进入教室" forState:UIControlStateNormal];
  66. [self.opreationButton setTitleColor:HexRGB(0xffffff) forState:UIControlStateNormal];
  67. [self.opreationButton setBackgroundColor:THEMECOLOR];
  68. }
  69. else if ([model.status isEqualToString:@"COMPLETE"]) { // 已结束
  70. self.courseStatus.text = @"已结束";
  71. self.courseStatus.textColor = HexRGB(0x999999);
  72. // 判断显示评价还是已评价
  73. BOOL hasEvaluate = [model.teacherReplied isEqualToString:@"1"] ? YES : NO;
  74. if (hasEvaluate) {
  75. self.type = ACCOMPANY_DETAIL;
  76. self.opreationButton.userInteractionEnabled = YES;
  77. [self.opreationButton setTitle:@"评价" forState:UIControlStateNormal];
  78. [self.opreationButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
  79. [self.opreationButton setBackgroundColor:HexRGB(0xffffff)];
  80. }
  81. else {
  82. self.opreationButton.userInteractionEnabled = NO;
  83. [self.opreationButton setTitle:@"已评价" forState:UIControlStateNormal];
  84. [self.opreationButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
  85. [self.opreationButton setBackgroundColor:HexRGB(0xffffff)];
  86. }
  87. }
  88. }
  89. /// 课表使用
  90. - (void)configWithCourseMessage:(TableCourseModel *)model beforeTime:(NSInteger)beforeTime actionCallback:(AccompanyLessonCallback)callback {
  91. if (callback) {
  92. self.lessonCallback = callback;
  93. }
  94. self.lessonModel = model;
  95. [self.studentAvatar sd_setImageWithURL:[NSURL URLWithString:[model.cover getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
  96. if ([NSString isEmptyString:model.name]) {
  97. self.studentName.text = [NSString stringWithFormat:@"游客%@",model.userId];
  98. }
  99. else {
  100. self.studentName.text = model.name;
  101. }
  102. self.studentSubject.text = [NSString returnNoNullStringWithString:model.subjectName];
  103. // time
  104. [self evaluateTimeLabelWithBeginTime:model.startTime endTime:model.endTime];
  105. if ([model.status isEqualToString:@"NOT_START"]) { // 未开始
  106. self.courseStatus.text = @"未开始";
  107. self.courseStatus.textColor = HexRGB(0xff802C);
  108. // 判断按钮显示调课还是进入教室
  109. NSDate *currentDate = [NSDate date];
  110. NSDate *beginDate = [self getCourseBeginDate:model.startTime];
  111. NSTimeInterval beginTimeInterval = [beginDate timeIntervalSinceDate:currentDate];
  112. BOOL canChange = NO;
  113. if (beginTimeInterval > beforeTime * 60) {
  114. canChange = YES;
  115. }
  116. if (canChange) {
  117. self.type = ACCOMPANY_TYPE_ADJUST;
  118. self.opreationButton.userInteractionEnabled = YES;
  119. [self.opreationButton setTitle:@"调课" forState:UIControlStateNormal];
  120. [self.opreationButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
  121. [self.opreationButton setBackgroundColor:HexRGB(0xffffff)];
  122. }
  123. else {
  124. self.type = ACCOMPANY_DETAIL;
  125. self.opreationButton.userInteractionEnabled = YES;
  126. [self.opreationButton setTitle:@"进入教室" forState:UIControlStateNormal];
  127. [self.opreationButton setTitleColor:HexRGB(0xffffff) forState:UIControlStateNormal];
  128. [self.opreationButton setBackgroundColor:THEMECOLOR];
  129. }
  130. }
  131. else if ([model.status isEqualToString:@"ING"]) { // 进行中
  132. self.courseStatus.text = @"进行中";
  133. self.courseStatus.textColor = THEMECOLOR;
  134. self.type = ACCOMPANY_DETAIL;
  135. self.opreationButton.userInteractionEnabled = YES;
  136. [self.opreationButton setTitle:@"进入教室" forState:UIControlStateNormal];
  137. [self.opreationButton setTitleColor:HexRGB(0xffffff) forState:UIControlStateNormal];
  138. [self.opreationButton setBackgroundColor:THEMECOLOR];
  139. }
  140. else if ([model.status isEqualToString:@"COMPLETE"]) { // 已结束
  141. self.courseStatus.text = @"已结束";
  142. self.courseStatus.textColor = HexRGB(0x999999);
  143. // 判断显示评价还是已评价
  144. BOOL hasEvaluate = [model.teacherReplied isEqualToString:@"1"] ? YES : NO;
  145. if (hasEvaluate == NO) {
  146. self.type = ACCOMPANY_DETAIL;
  147. self.opreationButton.userInteractionEnabled = YES;
  148. [self.opreationButton setTitle:@"评价" forState:UIControlStateNormal];
  149. [self.opreationButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
  150. [self.opreationButton setBackgroundColor:HexRGB(0xffffff)];
  151. }
  152. else {
  153. self.opreationButton.userInteractionEnabled = NO;
  154. [self.opreationButton setTitle:@"已评价" forState:UIControlStateNormal];
  155. [self.opreationButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
  156. [self.opreationButton setBackgroundColor:HexRGB(0xffffff)];
  157. }
  158. }
  159. }
  160. - (NSDate *)getCourseBeginDate:(NSString *)beginTime {
  161. NSDateFormatter *dateFormatter = [NSObject getDateformatter];
  162. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  163. NSDate *beginDate = [dateFormatter dateFromString:beginTime];
  164. return beginDate;
  165. }
  166. - (void)evaluateTimeLabelWithBeginTime:(NSString *)beginTime endTime:(NSString *)endTime {
  167. // 时间
  168. NSDateFormatter *dateFormatter = [NSObject getDateformatter];
  169. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  170. NSDate *beginDate = [dateFormatter dateFromString:beginTime];
  171. NSDate *endDate = [dateFormatter dateFromString:endTime];
  172. [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm"];
  173. NSString *beginStr = [NSString returnNoNullStringWithString:[dateFormatter stringFromDate:beginDate]];
  174. [dateFormatter setDateFormat:@"HH:mm"];
  175. NSString *endStr = [NSString returnNoNullStringWithString:[dateFormatter stringFromDate:endDate]];
  176. self.courseTime.text = [NSString stringWithFormat:@"%@~%@", beginStr, endStr];
  177. }
  178. - (IBAction)chatAction:(id)sender {
  179. if (self.callback) {
  180. self.callback(ACCOMPANY_TYPE_CHAT, self.sourceModel);
  181. }
  182. else if (self.lessonCallback) {
  183. self.lessonCallback(ACCOMPANY_TYPE_CHAT, self.lessonModel);
  184. }
  185. }
  186. - (IBAction)courseAction:(UIButton *)sender {
  187. if (self.callback) {
  188. self.callback(self.type, self.sourceModel);
  189. }
  190. else if (self.lessonCallback) {
  191. self.lessonCallback(self.type, self.lessonModel);
  192. }
  193. }
  194. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  195. [super setSelected:selected animated:animated];
  196. // Configure the view for the selected state
  197. }
  198. @end