GXFNewProcessViewController.m 36.6 KB
Newer Older
freecui's avatar
freecui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
//
//  GXFProcessViewController.m
//  XFFruit
//
//  Created by freecui on 15/9/1.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//



#import "GXFNewProcessViewController.h"
#import "GXFBottomView.h"
#import "GXFTableViewCell.h"
#import "GXFButtonAndLineView.h"
#import "GXFSearchVendorViewController.h"
#import "Vendor.h"
#import "Warehouse.h"
#import "GXFProcessBill.h"
#import "GXFProcessMaterial.h"
#import "GXFProcessProduct.h"
#import "GXFPopNewMaterialViewController.h"
freecui's avatar
freecui committed
22
#import "GXFPopNewProductViewController.h"
freecui's avatar
freecui committed
23 24 25

#import "GXFProcessMaterialTableViewCell.h"
#import "GXFProcessProductTableViewCell.h"
freecui's avatar
freecui committed
26
#import "ProductBillCell.h"
freecui's avatar
freecui committed
27 28 29 30 31 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
typedef NS_ENUM(NSUInteger, processType){
    kMaterial = 0,
    kProduct
};
typedef NS_ENUM(NSInteger, cellRow) {
    kTitle = 0,
    kVendor,
    kContact,
    kContactPhone,
    kWarehouse,
    kTotal,
    kRemark,
};

@interface GXFNewProcessViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,GXFBottomViewDelegate>
{
    NSMutableArray *_selectRowArr;//记录当前选中的cell
}
@property (nonatomic, strong) UIScrollView *c_scrollView;
@property (nonatomic, strong) UITableView *c_tableView;
@property (nonatomic, strong) IBTSegmentContainer *c_segContainer;
@property (nonatomic, strong) IBTSegmentedControl *c_segmentControl;
@property (nonatomic, strong) GXFPopNewMaterialViewController *c_materialVC;
@property (nonatomic, strong) GXFButtonAndLineView *c_materialView;
@property (nonatomic, strong) GXFButtonAndLineView *c_productView;

@property (nonatomic, strong) NSArray *d_arrRightTableV;
@property (nonatomic, strong) NSArray *d_arrLeftTableV;
@property (nonatomic, strong) NSMutableArray *d_materialMuArr;
@property (nonatomic, strong) NSMutableArray *d_productMuArr;
@property (nonatomic, strong) GXFProcessBill *d_processBill;
@property (nonatomic, assign) BOOL d_isProduct;
@property (nonatomic, strong) NSArray *d_meteilHeaderArr;
@property (nonatomic, strong) NSArray *d_productHeaderArr;
freecui's avatar
freecui committed
61 62
//@property (nonatomic, strong) NSMutableArray *d_meteilArr;
//@property (nonatomic, strong) NSMutableArray *d_productArr;
freecui's avatar
freecui committed
63

freecui's avatar
freecui committed
64
@property (nonatomic, assign) NSInteger d_editOrDelete;
freecui's avatar
freecui committed
65 66 67


@property (nonatomic,assign)BOOL isHiddenEdit;
freecui's avatar
freecui committed
68 69
@property (nonatomic, copy) NSString *d_processUuid;
@property (nonatomic, assign) BOOL isProccessing;
freecui's avatar
freecui committed
70 71 72 73
@end

@implementation GXFNewProcessViewController

freecui's avatar
freecui committed
74 75 76 77 78 79 80 81 82 83 84
- (instancetype)initWithProcessUuid:(NSString *)processUuid {
    
    self = [super init];
    if (!self) {
        return nil;
    }
    self.d_processUuid = processUuid;
    self.isProccessing = YES;
    return self;
}

freecui's avatar
freecui committed
85 86 87
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
freecui's avatar
freecui committed
88 89
    
    self.title = @"添加加工单";
freecui's avatar
freecui committed
90
    [self http];
freecui's avatar
freecui committed
91 92
    [self initData];
    [self initSubViews];
freecui's avatar
freecui committed
93
    
freecui's avatar
freecui committed
94
    //原料明细
