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.
 
 
 
 

275 lines
9.5 KiB

//
// FamilyViewController.m
// tongxin
//
// Created by ecell on 2021/7/16.
// Copyright © 2021 xTT. All rights reserved.
//
#import "FamilyViewController.h"
#import "FamilyContact.h"
#import "SelectFamilyContactViewController.h"
#import "FamilyTableViewCell.h"
@interface FamilyViewController ()<LGAlertViewDelegate>
{
BOOL isDeletMode; ///删除模式
}
@property (nonatomic,strong) UIView * vbottom;
@property (nonatomic,strong) UIButton *leftBtn;
@property (nonatomic,strong) UIBarButtonItem *rightBarButton;
@property (nonatomic,strong) FamilyContact *familyContact;
@end
@implementation FamilyViewController
-(void)setRightBarBtnTitle:(NSString *)title RoImage:(UIImage *)image{
if(title){
self.rightBarButton = [[UIBarButtonItem alloc] initWithTitle:title
style:UIBarButtonItemStylePlain
target:self
action:@selector(setDeleteModel)];
}
if (image) {
self.rightBarButton = [[UIBarButtonItem alloc] initWithImage: [UIImage imageNamed:@"icon_delete"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(setDeleteModel)];
}
//self.navigationItem.rightBarButtonItem = self.rightBarButton;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setRightBarBtnTitle:nil RoImage:[UIImage imageNamed:@"icon_delete"]];
[self setTitle:@"情号码"];
CGRect newFrame = self.myTableView.frame;
newFrame.size.height = newFrame.size.height - 45 - 22;
self.myTableView.frame = newFrame;
self.view.backgroundColor = self.myTableView.backgroundColor;
[self.myTableView registerNib:[UINib nibWithNibName:@"FamilyTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"FamilyTableViewCellID"];
self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:self.myTableView];
self.familyContact = [[FamilyContact alloc] init];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self setUI];
[self loadData];
}
-(void)loadData{
WEAKSELF
[self.familyContact query:^(NSMutableArray *arr) {
[weakSelf.myDataSource removeAllObjects];
[weakSelf.myDataSource addObject:arr];
[weakSelf.myTableView reloadData];
} failure:^(NSError *error) {
if (!error) {
}
}];
}
-(void)setUI{
if(_vbottom){
[_vbottom removeFromSuperview];
_vbottom = nil;
}
CGFloat tempHeight = 45+11;
if(ScreenHeight >= 812){
tempHeight = 45+11+15;
}
_vbottom = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight-getRectNavAndStatusHight-tempHeight, ScreenWidth, tempHeight)];
_leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_leftBtn setTitle:@"添加亲情号码" forState:UIControlStateNormal];
[_leftBtn.layer setCornerRadius:3];
[_leftBtn.layer setMasksToBounds:YES];
[_leftBtn setBackgroundColor:mainColor];
[_leftBtn setTitleColor:[UIColor whiteColor] forState:0];
[_leftBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
_leftBtn.frame = CGRectMake(14, 1, (ScreenWidth-28), 44);
[_vbottom addSubview:_leftBtn];
[self.view addSubview:_vbottom];
[self.view bringSubviewToFront:_vbottom]; //置顶
[_leftBtn addTarget:self action:@selector(leftBtnAction:) forControlEvents:UIControlEventTouchUpInside];
}
//MARK: 删除的方法
-(void)deleteContactFuntionWith:(NSString*)deleteId imei:(NSString *)imei{
WEAKSELF
NSString *content = @"确认要删除亲情号?";
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"注意" message:content style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
[weakSelf.familyContact deleteOne:deleteId imei:imei success:^{
[UICommon MessageSuccessText:@"删除亲情号成功" isImg:YES];
xLog(@"删除联系人成功!")
[weakSelf loadData];
} failure:^(NSError *error) {
xLog(@"删除通讯录失败");
if (error) {
if(error.userInfo) {
if (error.userInfo[@"msg"]) {
[UICommon MessageErrorText:error.userInfo[@"msg"]];
};
}
}
}];
} cancelHandler:nil destructiveHandler:nil];
[alertView showAnimated:YES completionHandler:nil];
}
-(void)leftBtnAction:(UIButton*)sender {
SelectFamilyContactViewController * vc = [SelectFamilyContactViewController new];
vc.isContact = YES;
vc.isAddContact = YES;
vc.isAddFamilyContact = YES;
//WEAKSELF
//vc.selectContactBack = ^(NSString *contact, NSNumber *contactId, NSString *phone, NSString *name) {
// //刷新数据
// [weakSelf loadData];
//};
[self.navigationController pushViewController:vc animated:YES];
}
//MARK: 进入删除状态
-(void)setDeleteModel{
}
//MARK: 取消删除状态
-(void)clearBtnActoin{
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 31)];
view.backgroundColor = RGB(248, 248, 254);
UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(14, 0, ScreenWidth, 31)];
titleLabel.font = [UIFont systemFontOfSize:12];
titleLabel.textColor = RGB(102, 102, 102);
[view addSubview:titleLabel];
NSInteger tempCount = [self.myDataSource[section] count];
titleLabel.text = [NSString stringWithFormat:@"亲情号(%zd人)",tempCount];
return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
NSInteger tempCount = [self.myDataSource[section] count];
if (section == 1){
if(tempCount == 0){
return 0.01;
}
}
return 31;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
FamilyContact *contacts = self.myDataSource[indexPath.section][indexPath.row];
FamilyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FamilyTableViewCellID" forIndexPath:indexPath];
cell.nameLabel.text = contacts.name;
cell.phoneLabel.text = contacts.phone;
cell.shortcutLabel.text = [NSString stringWithFormat:@"快捷键:%@",contacts.number];
[cell isCanEditStatus:YES];
//普通联系人 出示箭头,有提示
[cell isCanEditStatus:YES];
[cell setDelectModel:isDeletMode];
if (contacts.phone.length == 0) {
cell.phoneLabel.text = @"未设置";
}else{
cell.phoneLabel.text = contacts.phone;
}
//根据 关系 显示对应的头像
cell.headImageView.image = [UIImage imageNamed:@"icon_phonebook"];//[myHelper getClickRelationshipImageWithCodeID:[contacts.relationship_image_id intValue]];
NSInteger lastIndex = [self.myDataSource[indexPath.section] count] - 1;
if(lastIndex < 0){
lastIndex = 0;
}
if(lastIndex > 0 && indexPath.row == lastIndex){
[cell.lineView setHidden:YES];
}else{
[cell.lineView setHidden:NO];
}
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 84;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
//MARK: 设置cell 的 交互 样式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
/**
UITableViewCellEditingStyleNone,
UITableViewCellEditingStyleDelete,
UITableViewCellEditingStyleInsert
*/
//设置右滑 删除的 样式
return UITableViewCellEditingStyleDelete;
//return UITableViewCellEditingStyleNone;
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"删除";
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
FamilyContact *contacts = self.myDataSource[indexPath.section][indexPath.row];
[self deleteContactFuntionWith:contacts.id imei:contacts.imei];
//[self.myDataSource[indexPath.section] removeObject:contacts];
//[tableView reloadData];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
FamilyContact *contacts = self.myDataSource[indexPath.section][indexPath.row];
//是自己---直接跳
[self jumpContactVCWith:contacts];
}
//MARK: 跳转到 修改/添加 联系人 页面
-(void)jumpContactVCWith:(FamilyContact*)contacts{
//跳转到选择关系页面
SelectFamilyContactViewController * vc = [SelectFamilyContactViewController new];
vc.isContact = YES;
vc.isUpdateFamilyContact = YES;
vc.phone = contacts.phone; //本机电话号码
vc.name = contacts.name;
vc.shortcut = contacts.number;
vc.familyContactModel = contacts;
//vc.selectContactBack = ^(NSString *contact, NSNumber *contactId, NSString *phone, NSString *name) {
// //刷新数据
// [self loadData];
//
//};
[self.navigationController pushViewController:vc animated:YES];
}
@end