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.
220 lines
9.4 KiB
220 lines
9.4 KiB
![]()
2 years ago
|
//
|
||
|
// AddClockAdnOtherViewController.m
|
||
|
// LekangGuard
|
||
|
//
|
||
|
// Created by ecell on 2022/12/5.
|
||
|
//
|
||
|
|
||
|
#import "AddClockAdnOtherViewController.h"
|
||
|
|
||
|
@interface AddClockAdnOtherViewController ()
|
||
|
|
||
|
/// 闹钟时间
|
||
|
@property (nonatomic ,weak) UIButton *timeBtn;
|
||
|
|
||
|
/// 闹钟标签
|
||
|
@property (nonatomic ,weak) UITextField *tagField;
|
||
|
|
||
|
@property (nonatomic ,strong) NSMutableArray *btnArr;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation AddClockAdnOtherViewController
|
||
|
|
||
|
- (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 SetaddAlarm];
|
||
|
}];
|
||
|
self.zx_navTitle = self.isRedact == 1 ? GJText(@"添加闹钟") : GJText(@"编辑闹钟");
|
||
|
|
||
|
|
||
|
NSArray *arr = @[GJText(@"标签"),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];
|
||
|
|
||
|
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 < arr.count)
|
||
|
{
|
||
|
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.top.equalTo(titleLabel.mas_bottom);
|
||
|
make.height.mas_equalTo(0.5);
|
||
|
}];
|
||
|
}
|
||
|
if (i == 0)
|
||
|
{
|
||
|
UIImageView *rightImg = [UICommon ui_imageView:CGRectZero fileName:@"icon_enter_gray"];
|
||
|
[bgView addSubview:rightImg];
|
||
|
[rightImg mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.right.equalTo(bgView.mas_right).inset(15);
|
||
|
make.centerY.equalTo(titleLabel);
|
||
|
make.size.mas_equalTo(rightImg.image.size);
|
||
|
}];
|
||
|
|
||
|
UITextField *textfield = [UICommon ui_textField:CGRectZero textColor:KKTextBlackColor backColor:KKClearColor font:FontADA_(13) maxTextNum:20 placeholderColor:KKGrey143 placeholder:@"" toMaxNum:^(UITextField *textField) {
|
||
|
|
||
|
} change:^(UITextField *textField) {
|
||
|
|
||
|
}];
|
||
|
textfield.text = self.isRedact == 2 ? self.alarmModel.tag : GJText(@"闹钟");
|
||
|
textfield.textAlignment = NSTextAlignmentRight;
|
||
|
self.tagField = textfield;
|
||
|
[bgView addSubview:textfield];
|
||
|
[textfield mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.right.equalTo(rightImg.mas_left).inset(5);
|
||
|
make.centerY.equalTo(titleLabel);
|
||
|
make.size.mas_equalTo(CGSizeMake(Adapted(100), Adapted(44)));
|
||
|
}];
|
||
|
}
|
||
|
else if (i == 1)
|
||
|
{
|
||
|
UIButton *timeBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKTextBlackColor normalText:self.isRedact == 2 ? self.alarmModel.alarmTime : @"08:00" click:^(id x) {
|
||
|
[UICommon resignKeyboard];
|
||
|
[BRDatePickerView showDatePickerWithMode:BRDatePickerModeHM title:GJText(@"选择时间") selectValue:self.timeBtn.currentTitle minDate:nil maxDate:nil isAutoSelect:NO resultBlock:^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
|
||
|
[self.timeBtn setTitle:selectValue forState:0];
|
||
|
}];
|
||
|
}];
|
||
|
timeBtn.layer.borderWidth = 0.5;
|
||
|
timeBtn.layer.borderColor = KKGrey219.CGColor;
|
||
|
timeBtn.layer.cornerRadius = Adapted(16);
|
||
|
self.timeBtn = timeBtn;
|
||
|
[bgView addSubview:timeBtn];
|
||
|
[timeBtn 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)));
|
||
|
}];
|
||
|
}
|
||
|
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)SetaddAlarm
|
||
|
{
|
||
|
if (self.tagField.text.length <= 0)
|
||
|
{
|
||
|
[UICommon MessageErrorText:@"标签不能为空"];
|
||
|
return;
|
||
|
}
|
||
|
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.timeBtn.currentTitle forKey:@"alarmTime"];
|
||
|
[parameters setValue:[self.btnArr componentsJoinedByString:@""] forKey:@"alarmWeek"];
|
||
|
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"];
|
||
|
[parameters setValue:self.tagField.text forKey:@"tag"];
|
||
|
if (self.isRedact == 2)
|
||
|
[parameters setValue:self.alarmModel.Id forKey:@"id"];
|
||
|
[[[APIManager sharedManager] APPOST:self.isRedact == 2 ? UpdateAlarm_URL : AddAlarm_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
|