freecui's avatar
freecui committed
95
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addNewMaterail:) name:KNOTIFICATION_saveMaterial object:nil];
freecui's avatar
freecui committed
96 97
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(editMaterail:) name:KNOTIFICATION_editMaterial object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteMaterail:) name:KNOTIFICATION_deleteMaterial object:nil];
freecui's avatar
freecui committed
98 99
    //货物明细
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addNewProduct:) name:KNOTIFICATION_saveProduct object:nil];
freecui's avatar
freecui committed
100 101
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(editProduct:) name:KNOTIFICATION_editProduct object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteProduct:) name:KNOTIFICATION_deleteProduct object:nil];
freecui's avatar
freecui committed
102
}
freecui's avatar
freecui committed
103 104 105 106 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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
- (void)http{
    if (!self.d_materialMuArr) {
        self.d_materialMuArr = [NSMutableArray array];
    }
    
    if (!self.d_productMuArr) {
        self.d_productMuArr = [NSMutableArray array];
    }

    __weak typeof(self)weakSelf = self;
    void (^success)(id) = ^(id data){
        [IBTLoadingView hideHUDWithText:nil];
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf fetchDataWithData:data];
    };
    void (^fail)(id) = ^(id data){
        [IBTLoadingView hideHUDWithText:nil];
        
    };
    [IBTLoadingView showProgressLabel:@"正在加载..."];
    [[ICRHTTPController sharedController] getResultWithProcessUuid:_d_processUuid success:success failure:fail];
}
- (void)fetchDataWithData: (id)data {
    if (data) {
        NSInteger success = [data[@"success"] integerValue];
        NSString *message = data[@"message"];
        if (success == 1) {
            NSDictionary *dict = (NSDictionary *)data[@"data"];
            self.d_processBill = [[GXFProcessBill alloc]initWithDict:dict];
            NSArray *arrMaterials = dict[@"materials"];
            if (arrMaterials.count > 0) {
                for (int i = 0; i < arrMaterials.count; i++) {
                    GXFProcessMaterial *material = [[GXFProcessMaterial alloc]initWithDict:arrMaterials[i]];
                    [self.d_materialMuArr addObject:material];
                }
            }
            
            NSArray *arrProducts = dict[@"products"];
            if (arrProducts.count > 0) {
                for (int i = 0; i < arrMaterials.count; i++) {
                    GXFProcessProduct *product = [[GXFProcessProduct alloc]initWithDict:arrProducts[i]];
                    [self.d_productMuArr addObject:product];
                }
            }
            
            
        }
        
    }
    [self.c_tableView reloadData];
}
freecui's avatar
freecui committed
154 155 156 157 158 159

//刷新数据
- (void)p_refreshData {
    NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndex:1];
    [self.c_tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
}
freecui's avatar
freecui committed
160 161

//原料明细
freecui's avatar
freecui committed
162 163
- (void)addNewMaterail: (NSNotification *)aNotification {
    GXFProcessMaterial *material = aNotification.object;
freecui's avatar
freecui committed
164
    if (_d_materialMuArr ) {
freecui's avatar
freecui committed
165
        [_d_materialMuArr addObject:material];
freecui's avatar
freecui committed
166 167 168
        [self p_refreshData];
    }
}
freecui's avatar
freecui committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
- (void)editMaterail: (NSNotification *)aNotification {
    GXFProcessMaterial *material = aNotification.object;
    if (_d_materialMuArr ) {
        [_d_materialMuArr replaceObjectAtIndex:_d_editOrDelete withObject:material];
        [self p_refreshData];
    }
}
- (void)deleteMaterail: (NSNotification *)aNotification {
    GXFProcessMaterial *material = aNotification.object;
    if (_d_materialMuArr) {
        [_d_materialMuArr removeObject:material];////待做:优化为刷新这一条
        [self p_refreshData];
    }
}
//产品明细
freecui's avatar
freecui committed
184 185
- (void)addNewProduct: (NSNotification *)aNotification {
    GXFProcessProduct *product = aNotification.object;
freecui's avatar
freecui committed
186 187
    if (_d_productMuArr) {
        [_d_productMuArr addObject:product];
freecui's avatar
freecui committed
188 189 190 191 192
        [self p_refreshData];
    }
}
- (void)editProduct: (NSNotification *)aNotification {
    GXFProcessProduct *product = aNotification.object;
freecui's avatar
freecui committed
193 194
    if (_d_productMuArr) {
        [_d_productMuArr replaceObjectAtIndex:_d_editOrDelete withObject:product];//待做:优化为刷新这一条
freecui's avatar
freecui committed
195 196 197 198 199
        [self p_refreshData];
    }
}
- (void)deleteProduct: (NSNotification *)aNotification {
    GXFProcessProduct *product = aNotification.object;
freecui's avatar
freecui committed
200 201
    if (_d_productMuArr) {
        [_d_productMuArr removeObject:product];////待做:优化为刷新这一条
freecui's avatar
freecui committed
202 203 204 205 206 207 208
        [self p_refreshData];
    }
}
- (void)viewWillAppear:(BOOL)animated {

}

