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

#import "TransportDetailViewController.h"
#import "TransportProductViewController.h"
#import "Transport.h"
#import "TransportPdtDetail.h"
#import "FeeAcountDetail.h"
#import "BottomTransportView.h"
Sandy's avatar
Sandy committed
15 16 17 18 19
#import "TransferPdtDetail.h"
#import "ReceiveProductViewController.h"
#import "NewReceiveProductViewController.h"


陈俊俊's avatar
陈俊俊 committed
20 21
#define BottomHeight                                50
#define LeftMargin                                  15
22
#define LeftWidth                                   130
陈俊俊's avatar
陈俊俊 committed
23 24 25 26
#define LeftHeight                                  30
#define TopMargin                                   15
typedef enum : NSUInteger {
    AbortTag = 20000,
27
    EndTag,
Sandy's avatar
Sandy committed
28 29
    SubmitTag,
    ReceiveTag,//收货状态:收货
30
    SaveTag
陈俊俊's avatar
陈俊俊 committed
31 32 33 34 35 36 37 38 39 40
} BtnTag;

@interface TransportDetailViewController ()
{
    UIScrollView *_scrollView;
    UIView *_transportView;
    UIView *_bottomView;
    UIButton *_firstBtn;
    UIButton *_secondBtn;
    BottomTransportView *_transView;
Sandy's avatar
Sandy committed
41 42 43
    ReceiveProductViewController *_pvc;
    UIView *_recieveBottomView;

陈俊俊's avatar
陈俊俊 committed
44 45 46 47 48 49 50 51 52
}
@property (nonatomic,strong)UILabel *billNumberLabel;
@property (nonatomic,strong)UILabel *purchaseLabel;
@property (nonatomic,strong)UILabel *stateLabel;
@property (nonatomic,strong)UILabel *warehouseLabel;
@property (nonatomic,strong)UILabel *rwarehouseLabel;
@property (nonatomic,strong)UILabel *carnumberLabel;
@property (nonatomic,strong)UILabel *carhoneLabel;
@property (nonatomic,strong)UILabel *createOperLabel;
53
@property (nonatomic, strong) UILabel *lastModifierLabel;
陈俊俊's avatar
陈俊俊 committed
54
@property (nonatomic,strong)UILabel *arriveDateLabel;
陈俊俊's avatar
陈俊俊 committed
55
@property (nonatomic,strong)UILabel *noteLabel;
56 57 58 59 60 61 62 63 64

@property (nonatomic,strong)UILabel *leftBillNumberLabel;
@property (nonatomic,strong)UILabel *leftPurchaseLabel;
@property (nonatomic,strong)UILabel *leftStateLabel;
@property (nonatomic,strong)UILabel *leftWarehouseLabel;
@property (nonatomic,strong)UILabel *leftRwarehouseLabel;
@property (nonatomic,strong)UILabel *leftCarnumberLabel;
@property (nonatomic,strong)UILabel *leftCarhoneLabel;
@property (nonatomic,strong)UILabel *leftCreateOperLabel;
65
@property (nonatomic, strong) UILabel *leftLastModifierLabel;
66 67
@property (nonatomic,strong)UILabel *leftArriveDateLabel;
@property (nonatomic,strong)UILabel *leftNoteLabel;
68

Sandy's avatar
Sandy committed
69

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
/**
 *  创建时间
 */
@property (strong, nonatomic) UILabel *labelCreateTime;
/**
 *  审核人
 */
@property (strong, nonatomic) UILabel *labelInspector;
/**
 *  审核时间
 */
@property (strong, nonatomic) UILabel *labelInspectTime;
/**
 *  收货人
 */
@property (strong, nonatomic) UILabel *labelReciever;
/**
 *  收货时间
 */
@property (strong, nonatomic) UILabel *labelRecieveTime;
/**
 *  有效期
 */
@property (strong, nonatomic) UILabel *labelExpiredDate;

@property (strong, nonatomic) NSArray *leftArr;
陈俊俊's avatar
陈俊俊 committed
96 97 98 99 100 101 102 103
@end

@implementation TransportDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"发运单详情";
    [self bulifLayout];
陈俊俊's avatar
陈俊俊 committed
104
    [self getDataFromServer];
Sandy's avatar
Sandy committed
105 106 107 108 109
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(editReceiveProduct:) name:KNOTIFICATION_EditReceiveProduct object:nil];
}

- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
陈俊俊's avatar
陈俊俊 committed
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 138 139 140 141 142 143 144
}

