| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326 |
- //
- // JOABFriendsVC.m
- // shiku_im
- //
- // Created by jobor Zhou on 2016/10/18.
- // Copyright © 2016年 Reese. All rights reserved.
- //
- #define Colorhui Color(235,233,233,1.0)
- #define Colorbai Color(244,245,245,1.0)
- #import "JOABFriendsVC.h"
- //个人资料
- //#import "PersonDetail.h"
- #import "JOAddressBookCell.h"//自定义cell
- #import "EmployeeModel.h"//原来的员工模型
- #import "JOEmployeeModel.h"//员工模型
- #import "JOSearchBar.h"//搜索框
- #import "JOABSearchBarVC.h"//自定义搜索框
- #import "JONewPersonDetailVC.h"
- #import "ChineseString.h"//指示条
- #import "HYPAddressBookManger.h"
- #import "UASUuFriendsManager.h"
- #import "ContactsCell.h"
- #import "MJRefresh.h"
- #import "MJExtension.h"
- NSString *cellId = @"cellResId";
- @interface JOABFriendsVC ()<UITableViewDelegate,UITableViewDataSource,UASUumanagerDelegate>
- {
- NSMutableArray * _IMFriendsArray;
- NSMutableArray * _friendsArray;
- NSMutableArray * _allDataArray;
- UIImageView * _noDataImage;
- //排序
- NSMutableArray * _indexArray;//首字母
- NSMutableArray * _letterOfName;//名字集合
- }
- @property (nonatomic,assign)int completeNum;
- @property (nonatomic,strong) UITableView * tableView;
- @property (nonatomic, strong) JXUserObject * friend;
- @property (nonatomic, copy) dispatch_block_t getUserBlock;
- @property (nonatomic,assign)BOOL canRead;
- @property(weak,nonatomic)UIButton *upBtn;
- @end
- @implementation JOABFriendsVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self setUpUI];
- [self getCacheData];
-
- }
- - (void)viewWillAppear:(BOOL)animated
- {
-
- self.completeNum = 0;
-
- // [[NSNotificationCenter defaultCenter] postNotificationName:@"hiddenTabBar" object:nil];
-
- }
- -(void)getCacheData{
-
- [SVProgressHUD showWithStatus:@"正在加载中"];
-
- [[UASUuFriendsManager shareManager] createUuFriendsTablewithtableName:UU_AllFriends completed:^{
-
- [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
-
- [SVProgressHUD dismiss];
-
- self.dataArr = arr;
-
- if (self.dataArr.count == 0 || self.dataArr == nil) {
-
- [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"uploadAddressBook"];
-
- [SVProgressHUD showWithStatus:@"正在加载中"];
-
- [self loadMoreData];
-
- }else{
-
- [self dataSort];
-
- }
- }];
-
- }];
-
-
- }
- -(void)setUpUI{
-
- self.view.backgroundColor = [UIColor whiteColor];
- self.completeNum = 0;
- self.title = Localized(@"UU_addressBook_UUGoodFriend");
- self.tableView=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
- self.tableView.delegate=self;
- self.tableView.dataSource=self;
- self.tableView.backgroundColor = BGKJ_COLOR;
- [self.view addSubview:self.tableView];
-
-
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.bottom.equalTo(self.view);
- }];
- UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
- btn2.frame = CGRectMake(0, 5, 22, 22);
- UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, iOS11?5:0, 22, 22)];
- image.image = [UIImage imageNamed:@"icon_back_nor3"];
- [btn2 addSubview:image];
- [btn2 addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *bbi2 = [[UIBarButtonItem alloc]initWithCustomView:btn2];
- self.navigationItem.leftBarButtonItems = @[bbi2];
-
- [self setUpSearchBar];
- //1,去掉多余的分割线
- [self setExtraCellLineHidden:self.tableView];
- [self.tableView registerClass:[ContactsCell class] forCellReuseIdentifier:cellId];
- _IMFriendsArray=[[NSMutableArray alloc]init];
- _allDataArray=[[NSMutableArray alloc]init];
- _friendsArray=[[NSMutableArray alloc]init];
-
- _noDataImage = [[UIImageView alloc]init];
- _noDataImage.image = [UIImage imageNamed:@"crm_all_noData"];
- [self.view addSubview:_noDataImage];
- _noDataImage.hidden=YES;
- [_noDataImage mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(100);
- make.height.mas_equalTo(126);
- make.center.equalTo(self.view);
- }];
-
- [UASUuFriendsManager shareManager].delegate = self;
- UIButton *upBtn = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 70, self.view.height-164, 0, 0)];
- [upBtn addTarget:self action:@selector(scrollUpToTop) forControlEvents:UIControlEventTouchUpInside];
- [upBtn setImage: [UIImage imageNamed:@"icon_shangla_nor3"] forState:UIControlStateNormal];
- [upBtn setImage: [UIImage imageNamed:@"icon_shangla_nor3"] forState:UIControlStateHighlighted];
- self.upBtn.hidden = YES;
- self.upBtn = upBtn;
- upBtn.backgroundColor = [UIColor lightGrayColor];
- [self.view addSubview:self.upBtn];
- [self.view bringSubviewToFront:self.upBtn];
- // self.upBtn.hidden = YES;
-
- //下拉刷新相关函数
- __weak typeof(self) weakSelf = self;
- _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- __strong JOABFriendsVC *strongSelf = weakSelf;
- strongSelf.completeNum = 0;
- [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"uploadAddressBook"];
-
- if (g_B2BUser)
- {
-
- [weakSelf loadMoreData];
-
- }else{
-
- [weakSelf loadMoreData];
-
- }
-
- });
- }];
-
-
-
-
-
-
-
-
-
-
- }
- /**
- 对数组进行排序
- */
- -(void)dataSort{
-
- NSMutableArray *zero = [NSMutableArray array];
- NSMutableArray *one = [NSMutableArray array];
- NSMutableArray *two = [NSMutableArray array];
- NSMutableArray *three = [NSMutableArray array];
- NSMutableArray *four = [NSMutableArray array];
- NSMutableArray *tempArr = [self.dataArr mutableCopy];
-
- for (ContactsModel *model in tempArr) {
- if([model.isfriend isEqualToString:@"1"]){//已添加
- [zero addObject:model];
- [self.dataArr removeObject:model];
- }
- }
- tempArr = [self.dataArr mutableCopy];
- for (ContactsModel *model in tempArr) {
-
- if ([model.isfriend isEqualToString:@"0"]) {
- [one addObject:model];
- [self.dataArr removeObject:model];
- }
-
- }
- tempArr = [self.dataArr mutableCopy];
- for (ContactsModel *model in tempArr) {
-
- if([model.type isEqualToString:@"1"]){
- [two addObject:model];
- [self.dataArr removeObject:model];
- }
- }
-
- tempArr = [self.dataArr mutableCopy];
- for (ContactsModel *model in tempArr) {
-
- if([model.type isEqualToString:@"3"]){
- [three addObject:model];
- [self.dataArr removeObject:model];
- }
- }
-
- four = [self.dataArr mutableCopy];
- [self.dataArr removeAllObjects];
- for (ContactsModel *model in zero) {
- [self.dataArr addObject:model];
- }
- for (ContactsModel *model in one) {
- [self.dataArr addObject:model];
- }
- for (ContactsModel *model in two) {
- [self.dataArr addObject:model];
- }
- for (ContactsModel *model in three) {
- [self.dataArr addObject:model];
- }
- for (ContactsModel *model in four) {
- [self.dataArr addObject:model];
- }
-
- [self.tableView reloadData];
- /*上传本地通讯录到我们服务器*/
- if ([[NSUserDefaults standardUserDefaults] boolForKey:@"uploadAddressBook"]) {
-
- [self uploadOwnTelephoneAddressBookToServer:self.dataArr];
-
- }
- }
- #pragma mark --- 网络请求UU好友,本地取手机通讯录,网络取企业架构
- -(void)loadMoreData{
-
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(12 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-
- [self loadDataFailed];
-
- });
- if(![[NSUserDefaults standardUserDefaults]boolForKey:@"netWorkStatus"]) {
-
- [JOShowMessageFromNavi showDropViewWithMessage:Localized(@"UU_custom_networkFaildPleaseCheck") ToNavi:self.navigationController withColor:nil];
-
- return;
- }
-
- [[UASUuFriendsManager shareManager] deleteDataWithTable:UU_AllFriends andCompany:g_companyName andWhichsys:g_companyMaster andUserId:MY_USER_ID completed:^{
-
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
-
- [self loadUuFriendsData];
-
- });
-
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
-
- [self loadAddressData];
- });
- if (g_PersonalUser) {
-
-
- }else {
-
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
-
- [self loadCompanyData];
- });
-
- }
-
- }];
-
-
- }
- -(void)loadDataFailed{
-
- if (self.completeNum == 0) {
- // [JOShowMessageFromNavi showDropViewWithMessage:@"当前网络环境差,请检查网络后重试" ToNavi:self.navigationController withColor:nil];
- }
- if (!g_PersonalUser) {
- if (self.canRead) {//允许读取通讯录
-
- if (self.completeNum < 3) {
- [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
-
- self.dataArr = arr;
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [SVProgressHUD dismiss];
- [_tableView.mj_header endRefreshing];
- [self dataSort];
- });
- }];
-
-
- }
-
- }else{//不能读取通讯录
- if (self.completeNum < 2) {
-
- [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
-
- self.dataArr = arr;
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [SVProgressHUD dismiss];
- [_tableView.mj_header endRefreshing];
- [self dataSort];
- });
- }];
-
- }
-
- }
-
- }else{
- if (self.canRead) {//允许读取通讯录
-
- if (self.completeNum < 2) {
-
- [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
-
- self.dataArr = arr;
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [SVProgressHUD dismiss];
- [_tableView.mj_header endRefreshing];
- [self dataSort];
- });
- }];
-
- }
-
- }else{//不能读取通讯录
- if (self.completeNum < 1) {
-
- [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
-
- self.dataArr = arr;
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [SVProgressHUD dismiss];
- [_tableView.mj_header endRefreshing];
- [self dataSort];
- });
- }];
-
- }
-
- }
-
-
- }
-
-
- }
- #pragma mark - 刷新数据
- -(void)loadAddressData{
-
- [self getAddressFriends];
- }
- -(void)loadCompanyData{
-
-
- UASNetworkManager *manager1 = [UASNetworkManager shareManager];
- manager1.responseSerializer = [AFHTTPResponseSerializer serializer];
- manager1.responseSerializer.acceptableContentTypes =[NSSet setWithObject:@"text/html"];
- manager1.responseSerializer.acceptableContentTypes =[NSSet setWithObject:@"application/json"];
-
- NSUserDefaults * userDefault=[NSUserDefaults standardUserDefaults];
-
- NSString *ip=[UASUserInfo shareManager].urlIp;
-
- NSString *sessionId=[userDefault objectForKey:@"sessionId"];
-
- NSString *master=[[userDefault objectForKey:@"masterDic"]objectForKey:@"ma_user"];
-
- NSString *paramSessionId=[@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
-
- NSString * userID=[[NSUserDefaults standardUserDefaults] objectForKey:@"erpaccount"];
-
- [manager1.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
-
-
- NSString * url=[@"" stringByAppendingFormat:@"%@mobile/getAllHrorgEmps.action?master=%@&lastdate=&sessionUser=%@",ip,master,userID];
- [manager1 request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
- NSData *data=responseObject;
-
- //1,系统自带的nsjson解析数据
- id rootDic =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
-
- //SLog(@"请求成功啦:%@",rootDic);
-
- rootDic =[NSDictionary changeType:rootDic];
- //DLog(@"去掉空字符串%@",rootDic);
-
-
- NSMutableArray * empArr=[rootDic objectForKey:@"employees"];
-
- NSString * companyName=[[[NSUserDefaults standardUserDefaults] objectForKey:@"masterDic"]objectForKey:@"ma_function"];
- companyName=[companyName stringByReplacingOccurrencesOfString:@"(" withString:@""];
- companyName=[companyName stringByReplacingOccurrencesOfString:@")" withString:@""];
-
- NSArray *arrayEmp = [JOEmployeeModel objectArrayWithKeyValuesArray:empArr];
-
-
- [[UASUuFriendsManager shareManager] insertCompanyFriendsWithDataArray:arrayEmp withTableName:UU_AllFriends];
-
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
-
-
-
- }];
-
- }
- -(void)loadUuFriendsData{
- [self getArrayData];
- }
- #pragma mark --- 取手机本地通讯录
- - (void)getAddressFriends{
-
- NSMutableArray *friends = [NSMutableArray array];
- [[HYPAddressBookManger shareManger]canReadAddressBookWithBlock:^(BOOL canRead, ABAuthorizationStatus authorStatus) {
- self.canRead = canRead;
- if (canRead) {
- ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
- CFArrayRef allLinkPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
- CFIndex num = ABAddressBookGetPersonCount(addressBook);
- for (NSInteger i = 0; i < num; i++) {
- ABRecordRef people = CFArrayGetValueAtIndex(allLinkPeople, i);
- /*电话*/
- ABMultiValueRef phones = ABRecordCopyValue(people, kABPersonPhoneProperty);
- for (int k = 0; k<ABMultiValueGetCount(phones); k++)
- {
- //获取該Label下的电话值
- NSString * personPhone = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phones, k);
- //获取该Label下的名值
- NSString * personFirstN = (__bridge NSString *)(ABRecordCopyValue(people, kABPersonFirstNameProperty));
- //获取该Label下的姓值
- NSString * personLastN = (__bridge NSString *)(ABRecordCopyValue(people, kABPersonLastNameProperty));
-
- NSString *newP = [personPhone stringByReplacingOccurrencesOfString:@" " withString:@""];
- newP = [newP stringByReplacingOccurrencesOfString:@"-" withString:@""];
-
- newP = [[newP componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] componentsJoinedByString:@""];
-
- // 去除+86
- if ([newP containsString:@"+86"]) {
- newP = [newP stringByReplacingOccurrencesOfString:@"+86" withString:@""];
- }
- // 去除+
- if ([newP containsString:@"+"]) {
- newP = [newP stringByReplacingOccurrencesOfString:@"+" withString:@""];
- }
-
- NSRange range = [newP rangeOfString:@"12593"];
- if (NSEqualRanges(range, NSMakeRange(0, 5))) {
- newP = [newP stringByReplacingOccurrencesOfString:@"12593" withString:@""];
- }
- if (![friends containsObject:newP]) {
- NSString *allName = FORMAT(@"%@%@",personLastN,personFirstN);
- if ([allName containsString:@"(null)"]) {
- allName = [allName stringByReplacingOccurrencesOfString:@"(null)" withString:@""];
- }
- NSDictionary *dic = @{@"name":allName,
- @"phone":newP};
- if([NSString valiMobile:[dic objectForKey:@"phone"]]){
- [friends addObject:dic];
- }
- }
-
- }
-
- }
-
- /*获取是否开通UU以及是否为好友数据*/
- [self judgeIfOpenUUOrIfMyUUFriend: friends];
-
- }else{
- [[HYPAddressBookManger shareManger] gotoSetting:self];
- }
- }];
-
- }
- #pragma mark --- 上传本地通讯录到我们服务器
- -(void)uploadOwnTelephoneAddressBookToServer:(NSMutableArray *)arr
- {
-
- NSMutableArray *allDataArr = [[NSMutableArray alloc]init];
- for (int i = 0; i < arr.count; i++) {
- ContactsModel *model = arr[i];
- if ([model.imid isEqualToString:@"xxxxx"]) {
- NSDictionary *changeDic = @{@"am_telephone":model.phoneStr,
- @"am_username":model.nameStr,
- @"am_userid":@"0"};
-
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:changeDic options:NSJSONWritingPrettyPrinted error:nil];
- NSString *paramStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
-
- [allDataArr addObject:paramStr];
- }
- }
-
- NSDictionary *params = @{@"map":FORMAT(@"[%@]",[allDataArr componentsJoinedByString:@","]),
- @"userid":g_server.myself.userId,
- @"username":g_server.myself.userNickname
- };
- SLog(@"这里的数据:%@",params);
-
- NSString *url = [NSString stringWithFormat:@"%@%@?token=%@",g_config.apiUrl,act_mobileContact,g_token];
-
- url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- UASNetworkManager *manager = [UASNetworkManager shareManager];
- manager.responseSerializer = [AFJSONResponseSerializer serializer];
- [manager request:url method:POST parameters:params progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
-
- SLog(@"chengogngyufou:%@",responseObject);
-
- if (responseObject[@"result"]) {
- NSString *str = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
- if ([str isEqualToString:@"true"]) {
-
- [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"uploadAddressBook"];
-
- }else{
- // [JOShowMessageFromNavi showDropViewWithMessage:responseObject[@"result"] ToNavi:self.navigationController withColor:nil];
- }
- }
-
-
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
- DLog(@"请求失败:%@",error);
- NSData *returnData = [[error userInfo] objectForKey:@"com.alamofire.serialization.response.error.data"];
- if (returnData) {
- NSDictionary *content = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:nil];//转换数据格式
-
- NSString *errorStr = [NSString stringWithFormat:@"%@",[content objectForKey:@"exceptionInfo"]];
-
- DLog(@"错误的原因:%@",errorStr);
- [JOShowMessageFromNavi showDropViewWithMessage:errorStr ToNavi:self.navigationController withColor:nil];
- }
- else{
- [JOShowMessageFromNavi showDropViewWithMessage:Localized(@"UU_custom_networkFaildPleaseCheck") ToNavi:self.navigationController withColor:nil];
- }
-
- }];
- }
- #pragma mark --- 获取是否开通UU以及是否为好友数据
- -(void)judgeIfOpenUUOrIfMyUUFriend:(NSMutableArray *)arr
- {
- NSString *telephones = @"";
- NSMutableArray *phoneArr = [[NSMutableArray alloc]init];
- for (int i = 0; i < arr.count; i++) {
- NSDictionary *dic = arr[i];
- [phoneArr addObject:[dic objectForKey:@"phone"]];
- }
- telephones = FORMAT(@"%@",[phoneArr componentsJoinedByString:@","]);
-
- // NSString *url = [NSString stringWithFormat:@"%@%@?telephones=%@&userid=%@&token=%@",g_config.apiUrl,act_Queryuser,telephones,g_server.myself.userId,g_token];
- NSString *url = [NSString stringWithFormat:@"%@%@",g_config.apiUrl,act_Queryuser];
-
- if (telephones == nil) {
- telephones = @" ";
- }
- NSDictionary *param = @{
- @"token":g_token,
- @"userid":g_server.myself.userId,
- @"telephones":telephones,
- };
-
- url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- UASNetworkManager *manager = [UASNetworkManager shareManager];
- manager.responseSerializer = [AFJSONResponseSerializer serializer];
- [manager request:url method:POST parameters:param progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
- if (responseObject[@"resultMsg"]) {
-
- [JOShowMessageFromNavi showDropViewWithMessage:responseObject[@"resultMsg"] ToNavi:self.navigationController withColor:nil];
- return ;
- }
-
- NSString *userJsonStr = responseObject[@"user"];
- SBJsonParser *parser = [[SBJsonParser alloc] init];
- NSArray *userjsonArray = [parser objectWithString:userJsonStr error:nil];
-
- [self handleAddressBookDataAndServerData:userjsonArray andLocalArr:arr];
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
-
- DLog(@"请求失败:%@",error);
- NSData *returnData = [[error userInfo] objectForKey:@"com.alamofire.serialization.response.error.data"];
- if (returnData) {
- NSDictionary *content = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:nil];//转换数据格式
-
- NSString *errorStr = [NSString stringWithFormat:@"%@",[content objectForKey:@"exceptionInfo"]];
- if (errorStr == nil || errorStr.length == 0) {
-
- errorStr = Localized(@"UU_custom_networkFaildPleaseCheck");
-
- }
- DLog(@"错误的原因:%@",errorStr);
- [JOShowMessageFromNavi showDropViewWithMessage:errorStr ToNavi:self.navigationController withColor:nil];
- }
- else{
- [JOShowMessageFromNavi showDropViewWithMessage:Localized(@"UU_custom_networkFaildPleaseCheck") ToNavi:self.navigationController withColor:nil];
- }
- }];
- }
- -(void)handleAddressBookDataAndServerData:(NSArray *)arr andLocalArr:(NSMutableArray *)localArr
- {
- NSMutableArray *array = [[NSMutableArray alloc]init];
- for (int i = 0; i < localArr.count; i++) {
- [array addObject:localArr[i]];
- }
- NSMutableArray *dateMutablearray = [[NSMutableArray alloc]init];
-
- for (int i = 0; i < array.count; i++) {
- NSDictionary *dataDic = array[i];
- NSMutableDictionary *newDataDic = [[NSMutableDictionary alloc]init];
- [newDataDic addEntriesFromDictionary:dataDic];
-
- NSString *telephone = [dataDic objectForKey:@"phone"];
- for (int j = 0; j < arr.count; j++) {
- NSDictionary *arrDic = arr[j];
- NSString *imid = FORMAT(@"%@",[arrDic objectForKey:@"_id"]); //IMID
- NSString *isfriend = FORMAT(@"%@",[arrDic objectForKey:@"isfriend"]);//是否为好友
- NSString *phone = FORMAT(@"%@",[arrDic objectForKey:@"telephone"]);//电话
- if ([telephone isEqualToString:phone]) {
- [newDataDic addEntriesFromDictionary:@{@"imid":imid,@"isfriend":isfriend}];
- }
- }
- if (newDataDic.count == 2) {
- [newDataDic addEntriesFromDictionary:@{@"imid":@"xxxxx",@"isfriend":@"2"}];
- }
-
- ContactsModel *model = [[ContactsModel alloc]initWithDic:newDataDic];
- [dateMutablearray addObject:model];
- }
- [[UASUuFriendsManager shareManager] insertAddressFriendsWithDataArray:dateMutablearray withTableName:UU_AllFriends];
- }
- -(void)backAction
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- //初始化搜索框
- - (void)setUpSearchBar
- {
-
- UIView * headerView=[[UIView alloc]init];
- headerView.frame=CGRectMake(0,0,self_width,40);
- headerView.backgroundColor=Colorbai;
-
-
- JOSearchBar * searcher=[JOSearchBar searchBar];
- searcher.frame=CGRectMake(10,5,self_width-20,30);
- searcher.backgroundColor=[UIColor whiteColor];
- [headerView addSubview:searcher];
-
- self.tableView.tableHeaderView=headerView;
-
- UIButton * searchBtn=[UIButton buttonWithType:UIButtonTypeCustom];
- searchBtn.frame=CGRectMake(0, 0,self_width-20,30);
- [searchBtn setTitle:@"" forState:UIControlStateNormal];
- [searchBtn addTarget:self action:@selector(pushToSeachVC) forControlEvents:UIControlEventTouchUpInside];
- [searcher addSubview:searchBtn];
-
-
- }
- #pragma mark -- 跳转搜索界面
- - (void)pushToSeachVC
- {
- DLog(@"searchBar被点击了");
- JOABSearchBarVC * vc = [[JOABSearchBarVC alloc]init];
- vc.fromType = JOABFriend;
- vc.back = ^{
- [_tableView.mj_header beginRefreshing];
- };
- if ([_type isEqualToString:@"bookPeople"]) {
- vc.bookType = @"bookPeople";
- vc.block = ^(ContactsModel *model) {
- self.block(model);
- [self.navigationController popViewControllerAnimated:YES];
- };
- }
-
- [self.navigationController pushViewController:vc animated:YES];
-
- }
- //-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
- //
- // //设置索引字体的颜色
- // tableView.sectionIndexColor =Color(60,162,226,1.0);
- //
- // tableView.sectionIndexBackgroundColor=[UIColor clearColor];
- //
- // return _indexArray;
- //
- //}
- //组数
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
-
- // return _letterOfName.count;
- return 1;
-
- }
- #pragma mark - 数据源以及代理方法
- //组元素个数
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
-
-
- return self.dataArr.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 60;
- }
- //cell初始化
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- // NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%ld%ld", (long)[indexPath section], (long)[indexPath row]];//以indexPath来唯一确定cell
- NSString *CellIdentifier = [NSString stringWithFormat:@"joabfriendsCellid"];
- ContactsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //出列可重用的cell
- if (cell == nil) {
- cell = [[ContactsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- }
- // ContactsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
- ContactsModel *model = self.dataArr[indexPath.row];
- SLog(@"用户IMID:%@",model.imid);
-
- if ([model.imid isEqualToString:@"xxxxx"]) {
-
- cell.friendStatu.numId = model.phoneStr;
- [cell.friendStatu removeTarget:self action:@selector(addFriendWithIMID:) forControlEvents:UIControlEventTouchUpInside];
- [cell.friendStatu removeTarget:self action:@selector(haveAddFriendWithIMID:) forControlEvents:UIControlEventTouchUpInside];
- [cell.friendStatu addTarget:self action:@selector(invitePeople:) forControlEvents:UIControlEventTouchUpInside];
- }else{
- if ([model.isfriend isEqualToString:@"0"]) {
- cell.friendStatu.numId = model.imid;
- [cell.friendStatu removeTarget:self action:@selector(invitePeople:) forControlEvents:UIControlEventTouchUpInside];
- [cell.friendStatu removeTarget:self action:@selector(haveAddFriendWithIMID:) forControlEvents:UIControlEventTouchUpInside];
- [cell.friendStatu addTarget:self action:@selector(addFriendWithIMID:) forControlEvents:UIControlEventTouchUpInside];
- }
- else if ([model.isfriend isEqualToString:@"1"]) {
- cell.friendStatu.numId = model.imid;
- [cell.friendStatu removeTarget:self action:@selector(invitePeople:) forControlEvents:UIControlEventTouchUpInside];
- [cell.friendStatu removeTarget:self action:@selector(addFriendWithIMID:) forControlEvents:UIControlEventTouchUpInside];
- [cell.friendStatu addTarget:self action:@selector(haveAddFriendWithIMID:) forControlEvents:UIControlEventTouchUpInside];
- }
- else{
- }
-
- }
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.EMModel = model;
- return cell;
-
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- if ([_type isEqualToString:@"bookPeople"]) {
- ContactsModel * model = self.dataArr[indexPath.row];
- self.block(model);
- [self.navigationController popViewControllerAnimated:YES];
- }else{
-
- JONewPersonDetailVC * person=[[JONewPersonDetailVC alloc]init];
-
- person.model=_dataArr[indexPath.row];
-
- [self.navigationController pushViewController:person animated:YES];
- }
- }
- - (EmployeeModel *)changeModel:(JOEmployeeModel *)model
- {
- EmployeeModel *model1 = [[EmployeeModel alloc] init];
-
- model1.em_id = model.EM_ID;
- model1.em_imid = model.EM_IMID;
- model1.em_flag=model.FLAG;
- model1.em_defaultorid=model.EM_DEFAULTORID;
- model1.em_code =model.EM_CODE;
- model1.em_name = model.EM_NAME;
- model1.em_position = model.EM_POSITION;
- model1.em_jobs = model.EM_JOBS;
- model1.em_lastdate = model.EM_LASTDATE;
- model1.em_defaultorname = model.EM_DEFAULTORNAME;
- model1.em_depart = model.EM_DEPART;
- model1.em_tel = model.EM_TEL;
- model1.em_mobile = model.EM_MOBILE;
- model1.em_email = model.EM_EMAIL;
- model1.em_uu = model.EM_UU;
- model1.em_iamgeid = model.EM_IMAGEID;
- model1.company =model.COMPANY;
- model1.whichsys = model.WHICHSYS;
-
- return model1;
- }
- #pragma mark -- 网络请求
- /**
- 请求好友列表
- */
- - (void)getArrayData
- {
- NSString *url = [NSString stringWithFormat:@"%@%@?access_token=%@",g_config.apiUrl,act_AttentionList,g_token];
- url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- [[UASNetworkManager shareManager] request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
- [_IMFriendsArray removeAllObjects];
- NSArray *dataArr = responseObject[@"data"];
- NSDictionary *tempDic;
- for (int i = 0 ; i < dataArr.count; i++)
- {
- JXUserObject *obj = [[JXUserObject alloc] init];
- tempDic = [dataArr objectAtIndex:i];
- obj.userNickname = tempDic[@"toNickname"];
-
- obj.userId = [NSString stringWithFormat:@"%@",tempDic[@"toUserId"]];
- obj.status = tempDic[@"status"];
- obj.roomId = tempDic[@"userId"];
- obj.toUserId = tempDic[@"toUserId"];
- obj.telephone = tempDic[@"telephone"];
- NSString *timestamp = [NSString stringWithFormat:@"%@",tempDic[@"createTime"]];
- long long int date1 = (long long int)[timestamp intValue];
- obj.timeCreate = [NSDate dateWithTimeIntervalSince1970:date1];
- [_IMFriendsArray addObject:obj];
- }
-
-
- [[UASUuFriendsManager shareManager] insertUUFriendsWithDataArray:_IMFriendsArray withTableName:UU_AllFriends];
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
- self.completeNum += 1;
- [self observerAllOperationIsOver];
- DLog(@"获取UU好友失败");
- }];
-
- }
- /**
- 请求好友数据
- */
- - (void)senderMessageForPerson:(NSString *)userIm_Id
- {
- [g_server getUser:userIm_Id toView:self];
-
-
- }
- -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
-
- [_IMFriendsArray removeAllObjects];
-
- if ([aDownload.action isEqualToString:act_AttentionList])
- {
- NSDictionary *tempDic;
- for (int i = 0 ; i < array1.count; i++)
- {
- JXUserObject *obj = [[JXUserObject alloc] init];
- tempDic = [array1 objectAtIndex:i];
- obj.userNickname = tempDic[@"toNickname"];
-
- obj.userId = [NSString stringWithFormat:@"%@",tempDic[@"toUserId"]];
- obj.status = tempDic[@"status"];
- obj.roomId = tempDic[@"userId"];
- obj.toUserId = tempDic[@"toUserId"];
- obj.telephone = tempDic[@"telephone"];
- NSString *timestamp = [NSString stringWithFormat:@"%@",tempDic[@"createTime"]];
- long long int date1 = (long long int)[timestamp intValue];
- obj.timeCreate = [NSDate dateWithTimeIntervalSince1970:date1];
- [_IMFriendsArray addObject:obj];
- }
-
-
- [[UASUuFriendsManager shareManager] insertUUFriendsWithDataArray:_IMFriendsArray withTableName:UU_AllFriends];
-
- }
-
-
-
- }
- -(int)didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
-
-
- [JOShowMessageFromNavi showDropViewWithMessage:@"IM掉线,请重新登录" ToNavi:self.navigationController withColor:nil];
- self.completeNum += 1;
- [self observerAllOperationIsOver];
- return hide_error;
-
- }
- -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{
-
- [JOShowMessageFromNavi showDropViewWithMessage:@"IM掉线,请重新登录" ToNavi:self.navigationController withColor:nil];
-
-
- return show_error;
- }
- -(void) didServerConnectStart:(JXConnection*)aDownload{
-
- }
- /**
- 去掉分割线
- */
- - (void)setExtraCellLineHidden: (UITableView *)tableView
- {
-
- UIView *view = [UIView new];
-
- view.backgroundColor = [UIColor clearColor];
-
- [tableView setTableFooterView:view];
- }
- #pragma mark --- 邀请用户,发短信
- -(void)invitePeople:(ZXsubButton *)sender
- {
- if (![NSString valiMobile:sender.numId]) {
- [JOShowMessageFromNavi showDropViewWithMessage:@"手机号码格式不准确,发送失败" ToNavi:self.navigationController withColor:nil];
- return;
- }
- NSURL *urlLoginAuthentication= [NSURL URLWithString:@"http://message.ubtob.com/sms/send"];
- NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:urlLoginAuthentication];
- NSDictionary * jsonDict = @{
- @"receiver":FORMAT(@"%@",sender.numId),
- @"params":@[g_personChineseName],
- @"templateId":@"4b60e18b-de2e-410f-9de1-819265d9e636",
- };
- SLog(@"Dict: %@",jsonDict);
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:NSJSONWritingPrettyPrinted error:nil];
- // NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
- // DLog(@"JSON String: %@",jsonString);
- [request setHTTPMethod:@"POST"];
- [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
- [request setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
- // [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[jsonData length]] forHTTPHeaderField:@"Content-Length"];
- [request setHTTPBody: jsonData];
- [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
- if ((data != nil) && (connectionError == nil)) {
- NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
- SLog(@"返回的数据是什么呢:%@",jsonDict);
- [JOShowMessageFromNavi showDropViewWithMessage:@"发送成功" ToNavi:self.navigationController withColor:nil];
- // [self invitePeople2:FORMAT(@"%ld",(long)sender.tag)];
- }
- else{
- NSString * error = [connectionError localizedDescription];
- [JOShowMessageFromNavi showDropViewWithMessage:error ToNavi:self.navigationController withColor:nil];
-
- }
-
- }];
-
- }
- -(void)invitePeople2:(NSString *)str
- {
- NSURL *urlLoginAuthentication= [NSURL URLWithString:@"http://message.ubtob.com/sms/send"];
- NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:urlLoginAuthentication];
- NSDictionary * jsonDict = @{
- @"receiver":str,
- @"params":@[g_personChineseName],
- @"templateId":@"fd4ac30e-b176-4410-ac0e-e39c8b71dfe0",
- };
- SLog(@"Dict: %@",jsonDict);
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:NSJSONWritingPrettyPrinted error:nil];
- // NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
- // DLog(@"JSON String: %@",jsonString);
- [request setHTTPMethod:@"POST"];
- [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
- [request setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
- // [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[jsonData length]] forHTTPHeaderField:@"Content-Length"];
- [request setHTTPBody: jsonData];
- [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
- if ((data != nil) && (connectionError == nil)) {
- NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
- SLog(@"返回的数据是什么呢:%@",jsonDict);
- [JOShowMessageFromNavi showDropViewWithMessage:@"发送成功" ToNavi:self.navigationController withColor:nil];
- }
- else{
- NSString * error = [connectionError localizedDescription];
- [JOShowMessageFromNavi showDropViewWithMessage:error ToNavi:self.navigationController withColor:nil];
-
- }
-
- }];
- }
- #pragma mark --- 添加好友
- -(void)addFriendWithIMID:(ZXsubButton *)sender
- {
-
- NSString *imidStr = [NSString stringWithFormat:@"%@",sender.numId];
- SLog(@"nini:%@",imidStr);
- ContactsModel *modelTemp = nil;
- for (int i = 0; i<self.dataArr.count; i++) {
- ContactsModel *model = self.dataArr[i];
- if ([imidStr isEqualToString:model.imid]) {
- modelTemp = model;
- }
- }
- NSString *url = [NSString stringWithFormat:@"%@%@?toUserId=%@&access_token=%@",g_config.apiUrl,act_AttentionAdd,FORMAT(@"%@",sender.numId),g_token];
-
- url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- UASNetworkManager *manager = [UASNetworkManager shareManager];
- manager.responseSerializer = [AFJSONResponseSerializer serializer];
- [manager request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
- DLog(@"添加成功好友列表:%@",responseObject);
- if (responseObject[@"resultMsg"]) {
- SLog(@"error:%@",responseObject[@"resultMsg"]);
- if([[NSString stringWithFormat:@"%@",[responseObject objectForKey:@"resultCode"]] isEqualToString:@"1"]){
- modelTemp.isfriend = @"1";
-
- [[UASUuFriendsManager shareManager] updateDataWithPhoneNunber:modelTemp.phoneStr completed:^{
-
- [self.tableView reloadData];
-
- }];
-
-
-
- }
- [JOShowMessageFromNavi showDropViewWithMessage:responseObject[@"resultMsg"] ToNavi:self.navigationController withColor:nil];
- }
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
- DLog(@"请求失败:%@",error);
- NSData *returnData = [[error userInfo] objectForKey:@"NSLocalizedDescription"];
- if (returnData) {
- NSDictionary *content = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:nil];//转换数据格式
-
- NSString *errorStr = [NSString stringWithFormat:@"%@",[content objectForKey:@"exceptionInfo"]];
-
- DLog(@"错误的原因:%@",errorStr);
- if ([errorStr isEqualToString:@"(null)"] || errorStr == nil) {
- [JOShowMessageFromNavi showDropViewWithMessage:@"关注失败,请重新关注" ToNavi:self.navigationController withColor:nil];
- }
- [JOShowMessageFromNavi showDropViewWithMessage:errorStr ToNavi:self.navigationController withColor:nil];
- }
- else{
- [JOShowMessageFromNavi showDropViewWithMessage:Localized(@"UU_custom_networkFaildPleaseCheck") ToNavi:self.navigationController withColor:nil];
- }
- }];
- }
- #pragma mark --- 已添加过好友
- -(void)haveAddFriendWithIMID:(UIButton *)sender
- {
- [JOShowMessageFromNavi showDropViewWithMessage:@"此用户已添加过" ToNavi:self.navigationController withColor:nil];
-
- }
- #pragma mark -- 数据库
- -(NSMutableArray *)dataArr{
- if (_dataArr == nil) {
- _dataArr = [NSMutableArray array];
- }
- return _dataArr;
- }
- #pragma mark - UASUuFriendsManager代理方法
- -(void)companyInsertCompleted{
-
- self.completeNum += 1;
- [self observerAllOperationIsOver];
-
- }
- -(void)uuFriendsInsertCompleted{
-
- self.completeNum += 1;
- [self observerAllOperationIsOver];
-
- }
- -(void)addressInsertCompleted{
-
-
- self.completeNum += 1;
- [self observerAllOperationIsOver];
-
- }
- -(void)observerAllOperationIsOver{
-
-
- if (!g_PersonalUser) {
- if (self.canRead) {//允许读取通讯录
-
- if (self.completeNum >= 3) {
-
-
- [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
-
- self.dataArr = [arr mutableCopy];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [SVProgressHUD dismiss];
- [_tableView.mj_header endRefreshing];
- [self dataSort];
- });
-
- }];
-
-
- }
-
- }else{//不能读取通讯录
- if (self.completeNum >= 2) {
-
-
- [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
-
- self.dataArr = [arr mutableCopy];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [SVProgressHUD dismiss];
- [_tableView.mj_header endRefreshing];
- [self dataSort];
-
- });
- }];
-
-
- }
-
- }
-
- }else{
- if (self.canRead) {//允许读取通讯录
-
- if (self.completeNum >= 2) {
-
- [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
-
- self.dataArr = [arr mutableCopy];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [SVProgressHUD dismiss];
- [_tableView.mj_header endRefreshing];
- [self dataSort];
-
- });
- }];
-
- }
-
- }else{//不能读取通讯录
- if (self.completeNum >= 1) {
-
- [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
-
- self.dataArr = [arr mutableCopy];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [SVProgressHUD dismiss];
- [_tableView.mj_header endRefreshing];
- [self dataSort];
-
- });
- }];
-
- }
-
- }
-
-
- }
- }
- -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
-
- if (scrollView.contentOffset.y > SCREEN_HEIGHT * 2.5) {
- [UIView animateWithDuration:0.4 animations:^{
- CGRect frame = self.upBtn.frame;
- self.upBtn.hidden = NO;
- frame = CGRectMake(SCREEN_WIDTH-70, SCREEN_HEIGHT-164, 50, 50);
- self.upBtn.frame = frame;
- self.upBtn.layer.cornerRadius = 25;
- self.upBtn.layer.masksToBounds = YES;
- }];
- }else{
-
- [UIView animateWithDuration:0.4 animations:^{
- CGRect frame = self.upBtn.frame;
- frame = CGRectMake(SCREEN_WIDTH-70, SCREEN_HEIGHT-164, 0, 0);
- self.upBtn.frame = frame;
- self.upBtn.layer.cornerRadius = 25;
- self.upBtn.layer.masksToBounds = YES;
- }];
-
-
- }
-
-
- }
- -(void)scrollUpToTop{
-
-
- [self.tableView setContentOffset:CGPointMake(0, 0) animated:NO];
-
-
- }
- -(void)dealloc{
-
- }
- -(void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
-
- [SVProgressHUD dismiss];
- }
- - (void)getFriendsData
- {
- // NSString * companyName=[[[NSUserDefaults standardUserDefaults] objectForKey:@"masterDic"]objectForKey:@"ma_function"];
- // _allDataArray=[NSMutableArray arrayWithArray:[self JOSelectTablewithtableName:companyName]];
- //
- // if (_allDataArray.count<=0)
- // {
- //
- // // _noDataImage.hidden=NO;
- // }
- //
- //
- // [_friendsArray removeAllObjects];
- //
- // NSMutableArray * SearchArr=[[NSMutableArray alloc]init];
- //
- // for (int i=0; i<_allDataArray.count; i++)
- // {
- // JOEmployeeModel * model=_allDataArray[i];
- // [_friendsArray addObject:model];
- // [SearchArr addObject:model.EM_NAME];
- //
- // }
- // NSMutableArray *tempArr = [NSMutableArray array];
- // tempArr = [_friendsArray mutableCopy];
- // NSMutableArray *addressArr = [self getAddressFriends];
- // for (int i = 0; i < addressArr.count; i++) {
- // JOEmployeeModel *model = [[JOEmployeeModel alloc]init];
- // model.EM_NAME = [(NSDictionary *)addressArr[i] objectForKey:@"name"];
- // model.EM_MOBILE = [(NSDictionary*)addressArr[i] objectForKey:@"phone"];
- // for (int j = 0; j<tempArr.count; j++) {
- // JOEmployeeModel *fModel = tempArr[i];
- // if ([fModel.EM_MOBILE isEqualToString:model.EM_MOBILE]) {
- // return;
- // }
- // }
- //
- // [_friendsArray addObject:model];
- // [SearchArr addObject:model.EM_NAME];
- // }
- // // 索引数组初始化
- // _indexArray=[[NSMutableArray alloc] initWithArray:@[UITableViewIndexSearch,@"a",@"d",@"f",@"b",@"k",@"m",@"s",@"n"]];
- // _letterOfName=[[NSMutableArray alloc]initWithArray:SearchArr];
- //
- // _indexArray=[ChineseString IndexArray:_letterOfName];
- //
- // _letterOfName=[ChineseString LetterSortArray:_letterOfName];
- //
- // [self.tableView reloadData];
-
-
- }
- @end
|