CostViewController.m 6.07 KB
Newer Older
n22's avatar
n22 committed
1 2 3 4 5 6 7 8 9 10 11
//
//  CostViewController.m
//  XFFruit
//
//  Created by n22 on 15/8/19.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "CostViewController.h"
#import "HeaderCell.h"
#import "FooterCell.h"
陈俊俊's avatar
陈俊俊 committed
12
#import "CostCell.h"
陈俊俊's avatar
陈俊俊 committed
13 14 15 16

#define TableHeight 44
#define ShowHeight  80

陈俊俊's avatar
陈俊俊 committed
17
@interface CostViewController ()<UITableViewDataSource,UITableViewDelegate,FooterCellDelegate,HeaderCellDelegate>
n22's avatar
n22 committed
18 19
{
    CGRect _tableFrame;
陈俊俊's avatar
陈俊俊 committed
20 21
    NSMutableArray *_selectRowArr;//记录当前选中的cell

n22's avatar
n22 committed
22 23 24 25 26 27 28 29 30
}
@end

@implementation CostViewController


- (void)viewDidLoad {
    self.view.backgroundColor  = XXFBgColor;
    [super viewDidLoad];
陈俊俊's avatar
陈俊俊 committed
31
    _selectRowArr = [[NSMutableArray alloc]init];
n22's avatar
n22 committed
32 33 34 35 36 37 38 39 40 41 42
    _costArr = [NSMutableArray array];
    [self createView];
}
- (void)setViewFrame:(CGRect)viewFrame{
    _tableFrame = viewFrame;
}
- (void)createView{
    self.tableView = [[UITableView alloc]initWithFrame:_tableFrame style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
陈俊俊's avatar
陈俊俊 committed
43
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
n22's avatar
n22 committed
44 45
    [self.view addSubview:self.tableView];
    
陈俊俊's avatar
陈俊俊 committed
46
    NSArray *arr = @[@"费用",@"应付金额",@"已付金额",@"尾款"];
n22's avatar
n22 committed
47
    
陈俊俊's avatar
陈俊俊 committed
48 49
    HeaderCell *headCell = [[HeaderCell alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, 38) withArr:arr withHiddenEdit:self.isHiddenEdit];
    headCell.delegate = self;
n22's avatar
n22 committed
50 51
    [self.view addSubview:headCell];
    self.tableView.tableHeaderView = headCell;
陈俊俊's avatar
陈俊俊 committed
52 53 54 55 56 57
    if (!self.isHiddenEdit) {
        FooterCell *footCell = [[FooterCell alloc]initWithFrame:CGRectMake(0, 0, _tableFrame.size.width, 50) withTitle:@"+点击添加费用明细" isTwo:@""];
        [self.view addSubview:footCell];
        footCell.delegate = self;
        self.tableView.tableFooterView = footCell;
    }
n22's avatar
n22 committed
58
}
陈俊俊's avatar
陈俊俊 committed
59 60 61
- (void)addClickList{
    [self addClick];
}
n22's avatar
n22 committed
62
- (void)addClick{
陈俊俊's avatar
陈俊俊 committed
63
    [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_AddTransportCost object:nil];
n22's avatar
n22 committed
64
}
陈俊俊's avatar
陈俊俊 committed
65 66 67 68 69 70
- (void)editClick:(UIButton *)btn{
    FeeAcountDetail *fee = self.costArr[btn.tag];
    [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_AddTransportCost object:nil userInfo:@{@"indexPath":[NSIndexPath indexPathForRow:btn.tag inSection:0],@"feeAccountDetail":fee}];
}
#pragma mark footDelegate
- (void)choosePurchase{}
n22's avatar
n22 committed
71 72 73 74 75 76 77 78
#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.costArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
陈俊俊's avatar
陈俊俊 committed
79 80
    static NSString *cellID = @"CostCell";
    CostCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
n22's avatar
n22 committed
81
    if (cell == nil) {
陈俊俊's avatar
陈俊俊 committed
82 83 84 85 86 87
        cell = [[CostCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (self.isHiddenEdit) {
            cell.editBtn.hidden = YES;
        }
    }
陈俊俊's avatar
陈俊俊 committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
    if ([self isHaveIndexPath:indexPath]) {
        cell.smallImageView.image = [UIImage imageNamed:@"arrowdown"];
//        CGRect Linefrmame = cell.lineLabel.frame;
//        Linefrmame.origin.y = ShowHeight + TableHeight -1;
//        cell.lineLabel.frame = Linefrmame;
        cell.lineLabel.top = ShowHeight + TableHeight -1;
//        CGRect showfrmame = cell.showView.frame;
//        showfrmame.size.height = ShowHeight;
//        cell.showView.frame = showfrmame;
        cell.showView.height = ShowHeight;
        cell.backgroundColor = XXFBgColor;
    }else{
        cell.smallImageView.image = [UIImage imageNamed:@"arrowright"];
//        CGRect Linefrmame = cell.lineLabel.frame;
//        Linefrmame.origin.y = TableHeight-1;
//        cell.lineLabel.frame = Linefrmame;
        cell.lineLabel.top = TableHeight-1;

//        CGRect showfrmame = cell.showView.frame;
//        showfrmame.size.height = 0;
//        cell.showView.frame = showfrmame;
        cell.showView.height = 0;

        cell.backgroundColor = [UIColor whiteColor];
    }
    
    
    
    
陈俊俊's avatar
陈俊俊 committed
117 118 119 120 121
    cell.editBtn.tag = indexPath.row;
    [cell.editBtn addTarget:self action:@selector(editClick:) forControlEvents:UIControlEventTouchUpInside];
    if (self.costArr.count) {
        FeeAcountDetail *fee = self.costArr[indexPath.row];
        [cell setFeeCost:fee row:indexPath.row];
n22's avatar
n22 committed
122 123 124
    }
    return cell;
}
陈俊俊's avatar
陈俊俊 committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CostCell *cell = (CostCell *)[tableView cellForRowAtIndexPath:indexPath];
    CGRect Linefrmame = cell.lineLabel.frame;
    CGRect showfrmame = cell.showView.frame;
    if (Linefrmame.origin.y == TableHeight - 1) {
        cell.smallImageView.image = [UIImage imageNamed:@"arrowdown"];
        Linefrmame.origin.y = ShowHeight + TableHeight - 1;
        showfrmame.size.height = ShowHeight;
        cell.backgroundColor = [UIColor whiteColor];
        [_selectRowArr addObject:indexPath];
    }else{
        cell.smallImageView.image = [UIImage imageNamed:@"arrowright"];
        Linefrmame.origin.y = TableHeight -1;
        showfrmame.size.height = 0;
        cell.backgroundColor = [UIColor whiteColor];
        [_selectRowArr removeObject:indexPath];
    }
    cell.lineLabel.frame = Linefrmame;
    cell.showView.frame = showfrmame;
    [self.tableView reloadData];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([self isHaveIndexPath:indexPath]) {
        return ShowHeight + TableHeight;
    }
    return TableHeight;
}
- (BOOL)isHaveIndexPath:(NSIndexPath *)indexPath{
    for (NSIndexPath *path in _selectRowArr) {
        if (path.row == indexPath.row) {
            return YES;
        }
    }
    return NO;
}



n22's avatar
n22 committed
165 166 167 168 169 170 171 172 173 174 175
/*
#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