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.
283 lines
13 KiB
283 lines
13 KiB
![]()
2 years ago
|
//
|
||
|
// AddRailViewController.m
|
||
|
// LekangGuard
|
||
|
//
|
||
|
// Created by ecell on 2022/12/12.
|
||
|
//
|
||
|
|
||
|
#import "AddRailViewController.h"
|
||
|
#import "RailNameTagViewController.h"
|
||
|
#import "RailAddressViewController.h"
|
||
|
|
||
|
@interface AddRailViewController ()
|
||
|
|
||
|
/// 地址标签
|
||
|
@property (nonatomic ,weak) UIButton *nameBtn;
|
||
|
|
||
|
/// 详细地址
|
||
|
@property (nonatomic ,weak) UIButton *addressBtn;
|
||
|
|
||
|
/// 开始时间
|
||
|
@property (nonatomic ,weak) UIButton *startTime;
|
||
|
|
||
|
/// 结束时间
|
||
|
@property (nonatomic ,weak) UIButton *endTime;
|
||
|
|
||
|
|
||
|
@property (nonatomic ,strong) NSMutableArray *btnArr;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation AddRailViewController
|
||
|
|
||
|
- (void)viewDidLoad {
|
||
|
[super viewDidLoad];
|
||
|
// Do any additional setup after loading the view.
|
||
|
|
||
|
self.zx_navTitle = self.isRedact == 1 ? GJText(@"添加电子围栏") : GJText(@"编辑电子围栏");
|
||
|
if (self.isRedact == 1)
|
||
|
self.railModel = [[SafetyRailModel alloc] init];
|
||
|
|
||
|
[self zx_setRightBtnWithText:GJText(@"保存") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
|
||
|
[self AddRails];
|
||
|
}];
|
||
|
|
||
|
kWeakSelf(self)
|
||
|
|
||
|
NSArray *arr = @[GJText(@"地址名称"),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 < 2)
|
||
|
{
|
||
|
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(CGSizeMake(Adapted(rightImg.image.size.width), Adapted(rightImg.image.size.height)));
|
||
|
}];
|
||
|
NSString *text;
|
||
|
if (i == 0)
|
||
|
text = self.isRedact == 1 ? GJText(@"请设置地址名称") : self.railModel.name;
|
||
|
else
|
||
|
text = self.isRedact == 1 ? GJText(@"请设置详细地址") : self.railModel.address;
|
||
|
UIButton *rightBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:self.isRedact == 1 ? KKGrey121 : KKTextBlackColor normalText:text click:^(UIButton *btn) {
|
||
|
if (btn.tag == 0)
|
||
|
{
|
||
|
RailNameTagViewController *vc = [RailNameTagViewController new];
|
||
|
vc.addressName = weakself.nameBtn.currentTitle;
|
||
|
vc.isAddressName = ^(NSString * _Nonnull name) {
|
||
|
[weakself.nameBtn setTitle:name forState:0];
|
||
|
self.railModel.name = name;
|
||
|
[weakself.nameBtn setTitleColor:KKTextBlackColor forState:0];
|
||
|
};
|
||
|
[weakself.navigationController pushViewController:vc animated:YES];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
RailAddressViewController *vc = [RailAddressViewController new];
|
||
|
vc.railModel = self.railModel;
|
||
|
vc.isRedact = self.isRedact;
|
||
|
vc.isAddressModel = ^(SafetyRailModel * _Nonnull model) {
|
||
|
[weakself.addressBtn setTitle:model.address forState:0];
|
||
|
self.railModel.address = model.address;
|
||
|
self.railModel.lat = model.lat;
|
||
|
self.railModel.lon = model.lon;
|
||
|
self.railModel.radius = model.radius;
|
||
|
[weakself.addressBtn setTitleColor:KKTextBlackColor forState:0];
|
||
|
};
|
||
|
[self.navigationController pushViewController:vc animated:YES];
|
||
|
}
|
||
|
}];
|
||
|
rightBtn.tag = i;
|
||
|
rightBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
|
||
|
if (i == 0) self.nameBtn = rightBtn;
|
||
|
else self.addressBtn = rightBtn;
|
||
|
[bgView addSubview:rightBtn];
|
||
|
[rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.right.equalTo(rightImg.mas_left).inset(5);
|
||
|
make.centerY.equalTo(titleLabel);
|
||
|
make.left.equalTo(bgView).offset(100);
|
||
|
make.height.mas_equalTo(Adapted(48));
|
||
|
}];
|
||
|
|
||
|
}
|
||
|
else if (i == 2)
|
||
|
{
|
||
|
UIButton *endTime = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKTextBlackColor normalText:self.isRedact == 2 ? self.railModel.endTime : @"17:00" click:^(id x) {
|
||
|
|
||
|
[BRDatePickerView showDatePickerWithMode:BRDatePickerModeHM title:GJText(@"选择结束时间") selectValue:self.endTime.currentTitle minDate:nil maxDate:nil isAutoSelect:NO resultBlock:^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
|
||
|
[weakself.endTime setTitle:selectValue forState:0];
|
||
|
}];
|
||
|
}];
|
||
|
endTime.layer.borderWidth = 0.5;
|
||
|
endTime.layer.borderColor = KKGrey219.CGColor;
|
||
|
endTime.layer.cornerRadius = Adapted(16);
|
||
|
self.endTime = endTime;
|
||
|
[bgView addSubview:endTime];
|
||
|
[endTime 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)));
|
||
|
}];
|
||
|
|
||
|
UIImageView *line1 = [UIImageView new];
|
||
|
line1.backgroundColor = KKGrey219;
|
||
|
[bgView addSubview:line1];
|
||
|
[line1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.right.equalTo(endTime.mas_left).inset(5);
|
||
|
make.centerY.equalTo(endTime);
|
||
|
make.size.mas_equalTo(CGSizeMake(Adapted(15), 0.5));
|
||
|
}];
|
||
|
|
||
|
UIButton *startTime = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(13) normalColor:KKTextBlackColor normalText:self.isRedact == 2 ? self.railModel.startTime : @"08:00" click:^(id x) {
|
||
|
|
||
|
[BRDatePickerView showDatePickerWithMode:BRDatePickerModeHM title:GJText(@"选择开始时间") selectValue:self.startTime.currentTitle minDate:nil maxDate:nil isAutoSelect:NO resultBlock:^(NSDate * _Nullable selectDate, NSString * _Nullable selectValue) {
|
||
|
[weakself.startTime setTitle:selectValue forState:0];
|
||
|
}];
|
||
|
}];
|
||
|
startTime.layer.borderWidth = 0.5;
|
||
|
startTime.layer.borderColor = KKGrey219.CGColor;
|
||
|
startTime.layer.cornerRadius = Adapted(16);
|
||
|
self.startTime = startTime;
|
||
|
[bgView addSubview:startTime];
|
||
|
[startTime mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.right.equalTo(line1.mas_left).inset(5);
|
||
|
make.centerY.equalTo(titleLabel);
|
||
|
make.size.mas_equalTo(CGSizeMake(Adapted(60), Adapted(32)));
|
||
|
}];
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (self.isRedact == 2)
|
||
|
self.btnArr = [self getWeekArr:self.railModel.week];
|
||
|
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);
|
||
|
}];
|
||
|
}
|
||
|
}
|
||
|
if (i < arr.count-1)
|
||
|
{
|
||
|
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);
|
||
|
}];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
#pragma mark 新增电子围栏
|
||
|
/// 新增电子围栏
|
||
|
- (void)AddRails
|
||
|
{
|
||
|
if (self.nameBtn.currentTitle <= 0)
|
||
|
{
|
||
|
[UICommon MessageErrorText:@"请设置地址名称"];
|
||
|
return;
|
||
|
}
|
||
|
if (self.addressBtn.currentTitle <= 0)
|
||
|
{
|
||
|
[UICommon MessageErrorText:@"请设置详细地址"];
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
[UICommon MessageUpload:@"加载中"];
|
||
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||
|
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"];
|
||
|
[parameters setValue:self.endTime.currentTitle forKey:@"endTime"];
|
||
|
[parameters setValue:self.startTime.currentTitle forKey:@"startTime"];
|
||
|
[parameters setValue:self.railModel.address forKey:@"address"];
|
||
|
[parameters setValue:self.railModel.lat forKey:@"lat"];
|
||
|
[parameters setValue:self.railModel.lon forKey:@"lon"];
|
||
|
[parameters setValue:self.nameBtn.currentTitle forKey:@"name"];
|
||
|
[parameters setValue:@(self.railModel.radius) forKey:@"radius"];
|
||
|
[parameters setValue:[self.btnArr componentsJoinedByString:@""] forKey:@"week"];
|
||
|
if (self.isRedact == 2)
|
||
|
[parameters setValue:self.railModel.Id forKey:@"id"];
|
||
|
[[[APIManager sharedManager] APPOST:self.isRedact == 1 ? AddRails_URL : UpdateRails_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) {
|
||
|
[UICommon HidenLoading];
|
||
|
self.isUpdataModel();
|
||
|
[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
|