//
//  HistoryTopView.m
//  vanke
//
//  Created by Z on 16/4/18.
//  Copyright © 2016年 gomore. All rights reserved.
//

#import "HistoryTopView.h"

@interface HistoryTopView ()<UITextFieldDelegate>
@property (nonatomic, strong) UIDatePicker *startDatePicker;
@property (nonatomic, strong) UIDatePicker *endDatePicker;
@end

@implementation HistoryTopView


-(void)awakeFromNib {
    [super awakeFromNib];
    self.startDate.text = [[NSDate date] yearMonthDayString];
    self.startDate.delegate = self;
    self.startDate.tag = 1;
    self.endDate.text = [[NSDate date] yearMonthDayString];
    self.endDate.delegate = self;
    self.endDate.tag = 2;
    
    self.startDatePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, kWidth, 216)];
    self.startDatePicker.datePickerMode = UIDatePickerModeDate;
    self.startDatePicker.maximumDate = [NSDate date];
    self.startDate.inputView = self.startDatePicker;
    
    self.endDatePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, kWidth, 216)];
    self.endDatePicker.datePickerMode = UIDatePickerModeDate;
    self.endDatePicker.maximumDate = [NSDate date];
    self.endDate.inputView = self.endDatePicker;
    
    if (!AppGlobal.isMall) {
        self.imgRight.hidden = YES;
        self.buttonChooseShop.userInteractionEnabled = NO;
    }
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    if (textField.tag == 1) {
        textField.text = [self.startDatePicker.date yearMonthDayString];
    }else{
        textField.text = [self.endDatePicker.date yearMonthDayString];
    }
}

- (IBAction)actionStart:(id)sender {
    [self startDateBecomeFistRespond];
}

- (IBAction)actionEnd:(id)sender {
    [self endDateBecomeFistRespond];
}
- (void)startDateBecomeFistRespond {
    [self.startDate becomeFirstResponder];
}

- (void)endDateBecomeFistRespond {
    [self.endDate becomeFirstResponder];
}
- (IBAction)queryAction:(id)sender {
    HIDE_KEYBOARD;
    NSLog(@"查询");
    self.blockQuery();
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