freecui's avatar
freecui committed
209 210 211 212 213 214
- (void)initData {
    self.d_arrLeftTableV =@[@"标题:",@"供应商:",@"联系人:",@"联系电话:",@"加工工厂:",@"总费用:",@"备注:"];
    self.d_arrRightTableV = @[@"请输入标题",@"选择供应商",@"请输入联系人姓名",@"请输入联系电话",@"选择加工工厂",@"",@"请输入备注"];
    self.d_meteilHeaderArr = @[@"原料",@"基础数量",@"入库时间"];
    self.d_productHeaderArr = @[@"原料",@"基础数量",@"出库时间"];
     _selectRowArr = [[NSMutableArray alloc]init];
freecui's avatar
freecui committed
215 216 217
    if (!_d_processBill) {
        self.d_processBill = [[GXFProcessBill alloc]init];
    }
freecui's avatar
freecui committed
218 219
    self.d_processBill = [[GXFProcessBill alloc]init];
    
freecui's avatar
freecui committed
220 221
    if (!self.d_materialMuArr) {
        self.d_materialMuArr = [NSMutableArray array];
freecui's avatar
freecui committed
222 223
    }
    
freecui's avatar
freecui committed
224 225
    if (!self.d_productMuArr) {
        self.d_productMuArr = [NSMutableArray array];
freecui's avatar
freecui committed
226
    }
freecui's avatar
freecui committed
227
    
freecui's avatar
freecui committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
}
- (void)initSubViews {
    self.view.backgroundColor = XXFBgColor;
    self.c_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height - BottomViewHeight - NavigationBarHeight) style:UITableViewStyleGrouped];
    self.c_tableView.dataSource = self;
    self.c_tableView.delegate = self;
    [self.view addSubview:_c_tableView];
    [_c_tableView reloadData];
    
    GXFBottomView *bottomV = [[GXFBottomView alloc]initWithFrame:CGRectMake(0, _c_tableView.bottom, self.view.width, BottomViewHeight) LeftBtnTitle:@"结束" rightBtnTitle:@"保存"];
    bottomV.delegate = self;
    [self.view addSubview:bottomV];

}

#pragma UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0) {
        return _d_arrLeftTableV.count;
    } else {
        if (_d_isProduct) {
freecui's avatar
freecui committed
250
            return 2 + _d_productMuArr.count;
freecui's avatar
freecui committed
251
        }
freecui's avatar
freecui committed
252
        return 2 + _d_materialMuArr.count;
freecui's avatar
freecui committed
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 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 342 343 344 345
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 1) {
        if (indexPath.row > 1) {
            if ([self isHaveIndexPath:indexPath]) {
                return 200;
            } else {
                return GXF_TABLEVIEW_NOMALCELL_HEIGHT;
            }
        } else {
            return GXF_TABLEVIEW_NOMALCELL_HEIGHT;
        }
    } else {
        return GXF_TABLEVIEW_NOMALCELL_HEIGHT;
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return nil;
    } else {
        UIView * headV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 44)];
        headV.backgroundColor = [UIColor whiteColor];

        GXFButtonAndLineView *materialView = [[GXFButtonAndLineView alloc]initViewLineAndButtonWithFrame:CGRectMake(0, 0, self.view.width * 0.5, headV.height )  isSeleted:!_d_isProduct buttonTitle: @"原料明细" selectColor:GXF_GREEN_COLOR];        [materialView.f_btn addTarget:self action:@selector(selecNewMaterial) forControlEvents:UIControlEventTouchUpInside];
        self.c_materialView = materialView;
       GXFButtonAndLineView *productView = [[GXFButtonAndLineView alloc]initViewLineAndButtonWithFrame:CGRectMake(self.view.width * 0.5, 0, materialView.width, materialView.height)   isSeleted:_d_isProduct buttonTitle: @"成品明细" selectColor:GXF_GREEN_COLOR];
        [productView.f_btn addTarget:self action:@selector(selecNewMaterial) forControlEvents:UIControlEventTouchUpInside];
        self.c_productView= productView;

        [headV addSubview:_c_materialView];
        [headV addSubview:_c_productView];
        [headV addSubview:productView];
        return headV;

    }
        
}


