//
//  MineViewController.m
//  TianLing_App
//
//  Created by 刘荣毅 on 2017/10/20.
//  Copyright © 2017年 Liu. All rights reserved.
//

#import "MineViewController.h"
#import "JX_MySettingViewController.h"
#import "JX_PersonalDataViewController.h"
#import "UIView+Tap.h"
#import "UIImageView+WebCache.h"


#import "MinePersonageInfoDataModels.h"

@interface MineViewController ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *personViewOriginy;
@property (weak, nonatomic) IBOutlet UIView *personalDataView;
@property (weak, nonatomic) IBOutlet UIImageView *personalHeadImgView;
@property (weak, nonatomic) IBOutlet UILabel *nameL;
@property (weak, nonatomic) IBOutlet UILabel *emailAddressL;
@property (weak, nonatomic) IBOutlet UILabel *companyL;

@property(nonatomic ,strong) MinePersonageInfoBaseClass *dataBaseModel;
@property(nonatomic ,strong) MinePersonageInfoData *dataModel ;

@end

@implementation MineViewController
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
     [self networkingRequest];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
      NSLog(@"before----%@",NSStringFromCGRect(self.personalHeadImgView.frame));
    
    [self initUI];
    
    if (kDevice_Is_iPhoneX) {
        self.personViewOriginy.constant = 84.0+20;
    }
   
}

-(void)initUI{
    self.title = @"我的";
    
    [self.personalDataView addTapBlock:^(id obj) {
        JX_PersonalDataViewController *personVc = [[JX_PersonalDataViewController alloc]init];
        personVc.dataModel = self.dataModel;
        personVc.nameStr = self.dataModel.name;
        personVc.personalImgStr = self.dataModel.avatar;
        personVc.phoneNumStr = self.dataModel.mobile;
        personVc.emailStr = self.dataModel.email;
        personVc.accountStr = self.dataModel.loginNo;
        personVc.subClassStr = self.dataModel.domain;
        personVc.classStr = self.dataModel.dept;
        [personVc popViewHandle:^(UIImage *image, NSString *name, NSString *email) {
            self.personalHeadImgView.image = image;
            self.nameL.text = name;
            self.emailAddressL.text =email;
        }];
        [self.navigationController pushViewController:personVc animated:YES];
    }];
    
//    self.personalHeadImgView.layer.cornerRadius = 6.f;
//    self.personalHeadImgView.layer.shadowColor = [UIColor blackColor].CGColor;
//    self.personalHeadImgView.layer.shadowOffset = CGSizeMake(10, 10);
//    self.personalHeadImgView.layer.shadowOpacity = 0.5;
//    self.personalHeadImgView.layer.shadowRadius = 6.f;
    
//    DLog(@"============== %f  ======= %f   ======== %f     ===== %f",self.personalHeadImgView.frame.origin.x, self.personalHeadImgView.frame.origin.y, self.personalHeadImgView.frame.size.width, self.personalHeadImgView.frame.size.height);
        UIView *shadowView = [[UIView alloc]initWithFrame:CGRectMake(20, 20, self.personalHeadImgView.frame.size.width, self.personalHeadImgView.frame.size.height)];
        [self.personalDataView addSubview:shadowView];
        shadowView.layer.shadowColor = [UIColor blackColor].CGColor;
        shadowView.layer.shadowOffset = CGSizeMake(0, 8);
        shadowView.layer.shadowOpacity = 0.1;
        shadowView.layer.shadowRadius = 8;
        shadowView.layer.cornerRadius = 5;
        shadowView.clipsToBounds = NO;
        [shadowView addSubview:self.personalHeadImgView];
    
    UIView *shadowView1 = [[UIView alloc]initWithFrame:CGRectMake(14, 84, self.personalDataView.frame.size.width, self.personalDataView.frame.size.height)];
    [self.view addSubview:shadowView1];
    shadowView1.layer.shadowColor = [UIColor blackColor].CGColor;
    shadowView1.layer.shadowOffset = CGSizeMake(0, 8);
    shadowView1.layer.shadowOpacity = 0.1;
    shadowView1.layer.shadowRadius = 8;
    shadowView1.layer.cornerRadius = 5;
    shadowView1.clipsToBounds = NO;
    [shadowView1 addSubview:self.personalDataView];
    

//    UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:self.personalHeadImgView.bounds];
//    self.personalHeadImgView.layer.masksToBounds = YES;
//    self.personalHeadImgView.layer.shadowColor = [UIColor blackColor].CGColor;
//    self.personalHeadImgView.layer.shadowOffset = CGSizeMake(0, 8);
//    self.personalHeadImgView.layer.shadowOpacity = 0.1;
//    self.personalHeadImgView.layer.cornerRadius = 20;
//    self.personalHeadImgView.layer.shadowPath = shadowPath.CGPath;
    
//    self.personalHeadImgView.layer.backgroundColor = [UIColor colorWithHexString:@"#999999"].CGColor;
//    self.personalHeadImgView.layer.shadowOffset = CGSizeMake(0, 8);
//    self.personalHeadImgView.layer.shadowOpacity = 0.1;
//    self.personalHeadImgView.layer.cornerRadius = 8;
//
//    self.personalDataView.backgroundColor = [UIColor whiteColor];
//    self.personalDataView.layer.backgroundColor = [UIColor colorWithHexString:@"#999999"].CGColor;
//    self.personalDataView.layer.shadowOffset = CGSizeMake(0, 8);
//    self.personalDataView.layer.shadowOpacity = 0.1;
//    self.personalDataView.layer.cornerRadius = 8;
    
    
}

