// // AddAttendClassAlarmViewController.m // LekangGuard // // Created by ecell on 2022/12/6. // #import "AddAttendClassAlarmViewController.h" @interface AddAttendClassAlarmViewController () /// 开始时间 @property (nonatomic ,weak) UIButton *startTime; /// 结束时间 @property (nonatomic ,weak) UIButton *endTime; @property (nonatomic ,strong) NSMutableArray *btnArr; @end @implementation AddAttendClassAlarmViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = KKBackgroundGrey; [self zx_setRightBtnWithText:GJText(@"保存") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) { [self addAndUpdataDisabled]; }]; self.zx_navTitle = self.isRedact == 1 ? GJText(@"添加上课禁用") : GJText(@"编辑上课禁用"); NSArray *arr = @[GJText(@"时间"),GJText(@"星期")]; NSArray *timeArr = @[GJText(@"一"),GJText(@"二"),GJText(@"三"),GJText(@"四"),GJText(@"五"),GJText(@"六"),GJText(@"日")]; UIView *bgView = [UICommon ui_view:CGRectMake(0, iPhoneX_NavHeight, SCREEN_WIDTH, Adapted(55)*arr.count) backgroundColor:KKWhiteColorColor cornerRadius:0 borderWidth:0 borderColor:KKWhiteColorColor]; [self.view addSubview:bgView]; UIImageView *line = [UIImageView new]; line.backgroundColor = KKLineColor; [bgView addSubview:line]; [line mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(bgView).offset(15); make.right.equalTo(bgView.mas_right); make.centerY.equalTo(bgView); make.height.mas_equalTo(0.5); }]; UILabel *headerTitle = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(12) textColor:KKGrey121 text:@"" Radius:0]; headerTitle.text = GJText(@"提示:可设置上课时段禁用,禁用时段开启后,设备将只有SOS呼救功能可使用,其他功能不能使用."); [self.view addSubview:headerTitle]; [headerTitle mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.view).inset(15); make.top.equalTo(bgView.mas_bottom).offset(Adapted(20)); }]; for (int i = 0; i < arr.count; i++) { UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(14) textColor:KKTextBlackColor text:arr[i] Radius:0]; [bgView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view).offset(15); make.top.equalTo(bgView).offset(i*Adapted(55)); make.height.mas_equalTo(Adapted(55)); }]; if (i == 0) { UIButton *endTime = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKTextBlackColor normalText:self.isRedact == 2 ? self.alarmModel.alarmEndTime : @"17:00" click:^(id x) { [UICommon resignKeyboard]; [BRDatePickerView showDatePickerWithMode:BRDatePickerModeHM title:GJText(@"选择结束时间") selectValue:self.endTime.currentTitle minDate:nil maxDate:nil isAutoSelect:NO resultBlock:^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) { [self.endTime setTitle:selectValue forState:0]; }]; }]; endTime.layer.borderWidth = 0.5; endTime.layer.borderColor = KKGrey219.CGColor; endTime.layer.cornerRadius = Adapted(16); self.endTime = endTime; [bgView addSubview:endTime]; [endTime mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(bgView.mas_right).inset(15); make.centerY.equalTo(titleLabel); make.size.mas_equalTo(CGSizeMake(Adapted(60), Adapted(32))); }]; UIImageView *line1 = [UIImageView new]; line1.backgroundColor = KKGrey219; [bgView addSubview:line1]; [line1 mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(endTime.mas_left).inset(5); make.centerY.equalTo(endTime); make.size.mas_equalTo(CGSizeMake(Adapted(15), 0.5)); }]; UIButton *startTime = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKTextBlackColor normalText:self.isRedact == 2 ? self.alarmModel.alarmStartTime : @"08:00" click:^(id x) { [UICommon resignKeyboard]; [BRDatePickerView showDatePickerWithMode:BRDatePickerModeHM title:GJText(@"选择开始时间") selectValue:self.startTime.currentTitle minDate:nil maxDate:nil isAutoSelect:NO resultBlock:^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) { [self.startTime setTitle:selectValue forState:0]; }]; }]; startTime.layer.borderWidth = 0.5; startTime.layer.borderColor = KKGrey219.CGColor; startTime.layer.cornerRadius = Adapted(16); self.startTime = startTime; [bgView addSubview:startTime]; [startTime mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(line1.mas_left).inset(5); make.centerY.equalTo(titleLabel); make.size.mas_equalTo(CGSizeMake(Adapted(60), Adapted(32))); }]; } else { if (self.isRedact == 2) self.btnArr = [self getWeekArr:self.alarmModel.alarmWeek]; else self.btnArr = [[NSMutableArray alloc] initWithArray:@[@"1",@"1",@"1",@"1",@"1",@"0",@"0"]]; for (int j = 0; j < timeArr.count; j++) { CGRect rect = [timeArr[j] boundingRectWithSize:CGSizeMake(MAXFLOAT, Adapted(32)) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:FontADA_(13)} context:nil]; CGFloat ww = 32; if (rect.size.width > 32) ww = rect.size.width+10; UIButton *button = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKTextBlackColor normalText:timeArr[j] click:^(UIButton *btn) { btn.selected = !btn.selected; btn.backgroundColor = btn.selected ? KKMainColor : KKClearColor; btn.layer.borderColor = btn.selected ? KKMainColor.CGColor : KKGrey219.CGColor; NSString *str = btn.selected ? @"1" : @"0"; [self.btnArr replaceObjectAtIndex:btn.tag withObject:str]; NSLog(@"%@",self.btnArr); }]; if (self.isRedact == 2) button.selected = [self.btnArr[j] isEqualToString:@"1"] ? YES : NO; else button.selected = j < 5 ? YES : NO; button.tag = j; button.layer.borderWidth = 0.5; button.layer.borderColor = button.selected ? KKMainColor.CGColor : KKGrey219.CGColor; button.layer.cornerRadius = Adapted(16); button.backgroundColor = button.selected ? KKMainColor : KKClearColor; [button setTitleColor:KKTextBlackColor forState:UIControlStateNormal]; [button setTitleColor:KKWhiteColorColor forState:UIControlStateSelected]; [bgView addSubview:button]; [button mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(titleLabel); make.size.mas_equalTo(CGSizeMake(Adapted(ww), Adapted(32))); make.left.equalTo(titleLabel.mas_right).offset(Adapted(20)+Adapted(10)*j+Adapted(ww)*j); }]; } } } } #pragma mark 添加或修改上课禁用 /// 添加或修改上课禁用 - (void)addAndUpdataDisabled { BOOL isIs = NO; for (NSString *str in self.btnArr) { if ([str isEqualToString:@"1"]) isIs = YES; } if (!isIs) { [UICommon MessageErrorText:@"请选择星期"]; return; } [UICommon MessageUpload:@"加载中"]; NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; [parameters setValue:self.endTime.currentTitle forKey:@"alarmEndTime"]; [parameters setValue:self.startTime.currentTitle forKey:@"alarmStartTime"]; [parameters setValue:[self.btnArr componentsJoinedByString:@""] forKey:@"alarmWeek"]; [parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"]; if (self.isRedact == 2) [parameters setValue:self.alarmModel.Id forKey:@"id"]; [[[APIManager sharedManager] APPOST:self.isRedact == 1 ? AddDisabled_URL : UpdataDisabled_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) { [UICommon HidenLoading]; [UICommon MessageSuccessText:self.isRedact == 2 ? @"修改成功" : @"新增成功"]; self.isUpdataMsg(); AfterDispatch(1, ^{ [self.navigationController popViewControllerAnimated:YES]; }); } error:^(NSError * _Nullable error) { NSDictionary *dic = error.userInfo; [UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; }]; } - (NSMutableArray *)getWeekArr:(NSString *)string { NSMutableArray *weekArr = [NSMutableArray arrayWithArray:@[@"",@"",@"",@"",@"",@"",@""]]; [string enumerateSubstringsInRange:NSMakeRange(0, string.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) { [weekArr replaceObjectAtIndex:substringRange.location withObject:substring]; }]; return weekArr; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end