//
//  LeftDrawerViewController.m
//  gaotingshan
//
//  Created by Mac Book DQ02 on 16/3/11.
//  Copyright © 2016年 Mac Book DQ02. All rights reserved.
//

#import "LeftDrawerViewController.h"
#import "MyViewController.h"
#import "LoginViewController.h"
#import "managementDeviceVC.h"
#import "Singleton.h"
#import "MyHeaderVC.h"
#import "SDImageCache.h"
#import "AboutViewController.h"
#import "UIView+UIView_Extension.h"

#define kScreenWidth [UIScreen mainScreen].bounds.size.width*0.75
#define KMargin [UIScreen mainScreen].bounds.size.height/10
#define HeightWidth 100
#define labelHeight 15


@interface LeftDrawerViewController () <UIViewControllerTransitioningDelegate,LoginViewControllerDelegate> {
    //用户未登录时的属性
    UIView *line1;
    UIButton *oneBtn;
    UIView *line2;
    UIButton *twoBtn;
    UIView *line3;
    UIButton *threeBtn;
    UIView *line4;
    UIButton *fourBtn;
    UIView *line5;
    UIButton *fiveBtn;
    UIView *line6;
    //用户登录后的属性
    UIButton *titleBtn;
    UILabel *nickNameLabel;
    UIView *line11;
    UIButton *oneBtn1;
    UIView *line22;
    UIButton *twoBtn2;
    UIView *line33;
    UIButton *threeBtn3;
    UIView *line44;
    UIButton *fourBtn4;
    UIView *line55;
    UIButton *fiveBtn5;
    UIView *line66;
    
    Singleton *singleton;
}

@property (nonatomic, strong) NSString *isLogin;

@end

@implementation LeftDrawerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //创建单例实例
    singleton = [Singleton defaultSingleton];
    
    self.view = [[UIView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    NSLog(@"%lf %lf %lf %lf", self.view.x, self.view.y, self.view.width, self.view.height);
    self.view.backgroundColor = [UIColor blackColor];
    
    
    //版本号是一直存在左下角的
    UILabel *editionLab = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width*0.75-130, self.view.frame.size.height-70, 100, 50)];
    editionLab.text = @"版本号： 3 .0 .0";
    editionLab.tag = 10001;
    editionLab.textAlignment = NSTextAlignmentRight;
    editionLab.font = [UIFont systemFontOfSize:12];
    editionLab.textColor = [UIColor whiteColor];
    [self.view addSubview:editionLab];
    
    
        //默认加载
    [self createNoLoginSubview];
    
    //添加观察者，接收通知中心传过来的值(来自于LoginVC页面)
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeLeftVCLayout:) name:@"changeLeftVCLayout" object:nil];
    //添加观察者，接收通知中心传过来的值(来自于MyVC页面)
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeLeftDrawerVCLayout:) name:@"changeLeftDrawerVCUILayout" object:nil];
    //添加观察者，接收通知中心传过来的值（来自UserInfoVC页面）
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nickNameIsAssignment:) name:@"ToAssignValueAndReLoadWebView" object:nil];
    //添加观察者，接收通知中心传过来的值（来自MyHeaderVC页面,修改头像成功）
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeHeadImage:) name:@"changeHeaderImage" object:nil];
    //用户信息修改页修改成功后，发送通知到此视图，修改昵称(来自UserInfoVC页面）
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeNick:) name:@"changeNickFromUsrInfoVC" object:nil];
    
    //changeNickFromHomeCompeteApply
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nickNameIsAssignment:) name:@"changeNickFromHomeCompeteApply" object:nil];

    
   
 }