- (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"];
                Transport *transport = [[Transport alloc]init];
                [transport setValuesForKeysWithDictionary:dictData];
                self.transport = transport;
                [strongSelf fetchtTransportDetail];
            }else{
                [IBTLoadingView showTips:message];
            }
        }else{
            [IBTLoadingView showTips:@"     无记录     "];
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
    [[ICRHTTPController sharedController] getTransportResultWithTransportUuid:self.transport.uuid success:succ failure:fail];
}




- (void)fetchtTransportDetail{
Sandy's avatar
Sandy committed
145
    _pvc.isHiddenEdit = ![self.transport.state isEqualToString:TRANSPORT_STATE_UNRECEIVED];
陈俊俊's avatar
陈俊俊 committed
146 147 148
    self.billNumberLabel.text = [IBTCommon checkString:self.transport.billnumber];
    if ([self.transport.state isEqualToString:TRANSPORT_STATE_UNRECEIVED]) {
        self.stateLabel.textColor = [UIColor redColor];
陈俊俊's avatar
陈俊俊 committed
149
        self.stateLabel.text = @"待收货";
陈俊俊's avatar
陈俊俊 committed
150 151
    }else if ([self.transport.state isEqualToString:TRANSPORT_STATE_RECEIVED]) {
        self.stateLabel.textColor = [UIColor greenColor];
陈俊俊's avatar
陈俊俊 committed
152
        self.stateLabel.text = @"已收货";
陈俊俊's avatar
陈俊俊 committed
153 154 155
    }else if ([self.transport.state isEqualToString:TRANSPORT_STATE_ABORTED]) {
        self.stateLabel.textColor = [UIColor grayColor];
        self.stateLabel.text = @"已作废";
156
    }else if ([self.transport.state isEqualToString:TRANSPORT_STATE_PROCESS]) {
陈俊俊's avatar
陈俊俊 committed
157
        self.stateLabel.textColor = [UIColor greenColor];
158 159 160 161
        self.stateLabel.text = @"提交系统处理";
    }else if ([self.transport.state isEqualToString:TRANSPORT_STATE_PROCESSFAIL]) {
        self.stateLabel.textColor = [UIColor blackColor];
        self.stateLabel.text = @"系统处理失败";
陈俊俊's avatar
陈俊俊 committed
162
    }
163
    self.purchaseLabel.text = [self getPurchaseWith:self.transport.pdtDetails];
陈俊俊's avatar
陈俊俊 committed
164 165 166 167
    self.warehouseLabel.text = [IBTCommon checkString:self.transport.warehouseName];
    self.rwarehouseLabel.text = [IBTCommon checkString:self.transport.rwarehouseName];
    self.carnumberLabel.text = [IBTCommon checkString:self.transport.carnumber];
    self.carhoneLabel.text = [IBTCommon checkString:self.transport.carphone];
陈俊俊's avatar
陈俊俊 committed
168
    self.noteLabel.text = [NSString stringWithFormat:@"%@",self.transport.note?self.transport.note:@"无"];
169 170 171
    self.createOperLabel.text = [IBTCommon checkString:self.transport.create_operName];
    self.labelCreateTime.text = [IBTCommon checkString:self.transport.create_time];
    self.labelCreateTime.text = [IBTCommon checkString:self.transport.create_time];
Sandy's avatar
Sandy committed
172 173
    self.labelReciever.text = [IBTCommon checkString:self.transport.receive_operName];
    self.labelRecieveTime.text = [IBTCommon checkString:self.transport.receive_time];
174
    self.labelExpiredDate.text = [IBTCommon checkString:self.transport.expiredDate];
175
    self.lastModifierLabel.text = [IBTCommon checkString:self.transport.lastModify_operName];
陈俊俊's avatar
陈俊俊 committed
176
    self.arriveDateLabel.text = [NSString stringWithFormat:@"%@",self.transport.arriveDate?[[IBTCommon checkString:self.transport.arriveDate]substringToIndex:10]:@"无"];
Sandy's avatar
Sandy committed
177 178 179 180 181 182 183 184 185 186
    
    NSMutableArray *productArr = [NSMutableArray array];
    if (self.type == TransportTypeAfterSubmit) {
        for (NSDictionary *billDict in self.transport.pdtDetails) {
            TransferPdtDetail *billProbuct = [TransferPdtDetail new];
            [billProbuct setValuesForKeysWithDictionary:billDict];
            TransportPdtDetail *t = [TransportPdtDetail new];
            [t setValuesForKeysWithDictionary:billDict];
            billProbuct.transportPdt = t;
            
Sandy's avatar
Sandy committed
187
            if ([self.transport.state isEqualToString:TRANSPORT_STATE_UNRECEIVED] && billProbuct.rctQty.floatValue == 0) {
Sandy's avatar
Sandy committed
188 189 190
                
                if (self.isWms){
                    [billProbuct z_setRctQty:0];
Sandy's avatar
Sandy committed
191 192 193 194
                }else{
                    billProbuct.rctQty = nil;
                    billProbuct.rctBaseQty = nil;
                    billProbuct.rctTotal = nil;
Sandy's avatar
Sandy committed
195
                }
Sandy's avatar
Sandy committed
196 197
            }else{
                [billProbuct z_setRctQty:billProbuct.rctQty.floatValue];
Sandy's avatar
Sandy committed
198
            }
Sandy's avatar
Sandy committed
199
            
Sandy's avatar
Sandy committed
200 201 202 203 204 205
            [productArr addObject:billProbuct];
        }
        _pvc.productArr = productArr;
        [_pvc.tableView reloadData];
    }else{
        [_transView refreshTranProduct:self.transport.pdtDetails];
Sandy's avatar
Sandy committed
206 207 208
    }
    
    
Sandy's avatar
Sandy committed
209 210 211
        [_transView refreshCost:self.transport.accountDetails];
        [self setNoteHeight];
    
陈俊俊's avatar
陈俊俊 committed
212
}
213 214 215 216
- (NSString *)getPurchaseWith:(NSArray *)purchases{
    NSString *purchseNumber = @"";
    
    NSInteger count = 0;
217

218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
    for (NSDictionary *billDict in purchases) {
        if (![billDict[@"purchasebillnumber"] isEqual:[NSNull null]]) {
            count ++;
            if (purchseNumber.length == 0) {
                purchseNumber = [purchseNumber stringByAppendingFormat:@"%@",billDict[@"purchasebillnumber"]];
            }else{
                purchseNumber = [purchseNumber stringByAppendingFormat:@",%@" ,billDict[@"purchasebillnumber"]];
            }
        }
    }
    if (count == 0) {
        purchseNumber = @"无";
    }
    return purchseNumber;
}
陈俊俊's avatar
陈俊俊 committed
233 234
- (void)setNoteHeight
{
235 236 237 238
    CGFloat purchaseHeight = [self.purchaseLabel calculateHeight];
    if (purchaseHeight < LeftHeight) {
        purchaseHeight = LeftHeight;
    }
239

240 241 242 243 244 245
    CGFloat height =  [self.noteLabel calculateHeight];
    if (height < LeftHeight) {
        height = LeftHeight;
    }

    self.noteLabel.height = height;
陈俊俊's avatar
陈俊俊 committed
246
    
247
    CGFloat totalHeight = height  - LeftHeight + LeftHeight*self.leftArr.count;
248 249 250 251 252
    
    CGRect purchaseFrame = _transportView.frame;
    purchaseFrame.size.height = totalHeight + LeftMargin;
    _transportView.frame = purchaseFrame;
    
Sandy's avatar
Sandy committed
253 254 255 256 257
        CGRect bottomFrame = _bottomView.frame;
        bottomFrame.origin.y = CGRectGetMaxY(_transportView.frame) + TopMargin;
        _bottomView.frame = bottomFrame;
        
        _scrollView.contentSize = CGSizeMake(ScreenSize.width, totalHeight + CGRectGetHeight(_bottomView.frame) + TopMargin*2);
Sandy's avatar
Sandy committed
258 259 260
    CGRect frame = _transView.productVC.viewFrame;
    _recieveBottomView.frame = frame;
    _pvc.viewFrame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height - 10);
