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.
174 lines
5.6 KiB
174 lines
5.6 KiB
// |
|
// ClockAndOtherTableViewCell.m |
|
// LekangGuard |
|
// |
|
// Created by ecell on 2022/12/5. |
|
// |
|
|
|
#import "ClockAndOtherTableViewCell.h" |
|
|
|
|
|
@interface ClockAndOtherTableViewCell () |
|
|
|
/// 事件 |
|
@property (nonatomic ,weak) UILabel *timeLabel; |
|
|
|
/// 星期 |
|
@property (nonatomic ,weak) UILabel *weekLabel; |
|
|
|
/// 开关 |
|
@property (nonatomic ,weak) UISwitch *customSwitch; |
|
|
|
@end |
|
@implementation ClockAndOtherTableViewCell |
|
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier |
|
{ |
|
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; |
|
if (self) |
|
{ |
|
self.selectionStyle = UITableViewCellSelectionStyleNone; |
|
self.backgroundColor = KKWhiteColorColor; |
|
[self subCellView]; |
|
} |
|
|
|
return self; |
|
} |
|
|
|
- (void)setViewType:(NSInteger)viewType |
|
{ |
|
_viewType = viewType; |
|
} |
|
|
|
- (void)setRows:(NSInteger)rows |
|
{ |
|
_rows = rows; |
|
} |
|
|
|
- (void)setAlarmModel:(AlarmModel *)alarmModel |
|
{ |
|
_alarmModel = alarmModel; |
|
[self.customSwitch setOn:alarmModel.alarmStatus]; |
|
NSMutableArray *weekArr = [UICommon getWeekStr:alarmModel.alarmWeek]; |
|
for (NSString *str in [UICommon getWeekStr:alarmModel.alarmWeek]) |
|
{ |
|
if (str.length <= 0) |
|
[weekArr removeObject:str]; |
|
} |
|
|
|
if (weekArr.count == 2 && |
|
[weekArr[0] isEqualToString:@"周六"] && |
|
[weekArr[1] isEqualToString:@"周日"]) |
|
self.weekLabel.text = GJText(@"周末"); |
|
else if (weekArr.count == 5 && |
|
[weekArr[0] isEqualToString:@"周一"] && |
|
[weekArr[1] isEqualToString:@"周二"] && |
|
[weekArr[2] isEqualToString:@"周三"] && |
|
[weekArr[3] isEqualToString:@"周四"] && |
|
[weekArr[4] isEqualToString:@"周五"]) |
|
self.weekLabel.text = GJText(@"工作日"); |
|
else if (weekArr.count == 7 && |
|
[weekArr[0] isEqualToString:@"周一"] && |
|
[weekArr[1] isEqualToString:@"周二"] && |
|
[weekArr[2] isEqualToString:@"周三"] && |
|
[weekArr[3] isEqualToString:@"周四"] && |
|
[weekArr[4] isEqualToString:@"周五"] && |
|
[weekArr[5] isEqualToString:@"周六"] && |
|
[weekArr[6] isEqualToString:@"周日"]) |
|
self.weekLabel.text = GJText(@"每天"); |
|
else |
|
self.weekLabel.text = F(@"%@", [weekArr componentsJoinedByString:@"、"]); |
|
|
|
if (self.viewType == 1) |
|
{ |
|
self.timeLabel.text = F(@"%@ | %@",alarmModel.alarmTime,alarmModel.tag); |
|
} |
|
else |
|
{ |
|
self.timeLabel.text = F(@"%@-%@", alarmModel.alarmStartTime,alarmModel.alarmEndTime); |
|
// self.weekLabel.text = F(@"%@", [weekArr componentsJoinedByString:@"、"]); |
|
} |
|
} |
|
|
|
- (void)subCellView |
|
{ |
|
UILabel *timeLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBoldADA_(20) textColor:KKTextBlackColor text:@"" Radius:0]; |
|
self.timeLabel = timeLabel; |
|
[self.contentView addSubview:timeLabel]; |
|
[timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(self.contentView).offset(15); |
|
make.top.equalTo(self.contentView).offset(5); |
|
}]; |
|
|
|
UISwitch *customSwitch = [[UISwitch alloc] init]; |
|
[customSwitch setOnTintColor:KKMainColor]; |
|
[customSwitch addTarget:self action:@selector(switchChange:) forControlEvents:UIControlEventValueChanged]; |
|
self.customSwitch = customSwitch; |
|
[self.contentView addSubview:customSwitch]; |
|
[customSwitch mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(self.contentView.mas_right).inset(15); |
|
make.centerY.equalTo(self.contentView); |
|
make.size.mas_equalTo(CGSizeMake(Adapted(45), Adapted(40))); |
|
}]; |
|
|
|
UILabel *weekLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(18) textColor:KKGrey121 text:@"" Radius:0]; |
|
self.weekLabel = weekLabel; |
|
[self.contentView addSubview:weekLabel]; |
|
[weekLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(self.contentView).offset(15); |
|
make.right.equalTo(customSwitch.mas_left).inset(15); |
|
make.top.equalTo(timeLabel.mas_bottom).offset(10); |
|
make.bottom.equalTo(self.contentView.mas_bottom).inset(10); |
|
}]; |
|
} |
|
|
|
|
|
/** |
|
* 按钮切换事件监听回调方法 |
|
*/ |
|
- (void) switchChange:(UISwitch*)sw |
|
{ |
|
if(sw.on == YES) { |
|
NSLog(@"开关切换为开"); |
|
} else if(sw.on == NO) { |
|
NSLog(@"开关切换为关"); |
|
} |
|
[self updateAlarmStatus:sw.on]; |
|
} |
|
|
|
|
|
#pragma mark 修改闹钟状态 |
|
/// 修改闹钟状态 |
|
- (void)updateAlarmStatus:(BOOL)alarmStatus |
|
{ |
|
NSInteger value = alarmStatus ? 1 : 0; |
|
[UICommon MessageUpload:@"加载中"]; |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[parameters setValue:@(value) forKey:@"alarmStatus"]; |
|
[parameters setValue:self.alarmModel.Id forKey:@"id"]; |
|
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"]; |
|
[[[APIManager sharedManager] APPOST:self.viewType == 1 ? UpdateAlarmStatus_URL : StatusDisabled_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) { |
|
[UICommon HidenLoading]; |
|
[UICommon MessageSuccessText:@"修改成功"]; |
|
self.isUpdataSucceed(self.rows, alarmStatus); |
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
|
|
|
|
- (void)awakeFromNib { |
|
[super awakeFromNib]; |
|
// Initialization code |
|
} |
|
|
|
- (void)setSelected:(BOOL)selected animated:(BOOL)animated { |
|
[super setSelected:selected animated:animated]; |
|
|
|
// Configure the view for the selected state |
|
} |
|
|
|
@end
|
|
|