ProductBillViewController.m 6.51 KB
Newer Older
n22's avatar
n22 committed
1 2 3 4 5 6 7 8
//
//  ProductViewController.m
//  XFFruit
//
//  Created by n22 on 15/8/21.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

陈俊俊's avatar
陈俊俊 committed
9
#import "ProductBillViewController.h"
n22's avatar
n22 committed
10 11
#import "FooterCell.h"
#import "HeaderCell.h"
陈俊俊's avatar
陈俊俊 committed
12
#import "ProductBillCell.h"
n22's avatar
n22 committed
13
#import "PurchaseBillProduct.h"
n22's avatar
n22 committed
14
#define TableHeight 44
陈俊俊's avatar
陈俊俊 committed
15
#define ShowHeight  130
n22's avatar
n22 committed
16

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

陈俊俊's avatar
陈俊俊 committed
24
@implementation ProductBillViewController
n22's avatar
n22 committed
25 26 27 28 29

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor  = XXFBgColor;
    [super viewDidLoad];
陈俊俊's avatar
陈俊俊 committed
30 31 32 33 34
    [self initData];
    [self createView];
}
- (void)initData{
    _selectRowArr = [[NSMutableArray alloc]init];
陈俊俊's avatar
陈俊俊 committed
35 36 37
    if (!self.productArr) {
        self.productArr = [NSMutableArray array];
    }
陈俊俊's avatar
陈俊俊 committed
38 39 40
    if (self.productArr.count > 0) {
         [[NSNotificationCenter defaultCenter] postNotificationName:SetProductTotalPrice object:nil];
    }
n22's avatar
n22 committed
41
}
陈俊俊's avatar
陈俊俊 committed
42