Sandy's avatar
Sandy committed
261
    
陈俊俊's avatar
陈俊俊 committed
262 263 264 265 266 267 268 269
}

- (void)btnClick:(UIButton *)btn{
    CLog(@"%ld",(long)btn.tag);
    switch (btn.tag) {
        case AbortTag:
        {
            CLog(@"作废");
陈俊俊's avatar
陈俊俊 committed
270 271 272 273
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认作废" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
            alertView.delegate = self;
            alertView.tag = AbortTag;
            [alertView show];
陈俊俊's avatar
陈俊俊 committed
274 275 276 277 278
        }
            break;
        case EndTag:
        {
            CLog(@"结束");
陈俊俊's avatar
陈俊俊 committed
279 280 281 282
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认结束" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
            alertView.delegate = self;
            alertView.tag = EndTag;
            [alertView show];
陈俊俊's avatar
陈俊俊 committed
283 284
        }
            break;
285 286 287 288 289 290 291
        case SubmitTag:
        {
            CLog(@"提交");
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请确认提交" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
            alertView.delegate = self;
            alertView.tag = SubmitTag;
            [alertView show];
Sandy's avatar
Sandy committed
292 293
        }
            break;
294 295
        
            case SaveTag:
Sandy's avatar
Sandy committed
296
        {
Sandy's avatar
Sandy committed
297 298 299
            if ([self checkReceive]) {
                [self httpSave];
            }
300 301
        }
            break;
Sandy's avatar
Sandy committed
302 303 304 305 306 307 308 309
        case ReceiveTag:{
            if ([self checkReceive]) {
                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"收货后不能重复收货,请确认是否要收货?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
                alertView.delegate = self;
                alertView.tag = ReceiveTag;
                [alertView show];
            }
        }break;
陈俊俊's avatar
陈俊俊 committed
310 311 312 313 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
        default:
            break;
    }
}
- (void)dealByAction:(NSString *)action{
    //保存
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        if (data) {
            NSInteger success = [data[@"success"] integerValue];
            NSString *message = data[@"message"];
            if (success == 1) {
                [ICRUserUtil sharedInstance].needFresh = YES;
                [self PopViewControllerAnimated:YES];
            }else{
                [IBTLoadingView showTips:message];
            }
        }else{
            [IBTLoadingView showTips:@"操作异常"];
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
    if ([action isEqualToString:TRANSPORT_STATE_ABORTED]) {
        [[ICRHTTPController sharedController] abortTransportWithTransportUuid:self.transport.uuid version:self.transport.version success:succ failure:fail];
    }else{
        [[ICRHTTPController sharedController] endTransportWithTransportUuid:self.transport.uuid version:self.transport.version success:succ failure:fail];
    }
}
陈俊俊's avatar
陈俊俊 committed
342 343 344 345 346
- (void)hiddenAllBtn{
    CGRect scrollViewFrame = _scrollView.frame;
    scrollViewFrame.size.height = ScreenSize.height - 64;
    _scrollView.frame = scrollViewFrame;
}
陈俊俊's avatar
陈俊俊 committed
347

陈俊俊's avatar
陈俊俊 committed
348 349 350 351 352 353 354 355
- (void)createBtnWithArr:(NSArray *)arr{
    CGFloat btnWidth = (ScreenSize.width - LeftMargin * (arr.count+1))/arr.count;
    for (NSInteger i = 0; i < arr.count; i++) {
        NSInteger btnTag = 0;
        if ([arr[i] isEqualToString:@"结束"]) {
            btnTag = EndTag;
        }else if ([arr[i] isEqualToString:@"作废"]) {
            btnTag = AbortTag;
356 357
        }else if ([arr[i] isEqualToString:@"提交"]) {
            btnTag = SubmitTag;
Sandy's avatar
Sandy committed
358 359
        }else if([arr[i] isEqualToString:@"收货"]){
            btnTag = ReceiveTag;
360 361
        }else if ([arr[i] isEqualToString:@"保存"]){
            btnTag = SaveTag;
陈俊俊's avatar
陈俊俊 committed
362 363 364 365 366 367 368 369
        }
        CGRect btnFrame = CGRectMake(LeftMargin + (LeftMargin + btnWidth)*i,  ScreenSize.height  - 64 - BottomHeight +5, btnWidth, 40);
        UIButton *perBtn = [IBTCustomButtom creatButtonWithFrame:btnFrame target:self sel:@selector(btnClick:) tag:btnTag image:nil title:arr[i] titleColor:[UIColor whiteColor] isCorner:YES corner:5 bgColor:GXF_COMMIT_COLOR];
        [self.view addSubview:perBtn];
    }
}


陈俊俊's avatar
陈俊俊 committed
370 371 372 373 374 375 376
#pragma mark - 视图初始化
- (void)bulifLayout{
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenSize.width, ScreenSize.height - 64 - BottomHeight)];
    _scrollView.showsHorizontalScrollIndicator  = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.backgroundColor = XXFBgColor;
    [self.view addSubview:_scrollView];
