//
//  GasStationListVC.m
//  Open
//
//  Created by qinxuyang on 2021/11/15.
//  Copyright © 2021 QXY. All rights reserved.
//

#import "GasStationListVC.h"
#import "SDCycleScrollView.h"
#import "GasStationSectinView.h"
#import "GasStationCell.h"
#import "ScreeningView.h"
#import "GasStationDetailsVC.h"
#import "GasStationPayListVC.h"
#import "GasStationModel.h"
#import <MapKit/MapKit.h>
@interface GasStationListVC ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate,GasStationItemDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) SDCycleScrollView *headerView;
@property (nonatomic, strong) ScreeningView *screening;
@property (nonatomic, strong) UIButton *selectbtn;
@property (nonatomic, strong) NSArray *gasNoList;//油号列表
@property (nonatomic, strong) NSArray *gasBrandList;//油号列表
@property (nonatomic, assign) int pageIndex;
@property (nonatomic, strong) NSMutableArray *dataArr;
@property (nonatomic, strong) NSArray *rangeArr;
@property (nonatomic, copy) NSString *range; //查找范围
@property (nonatomic, copy) NSString *rangeName;
@property (nonatomic, strong) NSArray *sortArr;
@property (nonatomic, copy) NSString *sort;//排序方式
@property (nonatomic, copy) NSString *sortName;
@property (nonatomic, copy) NSString *oilNo;//油号ID
@property (nonatomic, copy) NSString *oilName;
@property (nonatomic, strong) NSArray *brandTypesArr; //品牌
@property (nonatomic, copy) NSString *brandTypeName;
@property (nonatomic, strong) NSArray *gasStationNotice;//站内提示
@property (nonatomic, assign) CGFloat  TopHeight;
@property (nonatomic, strong) EmptyView *emptyView;
@end

