VisitDestinationVC.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. //
  2. // VisitDestinationVC.m
  3. // shiku_im
  4. //
  5. // Created by huangyp-pc on 17/1/17.
  6. // Copyright © 2017年 Reese. All rights reserved.
  7. //
  8. #import "VisitDestinationVC.h"
  9. #import <MAMapKit/MAMapKit.h>
  10. #import <AMapSearchKit/AMapSearchKit.h>
  11. #import "JOPOIAnnotation.h"
  12. #import <CoreLocation/CoreLocation.h>
  13. #import "JZLocationConverter.h"
  14. #import "AFNetworking.h"
  15. #import "MJExtension.h"
  16. #import "UASLocaManager.h"
  17. #pragma mark -- 自定义的cell
  18. @interface HYPCells : UITableViewCell
  19. -(void)setModel:(HypVisitDmodel *)model;
  20. -(void)setAPIModel:(AMapPOI *)model;
  21. @end
  22. @implementation HYPCells
  23. - (void)setModel:(HypVisitDmodel *)model
  24. {
  25. UILabel * companyTitle = [[UILabel alloc]initWithFrame:CGRectMake(10, 5,SCREEN_WIDTH-10, 30)];
  26. companyTitle.font =FONT_SIZE(13);
  27. companyTitle.numberOfLines = 0;
  28. companyTitle.text = model.CU_NAME;
  29. [self.contentView addSubview:companyTitle];
  30. UILabel * _AddressTitle =[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(companyTitle.frame)-5, SCREEN_WIDTH-20, 30)];
  31. _AddressTitle.font =FONT_SIZE(12);
  32. _AddressTitle.numberOfLines = 0;
  33. _AddressTitle.textColor = Color(150, 149, 149, 1.0);
  34. _AddressTitle.text = model.CU_ADD1;
  35. [self.contentView addSubview:_AddressTitle];
  36. }
  37. - (void)setAPIModel:(AMapPOI *)model
  38. {
  39. UILabel * companyTitle = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,SCREEN_WIDTH-90, 20)];
  40. companyTitle.font =FONT_SIZE(14);
  41. companyTitle.text = model.name;
  42. [self.contentView addSubview:companyTitle];
  43. UILabel * _AddressTitle =[[UILabel alloc]initWithFrame:CGRectMake(10,20, SCREEN_WIDTH-20, 20)];
  44. _AddressTitle.font =FONT_SIZE(12);
  45. _AddressTitle.numberOfLines = 0;
  46. _AddressTitle.textColor = Color(150, 149, 149, 1.0);
  47. _AddressTitle.text = model.address;
  48. [self.contentView addSubview:_AddressTitle];
  49. }
  50. @end
  51. @interface VisitDestinationVC ()<MAMapViewDelegate,AMapSearchDelegate,AMapNearbySearchManagerDelegate,UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate>
  52. {
  53. //地图APLI
  54. MAMapView *_mapView;
  55. //搜索API
  56. AMapSearchAPI * _search;
  57. //关键字搜索API
  58. AMapPOIKeywordsSearchRequest * _KWSerach;
  59. AMapGeoPoint * _MapPonit;
  60. UISearchBar * _searchBar;
  61. //两个tableView
  62. UITableView * _tableView;
  63. UITableView * _searchTableView;
  64. //请求的地址列表
  65. NSMutableArray * _dataArray;
  66. //本地搜索出的地址列表
  67. NSMutableArray * _searchArray;
  68. //本地搜索关键字字符串
  69. NSMutableArray * _searchStrArray;
  70. //地图搜索的API类
  71. NSMutableArray * _searchAPIArray;
  72. UIView *_noDataView;
  73. }
  74. @property(strong,nonatomic)UASLocaManager *locaManager;
  75. @end
  76. @implementation VisitDestinationVC
  77. - (void)viewDidLoad {
  78. [super viewDidLoad];
  79. _dataArray=[[NSMutableArray alloc]init];
  80. _searchArray=[[NSMutableArray alloc]init];
  81. _searchStrArray=[[NSMutableArray alloc]init];
  82. _searchAPIArray=[[NSMutableArray alloc]init];
  83. [self setNavi];
  84. [self setUpSearchBar];
  85. [self setUpMapView];
  86. [self initTableView];
  87. [self setNoDataView];
  88. if (!g_B2BUser) {
  89. [self getDataFromSever];
  90. }
  91. }
  92. - (void)setNavi
  93. {
  94. self.title = Localized(@"UU_work_CRM_visitReport_SelectDestination");
  95. UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
  96. btn2.frame = CGRectMake(0, 5, 22, 22);
  97. UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, iOS11?5:0, 22, 22)];
  98. image.image = [UIImage imageNamed:@"icon_back_nor3"];
  99. [btn2 addSubview:image];
  100. [btn2 addTarget:self action:@selector(NewBack) forControlEvents:UIControlEventTouchUpInside];
  101. UIBarButtonItem *bbi2 = [[UIBarButtonItem alloc]initWithCustomView:btn2];
  102. self.navigationItem.leftBarButtonItems = @[bbi2];
  103. self.view.backgroundColor = [UIColor colorWithRed:235/255.0 green:233/255.0 blue:233/255.0 alpha:1.0];
  104. }
  105. - (void)NewBack
  106. {
  107. [self.navigationController popViewControllerAnimated:YES];
  108. }
  109. - (void)setUpSearchBar
  110. {
  111. _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, 44)];
  112. _searchBar.placeholder = Localized(@"UU_custom_search");
  113. _searchBar.delegate = self;
  114. [self.view addSubview:_searchBar];
  115. }
  116. - (void)setUpMapView
  117. {
  118. if ([UASUserInfo shareManager].inRegion) {
  119. //地图
  120. _mapView = [[MAMapView alloc]initWithFrame:CGRectMake(0,44,SCREEN_WIDTH,162+64)];
  121. _mapView.delegate = self;
  122. // 不显示罗盘
  123. _mapView.showsCompass = NO;
  124. // 不显示比例尺
  125. _mapView.showsScale = NO;
  126. // 地图缩放等级
  127. _mapView.zoomLevel = 15;
  128. // 开启定位
  129. _mapView.showsUserLocation = YES;
  130. _mapView.distanceFilter=10;
  131. _mapView.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;
  132. [self.view addSubview:_mapView];
  133. //地图搜索基类
  134. _search = [[AMapSearchAPI alloc] init];
  135. _search.delegate = self;
  136. //关键字搜索
  137. _KWSerach = [[AMapPOIKeywordsSearchRequest alloc]init];
  138. _KWSerach.keywords =@"";
  139. _KWSerach.types=@"商务住宅|公司企业|地名地址信息";
  140. NSString * str=@"";
  141. str=[[NSUserDefaults standardUserDefaults] objectForKey:@"UUCurrentCity"];
  142. _KWSerach.city=str;
  143. }else{
  144. self.locaManager = [[UASLocaManager alloc] initWithMapviewLocationUpdate:^(UASUserLocation *location, NSError *error) {
  145. }];
  146. self.locaManager.mapView.frame = CGRectMake(0,44,self_width,162+64);
  147. [self.view addSubview:self.locaManager.mapView];
  148. __weak typeof(VisitDestinationVC) *weakSelf = self;
  149. [self.locaManager searchNearbyPlace:nil distance:500 completed:^(BOOL success, NSMutableArray<AMapPOI *> *result) {
  150. __strong typeof(VisitDestinationVC) *strongSelf = weakSelf;
  151. if (!strongSelf) {
  152. return;
  153. }
  154. [strongSelf->_searchAPIArray removeAllObjects];
  155. strongSelf->_searchAPIArray = [result mutableCopy];
  156. strongSelf->_noDataView.hidden = YES;
  157. [strongSelf->_searchTableView reloadData];
  158. }];
  159. }
  160. }
  161. ///**
  162. // 当位置更新时,会进定位回调,通过回调函数,能获取到定位点的经纬度坐标
  163. // */
  164. //
  165. //-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{
  166. //
  167. // [self.mkMapView setCenterCoordinate:CLLocationCoordinate2DMake(userLocation.coordinate.latitude, userLocation.coordinate.longitude) zoomLevel:16 animated:YES];
  168. //
  169. //}
  170. - (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation
  171. updatingLocation:(BOOL)updatingLocation
  172. {
  173. if(updatingLocation)
  174. {
  175. //取出当前位置的坐标
  176. [_mapView setCenterCoordinate:CLLocationCoordinate2DMake(userLocation.coordinate.latitude,userLocation.coordinate.longitude) animated:YES];
  177. }
  178. }
  179. - (void)initTableView
  180. {
  181. _tableView=[[UITableView alloc]init];
  182. _tableView.frame=CGRectMake(0,162+44,SCREEN_WIDTH,
  183. SCREEN_HEIGHT-162-44);
  184. _tableView.dataSource=self;
  185. _tableView.delegate=self;
  186. _tableView.estimatedRowHeight = 0;
  187. // [self setExtraCellLineHidden:_tableView];
  188. // _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  189. [self.view addSubview:_tableView];
  190. UIView *mapView = _mapView != nil?_mapView:self.locaManager.mapView;
  191. [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  192. make.left.right.bottom.equalTo(self.view);
  193. make.top.equalTo(mapView.mas_bottom);
  194. }];
  195. _searchTableView=[[UITableView alloc]init];
  196. _searchTableView.frame=CGRectMake(0,44,SCREEN_WIDTH, SCREEN_HEIGHT-44);
  197. _searchTableView.backgroundColor=[UIColor clearColor];
  198. _searchTableView.delegate=self;
  199. _searchTableView.dataSource=self;
  200. // [self setExtraCellLineHidden:_searchTableView];
  201. [self.view addSubview:_searchTableView];
  202. _searchTableView.hidden=YES;
  203. _searchTableView.estimatedRowHeight = 0;
  204. [_searchTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  205. make.top.equalTo(_searchBar.mas_bottom);
  206. make.left.right.bottom.equalTo(self.view);
  207. }];
  208. // 创建需要的毛玻璃特效类型
  209. UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  210. // 毛玻璃view 视图
  211. UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
  212. //添加到要有毛玻璃特效的控件中
  213. effectView.frame = _searchTableView.frame;
  214. //设置模糊透明度
  215. effectView.alpha = 1.0;
  216. _searchTableView.backgroundView=effectView;
  217. }
  218. -(void)setNoDataView
  219. {
  220. _noDataView = [[UIView alloc]initWithFrame:CGRectMake(0,162+44,SCREEN_WIDTH,SCREEN_HEIGHT-162-44)];
  221. _noDataView.hidden = YES;
  222. [self.view addSubview:_noDataView];
  223. UIView *mapView = _mapView != nil?_mapView:self.locaManager.mapView;
  224. [_noDataView mas_makeConstraints:^(MASConstraintMaker *make) {
  225. make.top.equalTo(mapView.mas_bottom);
  226. make.left.right.bottom.equalTo(self.view);
  227. }];
  228. UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-47)/2, (_noDataView.frame.size.height-57)/2, 47, 57)];
  229. imageV.image = [UIImage imageNamed:@"icon_unsuccessplace_nor2"];
  230. [_noDataView addSubview:imageV];
  231. [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
  232. make.centerX.equalTo(_noDataView);
  233. make.centerY.equalTo(_noDataView).offset(-30);
  234. make.width.mas_equalTo(47);
  235. make.height.mas_equalTo(57);
  236. }];
  237. UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(imageV.frame), SCREEN_WIDTH, 20)];
  238. lbl.textColor = [UIColor lightGrayColor];
  239. lbl.text = @"您还没有客户,请搜索客户名称后添加!";
  240. lbl.font = FONT_SIZE(12);
  241. lbl.textAlignment = NSTextAlignmentCenter;
  242. [_noDataView addSubview:lbl];
  243. [lbl mas_makeConstraints:^(MASConstraintMaker *make) {
  244. make.top.equalTo(imageV.mas_bottom);
  245. make.left.right.equalTo(_noDataView);
  246. make.height.mas_equalTo(20);
  247. }];
  248. }
  249. //请求数据
  250. -(void)getDataFromSever{
  251. NSString *sessionId = [[NSUserDefaults standardUserDefaults] stringForKey:@"sessionId"];
  252. NSString *ip = [UASUserInfo shareManager].urlIp;
  253. NSString *sellercode = [[NSUserDefaults standardUserDefaults] stringForKey:@"erpaccount"];
  254. NSString *master = [[[NSUserDefaults standardUserDefaults] objectForKey:@"masterDic"]objectForKey:@"ma_user"];
  255. NSString *sessionUser = [[NSUserDefaults standardUserDefaults] objectForKey:@"erpaccount"];
  256. NSString *url = [NSString stringWithFormat:@"%@mobile/crm/getCustomerbySeller.action?sellercode=%@&master=%@&sessionUser=%@&sessionId=%@",ip,sellercode,master,sessionUser,sessionId];
  257. UASNetworkManager *manager = [UASNetworkManager shareManager];
  258. manager.responseSerializer = [AFJSONResponseSerializer serializer];
  259. //拼接sessionID
  260. NSString *paramSessionId = [@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
  261. //设置cookie
  262. [manager.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
  263. [manager.requestSerializer setValue:[NSString stringWithFormat:@"%@",g_sessionUser] forHTTPHeaderField:@"sessionUser"];
  264. [manager request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
  265. DLog(@"------:%@",responseObject);
  266. NSString *sessionId = [NSString stringWithFormat:@"%@",responseObject[@"sessionId"]];
  267. if (![sessionId isEqualToString:@"(null)"]) {
  268. [[NSUserDefaults standardUserDefaults] setObject:sessionId forKey:@"sessionId"];
  269. }
  270. [_dataArray removeAllObjects];
  271. [_searchStrArray removeAllObjects];
  272. // NSData *data=responseObject;
  273. //1,系统自带的nsjson解析数据
  274. // id rootDic =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  275. NSDictionary *rootDic = responseObject;
  276. //SLog(@"请求成功:%@",rootDic);
  277. //过滤
  278. rootDic=[NSDictionary changeType:rootDic];
  279. SLog(@"过滤成功%@",rootDic);
  280. NSMutableArray * arr=[[NSMutableArray alloc]init];
  281. arr=[rootDic objectForKey:@"customers"];
  282. for (int i=0;i<arr.count ;i++)
  283. {
  284. HypVisitDmodel * model=[HypVisitDmodel mj_objectWithKeyValues:arr[i]];
  285. [_dataArray addObject:model];
  286. [_searchStrArray addObject:model.CU_NAME];
  287. }
  288. [_tableView reloadData];
  289. if (_dataArray.count == 0) {
  290. _noDataView.hidden = NO;
  291. }else{
  292. _noDataView.hidden = YES;
  293. }
  294. } failure:^(NSURLSessionDataTask *task, NSError *error) {
  295. DLog(@"请求失败:%@",error);
  296. [JOShowMessageFromNavi showDropViewWithMessage:@"客户数据请求失败" ToNavi:self.navigationController withColor:nil];
  297. }];
  298. }
  299. //实现POI搜索对应的回调函数
  300. - (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response
  301. {
  302. [_searchAPIArray removeAllObjects];
  303. DLog(@"%@",response.pois);
  304. for (int i=0; i<response.pois.count;i++)
  305. {
  306. AMapPOI * m=response.pois[i];
  307. [_searchAPIArray addObject:m];
  308. }
  309. _noDataView.hidden = YES;
  310. [_searchTableView reloadData];
  311. }
  312. #pragma mark - tableView展示区域
  313. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  314. if (tableView==_tableView)
  315. {
  316. return 1;
  317. }else{
  318. return 3;
  319. }
  320. }
  321. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  322. if (tableView==_tableView)
  323. {
  324. if (_dataArray.count == 0) {
  325. return 1;
  326. }
  327. return _dataArray.count;
  328. }else{
  329. if (section==0)
  330. {
  331. return _searchArray.count;
  332. }else if (section==1)
  333. {
  334. return _searchAPIArray.count;
  335. }else{
  336. return 1;
  337. }
  338. }
  339. }
  340. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  341. {
  342. if (tableView==_tableView)
  343. {
  344. if (_dataArray.count == 0) {
  345. return SCREEN_HEIGHT-162-64-44;
  346. }
  347. return 60;
  348. }else{
  349. if (indexPath.section==0)
  350. {
  351. return 80;
  352. }else if (indexPath.section==1)
  353. {
  354. return 40;
  355. }else{
  356. return 55;
  357. }
  358. }
  359. }
  360. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  361. {
  362. if (tableView==_searchTableView)
  363. {
  364. if (section<=1)
  365. {
  366. return 25;
  367. }else if (section==2)
  368. {
  369. return 5;
  370. }else{
  371. return 0;
  372. }
  373. }
  374. return 0;
  375. }
  376. //headerView
  377. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  378. {
  379. if (tableView==_searchTableView)
  380. {
  381. if (section<=1)
  382. {
  383. NSArray * array=@[FORMAT(@" %@",Localized(@"UU_work_CRM_visitReport_Enterprise")),FORMAT(@" %@",Localized(@"UU_work_CRM_visitReport_Map"))];
  384. UILabel * label=[[UILabel alloc]init];
  385. label.frame=CGRectMake(0,0,self_width,25);
  386. label.text=array[section];
  387. label.font=FONT_SIZE(12);
  388. label.textColor=Color(150, 149, 149, 1.0);
  389. label.backgroundColor=[UIColor whiteColor];
  390. return label;
  391. }else{
  392. return [UIView new];
  393. }
  394. }
  395. return nil;
  396. }
  397. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  398. {
  399. if (tableView==_searchTableView)
  400. {
  401. if (section<=1)
  402. {
  403. return 5;
  404. }
  405. }
  406. return 0;
  407. }
  408. //FooterView
  409. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  410. {
  411. if (tableView==_searchTableView)
  412. {
  413. if (section<=1)
  414. {
  415. UIView * view=[[UIView alloc]initWithFrame:CGRectMake(0,0,self_width,5)];
  416. view.backgroundColor=[UIColor clearColor];
  417. return view;
  418. }else{
  419. return [UIView new];
  420. }
  421. }
  422. return nil;
  423. }
  424. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  425. if (tableView==_tableView)
  426. {
  427. //1.cell初始化
  428. if(_dataArray.count == 0){
  429. [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
  430. static NSString * ID =@"JOBOR111";
  431. UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:ID];
  432. cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
  433. // tableView.separatorStyle=NO;
  434. UIImageView *imageV=[[UIImageView alloc]init];
  435. imageV.image=[UIImage imageNamed:@"crm_all_noData"];
  436. imageV.frame=CGRectMake((self_width-69)/2,94,69,78);
  437. cell.contentView.backgroundColor=[UIColor clearColor];
  438. // [cell.contentView addSubview:imageV];
  439. cell.selectionStyle=UITableViewCellSelectionStyleNone;
  440. cell.userInteractionEnabled=NO;
  441. return cell;
  442. }
  443. static NSString *identifier = @"cell";
  444. HYPCells * cell = [[HYPCells alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  445. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  446. // cell.backgroundColor=Color(250, 249, 249, 1);
  447. [cell setModel:_dataArray[indexPath.row]];
  448. return cell;
  449. }else if (tableView ==_searchTableView)
  450. {
  451. //1.cell初始化
  452. static NSString *identifier = @"cell";
  453. HYPCells * cell = [[HYPCells alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  454. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  455. cell.backgroundColor=Color(250, 249, 249, 1);
  456. if (indexPath.section==0)
  457. {
  458. [cell setModel:_searchArray[indexPath.row]];
  459. }else if(indexPath.section==1)
  460. {
  461. [cell setAPIModel:_searchAPIArray[indexPath.row]];
  462. }else if (indexPath.section==2)
  463. {
  464. UIImageView * imageV=[[UIImageView alloc]initWithFrame:CGRectMake(10,7.5,40, 40)];
  465. imageV.image=[UIImage imageNamed:@"oa_NoAddressImage"];
  466. [cell.contentView addSubview:imageV];
  467. UILabel * label1=[[UILabel alloc]initWithFrame:CGRectMake(60, 7.5,self_width-100, 20)];
  468. label1.text=Localized(@"UU_work_CRM_visitReport_NoQualifiedResults");
  469. label1.font=FONT_SIZE(14);
  470. [cell.contentView addSubview:label1];
  471. UILabel * label2=[[UILabel alloc]initWithFrame:CGRectMake(60,27.5, self_width-100, 20)];
  472. label2.text=Localized(@"UU_work_CRM_visitReport_CompleteCompanyName");
  473. label2.font=FONT_SIZE(12);
  474. label2.textColor=Color(150, 149, 149, 1.0);
  475. [cell.contentView addSubview:label2];
  476. }
  477. return cell;
  478. }
  479. return nil;
  480. }
  481. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  482. {
  483. if (tableView==_tableView)
  484. {
  485. HypVisitDmodel * model=_dataArray[indexPath.row];
  486. self.backAddress(model);
  487. [self.navigationController popViewControllerAnimated:YES];
  488. }else if (tableView==_searchTableView)
  489. {
  490. [self.view endEditing:YES];
  491. if (indexPath.section==0)
  492. {
  493. HypVisitDmodel * model=_searchArray[indexPath.row];
  494. self.backAddress(model);
  495. [self.navigationController popViewControllerAnimated:YES];
  496. }
  497. if (indexPath.section==1)
  498. {
  499. AMapPOI * model=_searchAPIArray[indexPath.row];
  500. self.backNewAddress(model);
  501. [self.navigationController popViewControllerAnimated:YES];
  502. }
  503. }
  504. }
  505. /**
  506. 去掉分割线
  507. */
  508. - (void)setExtraCellLineHidden: (UITableView *)tableView
  509. {
  510. UIView *view = [UIView new];
  511. view.backgroundColor = [UIColor clearColor];
  512. [tableView setTableFooterView:view];
  513. }
  514. -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  515. {
  516. //发起输入提示搜索
  517. _KWSerach.keywords = searchText;
  518. if ([searchText isEqualToString:@""])
  519. {
  520. _searchTableView.hidden=YES;
  521. [_searchArray removeAllObjects];
  522. }
  523. else{
  524. //匹配当前数据
  525. for (int i=0;i<_searchStrArray.count;i++)
  526. {
  527. searchText = [searchText stringByReplacingOccurrencesOfString:@" " withString:@""];
  528. /**
  529. options:匹配类型(比如是否区分大小写)
  530. */
  531. NSRange range = [_searchStrArray[i] rangeOfString:searchText options:NSCaseInsensitiveSearch];
  532. if (range.location != NSNotFound)
  533. {
  534. [_searchArray addObject:_dataArray[i]];
  535. }
  536. }
  537. _searchTableView.hidden=NO;
  538. [_searchTableView reloadData];
  539. if ([UASUserInfo shareManager].inRegion) {
  540. //搜索
  541. [_search AMapPOIKeywordsSearch:_KWSerach];
  542. // NSString *searchStr = searchBar.text.length > 0 ? searchBar.text:@"";
  543. // [self.locaManager searchWithKeywords:searchStr city:nil completed:^(BOOL success, NSMutableArray<AMapPOI *> *result) {
  544. //
  545. // [_searchAPIArray removeAllObjects];
  546. //
  547. // _searchAPIArray = [result mutableCopy];
  548. //
  549. // MKMapView *mapView = (MKMapView *)self.locaManager.mapView;
  550. //
  551. // if (_searchAPIArray.count>0)
  552. // {
  553. // AMapAOI * mm=_searchAPIArray[0];
  554. //
  555. // [mapView setCenterCoordinate:CLLocationCoordinate2DMake(mm.location.latitude, mm.location.longitude) zoomLevel:16 animated:YES];
  556. // }
  557. //
  558. //
  559. // _noDataView.hidden = YES;
  560. //
  561. // [_searchTableView reloadData];
  562. //
  563. // }];
  564. }else{
  565. NSString *searchStr = searchBar.text.length > 0 ? searchBar.text:@"";
  566. __weak typeof(VisitDestinationVC) *weakSelf = self;
  567. [self.locaManager searchWithKeywords:searchStr city:nil completed:^(BOOL success, NSMutableArray<AMapPOI *> *result) {
  568. __strong typeof(VisitDestinationVC) *strongSelf = weakSelf;
  569. if (!strongSelf) {
  570. return;
  571. }
  572. [strongSelf->_searchAPIArray removeAllObjects];
  573. strongSelf->_searchAPIArray = [result mutableCopy];
  574. MKMapView *mapView = (MKMapView *)strongSelf.locaManager.mapView;
  575. if (strongSelf->_searchAPIArray.count>0)
  576. {
  577. AMapAOI * mm=strongSelf->_searchAPIArray[0];
  578. [mapView setCenterCoordinate:CLLocationCoordinate2DMake(mm.location.latitude, mm.location.longitude) zoomLevel:16 animated:YES];
  579. }
  580. _noDataView.hidden = YES;
  581. [_searchTableView reloadData];
  582. }];
  583. }
  584. }
  585. }
  586. -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  587. {
  588. [_searchBar resignFirstResponder];
  589. }
  590. -(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  591. {
  592. [_searchBar resignFirstResponder];
  593. }
  594. -(void)scrollViewDidScroll:(UIScrollView *)scrollView
  595. {
  596. [self.view endEditing:YES];
  597. }
  598. -(void)viewWillDisappear:(BOOL)animated{
  599. _mapView.showsUserLocation=NO;//停止定位;
  600. }
  601. - (void)didReceiveMemoryWarning {
  602. [super didReceiveMemoryWarning];
  603. // Dispose of any resources that can be recreated.
  604. }
  605. @end