TransportPurchaseCell.m 4.95 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 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#import "HeaderCell.h"
@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
26 27 28 29 30 31
    self.contentView.backgroundColor = XXFBgColor;
    
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, 200)];
    bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:bgView];
    
陈俊俊's avatar
陈俊俊 committed
32 33 34 35 36 37
    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))];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.text = @"苹果桃子";
陈俊俊's avatar
陈俊俊 committed
38
    self.titleLabel.font = GXF_SEVENTEENTH_SIZE;
陈俊俊's avatar
陈俊俊 committed
39 40 41 42
    
    self.secondLabel = [[UILabel alloc]initWithFrame:(CGRectMake(0,44-1, ScreenSize.width, 1))];;
    self.secondLabel.backgroundColor = GXF_LINE_COLOR;
    
陈俊俊's avatar
陈俊俊 committed
43 44 45 46 47 48 49 50
    self.threeLabel = [[UILabel alloc]initWithFrame:(CGRectMake(0,200-1, ScreenSize.width, 1))];;
    self.threeLabel.backgroundColor = GXF_LINE_COLOR;
    
    [bgView addSubview:self.titleLabel];
    [bgView addSubview:self.lineLabel];
    [bgView addSubview:self.secondLabel];
    [bgView addSubview:self.threeLabel];

陈俊俊's avatar
陈俊俊 committed
51 52 53 54 55 56 57 58 59 60 61 62 63

}
- (void)setBill:(PurchaseBill *)bill{
    self.titleLabel.text = [NSString stringWithFormat:@"[采购单:%@]",bill.billNumber];
    self.secondArr = [NSMutableArray array];
    self.selectArr = [NSMutableArray array];
    [self.secondArr addObjectsFromArray:bill.products];
//    for (NSDictionary *billDict in bill.products) {
//        PurchaseBillProduct *billProcuct = [PurchaseBillProduct new];
//        [billProcuct setValuesForKeysWithDictionary:billDict];
//        [self.secondArr addObject:billProcuct];
//    }

陈俊俊's avatar
陈俊俊 committed
64
    self.secondTable = [[UITableView alloc]initWithFrame:(CGRectMake(0, 44,ScreenSize.width, 200-45)) style:(UITableViewStylePlain)];
陈俊俊's avatar
陈俊俊 committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

    self.secondTable.delegate = self;
    self.secondTable.dataSource = self;
    self.secondTable.bounces = NO;
    self.secondTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.contentView addSubview:self.secondTable];
    NSArray *arr = @[@"商品",@"单价",@"包装数量"];
    
    HeaderCell *headCell = [[HeaderCell alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, 38) withArr:arr];
    self.secondTable.tableHeaderView = headCell;
    //重要
    [self.secondTable reloadData];

}

-(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
91 92
    static NSString *cellID = @"TransportPurductCell";
    TransportPurductCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
陈俊俊's avatar
陈俊俊 committed
93
    if (cell == nil) {
陈俊俊's avatar
陈俊俊 committed
94
        cell = [[TransportPurductCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID withImageName:@"selected"];
陈俊俊's avatar
陈俊俊 committed
95
        cell.editBtn.hidden = YES;
陈俊俊's avatar
陈俊俊 committed
96
        cell.rightImageName = @"edit";
陈俊俊's avatar
陈俊俊 committed
97
    }
陈俊俊's avatar
陈俊俊 committed
98 99
    TransportPdtDetail * billProduct = self.secondArr[indexPath.row];
    [cell setPdtDetail:billProduct row:indexPath.row];
陈俊俊's avatar
陈俊俊 committed
100 101 102 103 104
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
陈俊俊's avatar
陈俊俊 committed
105 106
      TransportPurductCell *cell = (TransportPurductCell *)[tableView cellForRowAtIndexPath:indexPath];
      TransportPdtDetail * billProduct = self.secondArr[indexPath.row];
陈俊俊's avatar
陈俊俊 committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
        if (![self isHaveIndexPath:indexPath]) {
            cell.editBtn.hidden = NO;
            [self.selectArr addObject:indexPath];
            [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_getSelectPurchaseProduct object:nil userInfo:@{@"selectArr":billProduct,@"state":@"add"}];
        }else{
            [self.selectArr removeObject:indexPath];
            cell.editBtn.hidden = YES;
            [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_getSelectPurchaseProduct object:nil userInfo:@{@"selectArr":billProduct,@"state":@"remove"}];
        }
    
    ;
}
- (BOOL)isHaveIndexPath:(NSIndexPath *)indexPath{
    for (NSIndexPath *path in self.selectArr) {
        if (path.row == indexPath.row) {
            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