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.
282 lines
11 KiB
282 lines
11 KiB
// |
|
// AddFamilyNumberViewController.m |
|
// LekangGuard |
|
// |
|
// Created by ecell on 2022/12/6. |
|
// |
|
|
|
#import "AddFamilyNumberViewController.h" |
|
#import "ChoosePersonAddressVC.h" |
|
|
|
@interface AddFamilyNumberViewController () |
|
|
|
|
|
@property (nonatomic ,weak) UILabel *titleLabel; |
|
@property (nonatomic ,weak) UIView *bgView1; |
|
|
|
@property (nonatomic ,weak) UIButton *typeBtn; |
|
|
|
|
|
@property (nonatomic ,strong) NSMutableArray *btnArr; |
|
|
|
|
|
/// <#arguments#> |
|
@property (nonatomic ,weak) UITextField *nameField; |
|
|
|
@property (nonatomic ,weak) UITextField *phoneField; |
|
|
|
@property (nonatomic ,strong) NSString *typeStr; |
|
|
|
|
|
@end |
|
|
|
@implementation AddFamilyNumberViewController |
|
|
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
self.typeStr = @""; |
|
// Do any additional setup after loading the view. |
|
self.zx_navTitle = self.isRedact == 1 ? GJText(@"添加亲情号") : GJText(@"修改亲情号"); |
|
[self zx_setRightBtnWithText:GJText(@"保存") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) { |
|
[UICommon resignKeyboard]; |
|
self.typeBtn.selected = !self.typeBtn.selected; |
|
[self setFamilyDataModel]; |
|
}]; |
|
|
|
UIView *bgView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:10 borderWidth:0 borderColor:KKClearColor]; |
|
bgView.frame = CGRectMake(10, iPhoneX_NavHeight+10, SCREEN_WIDTH-20, 180); |
|
[self.view addSubview:bgView]; |
|
|
|
for (int i = 0; i < 3; i++) |
|
{ |
|
UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontBoldADA_(14) textColor:KKMainColor text:i == 0 ? GJText(@"关系:") : i == 1 ? GJText(@"电话:") : @"拨号快捷键:" Radius:0]; |
|
titleLabel.frame = CGRectMake(15, i*55, 100, i == 2 ? 65 : 55); |
|
[bgView addSubview:titleLabel]; |
|
// [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
// make.left.equalTo(bgView).offset(15); |
|
// make.top.equalTo(bgView).offset(i*55); |
|
// make.height.mas_equalTo(i == 2 ? 65 : 55); |
|
// }]; |
|
if (i == 2) |
|
self.titleLabel = titleLabel; |
|
|
|
if (i < 2) |
|
{ |
|
UITextField *textfield = [UICommon ui_textField:CGRectZero textColor:KKTextBlackColor backColor:KKClearColor font:FontADA_(14) maxTextNum:13 placeholderColor:KKGrey133 placeholder:i == 0 ? GJText(@"请输入与孩子的关系") : GJText(@"请输入或从通讯录导入") toMaxNum:^(UITextField *textField) { |
|
|
|
} change:^(UITextField *textField) { |
|
self.typeBtn.selected = NO; |
|
[self dismiss11]; |
|
}]; |
|
if (i == 0) self.nameField = textfield; |
|
else self.phoneField = textfield; |
|
[bgView addSubview:textfield]; |
|
[textfield mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(bgView.mas_right).inset(i == 0 ? 28 : 53); |
|
make.left.equalTo(bgView).offset(61); |
|
make.centerY.equalTo(titleLabel); |
|
make.height.mas_equalTo(Adapted(44)); |
|
}]; |
|
|
|
UILabel *line = [UILabel new]; |
|
line.backgroundColor = i == 0 ? KKMainColor : KKLineColor; |
|
[bgView addSubview:line]; |
|
[line mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.bottom.equalTo(titleLabel.mas_bottom); |
|
make.left.equalTo(bgView).offset(61); |
|
make.right.equalTo(bgView.mas_right).inset(28); |
|
make.height.mas_equalTo(0.5); |
|
}]; |
|
|
|
if (i == 1) |
|
{ |
|
UIButton *tongBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(0) normalColor:KKWhiteColorColor normalText:@"" click:^(id x) { |
|
ChoosePersonAddressVC *vc = [ChoosePersonAddressVC new]; |
|
vc.isAddFamily = YES; |
|
vc.isAddFamilySucceed = ^(NSString * _Nonnull name, NSString * _Nonnull phone) { |
|
self.nameField.text = name; |
|
self.phoneField.text = phone; |
|
}; |
|
[self.navigationController pushViewController:vc animated:YES]; |
|
}]; |
|
[tongBtn setImage:ImageName_(@"icon_contacts") forState:0]; |
|
[bgView addSubview:tongBtn]; |
|
[tongBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(bgView.mas_right).inset(28); |
|
make.centerY.equalTo(titleLabel); |
|
make.size.mas_equalTo(CGSizeMake(15, 17)); |
|
}]; |
|
} |
|
} |
|
} |
|
|
|
UIButton *typeBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(14) normalColor:KKTextBlackColor normalText:GJText(@"快捷键") click:^(UIButton *btn) { |
|
[UICommon resignKeyboard]; |
|
self.typeBtn.selected = !self.typeBtn.selected; |
|
if (self.typeBtn.selected) |
|
[self showView11]; |
|
else |
|
[self dismiss11]; |
|
}]; |
|
|
|
[typeBtn setImage:ImageName_(@"icon_arrow_down") forState:0]; |
|
[typeBtn setImage:ImageName_(@"icon_arrow_up") forState:UIControlStateSelected]; |
|
[self setButtonsTi:typeBtn]; |
|
self.typeBtn = typeBtn; |
|
[self.view addSubview:typeBtn]; |
|
[typeBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(bgView).offset(150); |
|
make.right.equalTo(bgView.mas_right).inset(10); |
|
make.centerY.equalTo(self.titleLabel.mas_centerY); |
|
make.height.mas_equalTo(50); |
|
}]; |
|
|
|
|
|
|
|
NSArray *titleArr = @[@"快捷键 1",@"快捷键 2",@"快捷键 3"]; |
|
|
|
UIView *bgView1 = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:8 borderWidth:0 borderColor:KKClearColor]; |
|
bgView1.frame = CGRectMake(120, bgView.bottom-20, 118, 0); |
|
self.bgView1 = bgView1; |
|
[self.view addSubview:bgView1]; |
|
|
|
self.btnArr = [NSMutableArray new]; |
|
for (int i = 0; i< titleArr.count; i++) |
|
{ |
|
UIButton *btn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(14) normalColor:KKTextBlackColor normalText:titleArr[i] click:^(UIButton *btn) { |
|
[self dismiss11]; |
|
self.typeBtn.selected = NO; |
|
self.typeStr = F(@"%ld", btn.tag); |
|
[self.typeBtn setTitle:F(@"快捷键 %ld", btn.tag) forState:0]; |
|
[self setButtonsTi:self.typeBtn]; |
|
}]; |
|
btn.hidden = YES; |
|
btn.tag = i+1; |
|
[bgView1 addSubview:btn]; |
|
[btn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(bgView1); |
|
make.top.equalTo(bgView1).offset(Adapted(40)*i+i*1); |
|
make.height.mas_equalTo(Adapted(40)); |
|
}]; |
|
[self.btnArr addObject:btn]; |
|
|
|
if (i <titleArr.count-1) |
|
{ |
|
UILabel *line1 = [UILabel new]; |
|
line1.backgroundColor = KKLineColor; |
|
[bgView1 addSubview:line1]; |
|
[line1 mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.bottom.equalTo(btn.mas_bottom); |
|
make.left.right.equalTo(bgView1); |
|
make.height.mas_equalTo(0.5); |
|
}]; |
|
} |
|
} |
|
|
|
if (self.isRedact == 2 && self.models) |
|
{ |
|
self.nameField.text = self.models.name; |
|
self.phoneField.text = self.models.phone; |
|
self.typeStr = self.models.number; |
|
[self.typeBtn setTitle:F(@"快捷键 %@", self.models.number) forState:0]; |
|
[self setButtonsTi:self.typeBtn]; |
|
} |
|
} |
|
|
|
|
|
- (void)showView11 |
|
{ |
|
[UIView animateWithDuration:0.25f |
|
delay:0.0f |
|
options:UIViewAnimationOptionCurveEaseOut |
|
animations:^{ |
|
self.bgView1.size = CGSizeMake(self.bgView1.width, 3*Adapted(40)+3*1); |
|
} |
|
completion:^(BOOL finished) { |
|
for (UIButton *btn in self.btnArr) { |
|
btn.hidden = NO; |
|
} |
|
}]; |
|
} |
|
|
|
- (void)dismiss11 |
|
{ |
|
for (UIButton *btn in self.btnArr) { |
|
btn.hidden = YES; |
|
} |
|
[UIView animateWithDuration:0.25f |
|
delay:0.0f |
|
options:UIViewAnimationOptionCurveEaseIn |
|
animations:^{ |
|
self.bgView1.size = CGSizeMake(self.bgView1.width, 0); |
|
} |
|
completion:^(BOOL finished) { |
|
}]; |
|
} |
|
|
|
|
|
#pragma mark 新增或编辑亲情号 |
|
/// 新增或编辑亲情号 |
|
- (void)setFamilyDataModel |
|
{ |
|
kWeakSelf(self) |
|
if (!STRINGHASVALUE(self.nameField.text)) |
|
{ |
|
[UICommon MessageErrorText:@"请输入昵称"]; |
|
return; |
|
} |
|
else if (!STRINGHASVALUE(self.phoneField.text)) |
|
{ |
|
[UICommon MessageErrorText:@"请输入电话"]; |
|
return; |
|
} |
|
else if (!STRINGHASVALUE(self.typeStr)) |
|
{ |
|
[UICommon MessageErrorText:@"请选择快捷键"]; |
|
return; |
|
} |
|
[UICommon MessageUpload:@"加载中"]; |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
if (self.isRedact == 2) |
|
[parameters setValue:self.models.Id forKey:@"id"]; |
|
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"]; |
|
[parameters setValue:self.nameField.text forKey:@"name"]; |
|
[parameters setValue:self.typeStr forKey:@"number"]; |
|
[parameters setValue:self.phoneField.text forKey:@"phone"]; |
|
NSArray *arr = @[parameters]; |
|
[[[APIManager sharedManager] APPOST:self.isRedact == 1 ? AddFamilyNumber_URL : EditFamilyNumber_URL parameters:arr isJson:YES resultClass:nil] subscribeNext:^(id _Nullable x) { |
|
[UICommon HidenLoading]; |
|
[UICommon MessageSuccessText:self.isRedact == 2 ? @"修改成功" : @"新增成功"]; |
|
AfterDispatch(1, ^{ |
|
weakself.isUpdataMsg(); |
|
[weakself.navigationController popViewControllerAnimated:YES]; |
|
}); |
|
|
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
|
|
- (void)setButtonsTi:(UIButton *)typeBtn |
|
{ |
|
typeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; |
|
CGSize textSize = [typeBtn.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:typeBtn.titleLabel.font}];//iOS7.0+ |
|
CGSize imageSize = typeBtn.currentImage.size; |
|
CGFloat marginGay = 10;//图片跟文字之间的间距 |
|
typeBtn.imageEdgeInsets = UIEdgeInsetsMake(0, textSize.width + marginGay - imageSize.width, 0, - textSize.width - marginGay + imageSize.width); |
|
typeBtn.titleEdgeInsets = UIEdgeInsetsMake(0, - imageSize.width - marginGay, 0, imageSize.width + marginGay); |
|
} |
|
|
|
/* |
|
#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
|
|
|