#pragma mark - 用户没有登录，UI布局
- (void)createNoLoginSubview {
    
    titleBtn = [[UIButton alloc] initWithFrame:CGRectMake((kScreenWidth - HeightWidth)/2,KMargin,HeightWidth,HeightWidth)];
    titleBtn.layer.cornerRadius = HeightWidth/2.;
    titleBtn.layer.masksToBounds = YES;
    self.transitioningDelegate = self;
    self.modalPresentationStyle = UIModalTransitionStyleFlipHorizontal;
    [titleBtn setBackgroundImage:[UIImage imageNamed:@"head.png"] forState:UIControlStateNormal];
    [self.view addSubview:titleBtn];
    
    //设置白线1
    line1 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titleBtn.frame) + KMargin, self.view.frame.size.width, 1)];
    line1.backgroundColor = [UIColor  grayColor];
    [self.view addSubview:line1];
    //设置oneBtn,
    oneBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    oneBtn.frame = CGRectMake(0, CGRectGetMaxY(line1.frame), self.view.frame.size.width, 40);
    [oneBtn setTitle:@"       用户登录" forState:UIControlStateNormal];
    [oneBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [oneBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    oneBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [oneBtn addTarget:self action:@selector(loginBtnIsClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:oneBtn];
    
    //设置白线2
    line2 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(oneBtn.frame), self.view.frame.size.width, 1)];
    line2.backgroundColor = [UIColor  grayColor];
    [self.view addSubview:line2];
    //设置twoBtn,
    twoBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    twoBtn.frame = CGRectMake(0, CGRectGetMaxY(line2.frame), self.view.frame.size.width, 40);
    [twoBtn setTitle:@"       登山设备管理" forState:(UIControlStateNormal)];
    [twoBtn setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentLeft)];
    [twoBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    twoBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [twoBtn addTarget:self action:@selector(loginBtnIsClicked) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:twoBtn];
    
    //设置白线3
    line3 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(twoBtn.frame), self.view.frame.size.width, 1)];
    line3.backgroundColor = [UIColor grayColor];
    [self.view addSubview:line3];
    //设置threeBtn，
    threeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    threeBtn.frame = CGRectMake(0, CGRectGetMaxY(line3.frame), self.view.frame.size.width, 40);
    [threeBtn setTitle:@"       清除缓存" forState:(UIControlStateNormal)];
    [threeBtn setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentLeft)];
    [threeBtn addTarget:self action:@selector(ClearCacheIsClicked) forControlEvents:(UIControlEventTouchUpInside)];
    [threeBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    threeBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.view addSubview:threeBtn];
    
    //设置白线4
    line4 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(threeBtn.frame), self.view.frame.size.width, 1)];
    line4.backgroundColor = [UIColor grayColor];
    [self.view addSubview:line4];
    //设置fourBtn，
    fourBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    fourBtn.frame = CGRectMake(0, CGRectGetMaxY(line4.frame), self.view.frame.size.width, 40);
    [fourBtn setTitle:@"       一键求助" forState:(UIControlStateNormal)];
    [fourBtn setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentLeft)];
    [fourBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [fourBtn addTarget:self action:@selector(HelpBtnClicked) forControlEvents:(UIControlEventTouchUpInside)];
    fourBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.view addSubview:fourBtn];
    
    //设置白线5
    line5 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(fourBtn.frame), self.view.frame.size.width, 1)];
    line5.backgroundColor = [UIColor grayColor];
    [self.view addSubview:line5];
    //设置fiveBtn，
    fiveBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    fiveBtn.frame = CGRectMake(0, CGRectGetMaxY(line5.frame), self.view.frame.size.width, 40);
    [fiveBtn setTitle:@"       关于" forState:(UIControlStateNormal)];
    [fiveBtn setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentLeft)];
    [fiveBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    fiveBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [fiveBtn addTarget:self action:@selector(aboutBtnIsClicked) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:fiveBtn];
    
    //设置白线6
    line6 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(fiveBtn.frame), self.view.frame.size.width, 1)];
    line6.backgroundColor = [UIColor grayColor];
    [self.view addSubview:line6];
    
}


