123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- //
- // AccompanyCourseCell.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/4/2.
- //
- #import "AccompanyCourseCell.h"
- @interface AccompanyCourseCell ()
- @property (weak, nonatomic) IBOutlet UILabel *courseTime;
- @property (weak, nonatomic) IBOutlet UILabel *courseStatus;
- @property (weak, nonatomic) IBOutlet UIImageView *studentAvatar;
- @property (weak, nonatomic) IBOutlet UILabel *studentName;
- @property (weak, nonatomic) IBOutlet UILabel *studentSubject;
- @property (weak, nonatomic) IBOutlet UIButton *opreationButton;
- @property (nonatomic, copy) AccompanyCourseCallback callback;
- @property (nonatomic, strong) AccompanyLessonModel *sourceModel;
- @property (nonatomic, assign) ACCOMPANY_TYPE type;
- /// 课表使用
- @property (nonatomic, copy) AccompanyLessonCallback lessonCallback;
- @property (nonatomic, strong) TableCourseModel *lessonModel;
- @end
- @interface AccompanyCourseCell ()
- @end
- @implementation AccompanyCourseCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- - (void)configWithSource:(AccompanyLessonModel *)model actionCallback:(AccompanyCourseCallback)callback {
- if (callback) {
- self.callback = callback;
- }
- self.sourceModel = model;
- [self.studentAvatar sd_setImageWithURL:[NSURL URLWithString:[model.avatar getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
- self.studentName.text = [NSString returnNoNullStringWithString:model.userName];
- self.studentSubject.text = [NSString returnNoNullStringWithString:model.subjectName];
- // time
- [self evaluateTimeLabelWithBeginTime:model.startTime endTime:model.endTime];
-
- if ([model.status isEqualToString:@"NOT_START"]) { // 未开始
- self.courseStatus.text = @"未开始";
- self.courseStatus.textColor = HexRGB(0xff802C);
- // 判断按钮显示调课还是进入教室
- BOOL canChange = NO;
- if (canChange) {
- self.type = ACCOMPANY_TYPE_ADJUST;
- self.opreationButton.userInteractionEnabled = YES;
- [self.opreationButton setTitle:@"调课" forState:UIControlStateNormal];
- [self.opreationButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
- [self.opreationButton setBackgroundColor:HexRGB(0xffffff)];
- }
- else {
- self.type = ACCOMPANY_DETAIL;
- self.opreationButton.userInteractionEnabled = YES;
- [self.opreationButton setTitle:@"进入教室" forState:UIControlStateNormal];
- [self.opreationButton setTitleColor:HexRGB(0xffffff) forState:UIControlStateNormal];
- [self.opreationButton setBackgroundColor:THEMECOLOR];
- }
- }
- else if ([model.status isEqualToString:@"ING"]) { // 进行中
- self.courseStatus.text = @"进行中";
- self.courseStatus.textColor = THEMECOLOR;
- self.type = ACCOMPANY_DETAIL;
- self.opreationButton.userInteractionEnabled = YES;
- [self.opreationButton setTitle:@"进入教室" forState:UIControlStateNormal];
- [self.opreationButton setTitleColor:HexRGB(0xffffff) forState:UIControlStateNormal];
- [self.opreationButton setBackgroundColor:THEMECOLOR];
- }
- else if ([model.status isEqualToString:@"COMPLETE"]) { // 已结束
- self.courseStatus.text = @"已结束";
- self.courseStatus.textColor = HexRGB(0x999999);
- // 判断显示评价还是已评价
- BOOL hasEvaluate = [model.teacherReplied isEqualToString:@"1"] ? YES : NO;
- if (hasEvaluate) {
- self.type = ACCOMPANY_DETAIL;
- self.opreationButton.userInteractionEnabled = YES;
- [self.opreationButton setTitle:@"评价" forState:UIControlStateNormal];
- [self.opreationButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
- [self.opreationButton setBackgroundColor:HexRGB(0xffffff)];
- }
- else {
- self.opreationButton.userInteractionEnabled = NO;
- [self.opreationButton setTitle:@"已评价" forState:UIControlStateNormal];
- [self.opreationButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
- [self.opreationButton setBackgroundColor:HexRGB(0xffffff)];
- }
- }
- }
- /// 课表使用
- - (void)configWithCourseMessage:(TableCourseModel *)model beforeTime:(NSInteger)beforeTime actionCallback:(AccompanyLessonCallback)callback {
- if (callback) {
- self.lessonCallback = callback;
- }
- self.lessonModel = model;
-
- [self.studentAvatar sd_setImageWithURL:[NSURL URLWithString:[model.cover getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
- if ([NSString isEmptyString:model.name]) {
- self.studentName.text = [NSString stringWithFormat:@"游客%@",model.userId];
- }
- else {
- self.studentName.text = model.name;
- }
-
- self.studentSubject.text = [NSString returnNoNullStringWithString:model.subjectName];
-
- // time
- [self evaluateTimeLabelWithBeginTime:model.startTime endTime:model.endTime];
-
- if ([model.status isEqualToString:@"NOT_START"]) { // 未开始
- self.courseStatus.text = @"未开始";
- self.courseStatus.textColor = HexRGB(0xff802C);
-
- // 判断按钮显示调课还是进入教室
- NSDate *currentDate = [NSDate date];
- NSDate *beginDate = [self getCourseBeginDate:model.startTime];
- NSTimeInterval beginTimeInterval = [beginDate timeIntervalSinceDate:currentDate];
- BOOL canChange = NO;
- if (beginTimeInterval > beforeTime * 60) {
- canChange = YES;
- }
- if (canChange) {
- self.type = ACCOMPANY_TYPE_ADJUST;
- self.opreationButton.userInteractionEnabled = YES;
- [self.opreationButton setTitle:@"调课" forState:UIControlStateNormal];
- [self.opreationButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
- [self.opreationButton setBackgroundColor:HexRGB(0xffffff)];
- }
- else {
- self.type = ACCOMPANY_DETAIL;
- self.opreationButton.userInteractionEnabled = YES;
- [self.opreationButton setTitle:@"进入教室" forState:UIControlStateNormal];
- [self.opreationButton setTitleColor:HexRGB(0xffffff) forState:UIControlStateNormal];
- [self.opreationButton setBackgroundColor:THEMECOLOR];
- }
- }
- else if ([model.status isEqualToString:@"ING"]) { // 进行中
- self.courseStatus.text = @"进行中";
- self.courseStatus.textColor = THEMECOLOR;
- self.type = ACCOMPANY_DETAIL;
- self.opreationButton.userInteractionEnabled = YES;
- [self.opreationButton setTitle:@"进入教室" forState:UIControlStateNormal];
- [self.opreationButton setTitleColor:HexRGB(0xffffff) forState:UIControlStateNormal];
- [self.opreationButton setBackgroundColor:THEMECOLOR];
- }
- else if ([model.status isEqualToString:@"COMPLETE"]) { // 已结束
- self.courseStatus.text = @"已结束";
- self.courseStatus.textColor = HexRGB(0x999999);
- // 判断显示评价还是已评价
- BOOL hasEvaluate = [model.teacherReplied isEqualToString:@"1"] ? YES : NO;
- if (hasEvaluate == NO) {
- self.type = ACCOMPANY_DETAIL;
- self.opreationButton.userInteractionEnabled = YES;
- [self.opreationButton setTitle:@"评价" forState:UIControlStateNormal];
- [self.opreationButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
- [self.opreationButton setBackgroundColor:HexRGB(0xffffff)];
- }
- else {
- self.opreationButton.userInteractionEnabled = NO;
- [self.opreationButton setTitle:@"已评价" forState:UIControlStateNormal];
- [self.opreationButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
- [self.opreationButton setBackgroundColor:HexRGB(0xffffff)];
- }
- }
- }
- - (NSDate *)getCourseBeginDate:(NSString *)beginTime {
- NSDateFormatter *dateFormatter = [NSObject getDateformatter];
- [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- NSDate *beginDate = [dateFormatter dateFromString:beginTime];
- return beginDate;
- }
- - (void)evaluateTimeLabelWithBeginTime:(NSString *)beginTime endTime:(NSString *)endTime {
- // 时间
- NSDateFormatter *dateFormatter = [NSObject getDateformatter];
- [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- NSDate *beginDate = [dateFormatter dateFromString:beginTime];
- NSDate *endDate = [dateFormatter dateFromString:endTime];
- [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm"];
- NSString *beginStr = [NSString returnNoNullStringWithString:[dateFormatter stringFromDate:beginDate]];
- [dateFormatter setDateFormat:@"HH:mm"];
- NSString *endStr = [NSString returnNoNullStringWithString:[dateFormatter stringFromDate:endDate]];
- self.courseTime.text = [NSString stringWithFormat:@"%@~%@", beginStr, endStr];
- }
- - (IBAction)chatAction:(id)sender {
- if (self.callback) {
- self.callback(ACCOMPANY_TYPE_CHAT, self.sourceModel);
- }
- else if (self.lessonCallback) {
- self.lessonCallback(ACCOMPANY_TYPE_CHAT, self.lessonModel);
- }
- }
- - (IBAction)courseAction:(UIButton *)sender {
- if (self.callback) {
- self.callback(self.type, self.sourceModel);
- }
- else if (self.lessonCallback) {
- self.lessonCallback(self.type, self.lessonModel);
- }
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- @end
|