JOGETAddressTableViewController.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // JOGETAddressTableViewController.m
  3. // shiku_im
  4. //
  5. // Created by jobor Zhou on 16/9/29.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #import "JOGETAddressTableViewController.h"
  9. #import "UITableView+WFEmpty.h"
  10. @interface JOGETAddressTableViewController ()
  11. {
  12. NSMutableArray * _dataArray;
  13. NSMutableArray * _dataBrray;
  14. }
  15. @end
  16. @implementation JOGETAddressTableViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. _dataArray=[[NSMutableArray alloc]init];
  20. _dataBrray=[[NSMutableArray alloc]init];
  21. [self setupNav];
  22. [self getDataFromServer];
  23. [self setExtraCellLineHidden:self.tableView];
  24. }
  25. /**
  26. * 设置导航栏内容
  27. */
  28. - (void)setupNav
  29. {
  30. //1,设置标题
  31. UILabel * laebl=[[UILabel alloc]initWithFrame:CGRectMake(0,0,200,40)];
  32. laebl.text=@"请选择会议地点";
  33. laebl.font=FONT_SIZE(18);
  34. laebl.textAlignment=1;
  35. laebl.textColor=[UIColor whiteColor];
  36. self.navigationItem.titleView=laebl;
  37. //2设置导航栏背景颜色
  38. if(iPhoneX){
  39. [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"UU_newPG0X"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
  40. }else{
  41. [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"UU_newPG0"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
  42. }
  43. //3设置导航栏左右按钮
  44. UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
  45. btn2.frame = CGRectMake(0, 5, 22, 22);
  46. UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, iOS11?5:0, 22, 22)];
  47. image.image = [UIImage imageNamed:@"icon_back_nor3"];
  48. [btn2 addSubview:image];
  49. [btn2 addTarget:self action:@selector(backView) forControlEvents:UIControlEventTouchUpInside];
  50. UIBarButtonItem *bbi2 = [[UIBarButtonItem alloc]initWithCustomView:btn2];
  51. self.navigationItem.leftBarButtonItems = @[bbi2];
  52. self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
  53. }
  54. - (void)backView
  55. {
  56. [self dismissViewControllerAnimated:YES completion:nil];
  57. }
  58. - (void)backAddressName:(backAddress)selectAddressName
  59. {
  60. self.selectAddressName=selectAddressName;
  61. }
  62. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  63. {
  64. [self.navigationController dismissViewControllerAnimated:YES completion:^{
  65. self.selectAddressName(_dataArray[indexPath.row],_dataBrray[indexPath.row]);
  66. }];
  67. }
  68. - (void)getDataFromServer
  69. {
  70. [_dataArray removeAllObjects];
  71. //1,创建一个网络请求管理对象
  72. UASNetworkManager *manager1 = [UASNetworkManager shareManager];
  73. manager1.responseSerializer=[AFHTTPResponseSerializer serializer];
  74. //2,取出sessionID和IP
  75. NSUserDefaults *userDefault=[NSUserDefaults standardUserDefaults];
  76. NSString *sessionId=[userDefault stringForKey:@"sessionId"];
  77. NSString * ips=[UASUserInfo shareManager].urlIp;
  78. NSString * userID=[userDefault objectForKey:@"erpaccount"];
  79. //3.拼接sessionID
  80. NSString *paramSessionId=[@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
  81. //4.设置cookie
  82. [manager1.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
  83. NSString *currentMaster=[[userDefault objectForKey:@"masterDic"] objectForKey:@"ma_user"];
  84. /**
  85. url:http://218.17.158.219:8090/ERP//mobile/common/list.action
  86. parms:{emcode=CHENAP, condition=1=1, sessionId=2E3D6B1C3725FC641C5E381A4D95F01B, caller=MeetingRoom, page=1, currentMaster=UAS, pageSize=30}
  87. */
  88. //param.put('condition', 'mr_statuscode='AUDITED'');
  89. //5,接口
  90. NSString * urlAddress=@"mobile/common/list.action";
  91. NSString * caller=@"MeetingRoom";
  92. NSString *url=[@"" stringByAppendingFormat:@"%@%@?emcode=%@&condition=%@&sessionId=%@&caller=%@&page=%@&currentMaster=%@&pageSize=%@",ips,urlAddress,userID,@"mr_statuscode='AUDITED'",sessionId,caller,@"1",currentMaster,@"30"];
  93. DLog(@"url=%@",url);
  94. //7.二进制数据转换
  95. NSString *urlStringUTF8 = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  96. [manager1 request:url method:GET parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  97. NSData *data=responseObject;
  98. //1,系统自带的nsjson解析数据
  99. id rootDic =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  100. // DLog(@"请求会议标签成功:%@",rootDic);
  101. if ([[rootDic allKeys] containsObject:@"sessionId"]==YES)
  102. {
  103. NSString * sessionId=[NSString stringWithFormat:@"%@",[rootDic objectForKey:@"sessionId"]];
  104. [[NSUserDefaults standardUserDefaults] setObject:sessionId forKey:@"sessionId"];
  105. }
  106. /**
  107. "mr_code" = 2016070001;
  108. "mr_name" = test;
  109. */
  110. NSMutableArray * arr=[[NSMutableArray alloc]init];
  111. arr=[rootDic objectForKey:@"listdata"];
  112. for (NSDictionary * obj in arr)
  113. {
  114. [_dataArray addObject:[NSString stringWithFormat:@"%@",[obj objectForKey:@"mr_name"]] ];
  115. [_dataBrray addObject:[NSString stringWithFormat:@"%@",[obj objectForKey:@"mr_code"]]];
  116. }
  117. if(_dataArray.count == 0)
  118. {
  119. [self.tableView addEmptyViewWithImageName:@"crm_all_noData" title:@""];
  120. }
  121. [self.tableView reloadData];
  122. } failure:^(NSURLSessionDataTask *task, NSError *error) {
  123. DLog(@"什么错误呀==%@",error);
  124. [self.tableView addEmptyViewWithImageName:@"crm_all_noData" title:@""];
  125. [((AppDelegate*)[[UIApplication sharedApplication] delegate]) showAlertController:self withMessage:@"获取失败"];
  126. }];
  127. }
  128. - (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  129. {
  130. return _dataArray.count;
  131. }
  132. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  133. {
  134. static NSString *identifier = @"cell";
  135. UITableViewCell * cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  136. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  137. cell.backgroundColor=[UIColor whiteColor];
  138. cell.textLabel.text=_dataArray[indexPath.row];
  139. cell.textLabel.font = FONT_SIZE(15);
  140. return cell;
  141. }
  142. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  143. {
  144. return 40 + cellScale;
  145. }
  146. /**
  147. 去掉分割线
  148. */
  149. - (void)setExtraCellLineHidden: (UITableView *)tableView
  150. {
  151. UIView *view = [UIView new];
  152. view.backgroundColor = [UIColor clearColor];
  153. [tableView setTableFooterView:view];
  154. }
  155. @end