陈俊俊's avatar
陈俊俊 committed
377

陈俊俊's avatar
陈俊俊 committed
378
    
陈俊俊's avatar
陈俊俊 committed
379 380 381 382
    if ([self.transport.state isEqualToString:TRANSPORT_STATE_ABORTED]) {
        [self hiddenAllBtn];
    }else if([self.transport.state isEqualToString:TRANSPORT_STATE_FINISHED]){
        if ([IBTCommon checkIsPermission:TRANSPORT_ACTION_ABORT]) {
陈俊俊's avatar
陈俊俊 committed
383 384
            NSArray *arr = @[@"作废"];
            [self createBtnWithArr:arr];
陈俊俊's avatar
陈俊俊 committed
385 386 387
        }else{
            [self hiddenAllBtn];
        }
陈俊俊's avatar
陈俊俊 committed
388 389 390 391 392
    }else if([self.transport.state isEqualToString:TRANSPORT_STATE_RECEIVED]){
        NSMutableArray *arr = [NSMutableArray array];
        if ([IBTCommon checkIsPermission:TRANSPORT_ACTION_ABORT]) {
            [arr addObject:@"作废"];
        }
Sandy's avatar
Sandy committed
393 394 395 396
//        if([IBTCommon checkIsPermission:TRANSPORT_ACTION_FINISH])
//        {
//            [arr addObject:@"结束"];
//        }
陈俊俊's avatar
陈俊俊 committed
397 398
        if (arr.count == 0) {
            [self hiddenAllBtn];
陈俊俊's avatar
陈俊俊 committed
399
        }else{
陈俊俊's avatar
陈俊俊 committed
400
            [self createBtnWithArr:arr];
陈俊俊's avatar
陈俊俊 committed
401
        }
402 403 404 405 406 407 408 409 410 411 412 413
    }else if ([self.transport.state isEqualToString:TRANSPORT_STATE_PROCESSFAIL]){
        NSMutableArray *arr = [NSMutableArray array];
        if ([IBTCommon checkIsPermission:TRANSPORT_ACTION_ABORT]) {
            [arr addObject:@"作废"];
        }if ([IBTCommon checkIsPermission:TRANSPORT_ACTION_NEW]) {
            [arr addObject:@"提交"];
        }
        if (arr.count == 0) {
            [self hiddenAllBtn];
        }else{
            [self createBtnWithArr:arr];
        }
414 415 416 417 418 419 420 421
    }else if ([self.transport.state isEqualToString:TRANSPORT_STATE_UNRECEIVED] && !self.isWms){
        NSMutableArray *arr = [NSMutableArray array];
        if ([IBTCommon checkIsPermission:TRANSPORT_ACTION_RECEIVE]) {//如果有收货权,则显示收货按钮
            [arr addObjectsFromArray:@[@"保存",@"收货"]];
        }
        //这里作废不受权限控制
        [arr addObject:@"作废"];
        [self createBtnWithArr:arr];
Sandy's avatar
Sandy committed
422
        
423 424
    }else{
        [self hiddenAllBtn];
陈俊俊's avatar
陈俊俊 committed
425
    }