- (UIView *)viewLineAndButtonWithFrame: (CGRect)frame
                             isSeleted: (BOOL)isSelected
                           buttonTitle: (NSString *)title
                           selectColor: (UIColor *)color
                               // target: (id)target
                                action:(SEL)action
                      forControlEvents:(UIControlEvents)controlEvents
{
    UIView *view = [[UIView alloc]initWithFrame:frame];

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, view.width, view.height - 1);
    [btn setTitle:title forState:UIControlStateNormal];
    [btn addTarget:self action:action forControlEvents:controlEvents];
    
    CGSize labelSize = [btn.titleLabel.text sizeWithAttributes:@{NSFontAttributeName: btn.titleLabel.font}];
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake((view.width - labelSize.width ) * 0.5, btn.bottom, labelSize.width, 1)];
    if (isSelected) {
        [btn setTitleColor:GXF_GREEN_COLOR forState:UIControlStateNormal];
         line.backgroundColor = GXF_GREEN_COLOR;
        
    } else {
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        line.backgroundColor = [UIColor whiteColor];
    }

    [view addSubview:line];
    [view addSubview:btn];
    
    return view;
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 0.1;
    } else {
        return 44;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    GXFTableViewCell *xfCell ;
    if (indexPath.section == 0) {
        if (indexPath.row == kTitle || indexPath.row == kContact ||
            indexPath.row == kContactPhone ||indexPath.row == kRemark) {
            xfCell = [tableView dequeueReusableCellWithIdentifier:noLblCell];
            if (!xfCell ) {
                xfCell = [[GXFTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:noLblCell textFieldPlaceholder:_d_arrRightTableV[indexPath.row] isEdit:YES];
            }
freecui's avatar
freecui committed
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
            if (_isProccessing) {
                switch (indexPath.row) {
                    case kTitle:
                        xfCell.f_textField.text =  _d_processBill.title;
                        break;
                    case kContact:
                        xfCell.f_textField.text =  _d_processBill.contact;
                        break;
                    case kContactPhone:
                        xfCell.f_textField.text =  _d_processBill.contactPhone;
                        break;
                    case kRemark:
                        xfCell.f_textField.text =  _d_processBill.remark;
                        break;
                    default:
                        break;
                }
            }
freecui's avatar
freecui committed
364 365 366 367 368 369 370
        } else if (indexPath.row == kVendor || indexPath.row ==kWarehouse ) {
            xfCell = [tableView dequeueReusableCellWithIdentifier:arrowCell];
                    if ( !xfCell) {
                                    xfCell = [[GXFTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:arrowCell textFieldPlaceholder:_d_arrRightTableV[indexPath.row] isEdit:NO];
                        //xfCell = [[GXFTableViewCell alloc]initWithStyle:UITableVie<#(NSString *)#>wCellStyleDefault reuseIdentifier:arrowCell];
                    }
            xfCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
freecui's avatar
freecui committed
371 372 373 374 375 376 377 378 379 380 381 382 383
            if (_isProccessing) {
                switch (indexPath.row) {
                    case kVendor:
                        xfCell.f_textField.text =  _d_processBill.vendor_name;
                        break;
                    case kWarehouse:
                        xfCell.f_textField.text = [NSString stringWithFormat:@"%@[%@]",_d_processBill.warehouse_name,_d_processBill.warehouse_uuid];// _d_processBill.warehouse_name;
                        break;
                    default:
                        break;
                }
            }

freecui's avatar
freecui committed
384 385 386 387 388
        } else if (indexPath.row == kTotal ){
            xfCell = [tableView dequeueReusableCellWithIdentifier:lblCell];
            if (!xfCell ) {
                xfCell = [[GXFTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:lblCell textFieldPlaceholder:_d_arrRightTableV[indexPath.row] hasLable:YES backLableText:@"元"];
            }
freecui's avatar
freecui committed
389 390 391
            if (_isProccessing) {
                xfCell.f_textField.text = [NSString stringWithFormat:@"%@",_d_processBill.total];
            }
freecui's avatar
freecui committed
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
        } else {
            xfCell = [tableView dequeueReusableCellWithIdentifier:noLblCell];
            if (!xfCell ) {
                xfCell = [[GXFTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:noLblCell textFieldPlaceholder:_d_arrRightTableV[indexPath.row] isEdit:YES];
            }
        }

        if (xfCell.f_textField) {
            xfCell.f_textField.delegate = self;
        }
        xfCell.f_textField.tag = indexPath.row;
        xfCell.textLabel.text = _d_arrLeftTableV[indexPath.row];
        xfCell.textLabel.textColor = [UIColor blackColor];
        xfCell.selectionStyle = UITableViewCellAccessoryNone;
        return xfCell;
    } else {
        if (indexPath.row == 0) {
            xfCell = [tableView dequeueReusableCellWithIdentifier:addDetailCell];
freecui's avatar
freecui committed
410 411 412
            xfCell = [[GXFTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:addDetailCell];
            UIButton *addDetailedButton=[UIButton  buttonWithType: UIButtonTypeCustom];
            [addDetailedButton  setFrame:CGRectMake(xfCell.width * 0.5, 0, xfCell.width * 0.5, xfCell.height)];
freecui's avatar
freecui committed
413
            
freecui's avatar
freecui committed
414 415 416 417 418
            [addDetailedButton addTarget:self action:@selector(addNewInfoDetailed) forControlEvents:UIControlEventTouchUpInside];
            [addDetailedButton setTitleColor:HexColor(@"444444") forState:UIControlStateNormal];
            [xfCell.contentView addSubview:addDetailedButton];
            //if (!xfCell) {
            if (_d_isProduct) {
freecui's avatar
freecui committed
419
                [addDetailedButton setTitle:@"+ 点击添加商品明细" forState:UIControlStateNormal];
freecui's avatar
freecui committed
420 421 422 423 424
            } else {
                [addDetailedButton setTitle:@"+ 点击添加原料明细" forState:UIControlStateNormal];
            }
            
              //  }
freecui's avatar
freecui committed
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
            
            xfCell.selectionStyle = UITableViewCellAccessoryNone;
            return xfCell;
            } else if ( indexPath.row == 1){
                 xfCell = [tableView dequeueReusableCellWithIdentifier:addHeaderCell];
                if (!xfCell) {
                    NSArray *arr = [NSArray arrayWithArray: _d_isProduct ? _d_productHeaderArr :_d_meteilHeaderArr] ;
                    if (arr) {
                        xfCell = [[GXFTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:addHeaderCell contentArray:arr];
                    } else {
                        xfCell = [[GXFTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:addHeaderCell];
                    }
                    
   
                }
            
                xfCell.selectionStyle = UITableViewCellAccessoryNone;
                return xfCell;

            }else  {
freecui's avatar
freecui committed
445 446 447
                static NSString *cellIDProduct = @"ProductCell";
                static NSString *cellIDMaterial = @"materialCell";
                if(_d_isProduct){
freecui's avatar
freecui committed
448
                
freecui's avatar
freecui committed
449 450 451 452 453 454 455 456 457 458 459
                     //GXFProcessProductTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIDProduct];
                    //if (cell == nil) {
                        
                            GXFProcessProduct *processP = (GXFProcessProduct *)_d_productMuArr[indexPath.row - 2];
                            GXFProcessProductTableViewCell *cell = [[GXFProcessProductTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIDProduct processProduct:processP];
                        
//                    } else {
//                        while (cell.contentView.subviews.lastObject != nil) {
//                            [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
//                        }
//                    }
freecui's avatar
freecui committed
460 461 462 463
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    if (self.isHiddenEdit) {
                        cell.editBtn.hidden = YES;
                    }
freecui's avatar
freecui committed
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
                    if ([self isHaveIndexPath:indexPath]) {
                        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;
                    }else{
                        cell.smallImageView.image = [UIImage imageNamed:@"arrowright"];
                        CGRect Linefrmame = cell.lineLabel.frame;
                        Linefrmame.origin.y = GXF_TABLEVIEW_NOMALCELL_HEIGHT-1;
                        cell.lineLabel.frame = Linefrmame;
                        CGRect showfrmame = cell.showView.frame;
                        showfrmame.size.height = 0;
                        cell.showView.frame = showfrmame;
                        cell.backgroundColor = [UIColor whiteColor];
freecui's avatar
freecui committed
482
                    }
freecui's avatar
freecui committed
483 484 485 486
                    cell.editBtn.tag = indexPath.row;
                    [cell.editBtn addTarget:self action:@selector(editClick:) forControlEvents:UIControlEventTouchUpInside];
                    return cell;

freecui's avatar
freecui committed
487
                } else {
freecui's avatar
freecui committed
488 489 490 491 492 493 494
                   // GXFProcessMaterialTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIDProduct];
                    //if (cell == nil) {
                        
                        GXFProcessMaterial *processM = (GXFProcessMaterial *)_d_materialMuArr[indexPath.row - 2];
                      GXFProcessMaterialTableViewCell * cell = [[ GXFProcessMaterialTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIDMaterial processMaterial:processM];
                        
                   // }
freecui's avatar
freecui committed
495 496 497 498
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    if (self.isHiddenEdit) {
                        cell.editBtn.hidden = YES;
                    }
freecui's avatar
freecui committed
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
                    if ([self isHaveIndexPath:indexPath]) {
                        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;
                    }else{
                        cell.smallImageView.image = [UIImage imageNamed:@"arrowright"];
                        CGRect Linefrmame = cell.lineLabel.frame;
                        Linefrmame.origin.y = GXF_TABLEVIEW_NOMALCELL_HEIGHT-1;
                        cell.lineLabel.frame = Linefrmame;
                        CGRect showfrmame = cell.showView.frame;
                        showfrmame.size.height = 0;
                        cell.showView.frame = showfrmame;
                        cell.backgroundColor = [UIColor whiteColor];
                    }
                    cell.editBtn.tag = indexPath.row;
                    [cell.editBtn addTarget:self action:@selector(editClick:) forControlEvents:UIControlEventTouchUpInside];
                    return cell;
freecui's avatar
freecui committed
521

freecui's avatar
freecui committed
522 523 524 525
                
                
                }
                
freecui's avatar
freecui committed
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
            }
           
    }
}

#pragma UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        GXFTableViewCell *xfCell = (GXFTableViewCell *)[_c_tableView cellForRowAtIndexPath:indexPath];
        switch (indexPath.row) {
            case kVendor:
            {
                GXFSearchVendorViewController *vc = [[GXFSearchVendorViewController alloc]initWithTitle:[IBTCommon localizableString:@"VendorTitle"]];
                vc.choseVendor = ^(NSArray *vendors){
                    if (vendors.count > 0) {
                        Vendor *vendor = vendors[0];
                        xfCell.f_textField.text = [NSString stringWithFormat:@"%@[%@]",vendor.name,vendor.code];
                        _d_processBill.vendor_uuid = vendor.uuid;
                        _d_processBill.vendor_code = vendor.code;
                        _d_processBill.vendor_name = vendor.name;
                    }
                };
                [self PushViewController:vc animated:YES];
            }
                break;
            case kWarehouse:
            {
                GXFSearchVendorViewController *vc = [[GXFSearchVendorViewController alloc]initWithTitle:[IBTCommon localizableString:@"WarehouseTitle"]];
                vc.choseVendor = ^(NSArray *vendors){
                    if (vendors.count > 0) {
                        Warehouse *warehouse = vendors[0];
                        xfCell.f_textField.text = [NSString stringWithFormat:@"%@[%@]",warehouse.name,warehouse.code];
                        _d_processBill.warehouse_uuid = warehouse.uuid;
                        _d_processBill.warehouse_code = warehouse.code;
                        _d_processBill.warehouse_name = warehouse.name;
                    }
                };
                [self PushViewController:vc animated:YES];
            }
                
                break;
                
            default:
                break;
        }

    } else {
    
freecui's avatar
freecui committed
574 575
    ProductBillCell *cell = (ProductBillCell *)[tableView cellForRowAtIndexPath:indexPath];
       // ProductCell *cell = (ProductCell *)[tableView cellForRowAtIndexPath:indexPath];
freecui's avatar
freecui committed
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
        CGRect Linefrmame = cell.lineLabel.frame;
        CGRect showfrmame = cell.showView.frame;
        if (Linefrmame.origin.y == GXF_TABLEVIEW_NOMALCELL_HEIGHT - 1) {
            cell.smallImageView.image = [UIImage imageNamed:@"arrowdown"];
            
            Linefrmame.origin.y = 200-1;
            showfrmame.size.height = 150;
            cell.backgroundColor = [UIColor whiteColor];
            [_selectRowArr addObject:indexPath];
        }else{
            cell.smallImageView.image = [UIImage imageNamed:@"arrowright"];
            Linefrmame.origin.y = GXF_TABLEVIEW_NOMALCELL_HEIGHT -1;
            showfrmame.size.height = 0;
            cell.backgroundColor = [UIColor whiteColor];
            [_selectRowArr removeObject:indexPath];
        }
        cell.lineLabel.frame = Linefrmame;
        cell.showView.frame = showfrmame;
freecui's avatar
freecui committed
594 595 596
        [self p_refreshData];
//        NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndex:1];
//        [self.c_tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
freecui's avatar
freecui committed
597 598 599 600 601 602 603 604 605 606 607 608 609 610

    
    }
}

- (BOOL)isHaveIndexPath:(NSIndexPath *)indexPath{
    for (NSIndexPath *path in _selectRowArr) {
        if (path.row == indexPath.row) {
            return YES;
        }
    }
    return NO;
}
#pragma buttonAction 
freecui's avatar
freecui committed
611
- (void)addNewInfoDetailed {
freecui's avatar
freecui committed
612

freecui's avatar
freecui committed
613 614 615 616
    if (_d_isProduct) {
        GXFPopNewProductViewController *productVC = [[GXFPopNewProductViewController alloc]init];
        [self PushViewController:productVC animated:NO];
    } else {
freecui's avatar
freecui committed
617 618
    GXFPopNewMaterialViewController *materialVC = [[GXFPopNewMaterialViewController alloc]init];
    [self PushViewController:materialVC animated:YES];
freecui's avatar
freecui committed
619
    }
freecui's avatar
freecui committed
620 621
  
}
freecui's avatar
freecui committed
622 623 624
- (void)editClick: (UIButton *)btn{
    if (_d_isProduct) {
        self.d_editOrDelete = btn.tag - 2;
freecui's avatar
freecui committed
625
        GXFProcessProduct *product = _d_productMuArr[btn.tag - 2];
freecui's avatar
freecui committed
626 627 628
        GXFPopNewProductViewController *productVC = [[GXFPopNewProductViewController alloc]initWithProcessProduct:product isEdit: YES];
        [self PushViewController:productVC animated:NO];
    } else {
freecui's avatar
freecui committed
629 630 631 632
        self.d_editOrDelete = btn.tag - 2;
        GXFProcessMaterial *material = _d_materialMuArr[btn.tag - 2];
        GXFPopNewMaterialViewController *materialVC = [[GXFPopNewMaterialViewController alloc]initWithProcessMaterial:material isEdit:YES];
        [self PushViewController:materialVC animated:NO];
freecui's avatar
freecui committed
633 634
    }
}
freecui's avatar
freecui committed
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
- (void)selecNewMaterial {
    self.d_isProduct = !_d_isProduct;
    if (!_d_isProduct) {
        [self.c_materialView.f_btn setTitleColor:GXF_GREEN_COLOR forState:UIControlStateNormal];
        self.c_materialView.f_line.backgroundColor = GXF_GREEN_COLOR;
        
        [self.c_productView.f_btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.c_productView.f_line.backgroundColor = [UIColor whiteColor];
        
    } else {
        [self.c_materialView.f_btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.c_materialView.f_line.backgroundColor = [UIColor whiteColor];
        
        [self.c_productView.f_btn setTitleColor:GXF_GREEN_COLOR forState:UIControlStateNormal];
        self.c_productView.f_line.backgroundColor = GXF_GREEN_COLOR;
    }

freecui's avatar
freecui committed
652 653 654
    [self p_refreshData];
//    NSIndexSet *indexSet = [[NSIndexSet alloc]initWithIndex:1];
//     [self.c_tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
freecui's avatar
freecui committed
655 656 657 658
}

#pragma GXFBottomViewDelegate
- (void)bottomViewleftButtonClicked:(UIButton *)leftBtn {
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
    [self p_processBillSaveOrFinishWithIsSave:NO];
//    void(^succ)(id) = ^(id data) {
//        [IBTLoadingView hideHUDWithText:nil];
//        CLog(@"%@",data[@"message"]);};
//    void(^fail)(id) = ^(id data) {
//        [IBTLoadingView hideHUDWithText:nil];
//        [IBTLoadingView showTips:data];
//    };
//    
//    NSDictionary *material = @{@"basePrice":@"222",@"baseQty":@"3434",@"instockDate":@"2015-09-08 10:24:23",@"place":@"测试",
//                               @"productCode":@"100101",@"productName":@"可比克薯片紫色",@"productUuid":@"5a7417014e29bb2c014e351643f70032",@"quality":@"123",
//                               @"remark":@"",@"total":@"4",@"uuid":[NSNull null]};
//    NSDictionary *product =  @{@"baseQty":@"2344",@"outstockDate":@"2015-09-08 10:24:42",@"productCode":@"农夫山泉",@"productName":@"dd",
//                                @"productUuid":@"402880e64e287fe2014e28895b8a0032",@"qpc":@"123",@"qpcStr":@"1 X123.0",@"quantity":@"234",
//                              @"remark":@"",@"unit":@"篮",@"uuid":[NSNull null]};
//    NSDictionary *para = @{//@"uuid":@"",
//                           @"contact":@"222",
//                           @"contactPhone":@"3434",
//                           @"materials":@[material],
//                           @"products":@[product],
//                           @"remark":@"100101",@"title":@"可色",@"total":@"32",@"vendor_code":@"0001",
//                           @"vendor_name":@"卖香蕉的",@"vendor_uuid":@"297e48a24f0e3750014f0e3850a60001",@"version":@"0",@"warehouse_code":@"4028e4284f6e3ce5014f6e41a01b0001",@"warehouse_name":@"123",@"warehouse_uuid":@"123"};
// [[ICRHTTPController sharedController] saveProcessWithAuthenticode:para success:succ failure:fail];
freecui's avatar
freecui committed
682 683
}
- (void)bottomViewRightButtonClicked:(UIButton *)rightBtn {
684 685 686 687
    [self p_processBillSaveOrFinishWithIsSave:YES];
}

- (void)p_processBillSaveOrFinishWithIsSave: (BOOL)isSave {
freecui's avatar
freecui committed
688 689
    CLog(@"ffff");
    //[IBTCommon checkString:_d_processBill.title]
freecui's avatar
freecui committed
690 691 692 693 694 695 696 697 698 699 700
    //    if ([IBTCommon checkStringIsNilOrSpance:_d_processBill.title]) {
    //        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示信息" message:@"标题不能为空" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    //        [alert show];
    //        return;
    //    }
    //    if ([IBTCommon checkStringIsNilOrSpance:_d_processBill.vendor_name]) {
    //        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示信息" message:@"请选择供应商" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    //        [alert show];
    //        return;
    //    }
    
freecui's avatar
freecui committed
701 702 703 704 705 706 707
    if ([IBTCommon checkStringIsNilOrSpance:_d_processBill.warehouse_name]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示信息" message:@"请选择加工工厂" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
    
    
freecui's avatar
freecui committed
708 709
    
    
freecui's avatar
freecui committed
710 711 712
    //保存
    void(^succ)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
freecui's avatar
freecui committed
713
        CLog(@"%@",data[@"message"]);
freecui's avatar
freecui committed
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
        //        if (data) {
        //            NSInteger success = [data[@"success"] integerValue];
        //            NSString *message = data[@"message"];
        //            if (success == 1) {
        //                //成功
        //                if ([state isEqualToString:@"initial"]) {//保存成功
        //                    [IBTLoadingView showTips:@"操作成功"];
        //                }else{//提交成功
        //                    SurveyViewController *svc = [SurveyViewController new];
        //                    [self PushViewController:svc animated:YES];
        //                }
        //            }else{
        //                [IBTLoadingView showTips:message];
        //            }
        //        }
    };
    void(^fail)(id) = ^(id data) {
        [IBTLoadingView hideHUDWithText:nil];
        [IBTLoadingView showTips:data];
    };
freecui's avatar
freecui committed
734 735 736 737 738 739 740 741 742 743 744 745
    
    //    if(self.survey.uuid.length > 0 && uuidObject == [NSNull null]){
    //        uuidObject = self.survey.uuid;
    //    }
    //    if (self.survey.billNumber > 0 && billNumberObject == [NSNull null]) {
    //        billNumberObject = self.survey.billNumber;
    //    }
    //    if (self.survey && [version integerValue] == 0) {
    //        version = self.survey.version;
    //    }
    
    NSMutableArray *productMuArr = [NSMutableArray array];
freecui's avatar
freecui committed
746 747 748 749 750 751
    for (int count = 0; count < _d_productMuArr.count; count ++) {
        GXFProcessProduct *product = (GXFProcessProduct *)_d_productMuArr[count];
        NSMutableDictionary *dic = [product mutableDictDateToStringForCommit];
        
        //       NSDictionary *materialdict = @{@"uuid":@"11",@"productUuid":@"402880e64e287fe2014e28895b8a0032",@"productCode":@"农夫山泉",@"productName":@"dd",@"outstockDate":@"2015-09-05 13:36:16 +0000",@"unit":@"",@"qpc":@"kk",@"qpcStr":@"ll",@"quality":@"9",@"baseQty":@"8",@"remark":@""};
        [productMuArr addObject:dic];//productdict];
freecui's avatar
freecui committed
752 753 754
    }
    
    NSMutableArray *materialMuArr = [NSMutableArray array];
freecui's avatar
freecui committed
755
    for (int count = 0; count < _d_materialMuArr.count; count ++) {
freecui's avatar
freecui committed
756
        GXFProcessMaterial *material = (GXFProcessMaterial *)_d_materialMuArr[count];
freecui's avatar
freecui committed
757 758 759 760
        NSMutableDictionary *dic = [material mutableDictDateToStringForCommit];
        
        //        NSDictionary *productdict = @{@"uuid":@"",@"productUuid":@"402880e64e287fe2014e28895b8a0032",@"productCode":@"农夫山泉",@"productName":@"dd",@"outstockDate":@"2015-09-05 13:36:16 +0000",@"place":@"",@"quality":@"",@"baseQty":@"1",@"basePrice":@"2",@"total":@"2",@"remark":@""};
        [materialMuArr addObject:dic];//materialdict];
freecui's avatar
freecui committed
761 762
    }
    
freecui's avatar
freecui committed
763 764
    [IBTLoadingView showProgressLabel:@"正在加载..."];
    NSDictionary *dict = @{
765 766 767 768
                           @"uuid":_isProccessing?[IBTCommon checkString:_d_processBill.uuid]:[NSNull null],
                           @"version":_isProccessing?_d_processBill.version:@(0),
                           @"billNumber":_isProccessing?[IBTCommon checkString:_d_processBill.billNumber]:[NSNull null],
                           @"title":[IBTCommon checkString:_d_processBill.title],
freecui's avatar
freecui committed
769 770 771
                           @"vendor_uuid": _d_processBill.vendor_uuid,
                           @"vendor_code": _d_processBill.vendor_code,
                           @"vendor_name": _d_processBill.vendor_name,
freecui's avatar
freecui committed
772 773 774 775 776 777 778 779 780 781
                           @"warehouse_uuid":_d_processBill.warehouse_uuid,
                           @"warehouse_code":_d_processBill.warehouse_code,
                           @"warehouse_name":_d_processBill.warehouse_name,
                           @"contact":[IBTCommon checkString: _d_processBill.contact],
                           @"contactPhone":[IBTCommon checkString:_d_processBill.contactPhone],
                           @"total":_d_processBill.total,
                           @"remark":[IBTCommon checkString:_d_processBill.remark],
                           @"materials":materialMuArr,
                           @"products":productMuArr};
    //[IBTLoadingView showProgressLabel:msg];
782 783 784 785 786 787 788
    if (isSave) {
         [[ICRHTTPController sharedController] saveProcessWithAuthenticode:dict success:succ failure:fail];
    } else {
        [[ICRHTTPController sharedController] finishProcessWithAuthenticode:dict success:succ failure:fail];
    }
   
 
freecui's avatar
freecui committed
789 790 791 792 793 794 795 796 797 798
}
/*
 kTitle = 0, 不为空
 kVendor, 不为空
 kContact,
 kContactPhone,
 kWarehouse, 不为空
 kTotal,
 kRemark,
 */
freecui's avatar
freecui committed
799

freecui's avatar
freecui committed
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    switch (textField.tag) {
        case kTitle:
            self.d_processBill.title = textField.text;
            break;
        case kVendor:
           // self.d_processBill.title = textField.text;
            break;
        case kContact:
            self.d_processBill.contact = textField.text;
            break;
        case kContactPhone:
            self.d_processBill.contactPhone = textField.text;
            break;
        case kTotal:
freecui's avatar
freecui committed
815
            self.d_processBill.total = @([textField.text floatValue]);
freecui's avatar
freecui committed
816 817 818 819 820 821 822 823 824 825 826 827
            break;
        case kRemark:
            self.d_processBill.remark = textField.text;
            break;
        default:
            break;
    }
    [textField resignFirstResponder];
    
    return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
freecui's avatar
freecui committed
828
    [self textFieldShouldReturn:textField];
freecui's avatar
freecui committed
829 830 831 832 833 834 835 836 837 838
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end