// // AddFamilyNumberViewController.m // LekangGuard // // Created by ecell on 2022/12/6. // #import "AddFamilyNumberViewController.h" @interface AddFamilyNumberViewController () @property (nonatomic ,weak) UIView *bgView; @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.view.backgroundColor = KKWhiteColorColor; 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]; }]; for (int i = 0; i < 2; i++) { UIView *bgView = [UICommon ui_view:CGRectZero backgroundColor:KKLineColor cornerRadius:5 borderWidth:0 borderColor:KKClearColor]; bgView.frame = CGRectMake(15, iPhoneX_NavHeight+30+Adapted(50)*i+i*15, SCREEN_WIDTH, Adapted(50)); if (i == 1) self.bgView = bgView; [self.view addSubview:bgView]; // [bgView mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.right.equalTo(self.view).inset(15); // make.top.equalTo(self.view).offset(iPhoneX_NavHeight+30+Adapted(50)*i+i*15); // make.height.mas_equalTo(Adapted(50)); // }]; UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(14) textColor:KKTextBlackColor text:i == 0 ? GJText(@"联系人") : GJText(@"电话号码") Radius:0]; [bgView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(bgView).offset(15); make.centerY.equalTo(bgView); }]; UITextField *textfield = [UICommon ui_textField:CGRectZero textColor:KKTextBlackColor backColor:KKClearColor font:FontADA_(14) maxTextNum:13 placeholderColor:KKGrey143 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(15); make.left.equalTo(bgView).offset(100); make.centerY.equalTo(bgView); make.height.mas_equalTo(Adapted(44)); }]; } UIButton *typeBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(14) normalColor:KKWhiteColorColor normalText:GJText(@"选择快捷键") click:^(UIButton *btn) { [UICommon resignKeyboard]; self.typeBtn.selected = !self.typeBtn.selected; if (self.typeBtn.selected) [self showView11]; else [self dismiss11]; }]; typeBtn.frame = CGRectMake(100, self.bgView.bottom+20, SCREEN_WIDTH-115, Adapted(40)); typeBtn.backgroundColor = KKMainColor; typeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [typeBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 15, 0, 0)]; self.typeBtn = typeBtn; [self.view addSubview:typeBtn]; // [typeBtn mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(self.view).offset(100); // make.right.equalTo(self.view).inset(15); // make.top.equalTo(self.bgView.mas_bottom).offset(20); // make.height.mas_equalTo(Adapted(40)); // }]; UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(14) textColor:KKTextBlackColor text:GJText(@"快捷键") Radius:0]; [self.view addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view).offset(30); make.centerY.equalTo(typeBtn); }]; NSArray *titleArr = @[@"1",@"2",@"3",@"4"]; UIView *bgView1 = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:0 borderWidth:0 borderColor:KKClearColor]; bgView1.frame = CGRectMake(100, typeBtn.bottom+3, typeBtn.width, 0); self.bgView1 = bgView1; [self.view addSubview:bgView1]; // [bgView1 mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(typeBtn.mas_left); // make.right.equalTo(typeBtn.mas_right); // make.top.equalTo(typeBtn.mas_bottom).offset(3); // make.height.mas_equalTo(titleArr.count*Adapted(30)+(titleArr.count-1)*3); // }]; self.btnArr = [NSMutableArray new]; for (int i = 0; i< titleArr.count; i++) { UIButton *btn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(14) normalColor:KKWhiteColorColor normalText:titleArr[i] click:^(UIButton *btn) { [self dismiss11]; self.typeStr = F(@"%ld", btn.tag); [self.typeBtn setTitle:F(@"快捷键:%ld", btn.tag) forState:0]; }]; btn.hidden = YES; btn.backgroundColor = KKMainColor; btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 15, 0, 0)]; btn.tag = i+1; [bgView1 addSubview:btn]; [btn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(bgView1); make.top.equalTo(bgView1).offset(Adapted(30)*i+i*1); make.height.mas_equalTo(Adapted(30)); }]; [self.btnArr addObject:btn]; } 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]; } } - (void)showView11 { [UIView animateWithDuration:0.25f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{ self.bgView1.size = CGSizeMake(self.bgView1.width, 4*Adapted(30)+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]]; }]; } /* #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