Sandy's avatar
Sandy committed
426
    NSArray *leftArr = @[@"单号:",@"采购单:",@"状态:",@"发货仓库:",@"收货仓库:",@"车辆:",@"司机电话:",@"创建人:",@"创建时间:",@"收货人:",@"收货时间:",@"有效期:",@"最后修改人:", @"预计到货时间:",@"备注:"];
427 428 429
    self.leftArr = leftArr;
    CGFloat height = LeftHeight * leftArr.count +LeftMargin;
    _transportView= [[UIView alloc]initWithFrame:CGRectMake(0, TopMargin, ScreenSize.width, height)];
陈俊俊's avatar
陈俊俊 committed
430 431 432 433 434
    _transportView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_transportView];
    
    
    for (NSInteger i = 0 ; i < leftArr.count; i++) {
435
        NSString *title = leftArr[i];
陈俊俊's avatar
陈俊俊 committed
436 437
        UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(LeftMargin, 10 + LeftHeight *i, LeftWidth, LeftHeight)];
        leftLabel.font = GXF_SEVENTEENTH_SIZE;
438
        leftLabel.text = title;
陈俊俊's avatar
陈俊俊 committed
439 440 441 442 443 444 445
        leftLabel.textColor = GXF_DETAIL_COLOR;
        [_transportView addSubview:leftLabel];
        
        UILabel *rightLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(leftLabel.frame), 10 + LeftHeight *i, _transportView.frame.size.width - LeftMargin - LeftWidth, LeftHeight)];
        rightLabel.font = GXF_SEVENTEENTH_SIZE;
        rightLabel.textColor = GXF_DETAIL_COLOR;
        
