TransportPurchaseCell.m 6.75 KB
Newer Older
陈俊俊's avatar
陈俊俊 committed
1 2 3 4 5 6 7 8 9
//
//  TransportPurchaseCell.m
//  XFFruit
//
//  Created by 陈俊俊 on 15/9/6.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "TransportPurchaseCell.h"
陈俊俊's avatar
陈俊俊 committed
10
#import "TransportPurductCell.h"
陈俊俊's avatar
陈俊俊 committed
11
#import "HeaderCell.h"
12 13 14 15
#define TableHeight 44
#define ShowHeight  110


陈俊俊's avatar
陈俊俊 committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29
@implementation TransportPurchaseCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self bulidLayout];
    }
    return self;
}

- (void)bulidLayout
{
陈俊俊's avatar
陈俊俊 committed
30 31
    self.contentView.backgroundColor = XXFBgColor;
    
陈俊俊's avatar
陈俊俊 committed
32 33 34
    self.bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, 170)];
    self.bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.bgView];
陈俊俊's avatar
陈俊俊 committed
35
    
陈俊俊's avatar
陈俊俊 committed
36 37 38 39
    self.lineLabel = [[UILabel alloc]initWithFrame:(CGRectMake(0,0, ScreenSize.width, 1))];;
    self.lineLabel.backgroundColor = GXF_LINE_COLOR;

    self.titleLabel = [[UILabel alloc]initWithFrame:(CGRectMake(0, 0, ScreenSize.width, 44))];
陈俊俊's avatar
陈俊俊 committed
40
    self.titleLabel.textColor = GXF_NAVIGAYION_COLOR;
陈俊俊's avatar
陈俊俊 committed
41
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
陈俊俊's avatar
陈俊俊 committed
42
    self.titleLabel.font = GXF_SEVENTEENTH_SIZE;
陈俊俊's avatar
陈俊俊 committed
43 44 45
    
    self.secondLabel = [[UILabel alloc]initWithFrame:(CGRectMake(0,44-1, ScreenSize.width, 1))];;
    self.secondLabel.backgroundColor = GXF_LINE_COLOR;
陈俊俊's avatar
陈俊俊 committed
46

陈俊俊's avatar
陈俊俊 committed
47
    
陈俊俊's avatar
陈俊俊 committed
48 49 50
    [self.bgView addSubview:self.titleLabel];
    [self.bgView addSubview:self.lineLabel];
    [self.bgView addSubview:self.secondLabel];
陈俊俊's avatar
陈俊俊 committed
51

陈俊俊's avatar
陈俊俊 committed
52 53 54 55 56 57 58 59 60 61 62 63
    self.secondTable = [[UITableView alloc]initWithFrame:(CGRectMake(0, 44,ScreenSize.width, self.bgView.height-45)) style:(UITableViewStylePlain)];
    
    self.secondTable.delegate = self;
    self.secondTable.dataSource = self;
        self.secondTable.bounces = NO;
    self.secondTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.bgView addSubview:self.secondTable];
    NSArray *arr = @[@"商品",@"单价",@"包装数量"];
    
    HeaderCell *headCell = [[HeaderCell alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, 38) withArr:arr withHiddenEdit:YES];
    self.secondTable.tableHeaderView = headCell;
    
陈俊俊's avatar
陈俊俊 committed
64 65

}
66
- (void)setPurchaseBill:(PurchaseBill *)bill selectArr:(NSMutableArray *)selectArr{
陈俊俊's avatar
陈俊俊 committed
67 68
    self.bgView.height = 92 + bill.products.count * 44;
    self.secondTable.height = self.bgView.height - 45;
69
    self.titleLabel.text = [NSString stringWithFormat:@"采购单:%@",bill.billNumber];
陈俊俊's avatar
陈俊俊 committed
70
    self.secondArr = [NSMutableArray array];
71
    self.selectArr = selectArr;
陈俊俊's avatar
陈俊俊 committed
72 73 74 75 76
    [self.secondArr addObjectsFromArray:bill.products];
    
    //重要
    [self.secondTable reloadData];
}
陈俊俊's avatar
陈俊俊 committed
77 78 79 80 81 82 83 84

- (void)setTransPort:(Transport *)bill selectArr:(NSMutableArray *)selectArr{
    self.bgView.height = 92 + bill.pdtDetails.count * 44;
    self.secondTable.height = self.bgView.height - 45;
    self.titleLabel.text = [NSString stringWithFormat:@"发运单号:%@",bill.billnumber];
    self.secondArr = [NSMutableArray array];
    self.selectArr = selectArr;
    [self.secondArr addObjectsFromArray:bill.pdtDetails];
陈俊俊's avatar
陈俊俊 committed
85 86
    //重要
    [self.secondTable reloadData];
陈俊俊's avatar
陈俊俊 committed
87 88
}

