You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
263 lines
8.2 KiB
263 lines
8.2 KiB
// |
|
// AddCourseViewController.m |
|
// tongxin |
|
// |
|
// Created by ecell on 2021/11/25. |
|
// Copyright © 2021 xTT. All rights reserved. |
|
// |
|
|
|
#import "AddCourseViewController.h" |
|
#import "CourseModel.h" |
|
|
|
@interface AddCourseViewController () |
|
|
|
@property (nonatomic, strong)NSMutableArray *weekLabelArr; |
|
@property (nonatomic, strong)NSMutableArray *lessionLabelArr; |
|
@property (nonatomic, assign)NSInteger curWeek; |
|
@property (nonatomic, assign)NSInteger curLession; |
|
|
|
@end |
|
|
|
@implementation AddCourseViewController |
|
|
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
|
|
NSString *rightTitle; |
|
if (_curModel) { |
|
self.title = @"修改课程"; |
|
rightTitle = @"保存"; |
|
} else { |
|
self.title = @"添加课程"; |
|
rightTitle = @"添加"; |
|
} |
|
|
|
[self zx_setRightBtnWithText:rightTitle clickedBlock:^(ZXNavItemBtn * _Nonnull btn) { |
|
[self addCourse:nil]; |
|
}]; |
|
|
|
[self setUpUI]; |
|
[self setUpData]; |
|
[self setUpEvent]; |
|
} |
|
|
|
|
|
- (void)addCourse:(id)sender |
|
{ |
|
|
|
|
|
if (_tfCourseName.text && _tfCourseName.text.length <= 0) { |
|
[SVProgressHUD showInfoWithStatus:@"课程名不能为空"]; |
|
return; |
|
} |
|
if (_curWeek == -1) { |
|
[SVProgressHUD showInfoWithStatus:@"星期不能为空"]; |
|
return; |
|
} |
|
if (_curLession == -1) { |
|
[SVProgressHUD showInfoWithStatus:@"节次不能为空"]; |
|
return; |
|
} |
|
//比较2个时间段 结束时间需大于开始时间 |
|
|
|
NSDateFormatter * df = [[NSDateFormatter alloc]init]; |
|
[df setDateFormat:@"HH:mm"]; |
|
double startTime = [df dateFromString:self.tfStartTime.text].timeIntervalSince1970; |
|
double endTime =[df dateFromString:self.tfEndTime.text].timeIntervalSince1970; |
|
if(endTime <= startTime){ |
|
[SVProgressHUD showInfoWithStatus:@"结束时间需大于开始时间"]; |
|
// LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"提示" message:@"结束时间需大于开始时间" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:nil destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { |
|
// } cancelHandler:nil destructiveHandler:nil]; |
|
// [alertView showAnimated:YES completionHandler:nil]; |
|
return; |
|
} |
|
|
|
|
|
CourseModel *model = [CourseModel courseWithName:_tfCourseName.text dayIndex:_curWeek startCourseIndex:_curLession endCourseIndex:_curLession]; |
|
NSString *time = [NSString stringWithFormat:@"%@%@",_tfStartTime.text, _tfEndTime.text]; |
|
time = [time stringByReplacingOccurrencesOfString:@":" withString:@""]; |
|
|
|
if (self.delegate) { |
|
[self.delegate addCourse:self course:model time:time]; |
|
} |
|
|
|
[self goBack:nil]; |
|
} |
|
|
|
- (void)setUpData { |
|
if (_curModel) { |
|
_curWeek = _curModel.dayIndex; |
|
_curLession = _curModel.startCourseIndex; |
|
|
|
UILabel *selectedWeekLab = _weekLabelArr[_curWeek-1]; |
|
selectedWeekLab.backgroundColor = mainColor; |
|
selectedWeekLab.textColor = [UIColor whiteColor]; |
|
selectedWeekLab.layer.borderColor = [UIColor whiteColor].CGColor; |
|
|
|
UILabel *selectedLession = _lessionLabelArr[_curLession-1]; |
|
selectedLession.backgroundColor = mainColor; |
|
selectedLession.textColor = [UIColor whiteColor]; |
|
selectedLession.layer.borderColor = [UIColor whiteColor].CGColor; |
|
|
|
_tfCourseName.text = _curModel.courseName; |
|
|
|
if (_courseTime) { |
|
_tfStartTime.text = [_courseTime componentsSeparatedByString:@"-"][0]; |
|
_tfEndTime.text = [_courseTime componentsSeparatedByString:@"-"][1]; |
|
} |
|
|
|
} else { |
|
_curWeek = -1; |
|
_curLession = -1; |
|
} |
|
} |
|
|
|
- (void)setUpUI { |
|
_weekLabelArr = [NSMutableArray arrayWithArray:@[ |
|
_labMon,_labTues,_labWed,_labThur, |
|
_labFri,_labSat,_labSun |
|
]]; |
|
|
|
_lessionLabelArr = [NSMutableArray arrayWithArray:@[ |
|
_labFirst,_labSecond,_labThird,_labFourth, |
|
_labFifth,_labSixth,_labSeventh,_labEighth,_labNinth,_labTenth |
|
]]; |
|
|
|
for (int i = 0; i < _weekLabelArr.count; i++) { |
|
[self initLabel:_weekLabelArr[i] tag:i+1]; |
|
} |
|
|
|
for (int i = 0; i < _lessionLabelArr.count; i++) { |
|
[self initLabel:_lessionLabelArr[i] tag:i+1]; |
|
} |
|
|
|
[self initStartTime:_tfStartTime]; |
|
[self initEndTime:_tfEndTime]; |
|
} |
|
|
|
- (void)initLabel:(UILabel *)label tag:(NSInteger)tag { |
|
label.userInteractionEnabled = YES; |
|
label.textColor = [UIColor blackColor]; |
|
label.font = [UIFont systemFontOfSize:12]; |
|
label.backgroundColor = [UIColor whiteColor]; |
|
label.layer.backgroundColor = [UIColor whiteColor].CGColor; |
|
label.layer.cornerRadius = 12; |
|
label.layer.borderColor = RGB(240, 240, 240).CGColor; |
|
label.layer.borderWidth = 1; |
|
label.tag = tag; |
|
label.layer.masksToBounds = YES; |
|
} |
|
|
|
- (void)initStartTime:(UITextField *)label { |
|
label.layer.cornerRadius = 15; |
|
label.layer.borderColor = RGB(240, 240, 240).CGColor; |
|
label.layer.borderWidth = 1; |
|
label.layer.masksToBounds = YES; |
|
|
|
UIDatePicker *datePicker = [[UIDatePicker alloc] init]; |
|
datePicker.datePickerMode = UIDatePickerModeTime; |
|
datePicker.date = [NSDate new]; |
|
|
|
if (@available(iOS 13.4, *)) { |
|
datePicker.preferredDatePickerStyle = UIDatePickerStyleWheels; |
|
} |
|
|
|
[datePicker addTarget:self |
|
action:@selector(startTimeClick:) |
|
forControlEvents:UIControlEventValueChanged]; |
|
|
|
label.inputView = datePicker; |
|
} |
|
|
|
- (void)initEndTime:(UITextField *)label { |
|
label.layer.cornerRadius = 15; |
|
label.layer.borderColor = RGB(240, 240, 240).CGColor; |
|
label.layer.borderWidth = 1; |
|
label.layer.masksToBounds = YES; |
|
|
|
UIDatePicker *datePicker = [[UIDatePicker alloc] init]; |
|
datePicker.datePickerMode = UIDatePickerModeTime; |
|
datePicker.date = [NSDate new]; |
|
|
|
if (@available(iOS 13.4, *)) { |
|
datePicker.preferredDatePickerStyle = UIDatePickerStyleWheels; |
|
} |
|
|
|
[datePicker addTarget:self |
|
action:@selector(endTimeClick:) |
|
forControlEvents:UIControlEventValueChanged]; |
|
|
|
label.inputView = datePicker; |
|
} |
|
|
|
- (void)startTimeClick:(id)sender{ |
|
UIDatePicker * datePic = (UIDatePicker*)sender; |
|
|
|
NSString *text = [myHelper getDateFormatWithStr:@"HH:mm"date:[datePic date]]; |
|
_tfStartTime.text = text; |
|
} |
|
|
|
- (void)endTimeClick:(id)sender{ |
|
UIDatePicker * datePic = (UIDatePicker*)sender; |
|
|
|
NSString *text = [myHelper getDateFormatWithStr:@"HH:mm"date:[datePic date]]; |
|
_tfEndTime.text = text; |
|
} |
|
|
|
- (void)setUpEvent { |
|
|
|
for (UILabel *lab in _weekLabelArr) { |
|
UITapGestureRecognizer *uiTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapWeek:)]; |
|
[lab addGestureRecognizer:uiTap]; |
|
} |
|
|
|
for (UILabel *lab in _lessionLabelArr) { |
|
UITapGestureRecognizer *uiTap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapLession:)]; |
|
[lab addGestureRecognizer:uiTap2]; |
|
} |
|
|
|
} |
|
|
|
- (void)tapWeek:(UITapGestureRecognizer *)param{ |
|
[self resetWeek]; |
|
UILabel *lab = (UILabel *)param.view; |
|
lab.backgroundColor = mainColor; |
|
lab.textColor = [UIColor whiteColor]; |
|
lab.layer.borderColor = [UIColor whiteColor].CGColor; |
|
_curWeek = lab.tag; |
|
|
|
NSLog(@"week = %zd",_curWeek); |
|
} |
|
|
|
- (void)tapLession:(UITapGestureRecognizer *)param{ |
|
[self resetLession]; |
|
|
|
UILabel *lab = (UILabel *)param.view; |
|
lab.backgroundColor = mainColor; |
|
lab.textColor = [UIColor whiteColor]; |
|
lab.layer.borderColor = [UIColor whiteColor].CGColor; |
|
_curLession = lab.tag; |
|
|
|
NSLog(@"lession = %zd", _curLession); |
|
} |
|
|
|
- (void) resetWeek { |
|
for (UILabel *label in _weekLabelArr) { |
|
label.textColor = [UIColor blackColor]; |
|
label.backgroundColor = [UIColor whiteColor]; |
|
label.layer.backgroundColor = [UIColor whiteColor].CGColor; |
|
label.layer.borderColor = RGB(240, 240, 240).CGColor; |
|
} |
|
} |
|
|
|
- (void) resetLession { |
|
for (UILabel *label in _lessionLabelArr) { |
|
label.textColor = [UIColor blackColor]; |
|
label.backgroundColor = [UIColor whiteColor]; |
|
label.layer.backgroundColor = [UIColor whiteColor].CGColor; |
|
label.layer.borderColor = RGB(240, 240, 240).CGColor; |
|
} |
|
} |
|
|
|
|
|
@end
|
|
|