n22's avatar
n22 committed
43 44 45 46 47 48 49 50 51 52
- (void)setViewFrame:(CGRect)viewFrame{
    _tableFrame = viewFrame;
}
- (void)createView{
    self.tableView = [[UITableView alloc]initWithFrame:_tableFrame style:(UITableViewStylePlain)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    
陈俊俊's avatar
陈俊俊 committed
53
    NSArray *arr = @[@"商品",@"单价",@"包装数量",@"已发运"];
n22's avatar
n22 committed
54
    
陈俊俊's avatar
陈俊俊 committed
55
    HeaderCell *headCell = [[HeaderCell alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, 38) withArr:arr withHiddenEdit:self.isHiddenEdit];
n22's avatar
n22 committed
56
    [self.view addSubview:headCell];
陈俊俊's avatar
陈俊俊 committed
57
    headCell.delegate = self;
n22's avatar
n22 committed
58 59
    self.tableView.tableHeaderView = headCell;
    
陈俊俊's avatar
陈俊俊 committed
60
    if (!self.isHiddenEdit) {
陈俊俊's avatar
陈俊俊 committed
61
        FooterCell *footCell = [[FooterCell alloc]initWithFrame:CGRectMake(0, 0, _tableFrame.size.width, 50) withTitle:@"+点击添加商品明细" isTwo:self.twoTitle];
陈俊俊's avatar
陈俊俊 committed
62 63 64 65
        [self.view addSubview:footCell];
        footCell.delegate = self;
        self.tableView.tableFooterView = footCell;
    }
n22's avatar
n22 committed
66
}
陈俊俊's avatar
陈俊俊 committed
67 68 69 70 71 72

- (void)addClickList{
     [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_AddPurchaseProduct object:nil];
}


n22's avatar
n22 committed
73
#pragma mark - footerDelegate
n22's avatar
n22 committed
74
- (void)addClick{
陈俊俊's avatar
陈俊俊 committed
75
    [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_AddPurchaseProduct object:nil];
n22's avatar
n22 committed
76
}
陈俊俊's avatar
陈俊俊 committed
77
- (void)choosePurchase{
陈俊俊's avatar
陈俊俊 committed
78
    [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_ChoseTransportPurchase object:nil];
陈俊俊's avatar
陈俊俊 committed
79
}
陈俊俊's avatar
陈俊俊 committed
80 81 82 83
- (void)editClick:(UIButton *)btn{
    PurchaseBillProduct *billProduct = self.productArr[btn.tag];
    [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_AddPurchaseProduct object:nil userInfo:@{@"purchaseBillProduct":billProduct,@"indexTag":@(btn.tag)}];
}
n22's avatar
n22 committed
84 85 86 87 88 89 90 91
#pragma mark - 协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.productArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
陈俊俊's avatar
陈俊俊 committed
92 93
    static NSString *cellID = @"ProductBillCell";
    ProductBillCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
n22's avatar
n22 committed
94
    if (cell == nil) {
陈俊俊's avatar
陈俊俊 committed
95
        cell = [[ProductBillCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
n22's avatar
n22 committed
96
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
陈俊俊's avatar
陈俊俊 committed
97 98 99
        if (self.isHiddenEdit) {
            cell.editBtn.hidden = YES;
        }
n22's avatar
n22 committed
100
    }
陈俊俊's avatar
陈俊俊 committed
101
    if ([self isHaveIndexPath:indexPath]) {
n22's avatar
n22 committed
102 103
        cell.smallImageView.image = [UIImage imageNamed:@"arrowdown"];
        CGRect Linefrmame = cell.lineLabel.frame;
陈俊俊's avatar
陈俊俊 committed
104
        Linefrmame.origin.y = ShowHeight + TableHeight -1;
n22's avatar
n22 committed
105 106
        cell.lineLabel.frame = Linefrmame;
        CGRect showfrmame = cell.showView.frame;
陈俊俊's avatar
陈俊俊 committed
107
        showfrmame.size.height = ShowHeight;
n22's avatar
n22 committed
108 109
        cell.showView.frame = showfrmame;
        cell.backgroundColor = XXFBgColor;
陈俊俊's avatar
陈俊俊 committed
110 111 112 113 114 115 116 117 118
    }else{
        cell.smallImageView.image = [UIImage imageNamed:@"arrowright"];
        CGRect Linefrmame = cell.lineLabel.frame;
        Linefrmame.origin.y = TableHeight-1;
        cell.lineLabel.frame = Linefrmame;
        CGRect showfrmame = cell.showView.frame;
        showfrmame.size.height = 0;
        cell.showView.frame = showfrmame;
        cell.backgroundColor = [UIColor whiteColor];
n22's avatar
n22 committed
119
    }
n22's avatar
n22 committed
120 121
    cell.editBtn.tag = indexPath.row;
    [cell.editBtn addTarget:self action:@selector(editClick:) forControlEvents:UIControlEventTouchUpInside];
陈俊俊's avatar
陈俊俊 committed
122 123 124 125 126 127 128
    
    if (self.productArr.count > 0) {
        PurchaseBillProduct *billP = self.productArr[indexPath.row];
        [cell setBillProduct:billP row:indexPath.row];
    }
    
    
n22's avatar
n22 committed
129 130
    return cell;
}
陈俊俊's avatar
陈俊俊 committed
131 132 133 134 135 136 137 138
- (BOOL)isHaveIndexPath:(NSIndexPath *)indexPath{
    for (NSIndexPath *path in _selectRowArr) {
        if (path.row == indexPath.row) {
            return YES;
        }
    }
    return NO;
}
n22's avatar
n22 committed
139 140
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
陈俊俊's avatar
陈俊俊 committed
141
    ProductBillCell *cell = (ProductBillCell *)[tableView cellForRowAtIndexPath:indexPath];
n22's avatar
n22 committed
142 143 144 145 146
    CGRect Linefrmame = cell.lineLabel.frame;
    CGRect showfrmame = cell.showView.frame;
    if (Linefrmame.origin.y == TableHeight - 1) {
        cell.smallImageView.image = [UIImage imageNamed:@"arrowdown"];

陈俊俊's avatar
陈俊俊 committed
147 148
        Linefrmame.origin.y = ShowHeight + TableHeight - 1;
        showfrmame.size.height = ShowHeight;
n22's avatar
n22 committed
149
        cell.backgroundColor = [UIColor whiteColor];
陈俊俊's avatar
陈俊俊 committed
150
        [_selectRowArr addObject:indexPath];
n22's avatar
n22 committed
151 152 153 154 155
    }else{
        cell.smallImageView.image = [UIImage imageNamed:@"arrowright"];
        Linefrmame.origin.y = TableHeight -1;
        showfrmame.size.height = 0;
        cell.backgroundColor = [UIColor whiteColor];
陈俊俊's avatar
陈俊俊 committed
156
        [_selectRowArr removeObject:indexPath];
n22's avatar
n22 committed
157 158 159 160 161 162
    }
    cell.lineLabel.frame = Linefrmame;
    cell.showView.frame = showfrmame;
    [self.tableView reloadData];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
陈俊俊's avatar
陈俊俊 committed
163
    if ([self isHaveIndexPath:indexPath]) {
陈俊俊's avatar
陈俊俊 committed
164
        return ShowHeight + TableHeight;
n22's avatar
n22 committed
165 166 167
    }
    return TableHeight;
}
n22's avatar
n22 committed
168

陈俊俊's avatar
陈俊俊 committed
169

n22's avatar
n22 committed
170 171 172



n22's avatar
n22 committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
- (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