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

#import "BottomTransportView.h"
陈俊俊's avatar
陈俊俊 committed
10 11
#import "TransportPdtDetail.h"
#import "FeeAcountDetail.h"
陈俊俊's avatar
陈俊俊 committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#define ContentHeight 44
#define BtnWidth 100
#define BeginTag 8000
#define SpaceWidth (ScreenSize.width - 100*2)/3

@interface BottomTransportView ()<UIScrollViewDelegate>
{
    UIScrollView *_bottomSV;
    UIImageView *_moveImageView;
    UIButton *_currentBtn;
    UIButton *_addBtn;
}
@end

@implementation BottomTransportView

陈俊俊's avatar
陈俊俊 committed
28
- (instancetype)initWithFrame:(CGRect)frame withHidden:(BOOL)isHidden{
陈俊俊's avatar
陈俊俊 committed
29 30
    self = [super initWithFrame:frame];
    if (self) {
陈俊俊's avatar
陈俊俊 committed
31
        self.isHiddenEdit = isHidden;
陈俊俊's avatar
陈俊俊 committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
        //界面
        [self bulidLayout];
    }
    return self;
}
#pragma mark - 布局
- (void)bulidLayout
{
    [self addChildView];
    
    [self createBottomView];
}
- (void)createBottomView{
    NSArray *arr = @[@"商品明细",@"费用明细"];
    
    _bottomSV = [[UIScrollView alloc]initWithFrame:CGRectMake(0,ContentHeight + 4, ScreenSize.width, CGRectGetHeight(self.frame) - ContentHeight-2)];
    _bottomSV.showsHorizontalScrollIndicator  = NO;
    _bottomSV.showsVerticalScrollIndicator = NO;
    _bottomSV.pagingEnabled = YES;
    _bottomSV.delegate = self;
    _bottomSV.contentSize = CGSizeMake(ScreenSize.width * arr.count, CGRectGetHeight(_bottomSV.frame));
    [self addSubview:_bottomSV];
    
    for (NSInteger i = 0; i < arr.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        [btn setTitle:arr[i] forState:UIControlStateNormal];
        btn.frame = CGRectMake(SpaceWidth + (BtnWidth+SpaceWidth) * i, 0, BtnWidth, ContentHeight);
        [btn setTitleColor:GXF_CONTENT_COLOR forState:UIControlStateNormal];
        [btn setTitleColor:GXF_SAVE_COLOR forState:UIControlStateDisabled];
        btn.titleLabel.font = GXF_SIXTEENTEH_SIZE;
        btn.tag = i + BeginTag;
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetWidth(_bottomSV.frame) * i, 0, CGRectGetWidth(_bottomSV.frame), CGRectGetHeight(_bottomSV.frame))];
        
        if (i == 0) {
            view.backgroundColor = [UIColor redColor];
            self.productVC.viewFrame = view.bounds;
陈俊俊's avatar
陈俊俊 committed
71
            self.productVC.isHiddenEdit = self.isHiddenEdit;
陈俊俊's avatar
陈俊俊 committed
72 73 74
            [view addSubview:self.productVC.view];
        }else if(i == 1){
            self.costVC.viewFrame = view.bounds;
陈俊俊's avatar
陈俊俊 committed
75
            self.costVC.isHiddenEdit = self.isHiddenEdit;
陈俊俊's avatar
陈俊俊 committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
            [view addSubview:self.costVC.view];
            view.backgroundColor = [UIColor blueColor];
        }
        [_bottomSV addSubview:view];
    }
    _moveImageView = [[UIImageView alloc]initWithFrame:CGRectMake(SpaceWidth, ContentHeight, BtnWidth,4)];
    _moveImageView.image  = [UIImage imageNamed:@"tab_line"];
    
     UILabel  *lineLabel = [[UILabel alloc]initWithFrame:(CGRectMake(0, ContentHeight +1, ScreenSize.width, 1))];
    lineLabel.backgroundColor = GXF_LINE_COLOR;
    lineLabel.font = GXF_FIFTEENTEN_SIZE;
    [self addSubview:lineLabel];
    [self addSubview:_moveImageView];
}

