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



#import "GXFPopNewProductViewController.h"
#import "GXFBottomView.h"
#import "GXFTableViewCell.h"
#import "StartTimeView.h"
#import "GXFProcessProduct.h"
freecui's avatar
freecui committed
16 17 18
#import "GXFSearchVendorViewController.h"
#import "Product.h"
#import "GXFProductUnit.h"
freecui's avatar
freecui committed
19 20 21 22 23 24 25 26 27 28 29
@interface GXFPopNewProductViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,StartTimeViewDelegate,GXFBottomViewDelegate>
{
    StartTimeView *_startTimeView;
}
@property (nonatomic, strong) UIView *c_bgView;
@property (nonatomic, strong) UITableView *c_tableView;
@property (nonatomic, strong) NSArray *d_leftArr;//uitableView左边显示的提示
@property (nonatomic, strong) NSArray *d_rightArr;//右边placeholder提示
@property (nonatomic, strong) NSArray *d_lableTextArr;
@property (nonatomic, strong) GXFProcessProduct *d_processProduct;
@property (nonatomic, strong) NSIndexPath *d_dateIndexPath;
freecui's avatar
freecui committed
30 31 32
@property (nonatomic, assign) BOOL d_hasSaved;
@property (nonatomic, strong) GXFBottomView *c_bottomV;
@property (nonatomic, assign) BOOL d_isEdited;
freecui's avatar
freecui committed
33 34 35
@end
@implementation GXFPopNewProductViewController

freecui's avatar
freecui committed
36 37 38 39 40 41 42 43 44 45

- (instancetype)initWithProcessProduct:(GXFProcessProduct *)processProduct isEdit: (BOOL) isEdited{
    self = [super init];
    if (!self) {
        return nil;
    }
    self.d_processProduct = processProduct;
    self.d_isEdited = isEdited;
    return self;
}
freecui's avatar
freecui committed
46 47 48 49 50 51 52 53 54 55 56 57
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"新增成品明细";
    [self initData];
    [self initSubViews];
}




- (void)initData {
    self.d_leftArr = @[@"商品:",@"出库时间:",@"包装单位:",@"包装规格:",@"包装数量",@"基础数量:",@"备注:",];
freecui's avatar
freecui committed
58
    self.d_rightArr = @[@"选择商品",@"选择出库时间",@"选择包装单位",@"包装规格",@"包装数量",@"基础数量",@"输入备注内容"];
freecui's avatar
freecui committed
59
    self.d_lableTextArr = @[@"斤",@"筐",@"斤"];
freecui's avatar
freecui committed
60 61 62 63
    if (!_d_processProduct) {
         self.d_processProduct = [[GXFProcessProduct alloc]init];
    }
   
freecui's avatar
freecui committed
64 65 66 67 68 69 70 71 72 73 74
}
- (void)initSubViews {

    self.c_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.width , GXF_TABLEVIEW_NOMALCELL_HEIGHT * _d_leftArr.count) style:UITableViewStylePlain];
    
    self.c_tableView.delegate = self;
    self.c_tableView.dataSource = self;
    
    [self.view addSubview:_c_tableView];
    
    
freecui's avatar
freecui committed
75
    GXFBottomView *bottomV = [[GXFBottomView alloc]initWithFrame:CGRectMake(0, _c_tableView.bottom, self.view.width, BottomViewHeight) leftButtonColor:GXF_ORIGIN_COLOR rightButtonColor:GXF_GREEN_COLOR LeftBtnTitle:@"删除" rightBtnTitle:@"保存"];;
freecui's avatar
freecui committed
76
    bottomV.delegate = self;
freecui's avatar
freecui committed
77
    self.c_bottomV = bottomV;
freecui's avatar
freecui committed
78 79 80 81 82 83 84 85 86 87 88
    [self.view addSubview:bottomV];
    
    
    
    
}

