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.
 
 
 
 

150 lines
5.3 KiB

//
// RailListCell.m
// tongxin
//
// Created by WeiChaoZheng on 2018/8/17.
// Copyright © 2018年 xTT. All rights reserved.
//
#import "RailListCell.h"
#import "CommonPopView.h"
@interface RailListCell ()
@property (nonatomic ,weak) UISwitch *uiSwitch;
@end
@implementation RailListCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
self.addressLabel.textColor = KKBlack20;
self.addressLabel.font = FontBold_(16);
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.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));
}];
[self.railRangeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.railNameLabel.mas_right).offset(10);
make.centerY.equalTo(self.railNameLabel);
//make.right.equalTo(self.contentView.mas_right).inset(15);
}];
[self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.contentView).inset(15);
make.top.equalTo(self.railNameLabel.mas_bottom).offset(10);
}];
[self.ruleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.contentView).inset(15);
make.top.equalTo(self.addressLabel.mas_bottom).offset(16);
}];
[self.line mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.contentView).inset(15);
make.top.equalTo(self.ruleLabel.mas_bottom).offset(15);
make.height.mas_equalTo(0.5);
}];
UISwitch *uiSwitch = [[UISwitch alloc] init];
[uiSwitch addTarget:self
action:@selector(cellClick:)
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(self.line.mas_bottom).offset(15);
make.size.mas_equalTo(CGSizeMake(48, 28));
make.bottom.equalTo(self.contentView.mas_bottom).inset(15);
}];
[self.editingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.railNameLabel);
make.centerY.equalTo(self.uiSwitch);
make.size.mas_equalTo(CGSizeMake(60, 24));
}];
[self.delectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.editingBtn.mas_right).offset(24);
make.centerY.equalTo(self.uiSwitch);
make.size.mas_equalTo(CGSizeMake(60, 24));
}];
self.railRangeLabel.textColor = mainColor;
self.railNameLabel.font = Font_(12);
[self.editingBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
[self.delectBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
self.contentView.backgroundColor = [UIColor clearColor];
self.backgroundColor = [UIColor clearColor];
}
-(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:Font_(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.textColor = mainColor;
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)btnAction:(UIButton*)sender{
if([sender.titleLabel.text isEqualToString:@"编辑"]){
if (self.editingBlock) {
self.editingBlock();
}
}else{
WEAKSELF
CommonPopView *popView = [CommonPopView new];
[popView subPopView:popViewType_ycgj PopTitle:@"提示" PopText:[NSString stringWithFormat:@"确定删除【%@】?",self.model.name] okTouchBlock:^{
//删除
[weakSelf.model deleteSuccess:^{
if (weakSelf.deleteBlock) {
weakSelf.deleteBlock();
}
} failure:^{
}];
}];
}
}
-(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)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end