#pragma mark - 用户已登录，UI布局
- (void)createDidLoginSubview {

    //设置头像button按钮
    titleBtn = [[UIButton alloc] initWithFrame:CGRectMake((kScreenWidth - HeightWidth)/2,KMargin,HeightWidth,HeightWidth)];
    titleBtn.layer.cornerRadius = HeightWidth/2.;
    titleBtn.layer.masksToBounds = YES;
    self.transitioningDelegate = self;
    self.modalPresentationStyle = UIModalTransitionStyleFlipHorizontal;

    __block NSData *data;
    dispatch_async(dispatch_queue_create("login", NULL), ^{
        data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", localRequestUrl,singleton.headImgUrl]]];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [titleBtn setImage:[UIImage imageWithData:data] forState:(UIControlStateNormal)];
        });
    });
    
    
    [titleBtn addTarget:self action:@selector(titleBtnIsClicked) forControlEvents:UIControlEventTouchUpInside];
    self.transitioningDelegate = self;
    self.modalPresentationStyle = UIModalTransitionStyleFlipHorizontal;
    [self.view addSubview:titleBtn];
    
    NSLog(@"%lf %lf %lf %lf", titleBtn.x, titleBtn.y, titleBtn.width, titleBtn.height);
    
    //设置头像下面的label
    nickNameLabel = [[UILabel alloc] initWithFrame:CGRectMake((kScreenWidth - HeightWidth)/2,CGRectGetMaxY(titleBtn.frame),HeightWidth,labelHeight)];
    nickNameLabel.text = singleton.nickName;
    nickNameLabel.textColor = [UIColor whiteColor];
    nickNameLabel.textAlignment = NSTextAlignmentCenter;
    nickNameLabel.font = [UIFont systemFontOfSize:13];
    //    nameLabel.backgroundColor = [UIColor redColor];
    [self.view addSubview:nickNameLabel];
    
    //设置白线1
    line11 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titleBtn.frame) + KMargin, self.view.frame.size.width, 1)];
    line11.backgroundColor = [UIColor  grayColor];
    [self.view addSubview:line11];
    //设置oneBtn,
    oneBtn1 = [UIButton buttonWithType:UIButtonTypeSystem];
    oneBtn1.frame = CGRectMake(0, CGRectGetMaxY(line11.frame), self.view.frame.size.width, 40);
    [oneBtn1 setTitle:@"       登山设备管理" forState:UIControlStateNormal];
    [oneBtn1 addTarget:self action:@selector(deviceMgtIsClicked:) forControlEvents:(UIControlEventTouchUpInside)];
    [oneBtn1 setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentLeft)];
    [oneBtn1 setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    oneBtn1.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.view addSubview:oneBtn1];
    NSLog(@"%lf %lf %lf %lf", oneBtn1.x, oneBtn1.y, oneBtn1.width, oneBtn1.height);
    
    //设置白线2
    line22 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(oneBtn1.frame), self.view.frame.size.width, 1)];
    line22.backgroundColor = [UIColor  grayColor];
    [self.view addSubview:line22];
    //设置twoBtn,并在button上面添加一个label
    twoBtn2 = [UIButton buttonWithType:UIButtonTypeSystem];
    twoBtn2.frame = CGRectMake(0, CGRectGetMaxY(line22.frame), self.view.frame.size.width, 40);
    [twoBtn2 setTitle:@"       清除缓存" forState:(UIControlStateNormal)];
    [twoBtn2 setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentLeft)];
    [twoBtn2 setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [twoBtn2 addTarget:self action:@selector(ClearCacheIsClicked) forControlEvents:(UIControlEventTouchUpInside)];
    twoBtn2.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.view addSubview:twoBtn2];
    
   // 设置白线3
        line33 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(twoBtn2.frame), self.view.frame.size.width, 1)];
        line33.backgroundColor = [UIColor grayColor];
        [self.view addSubview:line33];
        //设置threeBtn，并在button上面添加一个label
        threeBtn3 = [UIButton buttonWithType:UIButtonTypeSystem];
        threeBtn3.frame = CGRectMake(0, CGRectGetMaxY(line33.frame), self.view.frame.size.width, 40);
        [threeBtn3 setTitle:@"       紧急求助" forState:(UIControlStateNormal)];
        [threeBtn3 setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentLeft)];
        [threeBtn3 addTarget:self action:@selector(HelpBtnClicked) forControlEvents:(UIControlEventTouchUpInside)];
        [threeBtn3 setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        threeBtn3.titleLabel.font = [UIFont systemFontOfSize:18];
        [self.view addSubview:threeBtn3];
    
    //设置白线4
    line44 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(threeBtn3.frame), self.view.frame.size.width, 1)];
    line44.backgroundColor = [UIColor grayColor];
    [self.view addSubview:line44];
    //设置fourBtn，并在button上面添加一个label
    fourBtn4 = [UIButton buttonWithType:UIButtonTypeSystem];
    fourBtn4.frame = CGRectMake(0, CGRectGetMaxY(line44.frame), self.view.frame.size.width, 40);
    [fourBtn4 setTitle:@"       关于" forState:(UIControlStateNormal)];
    [fourBtn4 setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentLeft)];
    [fourBtn4 setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    fourBtn4.titleLabel.font = [UIFont systemFontOfSize:18];
    [fourBtn4 addTarget:self action:@selector(aboutBtnIsClicked) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:fourBtn4];
    
    //设置白线5
    line55 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(fourBtn4.frame), self.view.frame.size.width, 1)];
    line55.backgroundColor = [UIColor grayColor];
    [self.view addSubview:line55];
    //设置fiveBtn，并在button上面添加一个label
    fiveBtn5 = [UIButton buttonWithType:UIButtonTypeSystem];
    fiveBtn5.frame = CGRectMake(0, CGRectGetMaxY(line55.frame), self.view.frame.size.width, 40);
    [fiveBtn5 setTitle:@"       退出" forState:(UIControlStateNormal)];
    [fiveBtn5 setContentHorizontalAlignment:(UIControlContentHorizontalAlignmentLeft)];
    [fiveBtn5 setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    fiveBtn5.titleLabel.font = [UIFont systemFontOfSize:18];
    [fiveBtn5 addTarget:self action:@selector(dropOutBtnIsClicked:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:fiveBtn5];
    //设置白线6
    line66 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(fiveBtn5.frame), self.view.frame.size.width, 1)];
    line66.backgroundColor = [UIColor grayColor];
    [self.view addSubview:line66];
    
    
}