- (void)addChildView{
陈俊俊's avatar
陈俊俊 committed
92
    self.productVC = [[TransportProductViewController alloc]init];
陈俊俊's avatar
陈俊俊 committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    self.productVC.twoTitle = @"+选择采购单";
    self.costVC = [[CostViewController alloc]init];
}
- (void)btnClick:(UIButton *)btn{
    NSInteger index = btn.tag - BeginTag;
    _currentBtn.enabled = YES;
    btn.enabled = NO;
    _currentBtn = btn;
    [UIView animateWithDuration:0.5 animations:^{
        CGRect moveFrame = _moveImageView.frame;
        moveFrame.origin.x = SpaceWidth + (BtnWidth+SpaceWidth) * index;
        _moveImageView.frame = moveFrame;
        _bottomSV.contentOffset=CGPointMake(index * self.frame.size.width, 0);
    }];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    CGFloat offsetX = scrollView.contentOffset.x / self.frame.size.width;
    [UIView animateWithDuration:0.5 animations:^{
        CGRect moveFrame = _moveImageView.frame;
        moveFrame.origin.x = SpaceWidth + (BtnWidth+SpaceWidth) * offsetX;
        _moveImageView.frame = moveFrame;
    }];
    _currentBtn.enabled = YES;
    UIButton *btn = (UIButton *) [self viewWithTag:offsetX + BeginTag];
    btn.enabled = NO;
    _currentBtn = btn;
}
陈俊俊's avatar
陈俊俊 committed
121 122 123 124 125
//添加商品
- (void)refreshProduct:(TransportPdtDetail *)transportPdtDetail
{
    if (self.productVC.transportProductArr) {
        [self.productVC.transportProductArr addObject:transportPdtDetail];
陈俊俊's avatar
陈俊俊 committed
126 127 128
        [self.productVC.tableView reloadData];
    }
}
陈俊俊's avatar
陈俊俊 committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
//添加编辑
- (void)refreshCost:(FeeAcountDetail *)fee indexPath:(NSIndexPath *)indexPath{
    if (indexPath) {
        [self.costVC.costArr replaceObjectAtIndex:indexPath.row withObject:fee];
//        NSArray *indexArray=[NSArray arrayWithObject:indexPath];
//        [self.costVC.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.costVC.tableView reloadData];
    }else{
        if (self.costVC.costArr) {
            [self.costVC.costArr addObject:fee];
            [self.costVC.tableView reloadData];
        }
    }
}
//删除
- (void)refreshDelCost:(FeeAcountDetail *)fee indexPath:(NSIndexPath *)indexPath{
    if (indexPath) {
        [self.costVC.costArr removeObjectAtIndex:indexPath.row];
        [self.costVC.tableView reloadData];
    }
}
//刷新
陈俊俊's avatar
陈俊俊 committed
151
- (void)refreshCost:(NSArray *)costArr{
陈俊俊's avatar
陈俊俊 committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
    NSMutableArray *feeArr = [NSMutableArray array];
    for (NSDictionary *billDict in costArr) {
        FeeAcountDetail *billProbuct = [FeeAcountDetail new];
        [billProbuct setValuesForKeysWithDictionary:billDict];
        [feeArr addObject:billProbuct];
    }
    self.costVC.costArr = feeArr;
    [self.costVC.tableView reloadData];
}
- (void)refreshTranProduct:(NSArray *)tranProductArr{
    NSMutableArray *productArr = [NSMutableArray array];
    for (NSDictionary *billDict in tranProductArr) {
        TransportPdtDetail *billProbuct = [TransportPdtDetail new];
        [billProbuct setValuesForKeysWithDictionary:billDict];
        [productArr addObject:billProbuct];
    }
    self.productVC.transportProductArr = productArr;
    [self.productVC.tableView reloadData];
}
- (void)reProduct:(NSArray *)tranProductArr{
    [self.productVC.transportProductArr addObjectsFromArray:tranProductArr];
    [self.productVC.tableView reloadData];
陈俊俊's avatar
陈俊俊 committed
174
}
陈俊俊's avatar
陈俊俊 committed
175 176 177 178 179 180 181 182 183 184
- (void)refreshDelProduct:(TransportPdtDetail *)fee tag:(NSInteger)indexTag{
    if (fee) {
        [self.productVC.transportProductArr removeObjectAtIndex:indexTag];
        [self.productVC.tableView reloadData];
    }
}
- (void)refreshEditProduct:(TransportPdtDetail *)transportPdtDetail tag:(NSInteger)indexTag{
    [self.productVC.transportProductArr replaceObjectAtIndex:indexTag withObject:transportPdtDetail];
    [self.productVC.tableView reloadData];
}
陈俊俊's avatar
陈俊俊 committed
185 186

@end