//
//  OrderListFilterViewController.m
//  Car
//
//  Created by Javen on 2016/12/26.
//  Copyright © 2016年 上海勾芒信息科技. All rights reserved.
//

#import "OrderListFilterViewController.h"

@interface OrderListFilterViewController ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraintHeight;

/**
 阴影
 */
@property (weak, nonatomic) IBOutlet UIView *shadow;

/**
 整个输入面板
 */
@property (weak, nonatomic) IBOutlet UIView *board;

/**
 单号
 */
@property (weak, nonatomic) IBOutlet UITextField *textFieldBillNumber;

/**
 日期开始时间
 */
@property (weak, nonatomic) IBOutlet DateTextField *textFieldDate;
@property (weak, nonatomic) IBOutlet DateTextField *textFieldEndDate;

/**
 加油员
 */
@property (weak, nonatomic) IBOutlet UITextField *textFieldStationUser;

@end

@implementation OrderListFilterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    // Do any additional setup after loading the view.
    self.textFieldDate.type = DateTextFieldTime;
    self.textFieldEndDate.type = DateTextFieldTime;
    self.textFieldDate.text = [[[NSDate date] yearMonthDayString] stringByAppendingString:@" 00:00:00"];
}

- (IBAction)actionBac:(id)sender {
    [self hideFilterView];
}

- (void)configParam {
    self.param.billNumberLike = self.textFieldBillNumber.text;
    self.param.userNameLike = self.textFieldStationUser.text;
    self.param.beginDate = self.textFieldDate.text;
    self.param.endDate = self.textFieldEndDate.text;;
}

#pragma mark - actions

/**
 重置
 */
- (IBAction)actionReset:(id)sender {
    self.param.billNumberLike = nil;
    self.param.userNameLike = nil;
    self.param.endDate = nil;
    self.textFieldDate.text = nil;
    self.textFieldStationUser.text = nil;
    self.textFieldBillNumber.text = nil;
}

/**
 提交
 */
- (IBAction)actionSubmit:(id)sender {
    [self configParam];
    [self hideFilterView];
    if (self.blockSubmit) {
        self.blockSubmit();
    }
}

- (IBAction)actionChooseIsChecked:(UIButton *)sender {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请选择" message:nil preferredStyle:UIAlertControllerStyleAlert];
    WS(weakSelf);
    UIAlertAction *actionAll = [UIAlertAction actionWithTitle:@"全部"
                                                        style:(UIAlertActionStyleDefault)
                                                      handler:^(UIAlertAction *_Nonnull action) {
                                                          [sender setTitle:@"全部" forState:UIControlStateNormal];
                                                          weakSelf.param.checkState = nil;
                                                      }];
    [alert addAction:actionAll];

    UIAlertAction *actionChecked = [UIAlertAction actionWithTitle:@"已对账"
                                                            style:(UIAlertActionStyleDefault)
                                                          handler:^(UIAlertAction *_Nonnull action) {
                                                              [sender setTitle:@"已对账" forState:UIControlStateNormal];
                                                              weakSelf.param.checkState = @"checked";
                                                          }];

    [alert addAction:actionChecked];

    UIAlertAction *actionUnchecked = [UIAlertAction actionWithTitle:@"未对账"
                                                              style:(UIAlertActionStyleDefault)
                                                            handler:^(UIAlertAction *_Nonnull action) {
                                                                [sender setTitle:@"未对账" forState:UIControlStateNormal];
                                                                weakSelf.param.checkState = @"unchecked";
                                                            }];
    [alert addAction:actionUnchecked];
    
    UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:nil];
    [alert addAction:actionCancel];

    [self presentViewController:alert animated:YES completion:nil];
}

- (void)hideFilterView {
    HIDE_KEYBOARD;
    self.isOpen = NO;
//    self.constraintHeight.constant = 0;
    [UIView animateWithDuration:0.7
        delay:0
        usingSpringWithDamping:0.9
        initialSpringVelocity:1.0
        options:UIViewAnimationOptionCurveLinear
        animations:^{
            self.board.transform = CGAffineTransformMakeScale(1, 0);
            self.shadow.backgroundColor = [UIColor clearColor];
//            [self.view layoutIfNeeded];
        }
        completion:^(BOOL finished) {
            [self.view removeFromSuperview];
        }];
}

- (void)showFilterView {
    self.isOpen = YES;
//    self.constraintHeight.constant = 320;
    [UIView animateWithDuration:0.7
                          delay:0
         usingSpringWithDamping:0.9
          initialSpringVelocity:1.0
                        options:UIViewAnimationOptionCurveLinear
                     animations:^{
                         self.shadow.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.3];
//                         [self.view layoutIfNeeded];
                         self.board.transform = CGAffineTransformMakeScale(1, 0);
                     }
                     completion: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.
}
*/

@end
