JOABFriendsVC.m 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  1. //
  2. // JOABFriendsVC.m
  3. // shiku_im
  4. //
  5. // Created by jobor Zhou on 2016/10/18.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #define Colorhui Color(235,233,233,1.0)
  9. #define Colorbai Color(244,245,245,1.0)
  10. #import "JOABFriendsVC.h"
  11. //个人资料
  12. //#import "PersonDetail.h"
  13. #import "JOAddressBookCell.h"//自定义cell
  14. #import "EmployeeModel.h"//原来的员工模型
  15. #import "JOEmployeeModel.h"//员工模型
  16. #import "JOSearchBar.h"//搜索框
  17. #import "JOABSearchBarVC.h"//自定义搜索框
  18. #import "JONewPersonDetailVC.h"
  19. #import "ChineseString.h"//指示条
  20. #import "HYPAddressBookManger.h"
  21. #import "UASUuFriendsManager.h"
  22. #import "ContactsCell.h"
  23. #import "MJRefresh.h"
  24. #import "MJExtension.h"
  25. NSString *cellId = @"cellResId";
  26. @interface JOABFriendsVC ()<UITableViewDelegate,UITableViewDataSource,UASUumanagerDelegate>
  27. {
  28. NSMutableArray * _IMFriendsArray;
  29. NSMutableArray * _friendsArray;
  30. NSMutableArray * _allDataArray;
  31. UIImageView * _noDataImage;
  32. //排序
  33. NSMutableArray * _indexArray;//首字母
  34. NSMutableArray * _letterOfName;//名字集合
  35. }
  36. @property (nonatomic,assign)int completeNum;
  37. @property (nonatomic,strong) UITableView * tableView;
  38. @property (nonatomic, strong) JXUserObject * friend;
  39. @property (nonatomic, copy) dispatch_block_t getUserBlock;
  40. @property (nonatomic,assign)BOOL canRead;
  41. @property(weak,nonatomic)UIButton *upBtn;
  42. @end
  43. @implementation JOABFriendsVC
  44. - (void)viewDidLoad {
  45. [super viewDidLoad];
  46. [self setUpUI];
  47. [self getCacheData];
  48. }
  49. - (void)viewWillAppear:(BOOL)animated
  50. {
  51. self.completeNum = 0;
  52. // [[NSNotificationCenter defaultCenter] postNotificationName:@"hiddenTabBar" object:nil];
  53. }
  54. -(void)getCacheData{
  55. [SVProgressHUD showWithStatus:@"正在加载中"];
  56. [[UASUuFriendsManager shareManager] createUuFriendsTablewithtableName:UU_AllFriends completed:^{
  57. [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
  58. [SVProgressHUD dismiss];
  59. self.dataArr = arr;
  60. if (self.dataArr.count == 0 || self.dataArr == nil) {
  61. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"uploadAddressBook"];
  62. [SVProgressHUD showWithStatus:@"正在加载中"];
  63. [self loadMoreData];
  64. }else{
  65. [self dataSort];
  66. }
  67. }];
  68. }];
  69. }
  70. -(void)setUpUI{
  71. self.view.backgroundColor = [UIColor whiteColor];
  72. self.completeNum = 0;
  73. self.title = Localized(@"UU_addressBook_UUGoodFriend");
  74. self.tableView=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
  75. self.tableView.delegate=self;
  76. self.tableView.dataSource=self;
  77. self.tableView.backgroundColor = BGKJ_COLOR;
  78. [self.view addSubview:self.tableView];
  79. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.top.left.right.bottom.equalTo(self.view);
  81. }];
  82. UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
  83. btn2.frame = CGRectMake(0, 5, 22, 22);
  84. UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, iOS11?5:0, 22, 22)];
  85. image.image = [UIImage imageNamed:@"icon_back_nor3"];
  86. [btn2 addSubview:image];
  87. [btn2 addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  88. UIBarButtonItem *bbi2 = [[UIBarButtonItem alloc]initWithCustomView:btn2];
  89. self.navigationItem.leftBarButtonItems = @[bbi2];
  90. [self setUpSearchBar];
  91. //1,去掉多余的分割线
  92. [self setExtraCellLineHidden:self.tableView];
  93. [self.tableView registerClass:[ContactsCell class] forCellReuseIdentifier:cellId];
  94. _IMFriendsArray=[[NSMutableArray alloc]init];
  95. _allDataArray=[[NSMutableArray alloc]init];
  96. _friendsArray=[[NSMutableArray alloc]init];
  97. _noDataImage = [[UIImageView alloc]init];
  98. _noDataImage.image = [UIImage imageNamed:@"crm_all_noData"];
  99. [self.view addSubview:_noDataImage];
  100. _noDataImage.hidden=YES;
  101. [_noDataImage mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.width.mas_equalTo(100);
  103. make.height.mas_equalTo(126);
  104. make.center.equalTo(self.view);
  105. }];
  106. [UASUuFriendsManager shareManager].delegate = self;
  107. UIButton *upBtn = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 70, self.view.height-164, 0, 0)];
  108. [upBtn addTarget:self action:@selector(scrollUpToTop) forControlEvents:UIControlEventTouchUpInside];
  109. [upBtn setImage: [UIImage imageNamed:@"icon_shangla_nor3"] forState:UIControlStateNormal];
  110. [upBtn setImage: [UIImage imageNamed:@"icon_shangla_nor3"] forState:UIControlStateHighlighted];
  111. self.upBtn.hidden = YES;
  112. self.upBtn = upBtn;
  113. upBtn.backgroundColor = [UIColor lightGrayColor];
  114. [self.view addSubview:self.upBtn];
  115. [self.view bringSubviewToFront:self.upBtn];
  116. // self.upBtn.hidden = YES;
  117. //下拉刷新相关函数
  118. __weak typeof(self) weakSelf = self;
  119. _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  120. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  121. __strong JOABFriendsVC *strongSelf = weakSelf;
  122. strongSelf.completeNum = 0;
  123. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"uploadAddressBook"];
  124. if (g_B2BUser)
  125. {
  126. [weakSelf loadMoreData];
  127. }else{
  128. [weakSelf loadMoreData];
  129. }
  130. });
  131. }];
  132. }
  133. /**
  134. 对数组进行排序
  135. */
  136. -(void)dataSort{
  137. NSMutableArray *zero = [NSMutableArray array];
  138. NSMutableArray *one = [NSMutableArray array];
  139. NSMutableArray *two = [NSMutableArray array];
  140. NSMutableArray *three = [NSMutableArray array];
  141. NSMutableArray *four = [NSMutableArray array];
  142. NSMutableArray *tempArr = [self.dataArr mutableCopy];
  143. for (ContactsModel *model in tempArr) {
  144. if([model.isfriend isEqualToString:@"1"]){//已添加
  145. [zero addObject:model];
  146. [self.dataArr removeObject:model];
  147. }
  148. }
  149. tempArr = [self.dataArr mutableCopy];
  150. for (ContactsModel *model in tempArr) {
  151. if ([model.isfriend isEqualToString:@"0"]) {
  152. [one addObject:model];
  153. [self.dataArr removeObject:model];
  154. }
  155. }
  156. tempArr = [self.dataArr mutableCopy];
  157. for (ContactsModel *model in tempArr) {
  158. if([model.type isEqualToString:@"1"]){
  159. [two addObject:model];
  160. [self.dataArr removeObject:model];
  161. }
  162. }
  163. tempArr = [self.dataArr mutableCopy];
  164. for (ContactsModel *model in tempArr) {
  165. if([model.type isEqualToString:@"3"]){
  166. [three addObject:model];
  167. [self.dataArr removeObject:model];
  168. }
  169. }
  170. four = [self.dataArr mutableCopy];
  171. [self.dataArr removeAllObjects];
  172. for (ContactsModel *model in zero) {
  173. [self.dataArr addObject:model];
  174. }
  175. for (ContactsModel *model in one) {
  176. [self.dataArr addObject:model];
  177. }
  178. for (ContactsModel *model in two) {
  179. [self.dataArr addObject:model];
  180. }
  181. for (ContactsModel *model in three) {
  182. [self.dataArr addObject:model];
  183. }
  184. for (ContactsModel *model in four) {
  185. [self.dataArr addObject:model];
  186. }
  187. [self.tableView reloadData];
  188. /*上传本地通讯录到我们服务器*/
  189. if ([[NSUserDefaults standardUserDefaults] boolForKey:@"uploadAddressBook"]) {
  190. [self uploadOwnTelephoneAddressBookToServer:self.dataArr];
  191. }
  192. }
  193. #pragma mark --- 网络请求UU好友,本地取手机通讯录,网络取企业架构
  194. -(void)loadMoreData{
  195. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(12 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  196. [self loadDataFailed];
  197. });
  198. if(![[NSUserDefaults standardUserDefaults]boolForKey:@"netWorkStatus"]) {
  199. [JOShowMessageFromNavi showDropViewWithMessage:Localized(@"UU_custom_networkFaildPleaseCheck") ToNavi:self.navigationController withColor:nil];
  200. return;
  201. }
  202. [[UASUuFriendsManager shareManager] deleteDataWithTable:UU_AllFriends andCompany:g_companyName andWhichsys:g_companyMaster andUserId:MY_USER_ID completed:^{
  203. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  204. [self loadUuFriendsData];
  205. });
  206. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  207. [self loadAddressData];
  208. });
  209. if (g_PersonalUser) {
  210. }else {
  211. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  212. [self loadCompanyData];
  213. });
  214. }
  215. }];
  216. }
  217. -(void)loadDataFailed{
  218. if (self.completeNum == 0) {
  219. // [JOShowMessageFromNavi showDropViewWithMessage:@"当前网络环境差,请检查网络后重试" ToNavi:self.navigationController withColor:nil];
  220. }
  221. if (!g_PersonalUser) {
  222. if (self.canRead) {//允许读取通讯录
  223. if (self.completeNum < 3) {
  224. [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
  225. self.dataArr = arr;
  226. dispatch_async(dispatch_get_main_queue(), ^{
  227. [SVProgressHUD dismiss];
  228. [_tableView.mj_header endRefreshing];
  229. [self dataSort];
  230. });
  231. }];
  232. }
  233. }else{//不能读取通讯录
  234. if (self.completeNum < 2) {
  235. [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
  236. self.dataArr = arr;
  237. dispatch_async(dispatch_get_main_queue(), ^{
  238. [SVProgressHUD dismiss];
  239. [_tableView.mj_header endRefreshing];
  240. [self dataSort];
  241. });
  242. }];
  243. }
  244. }
  245. }else{
  246. if (self.canRead) {//允许读取通讯录
  247. if (self.completeNum < 2) {
  248. [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
  249. self.dataArr = arr;
  250. dispatch_async(dispatch_get_main_queue(), ^{
  251. [SVProgressHUD dismiss];
  252. [_tableView.mj_header endRefreshing];
  253. [self dataSort];
  254. });
  255. }];
  256. }
  257. }else{//不能读取通讯录
  258. if (self.completeNum < 1) {
  259. [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
  260. self.dataArr = arr;
  261. dispatch_async(dispatch_get_main_queue(), ^{
  262. [SVProgressHUD dismiss];
  263. [_tableView.mj_header endRefreshing];
  264. [self dataSort];
  265. });
  266. }];
  267. }
  268. }
  269. }
  270. }
  271. #pragma mark - 刷新数据
  272. -(void)loadAddressData{
  273. [self getAddressFriends];
  274. }
  275. -(void)loadCompanyData{
  276. UASNetworkManager *manager1 = [UASNetworkManager shareManager];
  277. manager1.responseSerializer = [AFHTTPResponseSerializer serializer];
  278. manager1.responseSerializer.acceptableContentTypes =[NSSet setWithObject:@"text/html"];
  279. manager1.responseSerializer.acceptableContentTypes =[NSSet setWithObject:@"application/json"];
  280. NSUserDefaults * userDefault=[NSUserDefaults standardUserDefaults];
  281. NSString *ip=[UASUserInfo shareManager].urlIp;
  282. NSString *sessionId=[userDefault objectForKey:@"sessionId"];
  283. NSString *master=[[userDefault objectForKey:@"masterDic"]objectForKey:@"ma_user"];
  284. NSString *paramSessionId=[@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
  285. NSString * userID=[[NSUserDefaults standardUserDefaults] objectForKey:@"erpaccount"];
  286. [manager1.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
  287. NSString * url=[@"" stringByAppendingFormat:@"%@mobile/getAllHrorgEmps.action?master=%@&lastdate=&sessionUser=%@",ip,master,userID];
  288. [manager1 request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  289. NSData *data=responseObject;
  290. //1,系统自带的nsjson解析数据
  291. id rootDic =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  292. //SLog(@"请求成功啦:%@",rootDic);
  293. rootDic =[NSDictionary changeType:rootDic];
  294. //DLog(@"去掉空字符串%@",rootDic);
  295. NSMutableArray * empArr=[rootDic objectForKey:@"employees"];
  296. NSString * companyName=[[[NSUserDefaults standardUserDefaults] objectForKey:@"masterDic"]objectForKey:@"ma_function"];
  297. companyName=[companyName stringByReplacingOccurrencesOfString:@"(" withString:@""];
  298. companyName=[companyName stringByReplacingOccurrencesOfString:@")" withString:@""];
  299. NSArray *arrayEmp = [JOEmployeeModel objectArrayWithKeyValuesArray:empArr];
  300. [[UASUuFriendsManager shareManager] insertCompanyFriendsWithDataArray:arrayEmp withTableName:UU_AllFriends];
  301. } failure:^(NSURLSessionDataTask *task, NSError *error) {
  302. }];
  303. }
  304. -(void)loadUuFriendsData{
  305. [self getArrayData];
  306. }
  307. #pragma mark --- 取手机本地通讯录
  308. - (void)getAddressFriends{
  309. NSMutableArray *friends = [NSMutableArray array];
  310. [[HYPAddressBookManger shareManger]canReadAddressBookWithBlock:^(BOOL canRead, ABAuthorizationStatus authorStatus) {
  311. self.canRead = canRead;
  312. if (canRead) {
  313. ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
  314. CFArrayRef allLinkPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
  315. CFIndex num = ABAddressBookGetPersonCount(addressBook);
  316. for (NSInteger i = 0; i < num; i++) {
  317. ABRecordRef people = CFArrayGetValueAtIndex(allLinkPeople, i);
  318. /*电话*/
  319. ABMultiValueRef phones = ABRecordCopyValue(people, kABPersonPhoneProperty);
  320. for (int k = 0; k<ABMultiValueGetCount(phones); k++)
  321. {
  322. //获取該Label下的电话值
  323. NSString * personPhone = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phones, k);
  324. //获取该Label下的名值
  325. NSString * personFirstN = (__bridge NSString *)(ABRecordCopyValue(people, kABPersonFirstNameProperty));
  326. //获取该Label下的姓值
  327. NSString * personLastN = (__bridge NSString *)(ABRecordCopyValue(people, kABPersonLastNameProperty));
  328. NSString *newP = [personPhone stringByReplacingOccurrencesOfString:@" " withString:@""];
  329. newP = [newP stringByReplacingOccurrencesOfString:@"-" withString:@""];
  330. newP = [[newP componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] componentsJoinedByString:@""];
  331. // 去除+86
  332. if ([newP containsString:@"+86"]) {
  333. newP = [newP stringByReplacingOccurrencesOfString:@"+86" withString:@""];
  334. }
  335. // 去除+
  336. if ([newP containsString:@"+"]) {
  337. newP = [newP stringByReplacingOccurrencesOfString:@"+" withString:@""];
  338. }
  339. NSRange range = [newP rangeOfString:@"12593"];
  340. if (NSEqualRanges(range, NSMakeRange(0, 5))) {
  341. newP = [newP stringByReplacingOccurrencesOfString:@"12593" withString:@""];
  342. }
  343. if (![friends containsObject:newP]) {
  344. NSString *allName = FORMAT(@"%@%@",personLastN,personFirstN);
  345. if ([allName containsString:@"(null)"]) {
  346. allName = [allName stringByReplacingOccurrencesOfString:@"(null)" withString:@""];
  347. }
  348. NSDictionary *dic = @{@"name":allName,
  349. @"phone":newP};
  350. if([NSString valiMobile:[dic objectForKey:@"phone"]]){
  351. [friends addObject:dic];
  352. }
  353. }
  354. }
  355. }
  356. /*获取是否开通UU以及是否为好友数据*/
  357. [self judgeIfOpenUUOrIfMyUUFriend: friends];
  358. }else{
  359. [[HYPAddressBookManger shareManger] gotoSetting:self];
  360. }
  361. }];
  362. }
  363. #pragma mark --- 上传本地通讯录到我们服务器
  364. -(void)uploadOwnTelephoneAddressBookToServer:(NSMutableArray *)arr
  365. {
  366. NSMutableArray *allDataArr = [[NSMutableArray alloc]init];
  367. for (int i = 0; i < arr.count; i++) {
  368. ContactsModel *model = arr[i];
  369. if ([model.imid isEqualToString:@"xxxxx"]) {
  370. NSDictionary *changeDic = @{@"am_telephone":model.phoneStr,
  371. @"am_username":model.nameStr,
  372. @"am_userid":@"0"};
  373. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:changeDic options:NSJSONWritingPrettyPrinted error:nil];
  374. NSString *paramStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  375. [allDataArr addObject:paramStr];
  376. }
  377. }
  378. NSDictionary *params = @{@"map":FORMAT(@"[%@]",[allDataArr componentsJoinedByString:@","]),
  379. @"userid":g_server.myself.userId,
  380. @"username":g_server.myself.userNickname
  381. };
  382. SLog(@"这里的数据:%@",params);
  383. NSString *url = [NSString stringWithFormat:@"%@%@?token=%@",g_config.apiUrl,act_mobileContact,g_token];
  384. url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  385. UASNetworkManager *manager = [UASNetworkManager shareManager];
  386. manager.responseSerializer = [AFJSONResponseSerializer serializer];
  387. [manager request:url method:POST parameters:params progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  388. SLog(@"chengogngyufou:%@",responseObject);
  389. if (responseObject[@"result"]) {
  390. NSString *str = [NSString stringWithFormat:@"%@",responseObject[@"result"]];
  391. if ([str isEqualToString:@"true"]) {
  392. [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"uploadAddressBook"];
  393. }else{
  394. // [JOShowMessageFromNavi showDropViewWithMessage:responseObject[@"result"] ToNavi:self.navigationController withColor:nil];
  395. }
  396. }
  397. } failure:^(NSURLSessionDataTask *task, NSError *error) {
  398. DLog(@"请求失败:%@",error);
  399. NSData *returnData = [[error userInfo] objectForKey:@"com.alamofire.serialization.response.error.data"];
  400. if (returnData) {
  401. NSDictionary *content = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:nil];//转换数据格式
  402. NSString *errorStr = [NSString stringWithFormat:@"%@",[content objectForKey:@"exceptionInfo"]];
  403. DLog(@"错误的原因:%@",errorStr);
  404. [JOShowMessageFromNavi showDropViewWithMessage:errorStr ToNavi:self.navigationController withColor:nil];
  405. }
  406. else{
  407. [JOShowMessageFromNavi showDropViewWithMessage:Localized(@"UU_custom_networkFaildPleaseCheck") ToNavi:self.navigationController withColor:nil];
  408. }
  409. }];
  410. }
  411. #pragma mark --- 获取是否开通UU以及是否为好友数据
  412. -(void)judgeIfOpenUUOrIfMyUUFriend:(NSMutableArray *)arr
  413. {
  414. NSString *telephones = @"";
  415. NSMutableArray *phoneArr = [[NSMutableArray alloc]init];
  416. for (int i = 0; i < arr.count; i++) {
  417. NSDictionary *dic = arr[i];
  418. [phoneArr addObject:[dic objectForKey:@"phone"]];
  419. }
  420. telephones = FORMAT(@"%@",[phoneArr componentsJoinedByString:@","]);
  421. // NSString *url = [NSString stringWithFormat:@"%@%@?telephones=%@&userid=%@&token=%@",g_config.apiUrl,act_Queryuser,telephones,g_server.myself.userId,g_token];
  422. NSString *url = [NSString stringWithFormat:@"%@%@",g_config.apiUrl,act_Queryuser];
  423. if (telephones == nil) {
  424. telephones = @" ";
  425. }
  426. NSDictionary *param = @{
  427. @"token":g_token,
  428. @"userid":g_server.myself.userId,
  429. @"telephones":telephones,
  430. };
  431. url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  432. UASNetworkManager *manager = [UASNetworkManager shareManager];
  433. manager.responseSerializer = [AFJSONResponseSerializer serializer];
  434. [manager request:url method:POST parameters:param progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  435. if (responseObject[@"resultMsg"]) {
  436. [JOShowMessageFromNavi showDropViewWithMessage:responseObject[@"resultMsg"] ToNavi:self.navigationController withColor:nil];
  437. return ;
  438. }
  439. NSString *userJsonStr = responseObject[@"user"];
  440. SBJsonParser *parser = [[SBJsonParser alloc] init];
  441. NSArray *userjsonArray = [parser objectWithString:userJsonStr error:nil];
  442. [self handleAddressBookDataAndServerData:userjsonArray andLocalArr:arr];
  443. } failure:^(NSURLSessionDataTask *task, NSError *error) {
  444. DLog(@"请求失败:%@",error);
  445. NSData *returnData = [[error userInfo] objectForKey:@"com.alamofire.serialization.response.error.data"];
  446. if (returnData) {
  447. NSDictionary *content = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:nil];//转换数据格式
  448. NSString *errorStr = [NSString stringWithFormat:@"%@",[content objectForKey:@"exceptionInfo"]];
  449. if (errorStr == nil || errorStr.length == 0) {
  450. errorStr = Localized(@"UU_custom_networkFaildPleaseCheck");
  451. }
  452. DLog(@"错误的原因:%@",errorStr);
  453. [JOShowMessageFromNavi showDropViewWithMessage:errorStr ToNavi:self.navigationController withColor:nil];
  454. }
  455. else{
  456. [JOShowMessageFromNavi showDropViewWithMessage:Localized(@"UU_custom_networkFaildPleaseCheck") ToNavi:self.navigationController withColor:nil];
  457. }
  458. }];
  459. }
  460. -(void)handleAddressBookDataAndServerData:(NSArray *)arr andLocalArr:(NSMutableArray *)localArr
  461. {
  462. NSMutableArray *array = [[NSMutableArray alloc]init];
  463. for (int i = 0; i < localArr.count; i++) {
  464. [array addObject:localArr[i]];
  465. }
  466. NSMutableArray *dateMutablearray = [[NSMutableArray alloc]init];
  467. for (int i = 0; i < array.count; i++) {
  468. NSDictionary *dataDic = array[i];
  469. NSMutableDictionary *newDataDic = [[NSMutableDictionary alloc]init];
  470. [newDataDic addEntriesFromDictionary:dataDic];
  471. NSString *telephone = [dataDic objectForKey:@"phone"];
  472. for (int j = 0; j < arr.count; j++) {
  473. NSDictionary *arrDic = arr[j];
  474. NSString *imid = FORMAT(@"%@",[arrDic objectForKey:@"_id"]); //IMID
  475. NSString *isfriend = FORMAT(@"%@",[arrDic objectForKey:@"isfriend"]);//是否为好友
  476. NSString *phone = FORMAT(@"%@",[arrDic objectForKey:@"telephone"]);//电话
  477. if ([telephone isEqualToString:phone]) {
  478. [newDataDic addEntriesFromDictionary:@{@"imid":imid,@"isfriend":isfriend}];
  479. }
  480. }
  481. if (newDataDic.count == 2) {
  482. [newDataDic addEntriesFromDictionary:@{@"imid":@"xxxxx",@"isfriend":@"2"}];
  483. }
  484. ContactsModel *model = [[ContactsModel alloc]initWithDic:newDataDic];
  485. [dateMutablearray addObject:model];
  486. }
  487. [[UASUuFriendsManager shareManager] insertAddressFriendsWithDataArray:dateMutablearray withTableName:UU_AllFriends];
  488. }
  489. -(void)backAction
  490. {
  491. [self.navigationController popViewControllerAnimated:YES];
  492. }
  493. //初始化搜索框
  494. - (void)setUpSearchBar
  495. {
  496. UIView * headerView=[[UIView alloc]init];
  497. headerView.frame=CGRectMake(0,0,self_width,40);
  498. headerView.backgroundColor=Colorbai;
  499. JOSearchBar * searcher=[JOSearchBar searchBar];
  500. searcher.frame=CGRectMake(10,5,self_width-20,30);
  501. searcher.backgroundColor=[UIColor whiteColor];
  502. [headerView addSubview:searcher];
  503. self.tableView.tableHeaderView=headerView;
  504. UIButton * searchBtn=[UIButton buttonWithType:UIButtonTypeCustom];
  505. searchBtn.frame=CGRectMake(0, 0,self_width-20,30);
  506. [searchBtn setTitle:@"" forState:UIControlStateNormal];
  507. [searchBtn addTarget:self action:@selector(pushToSeachVC) forControlEvents:UIControlEventTouchUpInside];
  508. [searcher addSubview:searchBtn];
  509. }
  510. #pragma mark -- 跳转搜索界面
  511. - (void)pushToSeachVC
  512. {
  513. DLog(@"searchBar被点击了");
  514. JOABSearchBarVC * vc = [[JOABSearchBarVC alloc]init];
  515. vc.fromType = JOABFriend;
  516. vc.back = ^{
  517. [_tableView.mj_header beginRefreshing];
  518. };
  519. if ([_type isEqualToString:@"bookPeople"]) {
  520. vc.bookType = @"bookPeople";
  521. vc.block = ^(ContactsModel *model) {
  522. self.block(model);
  523. [self.navigationController popViewControllerAnimated:YES];
  524. };
  525. }
  526. [self.navigationController pushViewController:vc animated:YES];
  527. }
  528. //-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
  529. //
  530. // //设置索引字体的颜色
  531. // tableView.sectionIndexColor =Color(60,162,226,1.0);
  532. //
  533. // tableView.sectionIndexBackgroundColor=[UIColor clearColor];
  534. //
  535. // return _indexArray;
  536. //
  537. //}
  538. //组数
  539. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  540. {
  541. // return _letterOfName.count;
  542. return 1;
  543. }
  544. #pragma mark - 数据源以及代理方法
  545. //组元素个数
  546. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  547. {
  548. return self.dataArr.count;
  549. }
  550. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  551. {
  552. return 60;
  553. }
  554. //cell初始化
  555. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  556. // NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%ld%ld", (long)[indexPath section], (long)[indexPath row]];//以indexPath来唯一确定cell
  557. NSString *CellIdentifier = [NSString stringWithFormat:@"joabfriendsCellid"];
  558. ContactsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //出列可重用的cell
  559. if (cell == nil) {
  560. cell = [[ContactsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  561. }
  562. // ContactsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
  563. ContactsModel *model = self.dataArr[indexPath.row];
  564. SLog(@"用户IMID:%@",model.imid);
  565. if ([model.imid isEqualToString:@"xxxxx"]) {
  566. cell.friendStatu.numId = model.phoneStr;
  567. [cell.friendStatu removeTarget:self action:@selector(addFriendWithIMID:) forControlEvents:UIControlEventTouchUpInside];
  568. [cell.friendStatu removeTarget:self action:@selector(haveAddFriendWithIMID:) forControlEvents:UIControlEventTouchUpInside];
  569. [cell.friendStatu addTarget:self action:@selector(invitePeople:) forControlEvents:UIControlEventTouchUpInside];
  570. }else{
  571. if ([model.isfriend isEqualToString:@"0"]) {
  572. cell.friendStatu.numId = model.imid;
  573. [cell.friendStatu removeTarget:self action:@selector(invitePeople:) forControlEvents:UIControlEventTouchUpInside];
  574. [cell.friendStatu removeTarget:self action:@selector(haveAddFriendWithIMID:) forControlEvents:UIControlEventTouchUpInside];
  575. [cell.friendStatu addTarget:self action:@selector(addFriendWithIMID:) forControlEvents:UIControlEventTouchUpInside];
  576. }
  577. else if ([model.isfriend isEqualToString:@"1"]) {
  578. cell.friendStatu.numId = model.imid;
  579. [cell.friendStatu removeTarget:self action:@selector(invitePeople:) forControlEvents:UIControlEventTouchUpInside];
  580. [cell.friendStatu removeTarget:self action:@selector(addFriendWithIMID:) forControlEvents:UIControlEventTouchUpInside];
  581. [cell.friendStatu addTarget:self action:@selector(haveAddFriendWithIMID:) forControlEvents:UIControlEventTouchUpInside];
  582. }
  583. else{
  584. }
  585. }
  586. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  587. cell.EMModel = model;
  588. return cell;
  589. }
  590. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  591. {
  592. if ([_type isEqualToString:@"bookPeople"]) {
  593. ContactsModel * model = self.dataArr[indexPath.row];
  594. self.block(model);
  595. [self.navigationController popViewControllerAnimated:YES];
  596. }else{
  597. JONewPersonDetailVC * person=[[JONewPersonDetailVC alloc]init];
  598. person.model=_dataArr[indexPath.row];
  599. [self.navigationController pushViewController:person animated:YES];
  600. }
  601. }
  602. - (EmployeeModel *)changeModel:(JOEmployeeModel *)model
  603. {
  604. EmployeeModel *model1 = [[EmployeeModel alloc] init];
  605. model1.em_id = model.EM_ID;
  606. model1.em_imid = model.EM_IMID;
  607. model1.em_flag=model.FLAG;
  608. model1.em_defaultorid=model.EM_DEFAULTORID;
  609. model1.em_code =model.EM_CODE;
  610. model1.em_name = model.EM_NAME;
  611. model1.em_position = model.EM_POSITION;
  612. model1.em_jobs = model.EM_JOBS;
  613. model1.em_lastdate = model.EM_LASTDATE;
  614. model1.em_defaultorname = model.EM_DEFAULTORNAME;
  615. model1.em_depart = model.EM_DEPART;
  616. model1.em_tel = model.EM_TEL;
  617. model1.em_mobile = model.EM_MOBILE;
  618. model1.em_email = model.EM_EMAIL;
  619. model1.em_uu = model.EM_UU;
  620. model1.em_iamgeid = model.EM_IMAGEID;
  621. model1.company =model.COMPANY;
  622. model1.whichsys = model.WHICHSYS;
  623. return model1;
  624. }
  625. #pragma mark -- 网络请求
  626. /**
  627. 请求好友列表
  628. */
  629. - (void)getArrayData
  630. {
  631. NSString *url = [NSString stringWithFormat:@"%@%@?access_token=%@",g_config.apiUrl,act_AttentionList,g_token];
  632. url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  633. [[UASNetworkManager shareManager] request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  634. [_IMFriendsArray removeAllObjects];
  635. NSArray *dataArr = responseObject[@"data"];
  636. NSDictionary *tempDic;
  637. for (int i = 0 ; i < dataArr.count; i++)
  638. {
  639. JXUserObject *obj = [[JXUserObject alloc] init];
  640. tempDic = [dataArr objectAtIndex:i];
  641. obj.userNickname = tempDic[@"toNickname"];
  642. obj.userId = [NSString stringWithFormat:@"%@",tempDic[@"toUserId"]];
  643. obj.status = tempDic[@"status"];
  644. obj.roomId = tempDic[@"userId"];
  645. obj.toUserId = tempDic[@"toUserId"];
  646. obj.telephone = tempDic[@"telephone"];
  647. NSString *timestamp = [NSString stringWithFormat:@"%@",tempDic[@"createTime"]];
  648. long long int date1 = (long long int)[timestamp intValue];
  649. obj.timeCreate = [NSDate dateWithTimeIntervalSince1970:date1];
  650. [_IMFriendsArray addObject:obj];
  651. }
  652. [[UASUuFriendsManager shareManager] insertUUFriendsWithDataArray:_IMFriendsArray withTableName:UU_AllFriends];
  653. } failure:^(NSURLSessionDataTask *task, NSError *error) {
  654. self.completeNum += 1;
  655. [self observerAllOperationIsOver];
  656. DLog(@"获取UU好友失败");
  657. }];
  658. }
  659. /**
  660. 请求好友数据
  661. */
  662. - (void)senderMessageForPerson:(NSString *)userIm_Id
  663. {
  664. [g_server getUser:userIm_Id toView:self];
  665. }
  666. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  667. [_IMFriendsArray removeAllObjects];
  668. if ([aDownload.action isEqualToString:act_AttentionList])
  669. {
  670. NSDictionary *tempDic;
  671. for (int i = 0 ; i < array1.count; i++)
  672. {
  673. JXUserObject *obj = [[JXUserObject alloc] init];
  674. tempDic = [array1 objectAtIndex:i];
  675. obj.userNickname = tempDic[@"toNickname"];
  676. obj.userId = [NSString stringWithFormat:@"%@",tempDic[@"toUserId"]];
  677. obj.status = tempDic[@"status"];
  678. obj.roomId = tempDic[@"userId"];
  679. obj.toUserId = tempDic[@"toUserId"];
  680. obj.telephone = tempDic[@"telephone"];
  681. NSString *timestamp = [NSString stringWithFormat:@"%@",tempDic[@"createTime"]];
  682. long long int date1 = (long long int)[timestamp intValue];
  683. obj.timeCreate = [NSDate dateWithTimeIntervalSince1970:date1];
  684. [_IMFriendsArray addObject:obj];
  685. }
  686. [[UASUuFriendsManager shareManager] insertUUFriendsWithDataArray:_IMFriendsArray withTableName:UU_AllFriends];
  687. }
  688. }
  689. -(int)didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  690. [JOShowMessageFromNavi showDropViewWithMessage:@"IM掉线,请重新登录" ToNavi:self.navigationController withColor:nil];
  691. self.completeNum += 1;
  692. [self observerAllOperationIsOver];
  693. return hide_error;
  694. }
  695. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{
  696. [JOShowMessageFromNavi showDropViewWithMessage:@"IM掉线,请重新登录" ToNavi:self.navigationController withColor:nil];
  697. return show_error;
  698. }
  699. -(void) didServerConnectStart:(JXConnection*)aDownload{
  700. }
  701. /**
  702. 去掉分割线
  703. */
  704. - (void)setExtraCellLineHidden: (UITableView *)tableView
  705. {
  706. UIView *view = [UIView new];
  707. view.backgroundColor = [UIColor clearColor];
  708. [tableView setTableFooterView:view];
  709. }
  710. #pragma mark --- 邀请用户,发短信
  711. -(void)invitePeople:(ZXsubButton *)sender
  712. {
  713. if (![NSString valiMobile:sender.numId]) {
  714. [JOShowMessageFromNavi showDropViewWithMessage:@"手机号码格式不准确,发送失败" ToNavi:self.navigationController withColor:nil];
  715. return;
  716. }
  717. NSURL *urlLoginAuthentication= [NSURL URLWithString:@"http://message.ubtob.com/sms/send"];
  718. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:urlLoginAuthentication];
  719. NSDictionary * jsonDict = @{
  720. @"receiver":FORMAT(@"%@",sender.numId),
  721. @"params":@[g_personChineseName],
  722. @"templateId":@"4b60e18b-de2e-410f-9de1-819265d9e636",
  723. };
  724. SLog(@"Dict: %@",jsonDict);
  725. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:NSJSONWritingPrettyPrinted error:nil];
  726. // NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  727. // DLog(@"JSON String: %@",jsonString);
  728. [request setHTTPMethod:@"POST"];
  729. [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
  730. [request setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
  731. // [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[jsonData length]] forHTTPHeaderField:@"Content-Length"];
  732. [request setHTTPBody: jsonData];
  733. [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
  734. if ((data != nil) && (connectionError == nil)) {
  735. NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  736. SLog(@"返回的数据是什么呢:%@",jsonDict);
  737. [JOShowMessageFromNavi showDropViewWithMessage:@"发送成功" ToNavi:self.navigationController withColor:nil];
  738. // [self invitePeople2:FORMAT(@"%ld",(long)sender.tag)];
  739. }
  740. else{
  741. NSString * error = [connectionError localizedDescription];
  742. [JOShowMessageFromNavi showDropViewWithMessage:error ToNavi:self.navigationController withColor:nil];
  743. }
  744. }];
  745. }
  746. -(void)invitePeople2:(NSString *)str
  747. {
  748. NSURL *urlLoginAuthentication= [NSURL URLWithString:@"http://message.ubtob.com/sms/send"];
  749. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:urlLoginAuthentication];
  750. NSDictionary * jsonDict = @{
  751. @"receiver":str,
  752. @"params":@[g_personChineseName],
  753. @"templateId":@"fd4ac30e-b176-4410-ac0e-e39c8b71dfe0",
  754. };
  755. SLog(@"Dict: %@",jsonDict);
  756. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:NSJSONWritingPrettyPrinted error:nil];
  757. // NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  758. // DLog(@"JSON String: %@",jsonString);
  759. [request setHTTPMethod:@"POST"];
  760. [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
  761. [request setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
  762. // [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[jsonData length]] forHTTPHeaderField:@"Content-Length"];
  763. [request setHTTPBody: jsonData];
  764. [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
  765. if ((data != nil) && (connectionError == nil)) {
  766. NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  767. SLog(@"返回的数据是什么呢:%@",jsonDict);
  768. [JOShowMessageFromNavi showDropViewWithMessage:@"发送成功" ToNavi:self.navigationController withColor:nil];
  769. }
  770. else{
  771. NSString * error = [connectionError localizedDescription];
  772. [JOShowMessageFromNavi showDropViewWithMessage:error ToNavi:self.navigationController withColor:nil];
  773. }
  774. }];
  775. }
  776. #pragma mark --- 添加好友
  777. -(void)addFriendWithIMID:(ZXsubButton *)sender
  778. {
  779. NSString *imidStr = [NSString stringWithFormat:@"%@",sender.numId];
  780. SLog(@"nini:%@",imidStr);
  781. ContactsModel *modelTemp = nil;
  782. for (int i = 0; i<self.dataArr.count; i++) {
  783. ContactsModel *model = self.dataArr[i];
  784. if ([imidStr isEqualToString:model.imid]) {
  785. modelTemp = model;
  786. }
  787. }
  788. NSString *url = [NSString stringWithFormat:@"%@%@?toUserId=%@&access_token=%@",g_config.apiUrl,act_AttentionAdd,FORMAT(@"%@",sender.numId),g_token];
  789. url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  790. UASNetworkManager *manager = [UASNetworkManager shareManager];
  791. manager.responseSerializer = [AFJSONResponseSerializer serializer];
  792. [manager request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  793. DLog(@"添加成功好友列表:%@",responseObject);
  794. if (responseObject[@"resultMsg"]) {
  795. SLog(@"error:%@",responseObject[@"resultMsg"]);
  796. if([[NSString stringWithFormat:@"%@",[responseObject objectForKey:@"resultCode"]] isEqualToString:@"1"]){
  797. modelTemp.isfriend = @"1";
  798. [[UASUuFriendsManager shareManager] updateDataWithPhoneNunber:modelTemp.phoneStr completed:^{
  799. [self.tableView reloadData];
  800. }];
  801. }
  802. [JOShowMessageFromNavi showDropViewWithMessage:responseObject[@"resultMsg"] ToNavi:self.navigationController withColor:nil];
  803. }
  804. } failure:^(NSURLSessionDataTask *task, NSError *error) {
  805. DLog(@"请求失败:%@",error);
  806. NSData *returnData = [[error userInfo] objectForKey:@"NSLocalizedDescription"];
  807. if (returnData) {
  808. NSDictionary *content = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:nil];//转换数据格式
  809. NSString *errorStr = [NSString stringWithFormat:@"%@",[content objectForKey:@"exceptionInfo"]];
  810. DLog(@"错误的原因:%@",errorStr);
  811. if ([errorStr isEqualToString:@"(null)"] || errorStr == nil) {
  812. [JOShowMessageFromNavi showDropViewWithMessage:@"关注失败,请重新关注" ToNavi:self.navigationController withColor:nil];
  813. }
  814. [JOShowMessageFromNavi showDropViewWithMessage:errorStr ToNavi:self.navigationController withColor:nil];
  815. }
  816. else{
  817. [JOShowMessageFromNavi showDropViewWithMessage:Localized(@"UU_custom_networkFaildPleaseCheck") ToNavi:self.navigationController withColor:nil];
  818. }
  819. }];
  820. }
  821. #pragma mark --- 已添加过好友
  822. -(void)haveAddFriendWithIMID:(UIButton *)sender
  823. {
  824. [JOShowMessageFromNavi showDropViewWithMessage:@"此用户已添加过" ToNavi:self.navigationController withColor:nil];
  825. }
  826. #pragma mark -- 数据库
  827. -(NSMutableArray *)dataArr{
  828. if (_dataArr == nil) {
  829. _dataArr = [NSMutableArray array];
  830. }
  831. return _dataArr;
  832. }
  833. #pragma mark - UASUuFriendsManager代理方法
  834. -(void)companyInsertCompleted{
  835. self.completeNum += 1;
  836. [self observerAllOperationIsOver];
  837. }
  838. -(void)uuFriendsInsertCompleted{
  839. self.completeNum += 1;
  840. [self observerAllOperationIsOver];
  841. }
  842. -(void)addressInsertCompleted{
  843. self.completeNum += 1;
  844. [self observerAllOperationIsOver];
  845. }
  846. -(void)observerAllOperationIsOver{
  847. if (!g_PersonalUser) {
  848. if (self.canRead) {//允许读取通讯录
  849. if (self.completeNum >= 3) {
  850. [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
  851. self.dataArr = [arr mutableCopy];
  852. dispatch_async(dispatch_get_main_queue(), ^{
  853. [SVProgressHUD dismiss];
  854. [_tableView.mj_header endRefreshing];
  855. [self dataSort];
  856. });
  857. }];
  858. }
  859. }else{//不能读取通讯录
  860. if (self.completeNum >= 2) {
  861. [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
  862. self.dataArr = [arr mutableCopy];
  863. dispatch_async(dispatch_get_main_queue(), ^{
  864. [SVProgressHUD dismiss];
  865. [_tableView.mj_header endRefreshing];
  866. [self dataSort];
  867. });
  868. }];
  869. }
  870. }
  871. }else{
  872. if (self.canRead) {//允许读取通讯录
  873. if (self.completeNum >= 2) {
  874. [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
  875. self.dataArr = [arr mutableCopy];
  876. dispatch_async(dispatch_get_main_queue(), ^{
  877. [SVProgressHUD dismiss];
  878. [_tableView.mj_header endRefreshing];
  879. [self dataSort];
  880. });
  881. }];
  882. }
  883. }else{//不能读取通讯录
  884. if (self.completeNum >= 1) {
  885. [[UASUuFriendsManager shareManager] selectTablewithtableName:UU_AllFriends andCompleted:^(NSMutableArray *arr) {
  886. self.dataArr = [arr mutableCopy];
  887. dispatch_async(dispatch_get_main_queue(), ^{
  888. [SVProgressHUD dismiss];
  889. [_tableView.mj_header endRefreshing];
  890. [self dataSort];
  891. });
  892. }];
  893. }
  894. }
  895. }
  896. }
  897. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  898. if (scrollView.contentOffset.y > SCREEN_HEIGHT * 2.5) {
  899. [UIView animateWithDuration:0.4 animations:^{
  900. CGRect frame = self.upBtn.frame;
  901. self.upBtn.hidden = NO;
  902. frame = CGRectMake(SCREEN_WIDTH-70, SCREEN_HEIGHT-164, 50, 50);
  903. self.upBtn.frame = frame;
  904. self.upBtn.layer.cornerRadius = 25;
  905. self.upBtn.layer.masksToBounds = YES;
  906. }];
  907. }else{
  908. [UIView animateWithDuration:0.4 animations:^{
  909. CGRect frame = self.upBtn.frame;
  910. frame = CGRectMake(SCREEN_WIDTH-70, SCREEN_HEIGHT-164, 0, 0);
  911. self.upBtn.frame = frame;
  912. self.upBtn.layer.cornerRadius = 25;
  913. self.upBtn.layer.masksToBounds = YES;
  914. }];
  915. }
  916. }
  917. -(void)scrollUpToTop{
  918. [self.tableView setContentOffset:CGPointMake(0, 0) animated:NO];
  919. }
  920. -(void)dealloc{
  921. }
  922. -(void)viewWillDisappear:(BOOL)animated{
  923. [super viewWillDisappear:animated];
  924. [SVProgressHUD dismiss];
  925. }
  926. - (void)getFriendsData
  927. {
  928. // NSString * companyName=[[[NSUserDefaults standardUserDefaults] objectForKey:@"masterDic"]objectForKey:@"ma_function"];
  929. // _allDataArray=[NSMutableArray arrayWithArray:[self JOSelectTablewithtableName:companyName]];
  930. //
  931. // if (_allDataArray.count<=0)
  932. // {
  933. //
  934. // // _noDataImage.hidden=NO;
  935. // }
  936. //
  937. //
  938. // [_friendsArray removeAllObjects];
  939. //
  940. // NSMutableArray * SearchArr=[[NSMutableArray alloc]init];
  941. //
  942. // for (int i=0; i<_allDataArray.count; i++)
  943. // {
  944. // JOEmployeeModel * model=_allDataArray[i];
  945. // [_friendsArray addObject:model];
  946. // [SearchArr addObject:model.EM_NAME];
  947. //
  948. // }
  949. // NSMutableArray *tempArr = [NSMutableArray array];
  950. // tempArr = [_friendsArray mutableCopy];
  951. // NSMutableArray *addressArr = [self getAddressFriends];
  952. // for (int i = 0; i < addressArr.count; i++) {
  953. // JOEmployeeModel *model = [[JOEmployeeModel alloc]init];
  954. // model.EM_NAME = [(NSDictionary *)addressArr[i] objectForKey:@"name"];
  955. // model.EM_MOBILE = [(NSDictionary*)addressArr[i] objectForKey:@"phone"];
  956. // for (int j = 0; j<tempArr.count; j++) {
  957. // JOEmployeeModel *fModel = tempArr[i];
  958. // if ([fModel.EM_MOBILE isEqualToString:model.EM_MOBILE]) {
  959. // return;
  960. // }
  961. // }
  962. //
  963. // [_friendsArray addObject:model];
  964. // [SearchArr addObject:model.EM_NAME];
  965. // }
  966. // // 索引数组初始化
  967. // _indexArray=[[NSMutableArray alloc] initWithArray:@[UITableViewIndexSearch,@"a",@"d",@"f",@"b",@"k",@"m",@"s",@"n"]];
  968. // _letterOfName=[[NSMutableArray alloc]initWithArray:SearchArr];
  969. //
  970. // _indexArray=[ChineseString IndexArray:_letterOfName];
  971. //
  972. // _letterOfName=[ChineseString LetterSortArray:_letterOfName];
  973. //
  974. // [self.tableView reloadData];
  975. }
  976. @end