| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857 |
- //
- // VisitDestinationVC.m
- // shiku_im
- //
- // Created by huangyp-pc on 17/1/17.
- // Copyright © 2017年 Reese. All rights reserved.
- //
- #import "VisitDestinationVC.h"
- #import <MAMapKit/MAMapKit.h>
- #import <AMapSearchKit/AMapSearchKit.h>
- #import "JOPOIAnnotation.h"
- #import <CoreLocation/CoreLocation.h>
- #import "JZLocationConverter.h"
- #import "AFNetworking.h"
- #import "MJExtension.h"
- #import "UASLocaManager.h"
- #pragma mark -- 自定义的cell
- @interface HYPCells : UITableViewCell
- -(void)setModel:(HypVisitDmodel *)model;
- -(void)setAPIModel:(AMapPOI *)model;
- @end
- @implementation HYPCells
- - (void)setModel:(HypVisitDmodel *)model
- {
- UILabel * companyTitle = [[UILabel alloc]initWithFrame:CGRectMake(10, 5,SCREEN_WIDTH-10, 30)];
- companyTitle.font =FONT_SIZE(13);
- companyTitle.numberOfLines = 0;
- companyTitle.text = model.CU_NAME;
- [self.contentView addSubview:companyTitle];
-
-
- UILabel * _AddressTitle =[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(companyTitle.frame)-5, SCREEN_WIDTH-20, 30)];
- _AddressTitle.font =FONT_SIZE(12);
- _AddressTitle.numberOfLines = 0;
- _AddressTitle.textColor = Color(150, 149, 149, 1.0);
- _AddressTitle.text = model.CU_ADD1;
- [self.contentView addSubview:_AddressTitle];
- }
- - (void)setAPIModel:(AMapPOI *)model
- {
- UILabel * companyTitle = [[UILabel alloc]initWithFrame:CGRectMake(10, 0,SCREEN_WIDTH-90, 20)];
- companyTitle.font =FONT_SIZE(14);
- companyTitle.text = model.name;
- [self.contentView addSubview:companyTitle];
-
-
- UILabel * _AddressTitle =[[UILabel alloc]initWithFrame:CGRectMake(10,20, SCREEN_WIDTH-20, 20)];
- _AddressTitle.font =FONT_SIZE(12);
- _AddressTitle.numberOfLines = 0;
- _AddressTitle.textColor = Color(150, 149, 149, 1.0);
- _AddressTitle.text = model.address;
- [self.contentView addSubview:_AddressTitle];
- }
- @end
- @interface VisitDestinationVC ()<MAMapViewDelegate,AMapSearchDelegate,AMapNearbySearchManagerDelegate,UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate>
- {
- //地图APLI
- MAMapView *_mapView;
- //搜索API
- AMapSearchAPI * _search;
- //关键字搜索API
- AMapPOIKeywordsSearchRequest * _KWSerach;
-
- AMapGeoPoint * _MapPonit;
-
- UISearchBar * _searchBar;
-
- //两个tableView
- UITableView * _tableView;
-
- UITableView * _searchTableView;
-
- //请求的地址列表
- NSMutableArray * _dataArray;
-
- //本地搜索出的地址列表
- NSMutableArray * _searchArray;
-
- //本地搜索关键字字符串
- NSMutableArray * _searchStrArray;
-
- //地图搜索的API类
- NSMutableArray * _searchAPIArray;
-
- UIView *_noDataView;
- }
- @property(strong,nonatomic)UASLocaManager *locaManager;
- @end
- @implementation VisitDestinationVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- _dataArray=[[NSMutableArray alloc]init];
- _searchArray=[[NSMutableArray alloc]init];
- _searchStrArray=[[NSMutableArray alloc]init];
- _searchAPIArray=[[NSMutableArray alloc]init];
-
- [self setNavi];
- [self setUpSearchBar];
- [self setUpMapView];
- [self initTableView];
- [self setNoDataView];
-
- if (!g_B2BUser) {
- [self getDataFromSever];
- }
- }
- - (void)setNavi
- {
- self.title = Localized(@"UU_work_CRM_visitReport_SelectDestination");
- 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(NewBack) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *bbi2 = [[UIBarButtonItem alloc]initWithCustomView:btn2];
- self.navigationItem.leftBarButtonItems = @[bbi2];
-
- self.view.backgroundColor = [UIColor colorWithRed:235/255.0 green:233/255.0 blue:233/255.0 alpha:1.0];
-
- }
- - (void)NewBack
- {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)setUpSearchBar
- {
- _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, 44)];
- _searchBar.placeholder = Localized(@"UU_custom_search");
- _searchBar.delegate = self;
-
- [self.view addSubview:_searchBar];
-
-
- }
- - (void)setUpMapView
- {
-
- if ([UASUserInfo shareManager].inRegion) {
-
- //地图
- _mapView = [[MAMapView alloc]initWithFrame:CGRectMake(0,44,SCREEN_WIDTH,162+64)];
- _mapView.delegate = self;
- // 不显示罗盘
- _mapView.showsCompass = NO;
- // 不显示比例尺
- _mapView.showsScale = NO;
- // 地图缩放等级
- _mapView.zoomLevel = 15;
- // 开启定位
- _mapView.showsUserLocation = YES;
-
- _mapView.distanceFilter=10;
-
- _mapView.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;
-
- [self.view addSubview:_mapView];
-
- //地图搜索基类
- _search = [[AMapSearchAPI alloc] init];
- _search.delegate = self;
-
- //关键字搜索
- _KWSerach = [[AMapPOIKeywordsSearchRequest alloc]init];
- _KWSerach.keywords =@"";
- _KWSerach.types=@"商务住宅|公司企业|地名地址信息";
- NSString * str=@"";
- str=[[NSUserDefaults standardUserDefaults] objectForKey:@"UUCurrentCity"];
- _KWSerach.city=str;
-
- }else{
-
-
- self.locaManager = [[UASLocaManager alloc] initWithMapviewLocationUpdate:^(UASUserLocation *location, NSError *error) {
-
-
-
- }];
-
- self.locaManager.mapView.frame = CGRectMake(0,44,self_width,162+64);
-
- [self.view addSubview:self.locaManager.mapView];
-
- __weak typeof(VisitDestinationVC) *weakSelf = self;
- [self.locaManager searchNearbyPlace:nil distance:500 completed:^(BOOL success, NSMutableArray<AMapPOI *> *result) {
-
- __strong typeof(VisitDestinationVC) *strongSelf = weakSelf;
-
- if (!strongSelf) {
-
- return;
-
- }
-
- [strongSelf->_searchAPIArray removeAllObjects];
-
- strongSelf->_searchAPIArray = [result mutableCopy];
-
- strongSelf->_noDataView.hidden = YES;
-
- [strongSelf->_searchTableView reloadData];
-
- }];
-
-
- }
-
- }
- ///**
- // 当位置更新时,会进定位回调,通过回调函数,能获取到定位点的经纬度坐标
- // */
- //
- //-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{
- //
- // [self.mkMapView setCenterCoordinate:CLLocationCoordinate2DMake(userLocation.coordinate.latitude, userLocation.coordinate.longitude) zoomLevel:16 animated:YES];
- //
- //}
- - (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation
- updatingLocation:(BOOL)updatingLocation
- {
- if(updatingLocation)
- {
- //取出当前位置的坐标
- [_mapView setCenterCoordinate:CLLocationCoordinate2DMake(userLocation.coordinate.latitude,userLocation.coordinate.longitude) animated:YES];
- }
- }
- - (void)initTableView
- {
- _tableView=[[UITableView alloc]init];
- _tableView.frame=CGRectMake(0,162+44,SCREEN_WIDTH,
- SCREEN_HEIGHT-162-44);
- _tableView.dataSource=self;
- _tableView.delegate=self;
- _tableView.estimatedRowHeight = 0;
- // [self setExtraCellLineHidden:_tableView];
- // _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
- [self.view addSubview:_tableView];
-
- UIView *mapView = _mapView != nil?_mapView:self.locaManager.mapView;
-
- [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.left.right.bottom.equalTo(self.view);
- make.top.equalTo(mapView.mas_bottom);
-
- }];
-
-
- _searchTableView=[[UITableView alloc]init];
- _searchTableView.frame=CGRectMake(0,44,SCREEN_WIDTH, SCREEN_HEIGHT-44);
- _searchTableView.backgroundColor=[UIColor clearColor];
- _searchTableView.delegate=self;
- _searchTableView.dataSource=self;
- // [self setExtraCellLineHidden:_searchTableView];
- [self.view addSubview:_searchTableView];
- _searchTableView.hidden=YES;
- _searchTableView.estimatedRowHeight = 0;
- [_searchTableView mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.top.equalTo(_searchBar.mas_bottom);
- make.left.right.bottom.equalTo(self.view);
-
- }];
-
- // 创建需要的毛玻璃特效类型
- UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
- // 毛玻璃view 视图
- UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
-
- //添加到要有毛玻璃特效的控件中
- effectView.frame = _searchTableView.frame;
- //设置模糊透明度
- effectView.alpha = 1.0;
- _searchTableView.backgroundView=effectView;
- }
- -(void)setNoDataView
- {
- _noDataView = [[UIView alloc]initWithFrame:CGRectMake(0,162+44,SCREEN_WIDTH,SCREEN_HEIGHT-162-44)];
- _noDataView.hidden = YES;
- [self.view addSubview:_noDataView];
- UIView *mapView = _mapView != nil?_mapView:self.locaManager.mapView;
- [_noDataView mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.top.equalTo(mapView.mas_bottom);
- make.left.right.bottom.equalTo(self.view);
-
- }];
-
- UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-47)/2, (_noDataView.frame.size.height-57)/2, 47, 57)];
- imageV.image = [UIImage imageNamed:@"icon_unsuccessplace_nor2"];
- [_noDataView addSubview:imageV];
- [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.centerX.equalTo(_noDataView);
- make.centerY.equalTo(_noDataView).offset(-30);
- make.width.mas_equalTo(47);
- make.height.mas_equalTo(57);
-
- }];
- UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(imageV.frame), SCREEN_WIDTH, 20)];
- lbl.textColor = [UIColor lightGrayColor];
- lbl.text = @"您还没有客户,请搜索客户名称后添加!";
- lbl.font = FONT_SIZE(12);
- lbl.textAlignment = NSTextAlignmentCenter;
- [_noDataView addSubview:lbl];
- [lbl mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.top.equalTo(imageV.mas_bottom);
- make.left.right.equalTo(_noDataView);
- make.height.mas_equalTo(20);
-
- }];
-
-
- }
- //请求数据
- -(void)getDataFromSever{
- NSString *sessionId = [[NSUserDefaults standardUserDefaults] stringForKey:@"sessionId"];
- NSString *ip = [UASUserInfo shareManager].urlIp;
- NSString *sellercode = [[NSUserDefaults standardUserDefaults] stringForKey:@"erpaccount"];
- NSString *master = [[[NSUserDefaults standardUserDefaults] objectForKey:@"masterDic"]objectForKey:@"ma_user"];
- NSString *sessionUser = [[NSUserDefaults standardUserDefaults] objectForKey:@"erpaccount"];
-
- NSString *url = [NSString stringWithFormat:@"%@mobile/crm/getCustomerbySeller.action?sellercode=%@&master=%@&sessionUser=%@&sessionId=%@",ip,sellercode,master,sessionUser,sessionId];
-
- UASNetworkManager *manager = [UASNetworkManager shareManager];
- manager.responseSerializer = [AFJSONResponseSerializer serializer];
- //拼接sessionID
- NSString *paramSessionId = [@"" stringByAppendingFormat:@"JSESSIONID=%@",sessionId];
- //设置cookie
- [manager.requestSerializer setValue:paramSessionId forHTTPHeaderField:@"Cookie"];
- [manager.requestSerializer setValue:[NSString stringWithFormat:@"%@",g_sessionUser] forHTTPHeaderField:@"sessionUser"];
- [manager request:url method:POST parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
- DLog(@"------:%@",responseObject);
- NSString *sessionId = [NSString stringWithFormat:@"%@",responseObject[@"sessionId"]];
- if (![sessionId isEqualToString:@"(null)"]) {
- [[NSUserDefaults standardUserDefaults] setObject:sessionId forKey:@"sessionId"];
- }
-
- [_dataArray removeAllObjects];
- [_searchStrArray removeAllObjects];
- // NSData *data=responseObject;
- //1,系统自带的nsjson解析数据
- // id rootDic =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
- NSDictionary *rootDic = responseObject;
- //SLog(@"请求成功:%@",rootDic);
- //过滤
- rootDic=[NSDictionary changeType:rootDic];
- SLog(@"过滤成功%@",rootDic);
-
- NSMutableArray * arr=[[NSMutableArray alloc]init];
- arr=[rootDic objectForKey:@"customers"];
- for (int i=0;i<arr.count ;i++)
- {
- HypVisitDmodel * model=[HypVisitDmodel mj_objectWithKeyValues:arr[i]];
- [_dataArray addObject:model];
- [_searchStrArray addObject:model.CU_NAME];
-
- }
-
- [_tableView reloadData];
-
- if (_dataArray.count == 0) {
- _noDataView.hidden = NO;
- }else{
- _noDataView.hidden = YES;
- }
- } failure:^(NSURLSessionDataTask *task, NSError *error) {
- DLog(@"请求失败:%@",error);
- [JOShowMessageFromNavi showDropViewWithMessage:@"客户数据请求失败" ToNavi:self.navigationController withColor:nil];
- }];
- }
- //实现POI搜索对应的回调函数
- - (void)onPOISearchDone:(AMapPOISearchBaseRequest *)request response:(AMapPOISearchResponse *)response
- {
- [_searchAPIArray removeAllObjects];
-
- DLog(@"%@",response.pois);
-
- for (int i=0; i<response.pois.count;i++)
- {
- AMapPOI * m=response.pois[i];
-
- [_searchAPIArray addObject:m];
-
- }
-
- _noDataView.hidden = YES;
-
- [_searchTableView reloadData];
-
- }
- #pragma mark - tableView展示区域
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
-
- if (tableView==_tableView)
- {
- return 1;
- }else{
-
- return 3;
- }
-
-
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-
- if (tableView==_tableView)
- {
- if (_dataArray.count == 0) {
- return 1;
- }
-
- return _dataArray.count;
- }else{
- if (section==0)
- {
- return _searchArray.count;
- }else if (section==1)
- {
- return _searchAPIArray.count;
- }else{
-
- return 1;
- }
-
- }
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (tableView==_tableView)
- {
- if (_dataArray.count == 0) {
- return SCREEN_HEIGHT-162-64-44;
- }
- return 60;
- }else{
- if (indexPath.section==0)
- {
- return 80;
- }else if (indexPath.section==1)
- {
- return 40;
- }else{
-
- return 55;
- }
-
- }
-
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- if (tableView==_searchTableView)
- {
- if (section<=1)
- {
- return 25;
- }else if (section==2)
- {
- return 5;
- }else{
- return 0;
- }
- }
- return 0;
- }
- //headerView
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
-
- if (tableView==_searchTableView)
- {
- if (section<=1)
- {
- NSArray * array=@[FORMAT(@" %@",Localized(@"UU_work_CRM_visitReport_Enterprise")),FORMAT(@" %@",Localized(@"UU_work_CRM_visitReport_Map"))];
-
- UILabel * label=[[UILabel alloc]init];
-
- label.frame=CGRectMake(0,0,self_width,25);
-
- label.text=array[section];
-
- label.font=FONT_SIZE(12);
-
- label.textColor=Color(150, 149, 149, 1.0);
-
- label.backgroundColor=[UIColor whiteColor];
-
- return label;
- }else{
-
- return [UIView new];
-
- }
-
- }
-
- return nil;
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
-
- if (tableView==_searchTableView)
- {
- if (section<=1)
- {
- return 5;
- }
- }
-
- return 0;
- }
- //FooterView
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- {
- if (tableView==_searchTableView)
- {
- if (section<=1)
- {
-
- UIView * view=[[UIView alloc]initWithFrame:CGRectMake(0,0,self_width,5)];
- view.backgroundColor=[UIColor clearColor];
- return view;
-
- }else{
-
- return [UIView new];
-
- }
-
- }
-
- return nil;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- if (tableView==_tableView)
- {
- //1.cell初始化
-
- if(_dataArray.count == 0){
- [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
- static NSString * ID =@"JOBOR111";
- UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:ID];
- cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
- // tableView.separatorStyle=NO;
-
- UIImageView *imageV=[[UIImageView alloc]init];
- imageV.image=[UIImage imageNamed:@"crm_all_noData"];
- imageV.frame=CGRectMake((self_width-69)/2,94,69,78);
- cell.contentView.backgroundColor=[UIColor clearColor];
-
- // [cell.contentView addSubview:imageV];
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
- cell.userInteractionEnabled=NO;
-
- return cell;
- }
-
- static NSString *identifier = @"cell";
- HYPCells * cell = [[HYPCells alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- // cell.backgroundColor=Color(250, 249, 249, 1);
-
- [cell setModel:_dataArray[indexPath.row]];
-
-
- return cell;
-
- }else if (tableView ==_searchTableView)
- {
- //1.cell初始化
- static NSString *identifier = @"cell";
- HYPCells * cell = [[HYPCells alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.backgroundColor=Color(250, 249, 249, 1);
-
- if (indexPath.section==0)
- {
- [cell setModel:_searchArray[indexPath.row]];
-
- }else if(indexPath.section==1)
- {
- [cell setAPIModel:_searchAPIArray[indexPath.row]];
-
- }else if (indexPath.section==2)
- {
-
- UIImageView * imageV=[[UIImageView alloc]initWithFrame:CGRectMake(10,7.5,40, 40)];
- imageV.image=[UIImage imageNamed:@"oa_NoAddressImage"];
- [cell.contentView addSubview:imageV];
-
- UILabel * label1=[[UILabel alloc]initWithFrame:CGRectMake(60, 7.5,self_width-100, 20)];
- label1.text=Localized(@"UU_work_CRM_visitReport_NoQualifiedResults");
- label1.font=FONT_SIZE(14);
- [cell.contentView addSubview:label1];
-
- UILabel * label2=[[UILabel alloc]initWithFrame:CGRectMake(60,27.5, self_width-100, 20)];
- label2.text=Localized(@"UU_work_CRM_visitReport_CompleteCompanyName");
- label2.font=FONT_SIZE(12);
- label2.textColor=Color(150, 149, 149, 1.0);
- [cell.contentView addSubview:label2];
- }
-
-
- return cell;
-
-
- }
-
- return nil;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (tableView==_tableView)
- {
-
- HypVisitDmodel * model=_dataArray[indexPath.row];
-
- self.backAddress(model);
-
- [self.navigationController popViewControllerAnimated:YES];
-
-
-
- }else if (tableView==_searchTableView)
- {
- [self.view endEditing:YES];
-
- if (indexPath.section==0)
- {
- HypVisitDmodel * model=_searchArray[indexPath.row];
-
- self.backAddress(model);
-
- [self.navigationController popViewControllerAnimated:YES];
-
- }
-
- if (indexPath.section==1)
- {
- AMapPOI * model=_searchAPIArray[indexPath.row];
- self.backNewAddress(model);
- [self.navigationController popViewControllerAnimated:YES];
-
- }
-
- }
-
- }
- /**
- 去掉分割线
- */
- - (void)setExtraCellLineHidden: (UITableView *)tableView
- {
-
- UIView *view = [UIView new];
-
- view.backgroundColor = [UIColor clearColor];
-
- [tableView setTableFooterView:view];
- }
- -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
- {
- //发起输入提示搜索
- _KWSerach.keywords = searchText;
-
- if ([searchText isEqualToString:@""])
- {
-
- _searchTableView.hidden=YES;
- [_searchArray removeAllObjects];
-
- }
- else{
-
- //匹配当前数据
- for (int i=0;i<_searchStrArray.count;i++)
- {
- searchText = [searchText stringByReplacingOccurrencesOfString:@" " withString:@""];
- /**
- options:匹配类型(比如是否区分大小写)
- */
- NSRange range = [_searchStrArray[i] rangeOfString:searchText options:NSCaseInsensitiveSearch];
-
-
- if (range.location != NSNotFound)
- {
-
- [_searchArray addObject:_dataArray[i]];
-
-
- }
- }
-
-
- _searchTableView.hidden=NO;
-
- [_searchTableView reloadData];
-
- if ([UASUserInfo shareManager].inRegion) {
-
- //搜索
- [_search AMapPOIKeywordsSearch:_KWSerach];
-
- // NSString *searchStr = searchBar.text.length > 0 ? searchBar.text:@"";
-
- // [self.locaManager searchWithKeywords:searchStr city:nil completed:^(BOOL success, NSMutableArray<AMapPOI *> *result) {
- //
- // [_searchAPIArray removeAllObjects];
- //
- // _searchAPIArray = [result mutableCopy];
- //
- // MKMapView *mapView = (MKMapView *)self.locaManager.mapView;
- //
- // if (_searchAPIArray.count>0)
- // {
- // AMapAOI * mm=_searchAPIArray[0];
- //
- // [mapView setCenterCoordinate:CLLocationCoordinate2DMake(mm.location.latitude, mm.location.longitude) zoomLevel:16 animated:YES];
- // }
- //
- //
- // _noDataView.hidden = YES;
- //
- // [_searchTableView reloadData];
- //
- // }];
-
-
- }else{
-
-
- NSString *searchStr = searchBar.text.length > 0 ? searchBar.text:@"";
- __weak typeof(VisitDestinationVC) *weakSelf = self;
- [self.locaManager searchWithKeywords:searchStr city:nil completed:^(BOOL success, NSMutableArray<AMapPOI *> *result) {
-
- __strong typeof(VisitDestinationVC) *strongSelf = weakSelf;
-
- if (!strongSelf) {
-
- return;
-
- }
-
- [strongSelf->_searchAPIArray removeAllObjects];
-
- strongSelf->_searchAPIArray = [result mutableCopy];
-
- MKMapView *mapView = (MKMapView *)strongSelf.locaManager.mapView;
-
- if (strongSelf->_searchAPIArray.count>0)
- {
- AMapAOI * mm=strongSelf->_searchAPIArray[0];
-
- [mapView setCenterCoordinate:CLLocationCoordinate2DMake(mm.location.latitude, mm.location.longitude) zoomLevel:16 animated:YES];
- }
-
-
- _noDataView.hidden = YES;
-
- [_searchTableView reloadData];
-
- }];
-
- }
- }
-
-
- }
- -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- {
-
- [_searchBar resignFirstResponder];
- }
- -(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
- {
- [_searchBar resignFirstResponder];
- }
- -(void)scrollViewDidScroll:(UIScrollView *)scrollView
- {
- [self.view endEditing:YES];
- }
- -(void)viewWillDisappear:(BOOL)animated{
-
- _mapView.showsUserLocation=NO;//停止定位;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|