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

#import "PurchaseDetailViewController.h"
陈俊俊's avatar
陈俊俊 committed
10 11
#import "ProductBillViewController.h"
#import "PurchaseBillProduct.h"
陈俊俊's avatar
陈俊俊 committed
12
#define BottomHeight 50
n22's avatar
n22 committed
13
#define LeftMargin 15
陈俊俊's avatar
陈俊俊 committed
14 15 16
#define LeftWidth 100
#define LeftHeight 30
#define TopMargin 15
n22's avatar
n22 committed
17 18 19

typedef enum : NSUInteger {
    CancleTag = 3500,
陈俊俊's avatar
陈俊俊 committed
20
    EndTag,
n22's avatar
n22 committed
21 22 23 24 25 26
    RejectTag,
    PassTag,
    SureTag
    
} BtnTag;

陈俊俊's avatar
陈俊俊 committed
27 28 29 30 31
@interface PurchaseDetailViewController ()
{
    UIScrollView *_scrollView;
    UIView *_purchaseView;
    UIView *_bottomView;
陈俊俊's avatar
陈俊俊 committed
32
    ProductBillViewController *_pvc;
n22's avatar
n22 committed
33 34 35
    NSArray *_leftArr;
    UIButton *_endBtn;
    UIButton *_rejectBtn;
陈俊俊's avatar
陈俊俊 committed
36 37 38 39 40 41
}
@property (nonatomic,strong)UILabel *billNumberLabel;
@property (nonatomic,strong)UILabel *noticeNumberLabel;
@property (nonatomic,strong)UILabel *createOperNameLabel;
@property (nonatomic,strong)UILabel *checkNameLabel;
@property (nonatomic,strong)UILabel *stateLabel;
n22's avatar
n22 committed
42 43 44
@property (nonatomic,strong)UILabel *lastModifyNameLabel;

@property (nonatomic,strong)UILabel *typeLabel;
陈俊俊's avatar
陈俊俊 committed
45
@property (nonatomic,strong)UILabel *vendorNameLabel;
n22's avatar
n22 committed
46 47 48 49 50 51
@property (nonatomic,strong)UILabel *vendorIsSureLabel;
@property (nonatomic,strong)UILabel *warehouseLabel;
@property (nonatomic,strong)UILabel *otherPriceLabel;



陈俊俊's avatar
陈俊俊 committed
52 53
@property (nonatomic,strong)UILabel *totalPriceLabel;
@property (nonatomic,strong)UILabel *noteLabel;
n22's avatar
n22 committed
54

陈俊俊's avatar
陈俊俊 committed
55 56 57 58 59 60 61
@end

@implementation PurchaseDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self bulidLayout];
陈俊俊's avatar
陈俊俊 committed
62 63 64 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 getDataFromServer];
}
- (void)getDataFromServer{
    __weak typeof(self)weakSelf = self;
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        if (data) {
            NSInteger success = [data[@"success"] integerValue];
            NSString *message  = data[@"message"] ;
            if (success == 1) {
                NSDictionary *dictData = data[@"data"];
                PurchaseBill *bill = [[PurchaseBill alloc]init];
                [bill setValuesForKeysWithDictionary:dictData];
                self.bill = bill;
                [strongSelf fetchtPurchaseDetail];
            }else{
                [IBTLoadingView showTips:message];
            }
        }else{
            [IBTLoadingView showTips:@"     无记录     "];
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
    [[ICRHTTPController sharedController] getPurchaseResultWithPurchaseUuid:@"5a7417014f926eb5014f93b18fbc000f" success:succ failure:fail];
陈俊俊's avatar
陈俊俊 committed
91 92 93 94 95 96 97 98
}


#pragma mark - 视图初始化
- (void)bulidLayout{
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, ScreenSize.height - 64 - BottomHeight)];
    _scrollView.showsHorizontalScrollIndicator  = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
陈俊俊's avatar
陈俊俊 committed
99
    _scrollView.backgroundColor = XXFBgColor;
陈俊俊's avatar
陈俊俊 committed
100
    [self.view addSubview:_scrollView];
n22's avatar
n22 committed
101 102 103 104 105 106 107 108 109 110 111 112 113
    [self createBtn];
    [self createPurchaseView];
    [self createBottomView];
    if ([self.bill.state isEqualToString:@"finished"]) {
        _endBtn.hidden = YES;
        _rejectBtn.hidden = YES;
        CGRect scrollViewFrame = _scrollView.frame;
        scrollViewFrame.size.height = ScreenSize.height - 64;
        _scrollView.frame = scrollViewFrame;
    }
}