- (void)viewDidAppear:(BOOL)animated {
    // [self registerForKeyboardNotifications];
}
- (void)viewWillDisappear:(BOOL)animated {
freecui's avatar
freecui committed
89
    [[NSNotificationCenter defaultCenter] removeObserver:self];
freecui's avatar
freecui committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
}
#pragma UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _d_leftArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    GXFTableViewCell *xfCell ;
    xfCell.width = _c_tableView.width;
    if ( indexPath.row == 0 || indexPath.row == 1 ||indexPath.row == 2) {
        xfCell = [tableView dequeueReusableCellWithIdentifier:arrowCell];
        if (!xfCell) {
            xfCell = [[GXFTableViewCell alloc]initWithWidth:_c_tableView.width Style:UITableViewCellStyleDefault reuseIdentifier:arrowCell textFieldPlaceholder:_d_rightArr[indexPath.row] isEdit:NO];
            xfCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            
        }
    } else if (  indexPath.row == 6) {
        xfCell = [tableView dequeueReusableCellWithIdentifier:noLblCell];//-
        if (!xfCell) {
            xfCell = [[GXFTableViewCell alloc]initWithWidth:_c_tableView.width Style:UITableViewCellStyleDefault reuseIdentifier:arrowCell textFieldPlaceholder:_d_rightArr[indexPath.row] isEdit:YES];
        }
        
    }else if (indexPath.row == 3 || indexPath.row == 4 || indexPath.row == 5) {
        xfCell = [tableView dequeueReusableCellWithIdentifier:lblCell];  //
        if (!xfCell) {
            xfCell = [[GXFTableViewCell alloc]initWithWidth:_c_tableView.width Style:UITableViewCellStyleDefault reuseIdentifier:lblCell textFieldPlaceholder:_d_rightArr[indexPath.row] hasLable:YES backLableText:_d_lableTextArr[indexPath.row - 3]];
freecui's avatar
freecui committed
116
             xfCell.f_textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
freecui's avatar
freecui committed
117 118 119 120 121 122 123 124 125 126
        }
        
    }
    if (xfCell.f_textField) {
        xfCell.f_textField.delegate = self;
    }
    
    xfCell.selectionStyle = UITableViewCellAccessoryNone;
    xfCell.f_textField.tag = indexPath.row;
    xfCell.textLabel.text = _d_leftArr[indexPath.row];
freecui's avatar
freecui committed
127 128 129
    if (_d_isEdited) {
        switch (indexPath.row) {
            case 0:
130
                xfCell.f_textField.text = [IBTCommon checkNull:_d_processProduct.productName];//_d_processProduct.productName;
freecui's avatar
freecui committed
131 132
                break;
            case 1:
133 134
                
                xfCell.f_textField.text = [IBTCommon checkNull:_d_processProduct.outstockDate];//[NSString stringWithFormat:@"%@",_d_processProduct.outstockDate];
freecui's avatar
freecui committed
135 136
                break;
            case 2:
137
                xfCell.f_textField.text = [IBTCommon checkNull:_d_processProduct.unit];//_d_processProduct.unit;
freecui's avatar
freecui committed
138 139
                break;
            case 3:
140
                xfCell.f_textField.text = [IBTCommon checkNull:_d_processProduct.qpc];//[NSString stringWithFormat:@"%@",_d_processProduct.qpc];
freecui's avatar
freecui committed
141 142
                break;
            case 4:
143
                xfCell.f_textField.text = [IBTCommon checkNull:_d_processProduct.quantity];//[NSString stringWithFormat:@"%@",_d_processProduct.quantity];
freecui's avatar
freecui committed
144 145
                break;
            case 5:
146
                xfCell.f_textField.text = [IBTCommon checkNull:_d_processProduct.baseQty];//[NSString stringWithFormat:@"%@",_d_processProduct.baseQty];
freecui's avatar
freecui committed
147 148
                break;
            case 6:
149
                xfCell.f_textField.text = [IBTCommon checkNull:_d_processProduct.remark];//_d_processProduct.remark;
freecui's avatar
freecui committed
150 151 152 153 154 155
                break;
            default:
                break;
        }
        
    }
freecui's avatar
freecui committed
156 157 158 159 160 161
    return xfCell;
    
}
#pragma UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
freecui's avatar
freecui committed
162 163 164 165 166 167 168 169 170 171
     GXFTableViewCell *xfCell = (GXFTableViewCell *)[_c_tableView cellForRowAtIndexPath:indexPath];
    if (indexPath.row == 0) {
        GXFSearchVendorViewController *vc = [[GXFSearchVendorViewController alloc]initWithTitle:[IBTCommon localizableString:@"ProductTitle"]];
        vc.choseVendor = ^(NSArray *vendors){
            if (vendors.count > 0) {
                Product *product = vendors[0];
                xfCell.f_textField.text = [NSString stringWithFormat:@"%@[%@]",product.name,product.code];
                _d_processProduct.productUuid = product.uuid;
                _d_processProduct.productCode = product.code;
                _d_processProduct.productName = product.name;
172
                _d_processProduct.qpcStr = @"1 X123.0";//product.qpcStr;
freecui's avatar
freecui committed
173 174 175 176 177 178
            }
        };
        [self PushViewController:vc animated:YES];

    }
    