#pragma mark - 登录成功后，观察者接收到通知后，做出的响应。
- (void)changeLeftVCLayout:(id)sender {
//    NSString *str = [sender valueForKey:@"object"];
    NSLog(@"哈哈哈哈哈哈%@", singleton.status);
    if ([singleton.status isEqualToString:@"9002"]) { //用户已登录
        //移除未登录时的所有Button
        [self removeAllButtonsAndLabels];
        [self createDidLoginSubview];
    }
}

- (void)changeLeftDrawerVCLayout:(id)sender {
    //移除登录之后的所有Button
    [self removeAllButtonsAndLabels];
    [self createNoLoginSubview];
}

- (void)nickNameIsAssignment:(id)sender {
    
    nickNameLabel.text = singleton.nickName;
    
}

- (void)changeHeadImage:(id)sender {
    NSLog(@"LeftVC:%@", singleton.headImgUrl);
    titleBtn = [[UIButton alloc] initWithFrame:CGRectMake((kScreenWidth - HeightWidth)/2,KMargin,HeightWidth,HeightWidth)];
//    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://gwms.517gts.com%@", singleton.headImgUrl]]];
   
    UIImage *savedImage = [[UIImage alloc] initWithContentsOfFile:singleton.headImgUrl];
    titleBtn.layer.cornerRadius = HeightWidth/2.;
    titleBtn.layer.masksToBounds = YES;
    [titleBtn setImage:savedImage forState:(UIControlStateNormal)];
    [titleBtn addTarget:self action:@selector(titleBtnIsClicked) forControlEvents:UIControlEventTouchUpInside];
    self.transitioningDelegate = self;
    self.modalPresentationStyle = UIModalTransitionStyleFlipHorizontal;
    [self.view addSubview:titleBtn];
    
}

#pragma mark 从用户信息修改页面成功页面传消息过来，修改用户的昵称
-(void)changeNick:(NSNotification *)noti
{
    nickNameLabel.text = noti.object;
}

#pragma mark - 在用户没有登录时，点击一系列button之后，页面的跳转
//头像按钮点击（实际情况下，用户没有登录是不能点击的，只有登录后才能点击）
-(void)titleBtnIsClicked {
    MyHeaderVC *headVC = [[MyHeaderVC alloc] init];
    UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:headVC];
    [self presentViewController:naVC animated:NO completion:nil];
}

//用户登录按钮点击 (弹出登录页面)
- (void)loginBtnIsClicked {
    LoginViewController *loginVC = [[LoginViewController alloc] init];
    UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:loginVC];
    [self presentViewController:naVC animated:YES completion:nil];
    
}


