|
|
|
//
|
|
|
|
// SelectFamilyContactViewController.m
|
|
|
|
// tongxin
|
|
|
|
//
|
|
|
|
// Created by ecell on 2021/7/19.
|
|
|
|
// Copyright © 2021 xTT. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "SelectFamilyContactViewController.h"
|
|
|
|
#import "NewCollectionTableViewCell.h"
|
|
|
|
#import "NewTableViewCell.h"
|
|
|
|
#import "WXPPickerView.h"
|
|
|
|
#import "SelectViewCell.h"
|
|
|
|
|
|
|
|
@interface SelectFamilyContactViewController ()<UITextFieldDelegate, LMJDropdownMenuDelegate, LMJDropdownMenuDataSource>
|
|
|
|
{
|
|
|
|
NSInteger lastIndex;
|
|
|
|
NSArray * _menu1OptionTitles;
|
|
|
|
NSArray * _menu1OptionIcons;
|
|
|
|
}
|
|
|
|
|
|
|
|
@property (assign , nonatomic) NewTableViewCell *contactCell;
|
|
|
|
@property (assign , nonatomic) NewTableViewCell *phoneCell;
|
|
|
|
@property (assign , nonatomic) NewTableViewCell *nameCell;
|
|
|
|
@property (assign , nonatomic) SelectViewCell *shortcatCell;
|
|
|
|
@property (strong , nonatomic) UIBarButtonItem *rightBarButton;
|
|
|
|
@property (strong , nonatomic) FamilyContact *apiFamily;
|
|
|
|
@property (strong , nonatomic) WXPPickerView *pickerOne;
|
|
|
|
@property (strong , nonatomic) NSArray *contactNamrArr;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SelectFamilyContactViewController
|
|
|
|
|
|
|
|
@synthesize myDataSource = _myDataSource;
|
|
|
|
|
|
|
|
-(NSMutableArray *)myDataSource{
|
|
|
|
if(!_myDataSource){
|
|
|
|
_myDataSource = [NSMutableArray arrayWithArray:@[@[@"联系人",@"电话号码",@"快捷键"]]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return _myDataSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(Contacts *)contactModel{
|
|
|
|
if(!_contactModel){
|
|
|
|
_contactModel = [Contacts new];
|
|
|
|
}
|
|
|
|
return _contactModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)viewWillAppear:(BOOL)animated{
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
|
|
|
self.contactNamrArr = [myHelper getRelationshipNameArr:cUser.cDevice.deviceType.integerValue];
|
|
|
|
|
|
|
|
if(self.isContact){
|
|
|
|
_myDataSource = [NSMutableArray arrayWithArray:@[@[@"联系人",@"电话号码",@"快捷键"]]];
|
|
|
|
}
|
|
|
|
|
|
|
|
lastIndex = [self.myDataSource.firstObject count]-1;
|
|
|
|
|
|
|
|
NSString * rightBtnName = @"保存";
|
|
|
|
self.rightBarButton = [[UIBarButtonItem alloc] initWithTitle:rightBtnName
|
|
|
|
style:UIBarButtonItemStylePlain
|
|
|
|
target:self
|
|
|
|
action:@selector(rightBarItemClick)];
|
|
|
|
self.navigationItem.rightBarButtonItem = self.rightBarButton;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
|
|
|
if (self.isAddFamilyContact) {
|
|
|
|
self.title = @"添加亲情号";
|
|
|
|
} else if (self.isUpdateFamilyContact) {
|
|
|
|
self.title = @"修改亲情号";
|
|
|
|
}
|
|
|
|
|
|
|
|
_menu1OptionTitles = cUser.cDevice.support_family && cUser.cDevice.support_family.intValue == 1 ? @[@"1",@"2",@"3"] : @[@"1",@"2",@"3",@"4"];
|
|
|
|
_menu1OptionIcons = cUser.cDevice.support_family && cUser.cDevice.support_family.intValue == 1 ? @[@"icon_to_enable",@"icon_to_enable",@"icon_to_enable"] : @[@"icon_to_enable",@"icon_to_enable",@"icon_to_enable",@"icon_to_enable"];
|
|
|
|
|
|
|
|
self.apiFamily = [[FamilyContact alloc] init];
|
|
|
|
[self.view setBackgroundColor:[UIColor whiteColor]];
|
|
|
|
[self initTableView];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)rightBarItemClick{
|
|
|
|
|
|
|
|
self.contact = self.contactCell.aTextField.text;
|
|
|
|
self.phone = self.phoneCell.aTextField.text;
|
|
|
|
self.name = self.nameCell.aTextField.text;
|
|
|
|
|
|
|
|
// 通讯录
|
|
|
|
if(self.nameCell.aTextField.text.length == 0){
|
|
|
|
[UICommon MessageErrorText:@"请输入联系人名称"];
|
|
|
|
return;
|
|
|
|
}else if (self.phoneCell.aTextField.text.length == 0 ){
|
|
|
|
[UICommon MessageErrorText:@"请输入电话号码"];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (!self.shortcut){
|
|
|
|
[UICommon MessageErrorText:@"请选择快捷键"];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.contactModel.name = self.nameCell.aTextField.text;
|
|
|
|
self.contactModel.phone = self.phoneCell.aTextField.text;
|
|
|
|
self.contactModel.relationship_image_id = self.contactId;
|
|
|
|
WEAKSELF
|
|
|
|
|
|
|
|
// add by lsz 2021-7-17
|
|
|
|
if (self.isAddFamilyContact) {
|
|
|
|
FamilyContact *parameter = [[FamilyContact alloc] init];
|
|
|
|
parameter.imei = cUser.cDevice.imei;
|
|
|
|
parameter.name = self.nameCell.aTextField.text;
|
|
|
|
parameter.number = self.shortcut;
|
|
|
|
parameter.phone = self.phoneCell.aTextField.text;
|
|
|
|
|
|
|
|
[self.apiFamily save:parameter success:^{
|
|
|
|
[weakSelf goBack:nil];
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
if (error) {
|
|
|
|
if(error.userInfo) {
|
|
|
|
if (error.userInfo[@"msg"]) {
|
|
|
|
[UICommon MessageErrorText:error.userInfo[@"msg"]];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
} else if(self.isUpdateFamilyContact) {
|
|
|
|
|
|
|
|
self.familyContactModel.imei = cUser.cDevice.imei;
|
|
|
|
self.familyContactModel.name = self.nameCell.aTextField.text;
|
|
|
|
self.familyContactModel.number = self.shortcut;
|
|
|
|
self.familyContactModel.phone = self.phoneCell.aTextField.text;
|
|
|
|
|
|
|
|
[self.apiFamily update:self.familyContactModel success:^{
|
|
|
|
[weakSelf goBack:nil];
|
|
|
|
} failure:^(NSError *error) {
|
|
|
|
if (error) {
|
|
|
|
if(error.userInfo) {
|
|
|
|
if (error.userInfo[@"msg"]) {
|
|
|
|
[UICommon MessageErrorText:error.userInfo[@"msg"]];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-(void)initTableView{
|
|
|
|
self.myTableView.frame = CGRectMake(0, 10, SWIDTH, SHEIGHT-64-10);
|
|
|
|
[self.view addSubview:self.myTableView];
|
|
|
|
//注册 cell
|
|
|
|
[self.myTableView registerNib:[UINib nibWithNibName:@"NewCollectionTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"NewCollectionTableViewCellID"];
|
|
|
|
[self.myTableView registerNib:[UINib nibWithNibName:@"NewTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"NewTableViewCellID"];
|
|
|
|
[self.myTableView registerNib: [UINib nibWithNibName:@"SelectViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"SelectViewCellID"];
|
|
|
|
|
|
|
|
//去线
|
|
|
|
self.myTableView.separatorStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
self.myTableView.backgroundColor = [UIColor whiteColor];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
return 60;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
|
|
|
|
|
|
|
|
NSString * title = self.myDataSource[0][indexPath.row];
|
|
|
|
|
|
|
|
NewTableViewCell *cell;
|
|
|
|
|
|
|
|
if([title isEqualToString:@"关系"]){
|
|
|
|
cell = [tableView dequeueReusableCellWithIdentifier:@"NewTableViewCellID" forIndexPath:indexPath];
|
|
|
|
cell.aTitleLabel.text = title;
|
|
|
|
cell.aTextField.textAlignment = NSTextAlignmentRight;
|
|
|
|
|
|
|
|
cell.aTextField.placeholder = @"请输入关系";
|
|
|
|
cell.aTextField.delegate = self;
|
|
|
|
cell.aTextField.tag = 9527;
|
|
|
|
if(cell.aTextField.text.length == 0){
|
|
|
|
cell.aTextField.text = self.contact;
|
|
|
|
}
|
|
|
|
self.contactCell = cell;
|
|
|
|
}else if([title isEqualToString:@"联系人"]){
|
|
|
|
cell = [tableView dequeueReusableCellWithIdentifier:@"NewTableViewCellID" forIndexPath:indexPath];
|
|
|
|
cell.aTitleLabel.text = title;
|
|
|
|
cell.aTextField.textAlignment = NSTextAlignmentRight;
|
|
|
|
|
|
|
|
cell.aTextField.placeholder = @"请输入联系人名称";
|
|
|
|
cell.aTextField.text = self.name;
|
|
|
|
cell.aTextField.delegate = self;
|
|
|
|
self.nameCell = cell;
|
|
|
|
self.contactCell = cell;
|
|
|
|
|
|
|
|
}else if([title isEqualToString:@"电话号码"]){
|
|
|
|
cell = [tableView dequeueReusableCellWithIdentifier:@"NewTableViewCellID" forIndexPath:indexPath];
|
|
|
|
cell.aTitleLabel.text = title;
|
|
|
|
cell.aTextField.textAlignment = NSTextAlignmentRight;
|
|
|
|
|
|
|
|
cell.aTextField.placeholder = @"请输入电话号码";
|
|
|
|
cell.aTextField.delegate = self; //限制
|
|
|
|
cell.aTextField.text = self.phone;
|
|
|
|
cell.aTextField.keyboardType = UIKeyboardTypePhonePad;
|
|
|
|
self.phoneCell =cell;
|
|
|
|
}else if([title isEqualToString:@"我的号码"]){
|
|
|
|
cell = [tableView dequeueReusableCellWithIdentifier:@"NewTableViewCellID" forIndexPath:indexPath];
|
|
|
|
cell.aTitleLabel.text = title;
|
|
|
|
cell.aTextField.textAlignment = NSTextAlignmentRight;
|
|
|
|
|
|
|
|
//我的号码
|
|
|
|
cell.aTextField.placeholder = @"请输入我的号码";
|
|
|
|
cell.aTextField.delegate = self; //限制
|
|
|
|
cell.aTextField.text = self.phone;
|
|
|
|
cell.aTextField.keyboardType = UIKeyboardTypePhonePad;
|
|
|
|
self.phoneCell =cell;
|
|
|
|
} else if([title isEqualToString:@"快捷键"]) {
|
|
|
|
SelectViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:@"SelectViewCellID" forIndexPath:indexPath];
|
|
|
|
[cell2 setSelectionStyle:UITableViewCellSelectionStyleNone];
|
|
|
|
|
|
|
|
/* LMJDropdownMenu */
|
|
|
|
cell2.menu.delegate = self;
|
|
|
|
cell2.menu.dataSource = self;
|
|
|
|
|
|
|
|
cell2.menu.layer.borderColor = [UIColor whiteColor].CGColor;
|
|
|
|
|
|
|
|
cell2.menu.title = self.shortcut ? self.shortcut : @"选择快捷键";
|
|
|
|
cell2.menu.titleBgColor = [UIColor colorWithRed:88/255.f green:157/255.f blue:245/255.f alpha:1];
|
|
|
|
cell2.menu.titleFont = [UIFont boldSystemFontOfSize:15];
|
|
|
|
cell2.menu.titleColor = [UIColor whiteColor];
|
|
|
|
cell2.menu.titleAlignment = NSTextAlignmentLeft;
|
|
|
|
cell2.menu.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
|
|
|
|
|
|
|
|
cell2.menu.rotateIcon = [UIImage imageNamed:@"arrow"];
|
|
|
|
cell2.menu.rotateIconSize = CGSizeMake(15, 15);
|
|
|
|
|
|
|
|
cell2.menu.optionBgColor = [UIColor colorWithRed:64/255.f green:151/255.f blue:255/255.f alpha:0.5];
|
|
|
|
cell2.menu.optionFont = [UIFont systemFontOfSize:13];
|
|
|
|
cell2.menu.optionTextColor = [UIColor blackColor];
|
|
|
|
cell2.menu.optionTextAlignment = NSTextAlignmentLeft;
|
|
|
|
cell2.menu.optionNumberOfLines = 0;
|
|
|
|
cell2.menu.optionLineColor = [UIColor whiteColor];
|
|
|
|
cell2.menu.optionIconSize = CGSizeMake(15, 15);
|
|
|
|
/* LMJDropdownMenu */
|
|
|
|
|
|
|
|
self.shortcatCell =cell2;
|
|
|
|
return cell2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - LMJDropdownMenu DataSource
|
|
|
|
- (NSUInteger)numberOfOptionsInDropdownMenu:(LMJDropdownMenu *)menu{
|
|
|
|
return _menu1OptionTitles.count;
|
|
|
|
}
|
|
|
|
- (CGFloat)dropdownMenu:(LMJDropdownMenu *)menu heightForOptionAtIndex:(NSUInteger)index{
|
|
|
|
return 30;
|
|
|
|
}
|
|
|
|
- (NSString *)dropdownMenu:(LMJDropdownMenu *)menu titleForOptionAtIndex:(NSUInteger)index{
|
|
|
|
return _menu1OptionTitles[index];
|
|
|
|
}
|
|
|
|
- (UIImage *)dropdownMenu:(LMJDropdownMenu *)menu iconForOptionAtIndex:(NSUInteger)index{
|
|
|
|
return [UIImage imageNamed:_menu1OptionIcons[index]];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - LMJDropdownMenu Delegate
|
|
|
|
- (void)dropdownMenu:(LMJDropdownMenu *)menu didSelectOptionAtIndex:(NSUInteger)index optionTitle:(NSString *)title{
|
|
|
|
NSLog(@"你选择了(you selected):menu1,index: %ld - title: %@", index, title);
|
|
|
|
self.shortcut = title;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dropdownMenuWillShow:(LMJDropdownMenu *)menu{
|
|
|
|
NSLog(@"--将要显示(will appear)--menu1");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dropdownMenuDidShow:(LMJDropdownMenu *)menu{
|
|
|
|
NSLog(@"--已经显示(did appear)--menu1");
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dropdownMenuWillHidden:(LMJDropdownMenu *)menu{
|
|
|
|
NSLog(@"--将要隐藏(will disappear)--menu1");
|
|
|
|
}
|
|
|
|
- (void)dropdownMenuDidHidden:(LMJDropdownMenu *)menu{
|
|
|
|
NSLog(@"--已经隐藏(did disappear)--menu1");
|
|
|
|
}
|
|
|
|
|
|
|
|
//-(BOOL)textFieldShouldReturn:(UITextField *)textField {
|
|
|
|
// [textField resignFirstResponder];
|
|
|
|
// return YES;
|
|
|
|
//}
|
|
|
|
|
|
|
|
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
|
|
|
|
|
|
|
|
if([textField.superview isEqual:self.phoneCell]){
|
|
|
|
if([@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" containsString:string]){
|
|
|
|
// 最终的结果
|
|
|
|
NSString *str = textField.text;
|
|
|
|
NSString *resultStr = [str stringByReplacingCharactersInRange:range withString:string];
|
|
|
|
self.phone = resultStr;
|
|
|
|
|
|
|
|
if(resultStr.length > 15){
|
|
|
|
return NO;
|
|
|
|
}else{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if([string isEqualToString:@""]){
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}else if ([textField.superview isEqual:self.contactCell] || [textField.superview isEqual:self.nameCell] ){
|
|
|
|
// 最终的结果
|
|
|
|
NSString *str = textField.text;
|
|
|
|
NSString *resultStr = [str stringByReplacingCharactersInRange:range withString:string];
|
|
|
|
self.contact = resultStr;
|
|
|
|
self.name = resultStr;
|
|
|
|
|
|
|
|
}else if(textField.tag == 9527) {
|
|
|
|
|
|
|
|
NSString *str = textField.text;
|
|
|
|
NSString *resultStr = [str stringByReplacingCharactersInRange:range withString:string];
|
|
|
|
|
|
|
|
NSLog(@"resultStr=%@",resultStr);
|
|
|
|
|
|
|
|
// add by lsz 限制
|
|
|
|
//if (resultStr.length > 8) {
|
|
|
|
// return NO;
|
|
|
|
//} else {
|
|
|
|
// return YES;
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|