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

#import "ProductViewController.h"
#import "FooterCell.h"
#import "HeaderCell.h"
#import "ProductCell.h"
n22's avatar
n22 committed
13
#import "AddProductViewController.h"
n22's avatar
n22 committed
14
#import "PurchaseBillProduct.h"
n22's avatar
n22 committed
15 16
#define TableHeight 44

n22's avatar
n22 committed
17
@interface ProductViewController ()<UITableViewDataSource,UITableViewDelegate,FooterCellDelegate,AddProductViewDelegate>
n22's avatar
n22 committed
18 19
{
    CGRect _tableFrame;
陈俊俊's avatar
陈俊俊 committed
20
    NSMutableArray *_selectRowArr;//记录当前选中的cell
n22's avatar
n22 committed
21
    AddProductViewController *_avc;
n22's avatar
n22 committed
22 23 24 25 26 27 28 29 30
}
@end

@implementation ProductViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor  = XXFBgColor;
    [super viewDidLoad];
陈俊俊's avatar
陈俊俊 committed
31 32 33 34 35
    [self initData];
    [self createView];
}
- (void)initData{
    _selectRowArr = [[NSMutableArray alloc]init];
陈俊俊's avatar
陈俊俊 committed
36 37 38
    if (!self.productArr) {
        self.productArr = [NSMutableArray array];
    }
n22's avatar
n22 committed
39 40 41 42 43 44
    PurchaseBillProduct *billProduct = [PurchaseBillProduct new];
    billProduct.total = [NSNumber numberWithFloat:25];
    
    
    [self.productArr addObject:billProduct];
    [self.productArr addObject:billProduct];
n22's avatar
n22 committed
45
}
陈俊俊's avatar
陈俊俊 committed
46

n22's avatar
n22 committed
47 48 49 50 51 52 53 54 55 56
- (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
57
    NSArray *arr = @[@"商品",@"单价",@"包装数量"];
n22's avatar
n22 committed
58 59 60 61 62
    
    HeaderCell *headCell = [[HeaderCell alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, 38) withArr:arr];
    [self.view addSubview:headCell];
    self.tableView.tableHeaderView = headCell;
    
陈俊俊's avatar
陈俊俊 committed
63 64 65 66 67 68
    if (!self.isHiddenEdit) {
        FooterCell *footCell = [[FooterCell alloc]initWithFrame:CGRectMake(0, 0, _tableFrame.size.width, 50) withTitle:@"+点击添加商品明细"];
        [self.view addSubview:footCell];
        footCell.delegate = self;
        self.tableView.tableFooterView = footCell;
    }
n22's avatar
n22 committed
69
}
n22's avatar
n22 committed
70
#pragma mark - footerDelegate
n22's avatar
n22 committed
71
- (void)addClick{
n22's avatar
n22 committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
//    [self.productArr addObject:@"dddd"];
//    [self.tableView reloadData];
    if (_avc == nil) {
        _avc = [[AddProductViewController alloc]init];
        _avc.delegate = self;
        _avc.view.backgroundColor = RGBA(0, 0, 0, 0.5);
        
        [AppWindow addSubview:_avc.view];
    }
}

#pragma mark - addProductViewDelegate
- (void)dissmiss{
    if (_avc) {
        [_avc.view removeFromSuperview];
        _avc = nil;
    }
}

- (void)pushViewController:(id)cvc{
    if (_avc) {
        [_avc.view removeFromSuperview];
    }
    if ([self.delegate respondsToSelector:@selector(pushViewController:selfController:)]) {
        [self.delegate pushViewController:cvc selfController:_avc];
    }
n22's avatar
n22 committed
98 99 100 101 102 103 104 105 106 107
}

#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
108
    static NSString *cellID = @"ProductCell";
n22's avatar
n22 committed
109 110 111 112
    ProductCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ProductCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
陈俊俊's avatar
陈俊俊 committed
113 114 115
        if (self.isHiddenEdit) {
            cell.editBtn.hidden = YES;
        }
n22's avatar
n22 committed
116
    }
陈俊俊's avatar
陈俊俊 committed
117
    if ([self isHaveIndexPath:indexPath]) {
n22's avatar
n22 committed
118 119 120 121 122 123 124 125
        cell.smallImageView.image = [UIImage imageNamed:@"arrowdown"];
        CGRect Linefrmame = cell.lineLabel.frame;
        Linefrmame.origin.y = 200-1;
        cell.lineLabel.frame = Linefrmame;
        CGRect showfrmame = cell.showView.frame;
        showfrmame.size.height = 150;
        cell.showView.frame = showfrmame;
        cell.backgroundColor = XXFBgColor;
陈俊俊's avatar
陈俊俊 committed
126 127 128 129 130 131 132 133 134
    }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
135
    }
n22's avatar
n22 committed
136 137
    cell.editBtn.tag = indexPath.row;
    [cell.editBtn addTarget:self action:@selector(editClick:) forControlEvents:UIControlEventTouchUpInside];
n22's avatar
n22 committed
138 139
    return cell;
}
陈俊俊's avatar
陈俊俊 committed
140 141 142 143 144 145 146 147
- (BOOL)isHaveIndexPath:(NSIndexPath *)indexPath{
    for (NSIndexPath *path in _selectRowArr) {
        if (path.row == indexPath.row) {
            return YES;
        }
    }
    return NO;
}
n22's avatar
n22 committed
148 149 150 151 152 153 154 155 156 157 158
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ProductCell *cell = (ProductCell *)[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 = 200-1;
        showfrmame.size.height = 150;
        cell.backgroundColor = [UIColor whiteColor];
陈俊俊's avatar
陈俊俊 committed
159
        [_selectRowArr addObject:indexPath];
n22's avatar
n22 committed
160 161 162 163 164
    }else{
        cell.smallImageView.image = [UIImage imageNamed:@"arrowright"];
        Linefrmame.origin.y = TableHeight -1;
        showfrmame.size.height = 0;
        cell.backgroundColor = [UIColor whiteColor];
陈俊俊's avatar
陈俊俊 committed
165
        [_selectRowArr removeObject:indexPath];
n22's avatar
n22 committed
166 167 168 169 170 171
    }
    cell.lineLabel.frame = Linefrmame;
    cell.showView.frame = showfrmame;
    [self.tableView reloadData];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
陈俊俊's avatar
陈俊俊 committed
172
    if ([self isHaveIndexPath:indexPath]) {
n22's avatar
n22 committed
173 174 175 176
        return 200;
    }
    return TableHeight;
}
n22's avatar
n22 committed
177 178 179 180 181 182 183 184

- (void)editClick:(UIButton *)btn{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"哈哈" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
}



n22's avatar
n22 committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
- (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