//
//  HomeViewController.m
//  ALand
//
//  Created by Z on 16/3/17.
//  Copyright © 2016年 Z. All rights reserved.
//

#import "HomeViewController.h"
#import "HomeTopView.h"
#import "HomeCollectionViewController.h"
#import "JavenShopModel.h"
@interface HomeViewController ()
@property (nonatomic, strong) HomeTopView *viewHomeTop;
@property (nonatomic, strong) JavenShopModel *shopModel;
@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpView];
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];
    [self setUpdata];
}

- (void)setUpdata {
    
    WS(weakSelf)
    [[HTTPCilent shareCilent] GET:[NSString stringWithFormat:@"shop/get/%@", [UserInfo shareInstance].shop.uuid] parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
       
        if (weakSelf.shopModel) {
            [weakSelf.shopModel updateWithDictionary:responseObject[@"shop"]];
        }else{
            weakSelf.shopModel = [JavenShopModel modelObjectWithDictionary:responseObject[@"shop"]];
        }
    CLog(@"%p",weakSelf.shopModel);
        [weakSelf.viewHomeTop updateTopViewInfo:weakSelf.shopModel];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
}




- (void)setUpView {
    HomeTopView *viewHomeTop = [HomeTopView viewWithNibName:@"HomeTopView"];
    self.viewHomeTop = viewHomeTop;
    [self.view addSubview:viewHomeTop];
    viewHomeTop.sd_layout.topEqualToView(self.view).leftEqualToView(self.view).rightEqualToView(self.view).heightIs(150);
    [viewHomeTop updateLayout];
    
    
    HomeCollectionViewController *homeCollectionView = [[HomeCollectionViewController alloc] init];
    [self addChildViewController:homeCollectionView];
    [self.view addSubview:homeCollectionView.view];
    homeCollectionView.view.sd_layout.topSpaceToView(viewHomeTop, 0).leftEqualToView(self.view).rightEqualToView(self.view).bottomEqualToView(self.view);
    [homeCollectionView.view updateLayout];    
}

- (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.
}
*/

@end