446 447 448
        
        
        if ([title isEqualToString:@"单号:"]) {
陈俊俊's avatar
陈俊俊 committed
449
            self.billNumberLabel = rightLabel;
450
            self.leftBillNumberLabel = leftLabel;
451
        }else if ([title isEqualToString:@"采购单:"]){
陈俊俊's avatar
陈俊俊 committed
452
            self.purchaseLabel = rightLabel;
453 454
            self.purchaseLabel.numberOfLines = 0;
            self.leftPurchaseLabel = leftLabel;
455
        }else if ([title isEqualToString:@"状态:"]){
陈俊俊's avatar
陈俊俊 committed
456
            self.stateLabel = rightLabel;
457
            self.leftStateLabel = leftLabel;
458
        }else if ([title isEqualToString:@"发货仓库:"]){
陈俊俊's avatar
陈俊俊 committed
459
            self.warehouseLabel = rightLabel;
460
            self.leftWarehouseLabel = leftLabel;
461
        }else if ([title isEqualToString:@"收货仓库:"]){
陈俊俊's avatar
陈俊俊 committed
462
            self.rwarehouseLabel = rightLabel;
463
            self.leftRwarehouseLabel = leftLabel;
464
        }else if ([title isEqualToString:@"车辆:"]){
陈俊俊's avatar
陈俊俊 committed
465
            self.carnumberLabel = rightLabel;
466
            self.leftCarnumberLabel = leftLabel;
467
        }else if ([title isEqualToString:@"司机电话:"]){
陈俊俊's avatar
陈俊俊 committed
468
            self.carhoneLabel = rightLabel;
469
            self.leftCarhoneLabel = leftLabel;
470
        }else if ([title isEqualToString:@"创建人:"]){
陈俊俊's avatar
陈俊俊 committed
471
            self.createOperLabel = rightLabel;
472
            self.leftCreateOperLabel = leftLabel;
473 474
        }
        else if ([title isEqualToString:@"最后修改人:"]){
475 476
            self.lastModifierLabel = rightLabel;
            self.leftLastModifierLabel = leftLabel;
477 478 479 480 481
        }
        else if ([title isEqualToString:@"预计到货时间:"]){
//            leftLabel.width = LeftWidth + 10;
//            rightLabel.left = leftLabel.right;
//            rightLabel.width = ScreenSize.width - leftLabel.width - LeftMargin;
陈俊俊's avatar
陈俊俊 committed
482
            self.arriveDateLabel = rightLabel;
483
            self.leftArriveDateLabel = leftLabel;
484
        }else if ([title isEqualToString:@"备注:"]){
陈俊俊's avatar
陈俊俊 committed
485 486
            rightLabel.numberOfLines = 0;
            self.noteLabel = rightLabel;
487
            self.leftNoteLabel = leftLabel;
488 489 490 491 492 493 494 495 496 497 498 499
        }else if ([title isEqualToString:@"创建时间:"]){
            self.labelCreateTime = rightLabel;
        }else if ([title isEqualToString:@"审核人:"]){
            self.labelInspector = rightLabel;
        }else if ([title isEqualToString:@"审核时间:"]){
            self.labelInspectTime = rightLabel;
        }else if ([title isEqualToString:@"收货人:"]){
            self.labelReciever = rightLabel;
        }else if ([title isEqualToString:@"收货时间:"]){
            self.labelRecieveTime = rightLabel;
        }else if ([title isEqualToString:@"有效期:"]){
            self.labelExpiredDate = rightLabel;
陈俊俊's avatar
陈俊俊 committed
500 501 502 503 504
        }
        [_transportView addSubview:rightLabel];
    }
    [self createBottomView];
}
陈俊俊's avatar
陈俊俊 committed
505

陈俊俊's avatar
陈俊俊 committed
506
- (void)createBottomView{
Sandy's avatar
Sandy committed
507 508 509 510 511 512
    _bottomView= [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_transportView.frame) + TopMargin, ScreenSize.width, 300)];
    _bottomView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_bottomView];
    _transView = [[BottomTransportView alloc]initWithFrame:_bottomView.bounds withHidden:YES];
    [_bottomView addSubview:_transView];
    
Sandy's avatar
Sandy committed
513 514 515 516 517 518 519 520 521 522
    if (self.type == TransportTypeAfterSubmit) {
        _recieveBottomView= [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_transportView.frame) + TopMargin, ScreenSize.width, 300)];
        _recieveBottomView.backgroundColor = [UIColor redColor];
        [_scrollView addSubview:_recieveBottomView];
        
        _pvc = [[ReceiveProductViewController alloc]init];
        _pvc.viewFrame = _recieveBottomView.bounds;
        _pvc.isHiddenAdd = YES;
        [_recieveBottomView addSubview:_pvc.view];
    }