freecui's avatar
freecui committed
179 180 181 182 183
    if (indexPath.row == 1) {
        [self startDatePickView];
        self.d_dateIndexPath = indexPath;
        
    }
freecui's avatar
freecui committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197
    
    if (indexPath.row == 2) {
        GXFSearchVendorViewController *vc = [[GXFSearchVendorViewController alloc]initWithTitle:[IBTCommon localizableString:@"ProductUnitTitle"]];
        vc.choseVendor = ^(NSArray *vendors){
            if (vendors.count > 0) {
                GXFProductUnit *productUnit = vendors[0];
                xfCell.f_textField.text = [NSString stringWithFormat:@"%@[%@]",productUnit.name,productUnit.uuid];
                _d_processProduct.productUuid = productUnit.uuid;
                
                _d_processProduct.productName = productUnit.name;
            }
        };
        [self PushViewController:vc animated:YES];
    }
freecui's avatar
freecui committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 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
}


#pragma StartTimeViewDelegate
- (void)cancelTimeView{
    [self clearDatePickView];
}
- (void)okTimeView:(NSDate *)time{
    GXFTableViewCell *xfCell = (GXFTableViewCell *)[_c_tableView cellForRowAtIndexPath:_d_dateIndexPath];
    xfCell.f_textField.text = [IBTCommon stringFromDate:time]; ;
    self.d_processProduct.outstockDate = time;
    // 关闭选择器
    [self clearDatePickView];
}
#pragma mark - 取消
- (void)clearDatePickView{
    [UIView animateWithDuration:0.15 animations:^{
        CGRect startFrame =  _startTimeView.frame;
        startFrame.origin.y = ScreenSize.height;
        _startTimeView.frame = startFrame;
    } completion:^(BOOL finished) {
        [_startTimeView removeFromSuperview];
        _startTimeView = nil;
    }];
}

- (void)startDatePickView{
    if (!_startTimeView) {
        _startTimeView = [[StartTimeView alloc] initWithFrame:CGRectMake(0, ScreenSize.height, ScreenSize.width, ScreenSize.height - 64)];
        _startTimeView.delegate = self;
        _startTimeView.backgroundColor   = RGBA(0, 0, 0 ,0.5);
        [self.view addSubview:_startTimeView];
        
        [UIView animateWithDuration:0.15 animations:^{
            CGRect startFrame =  _startTimeView.frame;
            startFrame.origin.y =  0;
            _startTimeView.frame = startFrame;
        } completion:^(BOOL finished) {
            
        }];
    }
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    [self textFieldShouldReturn:textField];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    // [self recoverTableViewFrame];
    [textField resignFirstResponder];
    switch (textField.tag) {
        case 0:
            self.d_processProduct.productName = textField.text;
            break;
        case 1:
            // self.d_processProduct.productName = textField.text;
            break;
        case 2:
freecui's avatar
freecui committed
255
            self.d_processProduct.unit = @"筐";//textField.text;
freecui's avatar
freecui committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
            break;
        case 3:
            self.d_processProduct.qpc = [NSNumber numberWithFloat:[textField.text floatValue]];
            break;
        case 4:
            self.d_processProduct.quantity= [NSNumber numberWithFloat:[textField.text floatValue]];
            break;
        case 5:
            self.d_processProduct.baseQty = [NSNumber numberWithFloat:[textField.text floatValue]];;
            break;
       
        case 6:
            self.d_processProduct.remark = textField.text;
            break;
        default:
            break;
    }
    return YES;
}
freecui's avatar
freecui committed
275 276 277 278 279 280 281 282 283 284
#pragma GXFBottomViewDelegate
- (void)bottomViewleftButtonClicked:(UIButton *)leftBtn {
    [self.c_bottomV.f_leftBtn setBackgroundColor:GXF_GRAY_COLOR];
    if (_d_isEdited) {
        [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_deleteProduct object:_d_processProduct];
    }
}
- (void)bottomViewRightButtonClicked:(UIButton *)rightBtn {
    self.d_hasSaved = YES;
    [self.c_bottomV.f_rightBtn setBackgroundColor:GXF_GRAY_COLOR];
freecui's avatar
freecui committed
285
    self.d_processProduct.unit = @"筐";
freecui's avatar
freecui committed
286 287 288 289 290 291 292 293 294 295
    if (_d_isEdited) {
        [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_editProduct object:_d_processProduct];
    } else {
        [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_saveProduct object:_d_processProduct];
    }
    
    
    
}

freecui's avatar
freecui committed
296
@end