陈俊俊's avatar
陈俊俊 committed
89 90 91 92 93 94 95 96 97 98 99
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.secondArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
陈俊俊's avatar
陈俊俊 committed
100 101
    static NSString *cellID = @"TransportPurductCell";
    TransportPurductCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
陈俊俊's avatar
陈俊俊 committed
102
    if (cell == nil) {
陈俊俊's avatar
陈俊俊 committed
103
        cell = [[TransportPurductCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID withImageName:@"selected"];
陈俊俊's avatar
陈俊俊 committed
104
        cell.editBtn.hidden = YES;
陈俊俊's avatar
陈俊俊 committed
105
        cell.rightImageName = @"edit";
陈俊俊's avatar
陈俊俊 committed
106
    }
陈俊俊's avatar
陈俊俊 committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
    if (self.secondArr.count > 0) {
        TransportPdtDetail * billProduct = self.secondArr[indexPath.row];
        [cell setPdtDetail:billProduct row:indexPath.row];
        
        if ([self isHaveIndexPath:billProduct]) {
            cell.editBtn.hidden = NO;
            //        cell.smallImageView.image = [UIImage imageNamed:@"arrowdown"];
            //        cell.lineLabel.y = ShowHeight + TableHeight -1;
            //        cell.showView.height = ShowHeight;
            //        cell.backgroundColor = XXFBgColor;
        }else{
            cell.editBtn.hidden = YES;
            //        cell.smallImageView.image = [UIImage imageNamed:@"arrowright"];
            //        cell.lineLabel.y =  TableHeight -1;
            //        cell.showView.height = 0;
            //        cell.backgroundColor = [UIColor whiteColor];
        }
124
    }
陈俊俊's avatar
陈俊俊 committed
125 126 127 128
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}
129
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
陈俊俊's avatar
陈俊俊 committed
130 131 132 133
//    TransportPdtDetail * billProduct = self.secondArr[indexPath.row];
//    if ([self isHaveIndexPath:billProduct]) {
//        return ShowHeight + TableHeight;
//    }
134 135 136 137
    return TableHeight;
}


陈俊俊's avatar
陈俊俊 committed
138
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
陈俊俊's avatar
陈俊俊 committed
139 140 141 142
    TransportPurductCell *cell = (TransportPurductCell *)[tableView cellForRowAtIndexPath:indexPath];
    TransportPdtDetail * billProduct = self.secondArr[indexPath.row];
    if (![self isHaveIndexPath:billProduct]) {
        cell.editBtn.hidden = NO;
143
//        cell.smallImageView.image = [UIImage imageNamed:@"arrowdown"];
陈俊俊's avatar
陈俊俊 committed
144 145
//        cell.lineLabel.y = ShowHeight + TableHeight -1;
//        cell.showView.height = ShowHeight;
146
//        cell.backgroundColor = [UIColor whiteColor];
陈俊俊's avatar
陈俊俊 committed
147
        
陈俊俊's avatar
陈俊俊 committed
148
        [self.selectArr addObject:billProduct];
149
//        [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_getSelectPurchaseProduct object:nil userInfo:@{@"selectArr":billProduct,@"state":@"add"}];
陈俊俊's avatar
陈俊俊 committed
150 151 152
    }else{
        [self.selectArr removeObject:billProduct];
        cell.editBtn.hidden = YES;
153
//        cell.smallImageView.image = [UIImage imageNamed:@"arrowright"];
陈俊俊's avatar
陈俊俊 committed
154 155
//        cell.lineLabel.y =  TableHeight -1;
//        cell.showView.height = 0;
156 157
//        cell.backgroundColor = [UIColor whiteColor];
//        [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_getSelectPurchaseProduct object:nil userInfo:@{@"selectArr":billProduct,@"state":@"remove"}];
陈俊俊's avatar
陈俊俊 committed
158 159
    }
    [self.secondTable reloadData];
陈俊俊's avatar
陈俊俊 committed
160
}
陈俊俊's avatar
陈俊俊 committed
161 162
- (BOOL)isHaveIndexPath:(TransportPdtDetail *)billProduct{
    for (TransportPdtDetail *detail in self.selectArr) {
陈俊俊's avatar
陈俊俊 committed
163
        if (detail.uuid == billProduct.uuid || [detail.uuid isEqualToString:billProduct.uuid]) {
陈俊俊's avatar
陈俊俊 committed
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
            return YES;
        }
    }
    return NO;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end