陈俊俊's avatar
陈俊俊 committed
523
    
Sandy's avatar
Sandy committed
524
    CGRect frame = _transView.productVC.viewFrame;
Sandy's avatar
Sandy committed
525
    _recieveBottomView.frame = frame;
Sandy's avatar
Sandy committed
526
    _pvc.viewFrame = frame;
Sandy's avatar
Sandy committed
527 528
    [_transView.productVC.view addSubview:_recieveBottomView];
    
陈俊俊's avatar
陈俊俊 committed
529 530 531
    
}

陈俊俊's avatar
陈俊俊 committed
532 533 534
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag == AbortTag) {
        if (buttonIndex == 1) {
Sandy's avatar
Sandy committed
535 536 537 538
            if (self.isWms) {
                ShowMessage(@"wms仓不允许作废!");
                return;
            }
陈俊俊's avatar
陈俊俊 committed
539 540 541 542 543 544
            [self dealByAction:TRANSPORT_STATE_ABORTED];//作废
        }
    }else if (alertView.tag == EndTag){
        if (buttonIndex == 1) {
            [self dealByAction:TRANSPORT_STATE_RECEIVED];//结束
        }
545 546 547 548
    }else if (alertView.tag == SubmitTag){
        if (buttonIndex == 1) {
            [self getDataFromServer:TRANSPORT_STATE_RECEIVED msg:@"正在提交..."];
        }
Sandy's avatar
Sandy committed
549 550
    }else if(alertView.tag == ReceiveTag){
        if (buttonIndex == 1) {
Sandy's avatar
Sandy committed
551
                [self httpRecieve];
Sandy's avatar
Sandy committed
552
        }
Sandy's avatar
Sandy committed
553 554 555 556
    }else if (alertView.tag == SaveTag){
        if (buttonIndex == 1) {
            [self httpSave];
        }
陈俊俊's avatar
陈俊俊 committed
557
    }
Sandy's avatar
Sandy committed
558

陈俊俊's avatar
陈俊俊 committed
559
}
陈俊俊's avatar
陈俊俊 committed
560