//- (void)viewDidLayoutSubviews
//{
//    [super viewDidLayoutSubviews];
//    UIView *shadowView = [[UIView alloc]initWithFrame:self.personalHeadImgView.frame];
//
//    [self.view addSubview:shadowView];
//
//    shadowView.layer.shadowColor = [UIColor blackColor].CGColor;
//
//    shadowView.layer.shadowOffset = CGSizeMake(5, 5);
//
//    shadowView.layer.shadowOpacity = 1;
//
//    shadowView.layer.shadowRadius = 9.0;
//
//    shadowView.layer.cornerRadius = 9.0;
//
//    shadowView.clipsToBounds = NO;
//
//    [shadowView addSubview:self.personalHeadImgView];
//
//}




#pragma mark- networking
-(void)networkingRequest{
    
    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    parDic[@"access_token"] = [[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"];
    DLog(@" 令牌 ==== %@",[[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"]);
    
    __weak typeof(self) weakSelf = self;
    [HttpClient sendPostWithURL:MINEPERSONAGEINFO_URL parameter:parDic success:^(id JSON) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:JSON options:0 error:nil];
        DLog(@"我的信息 ==== %@",dic);
      weakSelf.dataBaseModel  = [MinePersonageInfoBaseClass modelObjectWithDictionary:dic];
        
       weakSelf.dataModel  = weakSelf.dataBaseModel.data;
        
        dispatch_async(dispatch_get_main_queue(), ^{
            weakSelf.nameL.text = weakSelf.dataModel.name;
            weakSelf.emailAddressL.text = weakSelf.dataModel.email;
            [weakSelf.personalHeadImgView sd_setImageWithURL:[NSURL URLWithString:self.dataModel.avatar] placeholderImage:[UIImage imageNamed:@"LOGO"]];
            weakSelf.companyL.text = weakSelf.dataModel.domain;
        });
        
        
    } failure:^(NSError *error) {
        
    }];
    
    
    
}



#pragma mark- method

- (IBAction)DidTapSettingHadel:(id)sender {
     DLog(@"设置");
    
    JX_MySettingViewController *settingVC = [[JX_MySettingViewController alloc]init];
    settingVC.dataModel = self.dataModel;
    [self.navigationController pushViewController:settingVC animated:YES];
    
}

@end
