// // ElectronicFenceTableViewCell.m // LekangGuard // // Created by ecell on 2022/12/12. // #import "ElectronicFenceTableViewCell.h" #import "AddRailViewController.h" @interface ElectronicFenceTableViewCell () /// 间隔线 @property (nonatomic ,weak) UIImageView *line; /// 地址 @property (nonatomic ,weak) UILabel *addressLabel; /// 时间 @property (nonatomic ,weak) UILabel *timeLabel; /// 地址标签 @property (nonatomic ,weak) UILabel *tagLabel; /// 范围 @property (nonatomic ,weak) UILabel *scopeLabel; /// 是否启用 @property (nonatomic ,weak) UIButton *openBtn; @end @implementation ElectronicFenceTableViewCell - (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)setRailModel:(SafetyRailModel *)railModel { _railModel = railModel; self.tagLabel.text = railModel.name; self.scopeLabel.text = F(GJText(@"当前范围%ld米"), railModel.radius); self.openBtn.selected = railModel.status; self.addressLabel.text = railModel.address; NSMutableArray *weekArr = [UICommon getWeekStr:railModel.week]; for (NSString *str in [UICommon getWeekStr:railModel.week]) { if (str.length <= 0) [weekArr removeObject:str]; } self.timeLabel.text = F(@"%@-%@,%@", railModel.startTime, railModel.endTime, [weekArr componentsJoinedByString:@"、"]); } - (void)subCellView { /// 地址标签 UILabel *tagLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(13) textColor:KKTextBlackColor text:@"" Radius:0]; self.tagLabel = tagLabel; [self.contentView addSubview:tagLabel]; [tagLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.mas_left).offset(15); make.top.equalTo(self.contentView.mas_top).offset(15); }]; /// 范围 UILabel *scopeLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(13) textColor:RGB(255, 173, 1) text:@"" Radius:0]; self.scopeLabel = scopeLabel; [self.contentView addSubview:scopeLabel]; [scopeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.contentView.mas_right).inset(15); make.centerY.equalTo(tagLabel); }]; /// 时间 UILabel *timeLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(13) textColor:KKGrey121 text:@"" Radius:0]; self.timeLabel = timeLabel; [self.contentView addSubview:timeLabel]; [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(tagLabel.mas_left); make.right.equalTo(self.contentView.mas_right).inset(15); make.top.equalTo(tagLabel.mas_bottom).offset(10); }]; /// 地址 UILabel *addressLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(13) textColor:KKTextBlackColor text:@"" Radius:0]; self.addressLabel = addressLabel; [self.contentView addSubview:addressLabel]; [addressLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(tagLabel.mas_left); make.right.equalTo(self.contentView.mas_right).inset(15); make.top.equalTo(timeLabel.mas_bottom).offset(10); }]; /// 间隔线 UIImageView *line = [UIImageView new]; line.backgroundColor = KKBackgroundGrey; self.line = line; [self.contentView addSubview:line]; [line mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.contentView).inset(15); make.top.equalTo(addressLabel.mas_bottom).offset(10); make.height.mas_equalTo(0.5); }]; /// 是否启用 UIButton *openBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKMainColor normalText:@"" click:^(UIButton *btn) { btn.selected = !btn.selected; [self updateRailStatus]; }]; [openBtn setTitle:GJText(@"启用") forState:UIControlStateNormal]; [openBtn setTitle:GJText(@"已启用") forState:UIControlStateSelected]; [openBtn setTitleColor:KKTextBlackColor forState:UIControlStateNormal]; [openBtn setTitleColor:KKMainColor forState:UIControlStateSelected]; [openBtn setImage:ImageName_(@"icon_no_the_selected") forState:UIControlStateNormal]; [openBtn setImage:ImageName_(@"icon_the_selected") forState:UIControlStateSelected]; openBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [openBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)]; self.openBtn = openBtn; [self.contentView addSubview:openBtn]; [openBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(tagLabel.mas_left); make.top.equalTo(line.mas_bottom).offset(15); make.bottom.equalTo(self.contentView.mas_bottom).inset(15); make.size.mas_equalTo(CGSizeMake(100, 17)); }]; /// 删除 UIButton *deleteBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKTextBlackColor normalText:GJText(@"删除") click:^(id x) { self.isEditAndDeleteModel(self.railModel, 1); }]; [deleteBtn setImage:ImageName_(@"icon_delect_black") forState:UIControlStateNormal]; [deleteBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)]; CGRect rect = [UICommon GetTextWidth:deleteBtn.currentTitle ViewHeight:17 fontSize:FontADA_(13) type:@"w"]; [self.contentView addSubview:deleteBtn]; [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.contentView.mas_right).inset(10); make.centerY.equalTo(openBtn); make.size.mas_equalTo(CGSizeMake(Adapted(rect.size.width)+deleteBtn.currentImage.size.width, 17)); }]; /// 编辑 UIButton *editBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKTextBlackColor normalText:GJText(@"编辑") click:^(id x) { self.isEditAndDeleteModel(self.railModel, 2); }]; [editBtn setImage:ImageName_(@"icon_editor_black") forState:UIControlStateNormal]; [editBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)]; CGRect rect1 = [UICommon GetTextWidth:editBtn.currentTitle ViewHeight:17 fontSize:FontADA_(13) type:@"w"]; [self.contentView addSubview:editBtn]; [editBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(deleteBtn.mas_left).inset(10); make.centerY.equalTo(openBtn); make.size.mas_equalTo(CGSizeMake(Adapted(rect1.size.width+editBtn.currentImage.size.width)+5, 17)); }]; } #pragma mark 修改电子围栏启用状态 /// 修改电子围栏启用状态 - (void)updateRailStatus { NSInteger status = self.openBtn.selected == YES ? 1 : 0; [UICommon MessageUpload:@"加载中"]; NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; [parameters setValue:self.railModel.Id forKey:@"id"]; [parameters setValue:@(status) forKey:@"status"]; [[[APIManager sharedManager] APPOST:updateRailStatus_URL parameters:parameters isJson:NO resultClass:nil] subscribeNext:^(id _Nullable x) { [UICommon HidenLoading]; [UICommon MessageSuccessText:@"设置成功"]; } 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