|
|
// |
|
|
// RailListTableViewCell.m |
|
|
// tongxin |
|
|
// |
|
|
// Created by ecell on 2023/5/16. |
|
|
// Copyright © 2023 xTT. All rights reserved. |
|
|
// |
|
|
|
|
|
#import "RailListTableViewCell.h" |
|
|
|
|
|
@interface RailListTableViewCell () |
|
|
/** |
|
|
围栏地址 名称 eg : 学校 |
|
|
*/ |
|
|
@property (weak, nonatomic) UILabel *railNameLabel; |
|
|
/** |
|
|
规则 rg : 8:00-12:00,工作日 |
|
|
*/ |
|
|
@property (weak, nonatomic) UILabel *ruleLabel; |
|
|
/** |
|
|
地址 eg: 北京市朝阳区 .... |
|
|
*/ |
|
|
@property (weak, nonatomic) UILabel *addressLabel; |
|
|
|
|
|
|
|
|
/** |
|
|
范围 的距离显示 eg: 电子围栏 500米 |
|
|
*/ |
|
|
@property (weak, nonatomic) UILabel *railRangeLabel; |
|
|
|
|
|
|
|
|
/** |
|
|
删除按钮 |
|
|
*/ |
|
|
@property (weak, nonatomic) UIButton *delectBtn; |
|
|
|
|
|
/** |
|
|
编辑按钮 |
|
|
*/ |
|
|
@property (weak, nonatomic) UIButton *editingBtn; |
|
|
|
|
|
|
|
|
@property (nonatomic ,weak) UISwitch *uiSwitch; |
|
|
|
|
|
@end |
|
|
|
|
|
@implementation RailListTableViewCell |
|
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier |
|
|
{ |
|
|
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; |
|
|
if (self) |
|
|
{ |
|
|
self.selectionStyle = UITableViewCellSelectionStyleNone; |
|
|
self.backgroundColor = KKWhiteColorColor; |
|
|
self.layer.cornerRadius = 12; |
|
|
self.layer.masksToBounds = YES; |
|
|
[self subCellView]; |
|
|
} |
|
|
|
|
|
return self; |
|
|
} |
|
|
|
|
|
- (void)subCellView |
|
|
{ |
|
|
WEAKSELF |
|
|
UILabel *railNameLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(12) textColor:mainColor text:@"" Radius:10]; |
|
|
self.railNameLabel = railNameLabel; |
|
|
[self.contentView addSubview:railNameLabel]; |
|
|
[railNameLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
make.left.equalTo(self.contentView).offset(15); |
|
|
make.top.equalTo(self.contentView.mas_top).offset(15); |
|
|
make.size.mas_equalTo(CGSizeMake(28, 20)); |
|
|
}]; |
|
|
|
|
|
UILabel *railRangeLabel = [UICommon ui_label:CGRectZero lines:1 align:NSTextAlignmentLeft font:Font_(12) textColor:KKGrey102 text:@"" Radius:0]; |
|
|
self.railRangeLabel = railRangeLabel; |
|
|
[self.contentView addSubview:railRangeLabel]; |
|
|
[railRangeLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
make.left.equalTo(railNameLabel.mas_right).offset(4); |
|
|
make.centerY.equalTo(railNameLabel); |
|
|
//make.right.equalTo(self.contentView.mas_right).inset(15); |
|
|
}]; |
|
|
|
|
|
UILabel *addressLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontBold_(16) textColor:KKBlack20 text:@"" Radius:0]; |
|
|
self.addressLabel = addressLabel; |
|
|
[self.contentView addSubview:addressLabel]; |
|
|
[addressLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
make.left.right.equalTo(self.contentView).inset(15); |
|
|
make.top.equalTo(railNameLabel.mas_bottom).offset(10); |
|
|
}]; |
|
|
|
|
|
UILabel *ruleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:Font_(12) textColor:KKGrey163 text:@"" Radius:0]; |
|
|
self.ruleLabel = ruleLabel; |
|
|
[self.contentView addSubview:ruleLabel]; |
|
|
[ruleLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
make.left.right.equalTo(self.contentView).inset(15); |
|
|
make.top.equalTo(addressLabel.mas_bottom).offset(16); |
|
|
}]; |
|
|
|
|
|
UIView *line = [UIView new]; |
|
|
line.backgroundColor = RGB(240, 240, 240); |
|
|
[self.contentView addSubview:line]; |
|
|
[line mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
make.left.right.equalTo(self.contentView).inset(15); |
|
|
make.top.equalTo(ruleLabel.mas_bottom).offset(15); |
|
|
make.height.mas_equalTo(0.5); |
|
|
}]; |
|
|
|
|
|
UISwitch *uiSwitch = [[UISwitch alloc] init]; |
|
|
[uiSwitch addTarget:self |
|
|
action:@selector(switchBtnAction:) |
|
|
forControlEvents:UIControlEventValueChanged]; |
|
|
uiSwitch.onTintColor = mainColor; |
|
|
self.uiSwitch = uiSwitch; |
|
|
[self.contentView addSubview:uiSwitch]; |
|
|
[uiSwitch mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
make.right.equalTo(self.contentView.mas_right).inset(15); |
|
|
make.top.equalTo(line.mas_bottom).offset(15); |
|
|
make.size.mas_equalTo(CGSizeMake(48, 28)); |
|
|
make.bottom.equalTo(self.contentView.mas_bottom).inset(15); |
|
|
}]; |
|
|
|
|
|
UIButton *editingBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(14) normalColor:KKGrey102 normalText:@" 编辑" click:^(id x) { |
|
|
if (weakSelf.editingBlock) { |
|
|
weakSelf.editingBlock(); |
|
|
} |
|
|
}]; |
|
|
[editingBtn setImage:ImageName_(@"icon_editor_black") forState:0]; |
|
|
self.editingBtn = editingBtn; |
|
|
[self.contentView addSubview:editingBtn]; |
|
|
[editingBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
make.left.equalTo(railNameLabel); |
|
|
make.centerY.equalTo(uiSwitch); |
|
|
make.size.mas_equalTo(CGSizeMake(57, 24)); |
|
|
}]; |
|
|
|
|
|
UIButton *delectBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(14) normalColor:KKGrey102 normalText:@" 删除" click:^(id x) { |
|
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:@"确定删除【%@】?",self.model.name] style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { |
|
|
//删除 |
|
|
[weakSelf.model deleteSuccess:^{ |
|
|
if (weakSelf.deleteBlock) { |
|
|
weakSelf.deleteBlock(); |
|
|
} |
|
|
} failure:^{ |
|
|
|
|
|
}]; |
|
|
} cancelHandler:nil destructiveHandler:nil]; |
|
|
[alertView showAnimated:YES completionHandler:nil]; |
|
|
}]; |
|
|
[delectBtn setImage:ImageName_(@"icon_delect_black") forState:0]; |
|
|
self.delectBtn = delectBtn; |
|
|
[self.contentView addSubview:delectBtn]; |
|
|
[delectBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
|
make.left.equalTo(editingBtn.mas_right).offset(20); |
|
|
make.centerY.equalTo(uiSwitch); |
|
|
make.size.mas_equalTo(CGSizeMake(57, 24)); |
|
|
}]; |
|
|
|
|
|
} |
|
|
|
|
|
-(void)setModel:(Rail *)model |
|
|
{ |
|
|
_model = model; |
|
|
self.railNameLabel.text = model.name; |
|
|
self.railNameLabel.backgroundColor = [model.status boolValue] ? RGB(255, 243, 236) : RGB(240, 240, 240); |
|
|
self.railNameLabel.textColor = [model.status boolValue] ? mainColor : KKGrey163; |
|
|
CGRect ww = [UICommon GetTextWidth:model.name ViewHeight:20 fontSize:FontBold_(12) type:@"w"]; |
|
|
[self.railNameLabel mas_remakeConstraints:^(MASConstraintMaker *make) { |
|
|
make.left.equalTo(self.contentView).offset(15); |
|
|
make.top.equalTo(self.contentView).offset(15); |
|
|
make.size.mas_equalTo(CGSizeMake(ww.size.width+15, 20)); |
|
|
}]; |
|
|
|
|
|
self.railRangeLabel.text = [NSString stringWithFormat:@"安全范围:%@米",model.radius]; |
|
|
self.addressLabel.text = model.address; |
|
|
self.ruleLabel.text = [NSString stringWithFormat:@"%@-%@ %@",model.starttime,model.endedtime,[myHelper getWeekDayStr:model.week]]; |
|
|
|
|
|
self.uiSwitch.on = model.status.boolValue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
-(void)switchBtnAction:(UISwitch*)sender |
|
|
{ |
|
|
self.model.status = @(sender.on); |
|
|
[self.model saveSuccess:^{ |
|
|
self.model.status = @(sender.on); |
|
|
if(self.switchBlock){ |
|
|
self.switchBlock(); |
|
|
} |
|
|
} failure:^{ |
|
|
self.model.status = @(!sender.on); |
|
|
}]; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (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
|
|
|
|