|
|
|
//
|
|
|
|
// AddWhiteContactViewController.m
|
|
|
|
// tongxin
|
|
|
|
//
|
|
|
|
// Created by ecell on 2021/10/20.
|
|
|
|
// Copyright © 2021 xTT. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "AddWhiteContactViewController.h"
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
#import "WhiteContactModel.h"
|
|
|
|
|
|
|
|
@interface AddWhiteContactViewController ()<UITextFieldDelegate>
|
|
|
|
|
|
|
|
@property (nonatomic ,strong) UIScrollView *scrollview;
|
|
|
|
|
|
|
|
@property (nonatomic ,weak) UIView *bgView;
|
|
|
|
|
|
|
|
|
|
|
|
@property (nonatomic ,weak) UITextField *nameField1;
|
|
|
|
@property (nonatomic ,weak) UITextField *phoneField1;
|
|
|
|
|
|
|
|
@property (nonatomic ,weak) UITextField *nameField2;
|
|
|
|
@property (nonatomic ,weak) UITextField *phoneField2;
|
|
|
|
|
|
|
|
@property (nonatomic ,weak) UITextField *nameField3;
|
|
|
|
@property (nonatomic ,weak) UITextField *phoneField3;
|
|
|
|
|
|
|
|
@property (nonatomic ,weak) UITextField *nameField4;
|
|
|
|
@property (nonatomic ,weak) UITextField *phoneField4;
|
|
|
|
|
|
|
|
@property (nonatomic ,weak) UITextField *nameField5;
|
|
|
|
@property (nonatomic ,weak) UITextField *phoneField5;
|
|
|
|
|
|
|
|
|
|
|
|
@property (nonatomic,strong) WhiteContactModel *model;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation AddWhiteContactViewController
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view.
|
|
|
|
|
|
|
|
self.zx_navTitle = @"添加通讯录";
|
|
|
|
self.model = [[WhiteContactModel alloc] init];
|
|
|
|
|
|
|
|
[self.view addSubview:self.scrollview];
|
|
|
|
[self.scrollview mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.right.equalTo(self.view);
|
|
|
|
make.top.equalTo(self.view).offset(iPhoneX_NavHeight+15);
|
|
|
|
make.bottom.equalTo(self.view.mas_bottom);
|
|
|
|
}];
|
|
|
|
[self subViews];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)subViews
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
UIView *bgView = [UIView new];
|
|
|
|
bgView.frame = CGRectMake(15, 15+15*i+i*Adapted(90), ScreenWidth-30, Adapted(90));
|
|
|
|
bgView.layer.borderWidth = 0.5;
|
|
|
|
bgView.layer.borderColor = RGB(102, 102, 102).CGColor;
|
|
|
|
bgView.layer.cornerRadius = 3;
|
|
|
|
[self.scrollview addSubview:bgView];
|
|
|
|
if (i == 4) self.bgView = bgView;
|
|
|
|
|
|
|
|
UITextField *namefield = [UITextField new];
|
|
|
|
namefield.placeholder = @"名称";
|
|
|
|
//namefield.textColor = ;
|
|
|
|
namefield.font = [UIFont fontWithName:@"" size:15];
|
|
|
|
namefield.frame = CGRectMake(10, 0, bgView.frame.size.width-20, Adapted(40));
|
|
|
|
[bgView addSubview:namefield];
|
|
|
|
|
|
|
|
|
|
|
|
UITextField *phonefield = [UITextField new];
|
|
|
|
phonefield.keyboardType = UIKeyboardTypePhonePad;
|
|
|
|
phonefield.placeholder = @"号码";
|
|
|
|
phonefield.delegate = self;
|
|
|
|
//phonefield.textColor = disableColor;
|
|
|
|
phonefield.font = [UIFont fontWithName:@"" size:15];
|
|
|
|
phonefield.frame = CGRectMake(10, 5+Adapted(40), bgView.frame.size.width-20, Adapted(40));
|
|
|
|
[bgView addSubview:phonefield];
|
|
|
|
|
|
|
|
if(i < self.modelArr.count)
|
|
|
|
{
|
|
|
|
WhiteContactModel *model = self.modelArr[i];
|
|
|
|
namefield.text = model.name;
|
|
|
|
namefield.textColor = disableColor;
|
|
|
|
namefield.enabled = NO;
|
|
|
|
|
|
|
|
phonefield.text = model.phone;
|
|
|
|
phonefield.textColor = disableColor;
|
|
|
|
phonefield.enabled = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
self.nameField1 = namefield;
|
|
|
|
self.phoneField1 = phonefield;
|
|
|
|
}
|
|
|
|
else if (i == 1)
|
|
|
|
{
|
|
|
|
self.nameField2 = namefield;
|
|
|
|
self.phoneField2 = phonefield;
|
|
|
|
}
|
|
|
|
else if (i == 2)
|
|
|
|
{
|
|
|
|
self.nameField3 = namefield;
|
|
|
|
self.phoneField3 = phonefield;
|
|
|
|
}
|
|
|
|
else if (i == 3)
|
|
|
|
{
|
|
|
|
self.nameField4 = namefield;
|
|
|
|
self.phoneField4 = phonefield;
|
|
|
|
}
|
|
|
|
else if (i == 4)
|
|
|
|
{
|
|
|
|
self.nameField5 = namefield;
|
|
|
|
self.phoneField5 = phonefield;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
addBtn.frame = CGRectMake(15, self.bgView.frame.origin.y+Adapted(90)+20, ScreenWidth-30, 44);
|
|
|
|
[addBtn setTitle:@"提交" forState:UIControlStateNormal];
|
|
|
|
[addBtn.layer setCornerRadius:3];
|
|
|
|
[addBtn.layer setMasksToBounds:YES];
|
|
|
|
[addBtn setBackgroundColor:mainColor];
|
|
|
|
[addBtn setTitleColor:[UIColor whiteColor] forState:0];
|
|
|
|
[addBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
|
|
|
|
[self.view addSubview:addBtn];
|
|
|
|
[addBtn addTarget:self action:@selector(addlianxiren) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
|
|
|
[self.scrollview setContentSize:CGSizeMake(ScreenWidth, addBtn.frame.origin.y+44+30)];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)addlianxiren
|
|
|
|
{
|
|
|
|
AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
|
|
|
if (!app.isTouch)
|
|
|
|
{
|
|
|
|
[UICommon MessageErrorText:@"操作频繁,操作间隔时间为1分钟"];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NSMutableArray *nameArr = [NSMutableArray new];
|
|
|
|
NSMutableArray *phoneArr = [NSMutableArray new];
|
|
|
|
if(self.nameField1.text.length > 0 && self.phoneField1.text > 0)
|
|
|
|
{
|
|
|
|
[nameArr addObject:self.nameField1.text];
|
|
|
|
[phoneArr addObject:self.phoneField1.text];
|
|
|
|
}
|
|
|
|
if(self.nameField2.text.length > 0 && self.phoneField2.text > 0)
|
|
|
|
{
|
|
|
|
[nameArr addObject:self.nameField2.text];
|
|
|
|
[phoneArr addObject:self.phoneField2.text];
|
|
|
|
}
|
|
|
|
if(self.nameField3.text.length > 0 && self.phoneField3.text > 0)
|
|
|
|
{
|
|
|
|
[nameArr addObject:self.nameField3.text];
|
|
|
|
[phoneArr addObject:self.phoneField3.text];
|
|
|
|
}
|
|
|
|
if(self.nameField4.text.length > 0 && self.phoneField4.text > 0)
|
|
|
|
{
|
|
|
|
[nameArr addObject:self.nameField4.text];
|
|
|
|
[phoneArr addObject:self.phoneField4.text];
|
|
|
|
}
|
|
|
|
if(self.nameField5.text.length > 0 && self.phoneField5.text > 0)
|
|
|
|
{
|
|
|
|
[nameArr addObject:self.nameField5.text];
|
|
|
|
[phoneArr addObject:self.phoneField5.text];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nameArr.count == self.modelArr.count)
|
|
|
|
{
|
|
|
|
[UICommon MessageErrorText:@"没有新增数据,请新增联系人"];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (NSString *ss in phoneArr)
|
|
|
|
{
|
|
|
|
if (![self isPhone:ss])
|
|
|
|
{
|
|
|
|
[UICommon MessageErrorText:@"请输入正确的手机号码"];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (NSString *name in nameArr)
|
|
|
|
{
|
|
|
|
if ([name rangeOfString:@"_"].location != NSNotFound)
|
|
|
|
{
|
|
|
|
[UICommon MessageErrorText:@"名称不能包含下划线,请重新输入"];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NSMutableDictionary *parameter = [NSMutableDictionary dictionary];
|
|
|
|
[parameter setValue:[nameArr componentsJoinedByString:@"_"] forKey:@"name"];
|
|
|
|
[parameter setValue:[phoneArr componentsJoinedByString:@"_"] forKey:@"phone"];
|
|
|
|
[parameter setValue:cUser.cDevice.imei forKey:@"imei"];
|
|
|
|
|
|
|
|
WeakSelf
|
|
|
|
[self.model save:parameter success:^{
|
|
|
|
[app stajishiqi];
|
|
|
|
[weakSelf.navigationController popViewControllerAnimated:YES];
|
|
|
|
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-(BOOL)isPhone:(NSString*)phone {
|
|
|
|
NSString * regex = @"^1([3-9])\\d{9}$";
|
|
|
|
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
|
|
|
|
return [predicate evaluateWithObject:phone];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIScrollView *)scrollview
|
|
|
|
{
|
|
|
|
if (!_scrollview)
|
|
|
|
{
|
|
|
|
_scrollview = [UIScrollView new];
|
|
|
|
_scrollview.backgroundColor = UIColor.clearColor;
|
|
|
|
}
|
|
|
|
return _scrollview;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)textFieldDidEndEditing:(UITextField *)textField
|
|
|
|
{
|
|
|
|
if (textField == self.phoneField1 ||
|
|
|
|
textField == self.phoneField2 ||
|
|
|
|
textField == self.phoneField3 ||
|
|
|
|
textField == self.phoneField5 ||
|
|
|
|
textField == self.phoneField5)
|
|
|
|
{
|
|
|
|
for (WhiteContactModel *model in self.modelArr)
|
|
|
|
{
|
|
|
|
if ([textField.text isEqualToString:model.phone])
|
|
|
|
{
|
|
|
|
textField.text = @"";
|
|
|
|
[UICommon MessageErrorText:@"新增号码重复,请重新输入"];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (textField == self.nameField1 ||
|
|
|
|
textField == self.nameField2 ||
|
|
|
|
textField == self.nameField3 ||
|
|
|
|
textField == self.nameField4 ||
|
|
|
|
textField == self.nameField5)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
#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
|