#pragma mark - 在用户登录后，点击一系列button之后，页面的跳转
//点击登山设备管理按钮，页面跳转
- (void)deviceMgtIsClicked:(UIButton *)sender {
    managementDeviceVC *mgeDeviceVC = [[managementDeviceVC alloc] init];
    UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:mgeDeviceVC];
    [self presentViewController:naVC animated:YES completion:nil];
    
}

#pragma mark 点击退出按钮，页面的跳转
- (void)dropOutBtnIsClicked:(UIButton *)sender {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"退出窗口" message:@"你确定要退出吗？" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *ensure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        //移除登录之后的所有Button
        [self removeAllButtonsAndLabels];
        
        MapInfo *info = [MapInfo shareMapInfo];
        if (info.internetStatus != AFNetworkReachabilityStatusNotReachable) {
            //20160521 xmz 修改
            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            [defaults setObject:nil forKey:@"userName"];
            [defaults setObject:nil forKey:@"userPwd"];
    
            singleton.string = nil;
            singleton.sesskey = nil;
            singleton.reallyName = nil;
            singleton.JSESSIONIDValue = nil;
            singleton.userid = nil;
            singleton.status = nil;
            singleton.deviceSn = nil;
            singleton.watchSn = nil;
            
        }
        [self createNoLoginSubview];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"changeMyVCLogOut" object:nil];

    }];
    
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertController addAction:ensure];
    [alertController addAction:cancel];
    [self presentViewController:alertController animated:YES completion:nil];

}

#pragma mark 移除页面上所有的按钮和label
-(void)removeAllButtonsAndLabels
{
    for (UIView *view in [self.view subviews]) {
        if ([view isKindOfClass:[UIButton class]] || [view isKindOfClass:[UILabel class]]) {
            if (view.tag !=10001) {
                [view removeFromSuperview];
            }
            
        }
    }
}
//点击清除缓存按钮
- (void)ClearCacheIsClicked {
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        [[NSURLCache sharedURLCache] removeAllCachedResponses];//清除网页缓存
        
        [self performSelectorOnMainThread:@selector(clearCacheSuccess) withObject:nil waitUntilDone:YES];});
    
}

- (void)clearCacheSuccess {
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"提示" message:@"清除缓存成功！"  preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
    [alertVc addAction:action];
    [self presentViewController:alertVc animated:YES completion:nil];

}

//一键求助按钮点击事件
-(void)HelpBtnClicked
{
    if ([singleton.string isEqualToString:@"9002"]) {
        //登录后
        [self sendLocationToServer];
    }
    else
    {
        
    }
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt:0571-86656677"]];
}

#pragma mark 发送位置給服务器
-(void)sendLocationToServer
{
    AFHTTPSessionManager *manager= [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    //模拟数据，固定坐标
    NSDictionary *parameterDic = [[NSDictionary alloc]initWithObjectsAndKeys:singleton.userid,@"userId",singleton.reallyName,@"userName",[NSString stringWithFormat:@"%f",singleton.currentLocation.coordinate.longitude],@"axisX",[NSString stringWithFormat:@"%f",singleton.currentLocation.coordinate.latitude],@"axisY", nil];
    NSString *postStr = [NSString stringWithFormat:@"%@/terminal/userSeekHelp",localRequestUrl];
    
    [manager POST:postStr parameters:parameterDic constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
    //    NSString *str = [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
     //   NSLog(@"response = %@",str);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
      //
        NSLog(@"error = %@",error);
    }];

}

//关于按钮点击事件
- (void)aboutBtnIsClicked {
    AboutViewController *aboutVc = [[AboutViewController alloc] init];
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:aboutVc];
    
    [self presentViewController:nav animated:YES completion:nil];
    
}

#pragma mark - LoginViewControllerDelegate
- (void)viewController:(LoginViewController *)viewController
             passValue:(NSString *)string {
    self.isLogin = string;
//    NSLog(@"++++++%@", self.isLogin);

}