- (void)createBtn{
陈俊俊's avatar
陈俊俊 committed
114 115
    _rejectBtn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(LeftMargin, ScreenSize.height  - 64 - BottomHeight +5, (ScreenSize.width - LeftMargin*3)/2, 40) target:self sel:@selector(btnClick:) tag:RejectTag image:nil title:@"" titleColor: [UIColor whiteColor] isCorner:YES corner:5 bgColor:GXF_SAVE_COLOR];
    [self.view addSubview:_rejectBtn];
陈俊俊's avatar
陈俊俊 committed
116
    
陈俊俊's avatar
陈俊俊 committed
117
    _endBtn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(CGRectGetMaxX(_rejectBtn.frame)+ LeftMargin, ScreenSize.height  - 64 - BottomHeight +5, (ScreenSize.width - LeftMargin*3)/2, 40) target:self sel:@selector(btnClick:) tag:0 image:nil title:@"" titleColor:[UIColor whiteColor] isCorner:YES corner:5 bgColor:GXF_COMMIT_COLOR];
n22's avatar
n22 committed
118 119
    [self.view addSubview:_endBtn];
    if (self.indexPerson == 0) {
陈俊俊's avatar
陈俊俊 committed
120 121 122 123 124 125 126
        _rejectBtn.hidden = NO;
        
        _rejectBtn.tag = CancleTag;
        [_rejectBtn setTitle:@"作废" forState:UIControlStateNormal];
        
        _endBtn.tag = EndTag;
        [_endBtn setTitle:@"结束" forState:UIControlStateNormal];
n22's avatar
n22 committed
127
    }else if(self.indexPerson == 1){
陈俊俊's avatar
陈俊俊 committed
128 129 130 131
        _rejectBtn.hidden = NO;
        
        _rejectBtn.tag = RejectTag;
        [_rejectBtn setTitle:@"拒绝" forState:UIControlStateNormal];
n22's avatar
n22 committed
132 133 134 135
        
        [_endBtn setTitle:@"审核通过" forState:UIControlStateNormal];
        _endBtn.tag = PassTag;
    }else{
陈俊俊's avatar
陈俊俊 committed
136 137
        _rejectBtn.hidden = YES;
        _endBtn.frame = CGRectMake(LeftMargin, ScreenSize.height  - 64 - BottomHeight +5, ScreenSize.width - LeftMargin * 2, 40);
n22's avatar
n22 committed
138 139 140
        _endBtn.tag = SureTag;
        [_endBtn setTitle:@"确认" forState:UIControlStateNormal];
    }
陈俊俊's avatar
陈俊俊 committed
141
}
n22's avatar
n22 committed
142

陈俊俊's avatar
陈俊俊 committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
- (void)btnClick:(UIButton *)btn{
    NSLog(@"%ld",(long)btn.tag);
    switch (btn.tag) {
        case CancleTag:
        {
            NSLog(@"作废");
        }
            break;
        case EndTag:
        {
            NSLog(@"结束");
        }
            break;
        case RejectTag:
        {
            NSLog(@"拒绝");
        }
            break;
        case PassTag:
        {
            NSLog(@"审核通过");
        }
            break;
        case SureTag:
        {
            NSLog(@"确定");
        }
            break;
        default:
            break;
    }
n22's avatar
n22 committed
174 175 176 177 178 179
}

- (void)createBottomView{
    _bottomView= [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_purchaseView.frame) + TopMargin, ScreenSize.width, 200)];
    _bottomView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_bottomView];
陈俊俊's avatar
陈俊俊 committed
180
    
陈俊俊's avatar
陈俊俊 committed
181
    _pvc = [[ProductBillViewController alloc]init];
n22's avatar
n22 committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    [self addChildViewController:_pvc];
    
    _pvc.viewFrame = _bottomView.bounds;
    _pvc.isHiddenEdit = YES;
    [_bottomView addSubview:_pvc.view];
}

