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

#import "OrderDetailViewController.h"
#import "NSString+Category.h"
#import "OrderDetailTableViewCell.h"
#import "UITableView+Category.h"
#import "SeeLogistics.h"
#import "OrderDetailBottomView.h"

#define kCellId @"OrderDetailTableViewCell.h"
@interface OrderDetailViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) OrderDetailBottomView *bottomView;
@property (nonatomic, strong) OrderDetailTopView *atopView;
@end

@implementation OrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kCustomGreenColor;
    self.navigationItem.title = @"订单详情";
    
    //tableView
    self.tableView = [UITableView plainTableViewWithTarget:self cellNibName:@"OrderDetailTableViewCell" cellId:kCellId];
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundColor = kBacroundColor;
    
    [self.view addSubview:self.tableView];//topView
    
    
    OrderDetailTopView *topView = [OrderDetailTopView viewWithNibName:@"OrderDetailTopView"];
    self.atopView = topView;
    self.atopView.orderType = self.orderType;
    self.atopView.labelAddress.text = [NSString randomTestText];
    [self.tableView addSubview:topView];
    
    [self.atopView updateByOrderType];
    
    self.bottomView = [OrderDetailBottomView viewWithNibName:@"OrderDetailBottomView"];
    self.bottomView.laberRemark.text = [NSString randomTestText];
    
    self.tableView.tableFooterView = self.bottomView;
    
    //底部查看物流按钮
    if (self.orderType == ORDERTOPTYPE_TRANSPORTED) {
        SeeLogistics *viewBottom = [SeeLogistics viewWithNibName:@"SeeLogistics"];
        viewBottom.frame = CGRectMake(0, kHeight - 64 - 65, kWidth,  64 + 65);
        [self.view addSubview:viewBottom];
    }
    
    // Do any additional setup after loading the view.
}

- (void)viewDidLayoutSubviews {
    
    self.tableView.frame = CGRectMake(0, 0, kWidth, kHeight);
    
    [self.atopView updateHeight];
    self.atopView.frame = CGRectMake(0, -self.atopView.height, kWidth, self.atopView.height);
    
    
    
    [self.bottomView updateHeight];
    //self.bottomView.y = kHeight - self.bottomView.height;
    self.bottomView.width = kWidth;
    
    self.tableView.contentInset = UIEdgeInsetsMake(self.atopView.height, 0, self.bottomView.height - 250, 0);
    
//    self.tableView.frame = CGRectMake(0, 0, kWidth, kHeight - self.atopView.height);
    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    OrderDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId forIndexPath:indexPath];
    return cell;
}
- (void)setUpTableView {
    
}


- (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
