//
//  GasStationPayDetailsVC.m
//  Open
//
//  Created by qinxuyang on 2021/11/18.
//  Copyright © 2021 QXY. All rights reserved.
//

#import "GasStationPayDetailsVC.h"
#import "GasPayDetailCell.h"
#import "GasPayDetailHeader.h"
#import "GasPayDetailSectionHeader.h"
@interface GasStationPayDetailsVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) GasPayDetailHeader *headerView;
@property (nonatomic, strong) NSArray *titleArr;
@end

@implementation GasStationPayDetailsVC
- (NSArray *)titleArr{
    if (_titleArr == nil) {
        _titleArr = @[@"交易订单",@"油站名称",@"下单时间",@"加油金额",@"合计优惠",@"合计支付"];
    }
    return _titleArr;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    if (@available(iOS 11.0, *)) {
           self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
       self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self.view addSubview:self.tableView];
    self.tableView.tableHeaderView = self.headerView;
}
- (void)backClick{
    [self.navigationController popViewControllerAnimated:YES];
}
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStyleGrouped];
        _tableView.backgroundColor = [UIColor colorWithHex:0xf2f2f2];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;//推荐该方法
        [_tableView registerNib:[UINib nibWithNibName:@"GasPayDetailCell" bundle:nil] forCellReuseIdentifier:@"GasPayDetailCell"];
    }
    return _tableView;
}
- (GasPayDetailHeader *)headerView{
    if (_headerView == nil) {
        _headerView = [[[NSBundle mainBundle] loadNibNamed:@"GasPayDetailHeader" owner:nil options:nil] firstObject];
        _headerView.frame = CGRectMake(0, 0, ScreenWidth, 150 + STATUS_BAR_HEIGHT);
        [_headerView.backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
//        [[SetGradient instance] setViewBackground:_headerView.BaseView fromColor:@"#e52d36" toColor:@"#e8221c" fromCGPoint:CGPointMake(0, 0) toCGPoint:CGPointMake(1, 0)];
        _headerView.orderTime.text = _Model.orderTime;
        _headerView.price.text = _Model.amountPay;
    }
    return _headerView;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titleArr.count;
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    GasPayDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GasPayDetailCell"];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"GasPayDetailCell" owner:self options:nil] lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.titleLab.text = self.titleArr[indexPath.row];
    if ([cell.titleLab.text isEqualToString:@"交易订单"]) {
        cell.contentLab.text = self.Model.orderId;
    }
    if ([cell.titleLab.text isEqualToString:@"油站名称"]) {
        cell.contentLab.text = self.Model.gasName;
    }
    if ([cell.titleLab.text isEqualToString:@"下单时间"]) {
        cell.contentLab.text = self.Model.orderTime;
    }
    if ([cell.titleLab.text isEqualToString:@"加油金额"]) {
        cell.contentLab.text = [NSString stringWithFormat:@"¥%@",self.Model.amountGun];
    }
    if ([cell.titleLab.text isEqualToString:@"合计优惠"]) {
        cell.contentLab.text = [NSString stringWithFormat:@"-¥%@",self.Model.amountDiscounts];
        cell.contentLab.textColor = [UIColor colorWithHex:0xe52d36];
    }
    if ([cell.titleLab.text isEqualToString:@"合计支付"]) {
        cell.contentLab.text = [NSString stringWithFormat:@"¥%@",self.Model.amountPay];
        cell.contentLab.font = [UIFont boldSystemFontOfSize:16];
    }
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    GasPayDetailSectionHeader *SectionHeader = [[[NSBundle mainBundle] loadNibNamed:@"GasPayDetailSectionHeader" owner:nil options:nil] firstObject];
    return SectionHeader;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
/*
#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