- (void)createPurchaseView{
    if (self.indexPerson == 0) {
        _leftArr = @[@"单号:",@"采购通知单:",@"创建人:",@"最后修改人:",@"状态:",@"类型:",@"供应商:",@"供应商确认:",@"收货仓库:",@"其他费用:",@"总金额:",@"备注:"];
    }else if (self.indexPerson == 1) {
        _leftArr = @[@"单号:",@"采购通知单:",@"创建人:",@"审核人:",@"状态:",@"类型:",@"供应商:",@"供应商确认:",@"收货仓库:",@"其他费用:",@"总金额:",@"备注:"];
    }else{
        _leftArr = @[@"单号:",@"采购通知单:",@"创建人:",@"审核人:",@"状态:",@"供应商:",@"其他费用:",@"总金额:",@"备注:"];
    }
    _purchaseView= [[UIView alloc]initWithFrame:CGRectMake(0, TopMargin, ScreenSize.width, LeftHeight*_leftArr.count +LeftMargin)];
陈俊俊's avatar
陈俊俊 committed
198 199 200
    _purchaseView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_purchaseView];
    
n22's avatar
n22 committed
201
    for (NSInteger i = 0 ; i < _leftArr.count; i++) {
陈俊俊's avatar
陈俊俊 committed
202
        UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(LeftMargin, 10 + LeftHeight *i, LeftWidth, LeftHeight)];
陈俊俊's avatar
陈俊俊 committed
203
        leftLabel.font = GXF_SEVENTEENTH_SIZE;
n22's avatar
n22 committed
204
        leftLabel.text = _leftArr[i];
陈俊俊's avatar
陈俊俊 committed
205
        leftLabel.textColor = GXF_DETAIL_COLOR;
陈俊俊's avatar
陈俊俊 committed
206 207 208
        [_purchaseView addSubview:leftLabel];
        
        UILabel *rightLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(leftLabel.frame), 10 + LeftHeight *i, _purchaseView.frame.size.width - LeftMargin - LeftWidth, LeftHeight)];
陈俊俊's avatar
陈俊俊 committed
209 210
        rightLabel.font = GXF_SEVENTEENTH_SIZE;
        rightLabel.textColor = GXF_DETAIL_COLOR;
n22's avatar
n22 committed
211
        
陈俊俊's avatar
陈俊俊 committed
212 213 214 215 216 217
        if (i == 0) {
            self.billNumberLabel = rightLabel;
        }else if (i == 1) {
            self.noticeNumberLabel = rightLabel;
        }else if(i == 2){
            self.createOperNameLabel = rightLabel;
n22's avatar
n22 committed
218 219 220
        }else if(i == _leftArr.count - 3){
            self.otherPriceLabel = rightLabel;
        }else if(i == _leftArr.count - 2){
陈俊俊's avatar
陈俊俊 committed
221
            self.totalPriceLabel = rightLabel;
n22's avatar
n22 committed
222
        }else if(i == _leftArr.count - 1){
陈俊俊's avatar
陈俊俊 committed
223 224 225
            rightLabel.numberOfLines = 0;
            self.noteLabel = rightLabel;
        }
n22's avatar
n22 committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
        if (self.indexPerson == 0 || self.indexPerson == 1) {
            if (self.indexPerson == 0) {
                if (i == 3) {
                    self.lastModifyNameLabel = rightLabel;
                }
            }else{
                if (i == 3) {
                    self.checkNameLabel = rightLabel;
                }
            }
            if(i == 4){
                self.stateLabel = rightLabel;
            }else if(i == 5){
                self.typeLabel = rightLabel;
            }else if(i == 6){
                self.vendorNameLabel = rightLabel;
            }else if(i == 7){
                self.vendorIsSureLabel = rightLabel;
            }else if(i == 8){
                self.warehouseLabel = rightLabel;
            }
        }else{
            if(i == 3){
                self.checkNameLabel = rightLabel;
            }else if(i == 4){
                self.stateLabel = rightLabel;
            }else if(i == 5){
                self.vendorNameLabel = rightLabel;
            }
        }
陈俊俊's avatar
陈俊俊 committed
256 257 258 259 260 261
        [_purchaseView addSubview:rightLabel];
    }
}

