CNLiveTradingRecordDetailController.m 6.66 KB
//
//  CNLiveTradingRecordDetailController.m
//  CNLiveBalanceModule
//
//  Created by 153993236@qq.com on 11/12/2019.
//  Copyright (c) 2019 153993236@qq.com. All rights reserved.
//

#import "CNLiveTradingRecordDetailController.h"
#import "MJExtension.h"
#import <SDWebImage/SDWebImage.h>
#import "QMUIKit.h"
#import "CNLiveNetworking.h"
#import "CNLiveEnvironment.h"

#import "CNUserInfoManager.h"
#import "CNLiveBaseKit.h"
#import "CNLiveCategory.h"

#import "CNLiveServices.h"
#import "CNLiveBalanceRequest.h"

#import "CNLiveBalanceNavigationBar.h"
#import "CNLiveTradingRecordView.h"
#import "CNLiveTradingRecordModel.h"
#import "CNLiveTradingRecordDetailModel.h"
#import "CNLiveTradingRecordDetailCell.h"
#import "CNLiveTradingRecordDetailHeaderView.h"
#import "CNLiveTradingRecordController.h"

@interface CNLiveTradingRecordDetailController ()<UITableViewDelegate, UITableViewDataSource,CNLiveBalanceNavigationBarDelegate>
@property (nonatomic, strong) CNLiveBalanceNavigationBar *navigationBar;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) CNLiveTradingRecordDetailHeaderView *headerView;
@property (nonatomic, strong) NSMutableArray *data;

@end

@implementation CNLiveTradingRecordDetailController
static const CGFloat height = 80;

#pragma mark - 加载数据
- (void)loadData {
    [CNLiveBalanceRequest getTradingRecordDetailWithModel:self.model block:^(BOOL isSuccess, NSDictionary * _Nonnull data, NSError *error) {
        if (error) {
            [self showEmptyViewWithImage:[UIImage imageNamed:@"wufalianjie"] text:error.localizedDescription detailText:@"别紧张,试试看刷新页面~" buttonTitle:@"     重试     " buttonAction:@selector(loadData)];
            [self setCNAPIErrorEmptyView];
            self.emptyView.verticalOffset = -(NavigationContentTop+height);
            return;
        }
        if (isSuccess) {
            CNLiveTradingRecordDetailModel *model = [CNLiveTradingRecordDetailModel mj_objectWithKeyValues:data];
            self.data = [CNLiveBalanceRequest handleDataWithModel:model name:self.model.iconBean.nickName isAdd:self.type == TradingRecordDetailTypeDefault];
            [self.tableView reloadData];
        }
    }];

}

#pragma mark - 生命周期
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];

    if (@available(iOS 11, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self createSubViews];
    [self loadData];
    
}

- (void)createSubViews {
    [self.view addSubview:self.navigationBar];
    self.headerView.model = self.model;
    self.tableView.tableHeaderView = self.headerView;
    [self.view addSubview:self.tableView];
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CNLiveTradingRecordDetailModel *model = self.data[indexPath.row];
    return model.height;
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.data.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CNLiveTradingRecordDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:kCNLiveTradingRecordDetailCell];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = self.data[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    CNLiveTradingRecordDetailModel *model = self.data[indexPath.row];
    if([model.style isEqualToString:@"1"]){
        CNLiveTradingRecordController *vc = [[CNLiveTradingRecordController alloc]init];
        vc.type = TradingRecordTypeSpecial;
        vc.ID = self.model.toId;
        
        vc.date = self.date;
        vc.startTime = self.startTime;
        vc.endTime = self.endTime;
        
        [self.navigationController pushViewController:vc animated:YES];
        
    }
}

#pragma mark - 懒加载
- (NSMutableArray *)data {
    if (!_data) {
        _data = [[NSMutableArray alloc] init];
    }
    return _data;
}

- (CNLiveBalanceNavigationBar *)navigationBar {
    if (!_navigationBar) {
        _navigationBar = [[CNLiveBalanceNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
        _navigationBar.backgroundColor = [UIColor whiteColor];
        _navigationBar.delegate = self;
        _navigationBar.title.text = @"交易记录";
        _navigationBar.title.textColor = [UIColor blackColor];
        UIImage *image = [self getImageWithImageName:@"mine_back_black_b" bundleName:@"CNLiveBalanceModule" targetClass:[self class]];
        [_navigationBar.left setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        _navigationBar.right = nil;

    }
    return _navigationBar;
}
- (UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationContentTop) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        [_tableView registerClass:[CNLiveTradingRecordDetailCell class] forCellReuseIdentifier:kCNLiveTradingRecordDetailCell];
    }
    return _tableView;
}
- (CNLiveTradingRecordDetailHeaderView *)headerView {
    if (!_headerView) {
        _headerView = [[CNLiveTradingRecordDetailHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 160)];
    }
    return _headerView;
}

#pragma mark - 响应方法
- (void)goBack {
    if (self.presentingViewController != nil) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

#pragma mark - CNLiveBalanceNavigationBarDelegate
- (void)navigationBar:(CNLiveBalanceNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
    if ([actionEvents isEqualToString:@"1"]) {
        [self goBack];
    }else if ([actionEvents isEqualToString:@"2"]){
        
    }
}

@end