-(void)dealloc
{
     //changeLeftVCLayout changeNickFromHomeCompeteApply changeNickFromUsrInfoVC changeHeaderImage ToAssignValueAndReLoadWebView changeLeftDrawerVCUILayout
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"changeLeftVCLayout" object:nil];
     [[NSNotificationCenter defaultCenter] removeObserver:self name:@"changeNickFromHomeCompeteApply" object:nil];
     [[NSNotificationCenter defaultCenter] removeObserver:self name:@"changeNickFromUsrInfoVC" object:nil];
     [[NSNotificationCenter defaultCenter] removeObserver:self name:@"changeHeaderImage" object:nil];
     [[NSNotificationCenter defaultCenter] removeObserver:self name:@"ToAssignValueAndReLoadWebView" object:nil];
     [[NSNotificationCenter defaultCenter] removeObserver:self name:@"changeLeftDrawerVCUILayout" object:nil];
}


/////////////////////////////////////
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

//#pragma mark - LazyLoading
//- (UIView *)line1 {
//    if (!_line1) {
//        _line1 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titleBtn.frame), self.view.frame.size.width, 1)];
//        _line1.backgroundColor = [UIColor  grayColor];
//    }
//    return _line1;
//}
//
//- (UIButton *)oneBtn {
//    if (!_oneBtn) {
//        _oneBtn = [UIButton buttonWithType:UIButtonTypeSystem];
//        _oneBtn.frame = CGRectMake(0, CGRectGetMaxY(_line1.frame), self.view.frame.size.width, 40);
//        [_oneBtn setTitle:@"      用户登录" forState:UIControlStateNormal];
//        [_oneBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
//        [_oneBtn addTarget:self action:@selector(loginBtnIsClicked) forControlEvents:UIControlEventTouchUpInside];
//    }
//    return _oneBtn;
//}
//
//- (UIView *)line2 {
//    if (!_line2) {
//        _line2 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_oneBtn.frame), self.view.frame.size.width, 1)];
//        _line2.backgroundColor = [UIColor  grayColor];
//
//    }
//    return _line2;
//}
//
//- (UIButton *)twoBtn {
//    if (!_twoBtn) {
//        _twoBtn = [UIButton buttonWithType:UIButtonTypeSystem];
//        _twoBtn.frame = CGRectMake(0, CGRectGetMaxY(_line2.frame), self.view.frame.size.width, 40);
//    }
//    return _twoBtn;
//}
//
//- (UIView *)line3 {
//    if (_line3) {
//        _line3 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_twoBtn.frame), self.view.frame.size.width, 1)];
//        _line3.backgroundColor = [UIColor grayColor];
//    }
//    return _line3;
//}
//
//- (UIButton *)threeBtn {
//    if (!_threeBtn) {
//        _threeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
//        _threeBtn.frame = CGRectMake(0, CGRectGetMaxY(_line3.frame), self.view.frame.size.width, 40);
//    }
//    return _threeBtn;
//}
//
//- (UIView *)line4 {
//    if (!_line4) {
//        _line4 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_threeBtn.frame), self.view.frame.size.width, 1)];
//        _line4.backgroundColor = [UIColor grayColor];
//    }
//    return _line4;
//}
//
//- (UIButton *)fourBtn {
//    if (!_fourBtn) {
//        _fourBtn = [UIButton buttonWithType:UIButtonTypeSystem];
//        _fourBtn.frame = CGRectMake(0, CGRectGetMaxY(_line4.frame), self.view.frame.size.width, 40);
//    }
//    return _fourBtn;
//}
//
//- (UIView *)line5 {
//    if (_line5) {
//        _line5 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_fourBtn.frame), self.view.frame.size.width, 1)];
//        _line5.backgroundColor = [UIColor grayColor];
//    }
//    return _line5;
//}
//
//- (UIButton *)fiveBtn {
//    if (!_fiveBtn) {
//        _fiveBtn = [UIButton buttonWithType:UIButtonTypeSystem];
//        _fiveBtn.frame = CGRectMake(0, CGRectGetMaxY(_line5.frame), self.view.frame.size.width, 40);
//    }
//    return _fiveBtn;
//}
//
//- (UIView *)line6 {
//    if (_line6) {
//        _line6 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_fiveBtn.frame), self.view.frame.size.width, 1)];
//        _line6.backgroundColor = [UIColor grayColor];
//    }
//    return _line6;
//}

@end
