SaleViewController.m 4.58 KB
Newer Older
陈俊俊's avatar
陈俊俊 committed
1 2 3 4 5 6 7 8 9 10 11
//
//  SaleViewController.m
//  XFFruit
//
//  Created by 陈俊俊 on 15/11/6.
//  Copyright © 2015年 Xummer. All rights reserved.
//

#import "SaleViewController.h"
#import "SaleViewCell.h"
#import "SaleHeaderView.h"
陈俊俊's avatar
陈俊俊 committed
12
#import "ReportDetailViewController.h"
陈俊俊's avatar
陈俊俊 committed
13
#import "RSaleView.h"
14
#import "Compass.h"
陈俊俊's avatar
陈俊俊 committed
15 16 17 18
static NSString *saleCellIdentify = @"saleCellIdentify";
static NSString *saleHeaderIdentify = @"saleHeaderIdentify";


陈俊俊's avatar
陈俊俊 committed
19 20
@interface SaleViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong)RSaleView *rsaleView;
21
@property (nonatomic,strong)Compass *compass;
陈俊俊's avatar
陈俊俊 committed
22
@property (nonatomic,strong)NSIndexPath *currentIndex;
陈俊俊's avatar
陈俊俊 committed
23 24 25 26 27 28
@end

@implementation SaleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
陈俊俊's avatar
陈俊俊 committed
29
    [self initData];
陈俊俊's avatar
陈俊俊 committed
30 31
    [self bulidLayout];
}
陈俊俊's avatar
陈俊俊 committed
32 33 34 35 36 37
#pragma mark - 初始化数据
- (void)initData{
    if(!self.dataArr){
        self.dataArr = [NSMutableArray array];
    }
}
陈俊俊's avatar
陈俊俊 committed
38 39 40 41

#pragma mark - 布局
- (void)bulidLayout{
    
陈俊俊's avatar
陈俊俊 committed
42
    self.view .backgroundColor = [UIColor whiteColor];
陈俊俊's avatar
陈俊俊 committed
43
    
陈俊俊's avatar
陈俊俊 committed
44 45
    CGRect rect = CGRectMake(0, 0, ScreenSize.width, 145);
    self.rsaleView = [[RSaleView alloc]initWithFrame:rect];
46 47 48
    self.rsaleView.bgImage.image = [UIImage imageNamed:@"salebg_1"];
    self.rsaleView.cenImage.image = [UIImage imageNamed:@"sale_1"];
    [self.view addSubview:self.rsaleView];
陈俊俊's avatar
陈俊俊 committed
49 50
    
    CLog(@"%f---------",self.view.height);
陈俊俊's avatar
陈俊俊 committed
51 52
    
    rect = CGRectMake(0, 0, self.view.width, self.view.height- 158);
陈俊俊's avatar
陈俊俊 committed
53 54 55 56 57
    self.tableView = [[UITableView alloc]initWithFrame:rect style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[SaleViewCell class] forCellReuseIdentifier:saleCellIdentify];
    [self.tableView registerClass:[SaleHeaderView class] forHeaderFooterViewReuseIdentifier:saleHeaderIdentify];
58
    self.tableView.tableHeaderView = self.rsaleView;
陈俊俊's avatar
陈俊俊 committed
59 60 61 62

    [self.view addSubview:self.tableView];

}
陈俊俊's avatar
陈俊俊 committed
63
- (void)setValueInSale:(Compass *)compass  withType:(NSString *)type{
64
    self.compass = compass;
陈俊俊's avatar
陈俊俊 committed
65
    self.rsaleView.weekLabelStr = type;
陈俊俊's avatar
陈俊俊 committed
66
    [self.rsaleView setValueInSaleView:compass];
陈俊俊's avatar
陈俊俊 committed
67
    
陈俊俊's avatar
陈俊俊 committed
68
}
陈俊俊's avatar
陈俊俊 committed
69 70 71 72 73 74

#pragma mark - tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
陈俊俊's avatar
陈俊俊 committed
75
    return self.dataArr.count;
陈俊俊's avatar
陈俊俊 committed
76 77 78 79 80 81 82 83 84 85 86 87
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
     SaleViewCell *cell = (SaleViewCell *)[tableView dequeueReusableCellWithIdentifier:saleCellIdentify forIndexPath:indexPath];
    
    if(cell == nil) {
        cell = [[SaleViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:saleCellIdentify];
    }
    //没有选中风格
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //取消分割线
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
88
    Compass *test = _dataArr[indexPath.row];
陈俊俊's avatar
陈俊俊 committed
89 90 91 92 93
    if(test != nil) {
        [cell updateCellWith:test index:indexPath];
    }
    cell.detailBtn.tag = indexPath.row;
    [cell.detailBtn addTarget:self action:@selector(detailClick:) forControlEvents:UIControlEventTouchUpInside];
陈俊俊's avatar
陈俊俊 committed
94 95 96 97 98 99 100 101 102
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [SaleViewCell cellHeight];
}

陈俊俊's avatar
陈俊俊 committed
103 104 105 106
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [[NSNotificationCenter defaultCenter]postNotificationName:KNOTIFICATION_GetNextDetailData object:nil userInfo:@{@"indexPath":indexPath}];
}

陈俊俊's avatar
陈俊俊 committed
107 108 109 110 111 112 113 114 115

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    SaleHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:saleHeaderIdentify];
    
    if (headerView == nil) {
        headerView = [[SaleHeaderView alloc] initWithReuseIdentifier:saleHeaderIdentify];
    }
    [headerView buildLayout];
陈俊俊's avatar
陈俊俊 committed
116
    headerView.totalLabel.text = [NSString stringWithFormat:@"共%ld家",(long)self.count];
陈俊俊's avatar
陈俊俊 committed
117 118
    [headerView changeTypeName:self.typeStr];

陈俊俊's avatar
陈俊俊 committed
119 120 121 122 123 124 125 126 127
    return headerView;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return [SaleHeaderView viewHeight];
}

陈俊俊's avatar
陈俊俊 committed
128
- (void)detailClick:(UIButton *)btn{
129 130 131 132 133 134
    Compass *com = self.dataArr[btn.tag];
    NSObject *comObj = [NSNull null];
    if (com) {
        comObj = com;
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_GoReportDetail object:nil userInfo:@{@"compass":comObj}];
陈俊俊's avatar
陈俊俊 committed
135 136
}

陈俊俊's avatar
陈俊俊 committed
137

陈俊俊's avatar
陈俊俊 committed
138 139 140 141 142 143
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end