- (void)fetchtPurchaseDetail{
    self.billNumberLabel.text = [IBTCommon checkString:self.bill.billNumber];
n22's avatar
n22 committed
262
    if ([self.bill.state isEqualToString:PURCHASE_STATE_INITIAL]) {
陈俊俊's avatar
陈俊俊 committed
263 264
        self.stateLabel.textColor = [UIColor redColor];
        self.stateLabel.text = @"未提交";
n22's avatar
n22 committed
265
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_SUBMITTED]) {
陈俊俊's avatar
陈俊俊 committed
266 267
        self.stateLabel.textColor = [UIColor greenColor];
        self.stateLabel.text = @"已提交";
n22's avatar
n22 committed
268
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_REJECTED]) {
陈俊俊's avatar
陈俊俊 committed
269 270
        self.stateLabel.textColor = [UIColor grayColor];
        self.stateLabel.text = @"已拒绝";
n22's avatar
n22 committed
271
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_APPROVED]) {
陈俊俊's avatar
陈俊俊 committed
272 273
        self.stateLabel.textColor = [UIColor grayColor];
        self.stateLabel.text = @"已审批";
n22's avatar
n22 committed
274
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_SHIPPING]) {
陈俊俊's avatar
陈俊俊 committed
275 276
        self.stateLabel.textColor = [UIColor grayColor];
        self.stateLabel.text = @"发运中";
n22's avatar
n22 committed
277
    }else if ([self.bill.state isEqualToString:PURCHASE_STATE_FINISHED]) {
陈俊俊's avatar
陈俊俊 committed
278 279 280
        self.stateLabel.textColor = [UIColor blackColor];
        self.stateLabel.text = @"已完成";
    }
陈俊俊's avatar
陈俊俊 committed
281
    self.noticeNumberLabel.text = (self.bill.noticeNumber.length == 0) ? @"无":(self.bill.noticeNumber);
陈俊俊's avatar
陈俊俊 committed
282 283 284
    self.createOperNameLabel.text = [IBTCommon checkString:self.bill.create_operName];
    self.checkNameLabel.text = [IBTCommon checkString:self.bill.vendor_name];
    self.vendorNameLabel.text = [IBTCommon checkString:self.bill.vendor_name];
n22's avatar
n22 committed
285
    self.totalPriceLabel.text = [IBTCommon checkString:[self.bill.total stringValue]];
陈俊俊's avatar
陈俊俊 committed
286
    self.noteLabel.text = [IBTCommon checkString:self.bill.remark];
陈俊俊's avatar
陈俊俊 committed
287 288 289 290 291 292 293 294 295 296 297 298 299 300
    self.lastModifyNameLabel.text = [IBTCommon checkString:self.bill.lastModify_operName];
    NSString *type = [self.bill.type isEqualToString:GXF_Critical] ? @"紧急" : @"普通";
    self.typeLabel.text = type;
    self.vendorIsSureLabel.text = self.bill.vendorConfirmTime.length > 0 ? @"是":@"否";
    self.warehouseLabel.text = [IBTCommon checkString:self.bill.receiveWrh_name];
    self.otherPriceLabel.text = [self.bill.charge stringValue];
    NSMutableArray *productArr = [NSMutableArray array];
    for (NSDictionary *billDict in self.bill.products) {
        PurchaseBillProduct *billProbuct = [PurchaseBillProduct new];
        [billProbuct setValuesForKeysWithDictionary:billDict];
        [productArr addObject:billProbuct];
    }
    _pvc.productArr = productArr;
    [_pvc.tableView reloadData];
n22's avatar
n22 committed
301
    
陈俊俊's avatar
陈俊俊 committed
302 303 304 305 306 307 308 309 310 311 312
    [self setNoteHeight];
}

- (void)setNoteHeight
{
    CGFloat height =  [self.noteLabel calculateHeight];
    
    CGRect noteFrame = self.noteLabel.frame;
    noteFrame.size.height = height;
    self.noteLabel.frame = noteFrame;
    
n22's avatar
n22 committed
313
    CGFloat totalHeight = height + LeftHeight*_leftArr.count;
陈俊俊's avatar
陈俊俊 committed
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
    CGRect purchaseFrame = _purchaseView.frame;
    purchaseFrame.size.height = totalHeight;
    _purchaseView.frame = purchaseFrame;
    
    
    CGRect bottomFrame = _bottomView.frame;
    bottomFrame.origin.y = CGRectGetMaxY(_purchaseView.frame) + TopMargin;
    _bottomView.frame = bottomFrame;
    
    _scrollView.contentSize = CGSizeMake(ScreenSize.width, totalHeight + CGRectGetHeight(_bottomView.frame) + TopMargin*2);
}





- (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