561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
#pragma mark - 提交
- (void)getDataFromServer:(NSString *)state msg:(NSString *)msg{
    //保存
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        if (data) {
            NSInteger success = [data[@"success"] integerValue];
            NSString *message = data[@"message"];
            if (success == 1) {
                [ICRUserUtil sharedInstance].needFresh = YES;
                [self PopViewControllerAnimated:YES];
            }else{
                [IBTLoadingView showTips:message];
            }
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
    NSDictionary *dict = @{@"uuid":self.transport.uuid,
                           @"version":self.transport.version,
                           @"billnumber":self.transport.billnumber,
                           @"enterprise":[ICRUserUtil sharedInstance].orgId,
                           @"state":TRANSPORT_STATE_RECEIVED,
                           @"warehouseUuid":[IBTCommon checkString:self.transport.warehouseUuid],
                           @"warehouseCode":[IBTCommon checkString:self.transport.warehouseCode],
                           @"warehouseName":[IBTCommon checkString:self.transport.warehouseName],
                           @"rwarehouseUuid":[IBTCommon checkString:self.transport.rwarehouseUuid],
                           @"rwarehouseCode":[IBTCommon checkString:self.transport.rwarehouseCode],
                           @"rwarehouseName":[IBTCommon checkString:self.transport.rwarehouseName],
                           @"carnumber":[IBTCommon checkString:self.transport.carnumber],
                           @"type":[IBTCommon checkString:self.transport.type],
                           @"carphone":[IBTCommon checkString:self.transport.carphone],
                           @"arriveDate":[IBTCommon checkString:self.transport.arriveDate],
                           @"note":[IBTCommon checkString:self.transport.note],
                           @"pdtDetails":self.transport.pdtDetails,
                           @"accountDetails":self.transport.accountDetails};
    [IBTLoadingView showProgressLabel:msg];
    [[ICRHTTPController sharedController] saveAndSubmitTransportWithData:dict success:succ failure:fail];
    
}

Sandy's avatar
Sandy committed
604 605
- (void)editReceiveProduct:(NSNotification *)fination{
    NewReceiveProductViewController *nvc = [NewReceiveProductViewController new];
606
    NSInteger indexTag = [[[fination userInfo] objectForKey:@"indexPath"] integerValue];
Sandy's avatar
Sandy committed
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
    TransferPdtDetail *transferPdtDetail = [[fination userInfo] objectForKey:@"transferPdtDetail"];
    if (transferPdtDetail) {
        nvc.navTitle = @"商品明细";
        nvc.indexTag = indexTag;
        nvc.noticeProduct = transferPdtDetail;
    }
    nvc.editReceiveProduct = ^(TransferPdtDetail *transferPdtDetail,NSInteger indexTag){
        if (transferPdtDetail) {
            [_pvc.productArr replaceObjectAtIndex:indexTag withObject:transferPdtDetail];
            [_pvc.defaultState replaceObjectAtIndex:indexTag withObject:@"YES"];
            [_pvc.tableView reloadData];
        }
    };
    [self PushViewController:nvc animated:YES];
}

- (void)httpRecieve{
    NSString *receiveTime = [[NSDate date] httpParameterString];
    self.transport.receive_time = receiveTime;
    self.transport.receive_id = [ICRUserUtil sharedInstance].userId;
    self.transport.receive_operName = [ICRUserUtil sharedInstance].userName;
    
    NSMutableDictionary *param = [self.transport dictForCommit].mutableCopy;
    NSMutableArray *arrProduct = [NSMutableArray array];
    for (TransferPdtDetail *pdt in _pvc.productArr) {
        TransportPdtDetail *pPdt = [pdt changeToTransportPdt];
        NSDictionary *dict = [pPdt dictForCommit];
        [arrProduct addObject:dict];
    }
    
    [param setObject:arrProduct forKey:@"pdtDetails"];
    
    
    
    [param setObject:self.transport.accountDetails forKey:@"accountDetails"];
    
    IBTLoadingView *hud = [IBTLoadingView showHUDAddedTo:self.view animated:YES];
    __weak UIViewController *weakSelf = self;
    [HTTP recieveTransport:param success:^(id succ) {
        [hud hide:YES];
        if ([succ[@"success"] boolValue]) {
            [ICRUserUtil sharedInstance].needFresh = YES;
            [IBTLoadingView showTips:@"   收货成功!   "];
            [weakSelf.navigationController popViewControllerAnimated:YES];
651 652
        }else{
            [IBTLoadingView showTips:succ[@"message"]];
Sandy's avatar
Sandy committed
653 654 655 656 657 658
        }
    } failure:^(id fail) {
        [IBTLoadingView showTips:fail];
    }];
    
}
659 660 661


- (void)httpSave {
Sandy's avatar
Sandy committed
662 663 664 665 666 667 668 669
    
    for (TransferPdtDetail *detail in _pvc.productArr) {
        if (detail.rctQty == nil) {
            ShowMessage(@"请选择商品实收数量后再保存!");
            return;
            
        }
    }
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
    NSMutableDictionary *param = [self.transport dictForCommit].mutableCopy;
    NSMutableArray *arrProduct = [NSMutableArray array];
    for (TransferPdtDetail *pdt in _pvc.productArr) {
        TransportPdtDetail *pPdt = [pdt changeToTransportPdt];
        NSDictionary *dict = [pPdt dictForCommit];
        [arrProduct addObject:dict];
    }
    
    [param setObject:arrProduct forKey:@"pdtDetails"];
    [param setObject:self.transport.accountDetails forKey:@"accountDetails"];
    
    
    //保存
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        if (data) {
            NSInteger success = [data[@"success"] integerValue];
            NSString *message = data[@"message"];
            if (success == 1) {
                //成功
                [IBTLoadingView showTips:@"   保存成功!   "];
                [self PopViewControllerAnimated:YES];
            }else{
                [IBTLoadingView showTips:message];
            }
        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };

    

    [[ICRHTTPController sharedController] saveTransportWithData:param success:succ failure:fail];
    
}
Sandy's avatar
Sandy committed
707 708 709 710 711 712 713 714 715 716 717 718 719
- (BOOL)checkReceive{
    for (NSString *isEdit in _pvc.defaultState) {
        if ([isEdit isEqualToString:@"NO"]) {
            ShowMessage(@"有商品行没有编辑过收货数量,请先编辑再收货");
            return NO;
        }
    }
    
    if (_pvc.productArr.count == 0) {
        ShowMessage(@"商品不能为空");
        return NO;
    }
    
Sandy's avatar
Sandy committed
720 721 722 723 724 725 726
    for (TransferPdtDetail *pdt in _pvc.productArr) {
        if (pdt.rctQty == nil) {
            ShowMessage(@"有商品未填写收货数量!");
            return NO;
        }
    }
    
Sandy's avatar
Sandy committed
727 728
    return YES;
}
陈俊俊's avatar
陈俊俊 committed
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
- (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