@implementation GasStationListVC
- (NSArray *)rangeArr{
    if (_rangeArr == nil) {
        _rangeArr = @[@{@"name":@"500m内",@"type":@"7"},@{@"name":@"2公里内",@"type":@"1"},@{@"name":@"6公里内",@"type":@"2"},@{@"name":@"10公里内",@"type":@"3"},@{@"name":@"15公里内",@"type":@"4"},@{@"name":@"20公里内",@"type":@"5"},@{@"name":@"50公里内",@"type":@"6"}];
    }
    return _rangeArr;
}
- (NSArray *)sortArr{
    if (_sortArr == nil) {
        _sortArr = @[@{@"name":@"智能排序",@"type":@""},@{@"name":@"距离优先",@"type":@"0"},@{@"name":@"价格优先",@"type":@"1"}];
    }
    return _sortArr;
}
- (NSMutableArray *)dataArr{
    if (_dataArr == nil) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self configNav];
    
    _TopHeight = 170;
    
    [self.view addSubview:self.tableView];
    self.tableView.tableHeaderView = self.headerView;
    
    id traget = self.navigationController.interactivePopGestureRecognizer.delegate;
    UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];
    [self.view addGestureRecognizer:pan];
    
    //初始化
    self.range = self.rangeArr.lastObject[@"type"];
    self.rangeName = self.rangeArr.lastObject[@"name"];
    self.oilNo = @"92";
    self.oilName = @"92#";
    self.sort = self.sortArr.firstObject[@"type"];
    self.sortName = self.sortArr.firstObject[@"name"];
    self.brandTypeName = @"全部品牌";
    
    [self requestToken];
    
    [self loadBannerData];
    
    [self emptyViewInit];
}
- (void)emptyViewInit
{
    _emptyView = [[[NSBundle mainBundle]loadNibNamed:@"EmptyView" owner:nil options:nil] lastObject];
    _emptyView.frame = CGRectMake((ScreenWidth - 152)/2, (ScreenHeight - 160)/2 + 150, 152, 160);
    [self.view addSubview:_emptyView];
}
- (void)configNav
{
   UIView*nav = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, cl_kNavigationBarHeight)];
    nav.backgroundColor = [UIColor colorWithHex:0x086ed7];
    [self.view addSubview:nav];
    
    UIButton*backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:4];
    [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [nav addSubview:backBtn];
    
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.top.offset(cl_kStatusBarHeight);
        make.width.offset(80);
        make.height.offset(44);
    }];
    
    UILabel*titleLabel = [[UILabel alloc]init];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"团油";
    titleLabel.font = [UIFont boldSystemFontOfSize:17];
    [nav addSubview:titleLabel];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.offset(cl_kStatusBarHeight);
        make.width.offset(80);
        make.height.offset(44);
    }];
    
    UIButton *orderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    orderBtn.frame = CGRectMake(ScreenWidth - 100, cl_kStatusBarHeight, 100, 44);
    [orderBtn setTitle:@"订单详情" forState:UIControlStateNormal];
    [orderBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    orderBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
    [orderBtn addTarget:self action:@selector(orderBtn) forControlEvents:UIControlEventTouchUpInside];
    [nav addSubview:orderBtn];
}
- (void)orderBtn{
    GasStationPayListVC *VC = [[GasStationPayListVC alloc]init];
    
    [self.navigationController pushViewController:VC animated:YES];
}
- (void)backClick{
    [self.navigationController popViewControllerAnimated:YES];
    [self.screening removeFromSuperview];
}
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NAV_BAR_HEIGHT, ScreenWidth, ScreenHeight - NAV_BAR_HEIGHT) style:UITableViewStylePlain];
        _tableView.backgroundColor = [UIColor colorWithHex:0xf2f2f2];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;//推荐该方法
        __weak typeof(self) weakself = self;
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [weakself refreshHeader];
        }];
        _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            [weakself upDown];
        }];
        [_tableView registerNib:[UINib nibWithNibName:@"GasStationCell" bundle:nil] forCellReuseIdentifier:@"GasStationCell"];
    }
    return _tableView;
}
- (SDCycleScrollView *)headerView
{
    if (!_headerView) {
        CGFloat height = 120;
        _headerView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, ScreenWidth, height) delegate:self placeholderImage:[UIImage imageNamed:@""]];
        _headerView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        _headerView.autoScrollTimeInterval = 3.0;
        _headerView.currentPageDotColor = [UIColor whiteColor];
        NSMutableArray *array2 = [NSMutableArray array];
        [array2 addObject:[UIImage imageNamed:@"GasStation"]];
        _headerView.localizationImageNamesGroup = array2;
    }
    return _headerView;
}
- (void)refreshHeader{
    _pageIndex = 1;
    [self requestList];
}
- (void)upDown{
    _pageIndex++ ;
    [self requestList];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    GasStationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GasStationCell"];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"GasStationCell" owner:self options:nil] lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    GasStationModel *model = self.dataArr[indexPath.row];
    [cell.gasLogoSmall sd_setImageWithURL:[NSURL URLWithString:model.gasLogoSmall] completed:nil];
    cell.gasName.text = model.gasName;
    cell.gasAddress.text = model.gasAddress;
    cell.price.text = [NSString stringWithFormat:@"¥%@",model.price];

    NSString *priceOfficial = [NSString stringWithFormat:@"油站价¥%@",model.priceGun];
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:priceOfficial];
    [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle)  range:NSMakeRange(0, priceOfficial.length)];
    [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor colorWithHex:0x808080] range:NSMakeRange(0, priceOfficial.length)];
    [cell.priceOfficial setAttributedText:attri];
    
    cell.distance.text = [NSString stringWithFormat:@"%@km",model.distance];
    cell.navigationBtn.tag = indexPath.row;
    [cell.navigationBtn addTarget:self action:@selector(appleMap:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 120;

}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 50;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    GasStationSectinView *sectionView = [[[NSBundle mainBundle] loadNibNamed:@"GasStationSectinView" owner:nil options:nil] firstObject];
    [sectionView.rangeBtn setTitle:self.rangeName forState:UIControlStateNormal];
    [sectionView.rangeBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleRight imageTitleSpace:5.0];
    
    [sectionView.oilNoBtn setTitle:self.oilName forState:UIControlStateNormal];
    [sectionView.oilNoBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleRight imageTitleSpace:5.0];
    [sectionView.sortBtn setTitle:self.sortName forState:UIControlStateNormal];
    [sectionView.sortBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleRight imageTitleSpace:5.0];
    
    [sectionView.brandTypesBtn setTitle:self.brandTypeName forState:UIControlStateNormal];
    [sectionView.brandTypesBtn layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleRight imageTitleSpace:5.0];
 
    sectionView.delegate = self;
    return sectionView;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    GasStationModel *model = self.dataArr[indexPath.row];
    GasStationDetailsVC *VC = [[GasStationDetailsVC alloc]init];
    VC.gasStationNotice = self.gasStationNotice;
    VC.Model = model;
    [self.navigationController pushViewController:VC animated:YES];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat offsetY = scrollView.contentOffset.y;
    NSLog(@"tableView滚动距离===%f",offsetY);
    if (offsetY > 0) {
        if (offsetY > 120) {
            _TopHeight = 50;
        }else{
            _TopHeight = 170 - offsetY;
        }
    }else{
        _TopHeight = 170;
    }
}
#pragma mark - GasStationItemDelegate
- (void)GasStationItemClickWithBtn:(UIButton *)button{
    typeof(self) weakSelf = self;
    if (button.selected) {
        self.selectbtn.selected = NO;
        [self.selectbtn setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
        
        button.selected = NO;
        self.selectbtn = button;
        [button setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
        [self.screening removeFromSuperview];
        return;
    }else{
        self.selectbtn.selected = NO;
        [self.selectbtn setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
        
        button.selected = YES;
        [button setTitleColor:[UIColor colorWithHex:0xe8221c] forState:UIControlStateNormal];
        self.selectbtn = button;
        [self.screening removeFromSuperview];
    }
    if (button.tag == 10) {
        //距离
        ScreeningView *screening =  [[[NSBundle mainBundle] loadNibNamed:@"ScreeningView" owner:self options:nil] lastObject];
        screening.type = ScreeningTypeDistance;
        screening.menuItems = self.rangeArr;
        screening.indexStr = self.range;
        self.screening = screening;
        [screening showMenuInView:XYKEYWINDOW fromRect:CGRectMake(0, cl_kNavigationBarHeight + _TopHeight, ScreenWidth, ScreenHeight - _TopHeight - cl_kNavigationBarHeight)];
        screening.blockParm = ^(NSDictionary * _Nonnull parm) {
            weakSelf.range = parm[@"type"];
            weakSelf.rangeName = parm[@"name"];
            
            [button setTitle:parm[@"name"] forState:UIControlStateNormal];
            [button setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
            button.selected = NO;
            [button layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleRight imageTitleSpace:5.0];
            weakSelf.selectbtn = button;
            [weakSelf.screening removeFromSuperview];
            [weakSelf.tableView.mj_header beginRefreshing];
            return;
        };
        screening.blockDiss = ^{
            [weakSelf.selectbtn setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
            button.selected = NO;
            [button layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleRight imageTitleSpace:5.0];
            weakSelf.selectbtn = button;
            [weakSelf.screening removeFromSuperview];
            return;
        };
    }else if(button.tag == 20){
        //油号
        if (self.gasNoList.count > 0) {
            ScreeningView *screening =  [[[NSBundle mainBundle] loadNibNamed:@"ScreeningView" owner:self options:nil] lastObject];
            screening.type = ScreeningTypeOilno;
            screening.menuItems = self.gasNoList;
            screening.indexStr = self.oilNo;
            self.screening = screening;
            [screening showMenuInView:XYKEYWINDOW fromRect:CGRectMake(0, _TopHeight + NAV_BAR_HEIGHT, ScreenWidth, ScreenHeight - _TopHeight - NAV_BAR_HEIGHT)];
            screening.blockParm = ^(NSDictionary * _Nonnull parm) {
                weakSelf.oilNo = [NSString stringWithFormat:@"%@",parm[@"oilNo"]];
                weakSelf.oilName = parm[@"oilName"];
                
                [button setTitle:parm[@"oilName"] forState:UIControlStateNormal];
                [button setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
                button.selected = NO;
                [button layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleRight imageTitleSpace:5.0];
                weakSelf.selectbtn = button;
                [weakSelf.screening removeFromSuperview];
                [weakSelf.tableView.mj_header beginRefreshing];
                return;
            };
            screening.blockDiss = ^{
                [button setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
                button.selected = NO;
                [button layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleRight imageTitleSpace:5.0];
                weakSelf.selectbtn = button;
                [weakSelf.screening removeFromSuperview];
                return;
            };
        }
    }else if(button.tag == 30){
        //距离优先
        ScreeningView *screening =  [[[NSBundle mainBundle] loadNibNamed:@"ScreeningView" owner:self options:nil] lastObject];
        screening.type = ScreeningTypeDif;
        screening.menuItems = self.sortArr;
        if (self.sort.length > 0) {
            screening.indexStr = self.sort;
        }
        self.screening = screening;
        [screening showMenuInView:XYKEYWINDOW fromRect:CGRectMake(0, _TopHeight + NAV_BAR_HEIGHT, ScreenWidth, ScreenHeight - _TopHeight - NAV_BAR_HEIGHT)];
        screening.blockParm = ^(NSDictionary * _Nonnull parm) {
            weakSelf.sort = parm[@"type"];
            if ([parm[@"type"] isEqualToString:@""]) {
                weakSelf.sortName = @"智能排序";
            }else{
                weakSelf.sortName = parm[@"name"];
            }
            
            [button setTitle:weakSelf.sortName forState:UIControlStateNormal];
            [button setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
            button.selected = NO;
            [button layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleRight imageTitleSpace:5.0];
            weakSelf.selectbtn = button;
            [weakSelf.screening removeFromSuperview];
            [weakSelf.tableView.mj_header beginRefreshing];
            return;
        };
        screening.blockDiss = ^{
            [button setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
            button.selected = NO;
            [button layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleRight imageTitleSpace:5.0];
            weakSelf.selectbtn = button;
            [weakSelf.screening removeFromSuperview];
            return;
        };
    }else if(button.tag == 40){
        //品牌
        if (self.gasBrandList.count > 0) {
            ScreeningView *screening =  [[[NSBundle mainBundle] loadNibNamed:@"ScreeningView" owner:self options:nil] lastObject];
            screening.type = ScreeningTypeBrand;
            screening.menuItems = self.gasBrandList;
            screening.selectArr = [self.brandTypesArr mutableCopy];
            self.screening = screening;
            [screening showMenuInView:XYKEYWINDOW fromRect:CGRectMake(0, _TopHeight + NAV_BAR_HEIGHT, ScreenWidth, ScreenHeight - _TopHeight - NAV_BAR_HEIGHT)];
            screening.blockArray = ^(NSArray * _Nonnull Array) {
                weakSelf.brandTypesArr = Array;
                if (weakSelf.brandTypesArr.count == weakSelf.gasBrandList.count) {
                    weakSelf.brandTypeName = @"全部品牌";
                }else{
                    weakSelf.brandTypeName = @"部分品牌";
                }

                [button setTitle:weakSelf.brandTypeName forState:UIControlStateNormal];
                [button setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
                button.selected = NO;
                [button layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleRight imageTitleSpace:5.0];
                weakSelf.selectbtn = button;
                [weakSelf.screening removeFromSuperview];
                [weakSelf.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
                [weakSelf.tableView.mj_header beginRefreshing];
                return;
            };
            screening.blockDiss = ^{
                [button setTitleColor:[UIColor colorWithHex:0x4d4d4d] forState:UIControlStateNormal];
                button.selected = NO;
                [button layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleRight imageTitleSpace:5.0];
                weakSelf.selectbtn = button;
                [weakSelf.screening removeFromSuperview];
                return;
            };
        }
    }
}
#pragma mark - 获取token
- (void)requestToken{
    NSString *url = [NSString stringWithFormat:@"%@tuanyou/user/token",[NetworkConfig ipGasStationConfig]];
    NSDictionary *params = @{
        @"tel": [getPeopleID PeopleIphoneNmber],
    };
    typeof(self) wSelf = self;
    [NetworkRequest PostGasStation:url Params:params Success:^(id _Nonnull objc) {
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            if ([state isEqualToString:@"200"]) {
                NSString *result = objc[@"result"];
                if (result.length > 0) {
                    [UserDefault setValue:result forKey:@"GasToken"];
                    [UserDefault synchronize];
                }else{
                    [UserDefault setValue:@"" forKey:@"GasToken"];
                    [UserDefault synchronize];
                }
                [wSelf getMoreData];
            }
        }
    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
    }];
}
- (void)getMoreData{
    [self requestOilnoList];
    [self requestbrandList];
    
    [self.tableView.mj_header beginRefreshing];
//    dispatch_group_t downloadGroup = dispatch_group_create();
//    dispatch_group_enter(downloadGroup);
//    NSLog(@"1111111111111");
//
//    dispatch_group_leave(downloadGroup);
//    dispatch_group_enter(downloadGroup);
//    NSLog(@"22222222222222");
//
//    dispatch_group_leave(downloadGroup);
//    dispatch_group_notify(downloadGroup, dispatch_get_main_queue(), ^{
//        NSLog(@"333333333333");
//    });
}
#pragma mark - 油号列表
- (void)requestOilnoList{
    NSString *url = [NSString stringWithFormat:@"%@tuanyou/select/list",[NetworkConfig ipGasStationConfig]];
    NSDictionary *params = @{
        @"tel":[getPeopleID PeopleIphoneNmber],
    };
    typeof(self) wSelf = self;
    [NetworkRequest PostGasStation:url Params:params Success:^(id _Nonnull objc) {
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            if ([state isEqualToString:@"200"]) {
                NSArray *arr = objc[@"result"];
                if (arr.count > 0) {
                    wSelf.gasNoList = arr;
                }
                [wSelf.tableView reloadData];
            }
        }
    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
    }];
}
#pragma mark - 品牌列表
- (void)requestbrandList{
    NSString *url = [NSString stringWithFormat:@"%@tuanyou/gas/brand",[NetworkConfig ipGasStationConfig]];
    NSDictionary *params = @{
        @"tel":[getPeopleID PeopleIphoneNmber],
    };
    typeof(self) wSelf = self;
    [NetworkRequest PostGasStation:url Params:params Success:^(id _Nonnull objc) {
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            if ([state isEqualToString:@"200"]) {
                NSArray *arr = objc[@"result"];
                if (arr.count > 0) {
                    wSelf.gasBrandList = arr;
                    wSelf.brandTypesArr = arr;
                    wSelf.brandTypeName = @"全部品牌";
                }
                [wSelf.tableView reloadData];
            }
        }
    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
    }];
}
#pragma mark - 油站列表
- (void)requestList{
    NSString *url = [NSString stringWithFormat:@"%@tuanyou/gas/near",[NetworkConfig ipGasStationConfig]];
    
    NSString *locationCoordinate = [UserDefault objectForKey:@"locationCoordinate"];
    NSArray  *locationArray = nil;
    if (locationCoordinate) {
       locationArray =  [locationCoordinate componentsSeparatedByString:@","];
    }
    NSString *clientLng = locationArray ?locationArray[0] :@"121.48";
    NSString *clientLat = locationArray ?locationArray[1] :@"31.22";
    
    NSMutableDictionary *parms  = [NSMutableDictionary dictionary];
    [parms setValue:[getPeopleID PeopleIphoneNmber] forKey:@"userPhone"];
    [parms setValue:clientLng forKey:@"userLngStr"];
    [parms setValue:clientLat forKey:@"userLatStr"];
    [parms setValue:self.range forKey:@"range"];
    [parms setValue:self.sort forKey:@"sort"];
    if (self.brandTypesArr.count != self.gasBrandList.count) {
        NSMutableString *brandTypes = [NSMutableString string];
        for (NSDictionary *dic in self.brandTypesArr) {
            [brandTypes appendString:dic[@"gasBrandType"]];
            [brandTypes appendString:@","];
        }
        [parms setValue:brandTypes forKey:@"brandTypes"];
    }
    [parms setValue:self.oilNo forKey:@"oilNo"];
    [parms setValue:@(10) forKey:@"pageSize"];
    [parms setValue:@(_pageIndex) forKey:@"pageIndex"];
    NSLog(@"筛选参数=====%@",parms);
    typeof(self) wSelf = self;
    [NetworkRequest PostGasStation:url Params:parms Success:^(id _Nonnull objc) {
        [wSelf.tableView.mj_header endRefreshing];
        [wSelf.tableView.mj_footer endRefreshing];
        if ([objc isKindOfClass:[NSDictionary class]]) {
            NSString *state = [NSString stringWithFormat:@"%@",objc[@"state"]];
            if ([state isEqualToString:@"200"]) {
                if (wSelf.pageIndex == 1) {
                    [wSelf.dataArr removeAllObjects];
                }
                NSDictionary *dic = objc[@"result"];
                NSString *str = [NSString stringWithFormat:@"%@",dic[@"gasInfoList"]];
                if ([str isEqualToString:@"<null>"] || [str isEqualToString:@""]) {
                    if (wSelf.dataArr.count > 0) {
                        wSelf.emptyView.hidden = YES;
                    }else{
                        wSelf.emptyView.hidden = NO;
                    }
                    [wSelf.tableView reloadData];
                    return;
                }
                NSArray *arr = objc[@"result"][@"gasInfoList"];
                if (arr.count > 0) {
                    NSArray *resultArr = [GasStationModel mj_objectArrayWithKeyValuesArray:objc[@"result"][@"gasInfoList"]];
                    for (GasStationModel *model in resultArr) {
                        [self.dataArr addObject:model];
                    }
                }
                wSelf.gasStationNotice = objc[@"result"][@"gasStationNotice"];
                if (wSelf.dataArr.count > 0) {
                    wSelf.emptyView.hidden = YES;
                }else{
                    wSelf.emptyView.hidden = NO;
                }
                [wSelf.tableView reloadData];
            }
        }
    } Failure:^(NSError *error) {
        NSLog(@"error:%@",error);
        [wSelf.tableView.mj_header endRefreshing];
        [wSelf.tableView.mj_footer endRefreshing];
    }];
}
//苹果原生地图
- (void)appleMap:(UIButton *)button{
    GasStationModel *model = self.dataArr[button.tag];
    NSString *ToName =  [NSString stringWithFormat:@"%@%@%@%@",model.provinceName,model.cityName,model.countyName,model.gasAddress];
    NSString *locationCoordinate = [UserDefault objectForKey:@"locationCoordinate"];
    NSArray  *locationArray = nil;
    if (locationCoordinate) {
       locationArray =  [locationCoordinate componentsSeparatedByString:@","];
    }
    NSString *clientLng = locationArray ?locationArray[0] :@"121.48";
    NSString *clientLat = locationArray ?locationArray[1] :@"31.22";
    
    CLLocationCoordinate2D desCoordinate = CLLocationCoordinate2DMake([clientLat longLongValue], [clientLng longLongValue]);
    
    MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
    currentLocation.name = @"我的位置";
    MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:desCoordinate addressDictionary:nil]];
    toLocation.name = ToName;
    
    [MKMapItem openMapsWithItems:@[currentLocation, toLocation]
                   launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeTransit,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];
}
- (void)loadBannerData{
    NSString *url = [NSString stringWithFormat:@"%@tuanyou/get/banners",[NetworkConfig ipGasStationConfig]];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    typeof(self) wSelf = self;
    [NetworkRequest Get:url Params:params Success:^(id _Nonnull objc) {
        NSLog(@"objc:%@",objc);
        NSString* state = [NSString stringWithFormat:@"%@",objc[@"state"]];
        if ([state isEqualToString:@"200"]) {
            NSArray *array = objc[@"result"];
            NSMutableArray *array2 = [NSMutableArray array];
            if (array.count > 0) {
                for (NSDictionary *dic in array) {
                    [array2 addObject:dic[@"banner"]];
                }
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                SDCycleScrollView *cycleScrollView2 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, ScreenWidth, 120) delegate:self placeholderImage:[UIImage imageNamed:@"GasStation"]];
                cycleScrollView2.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
                cycleScrollView2.autoScrollTimeInterval = 3.0;
                cycleScrollView2.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色

                if (array2.count>0) {
                     cycleScrollView2.imageURLStringsGroup =array2;
                }else{
                    [array2 removeAllObjects];
                   
                    [array2 addObject:[UIImage imageNamed:@"GasStation"]];
                    cycleScrollView2.localizationImageNamesGroup = array2;
                }
                wSelf.headerView = cycleScrollView2;
                wSelf.tableView.tableHeaderView = cycleScrollView2;
             });
        }
    } Failure:^(NSError* error) {
        NSLog(@"error:%@",error);

    }];
}
@end
