GXFPopNewMaterialViewController.m 11.9 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
//
//  GXFPopNewMaterialView.m
//  XFFruit
//
//  Created by freecui on 15/9/3.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//


//#define GXF_LEFT_MARGIIN 0
//#define GXF_TABLEVIEW_HEADER_HEITHT 50
//#define GXF_TABLEVIEW_FOOT_HEITHT 50


#import "GXFPopNewMaterialViewController.h"
#import "GXFBottomView.h"
#import "GXFTableViewCell.h"
#import "StartTimeView.h"
#import "GXFProcessMaterial.h"
freecui's avatar
freecui committed
20 21 22
#import "GXFSearchVendorViewController.h"
#import "Product.h"

freecui's avatar
freecui committed
23 24
@interface GXFPopNewMaterialViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,StartTimeViewDelegate,GXFBottomViewDelegate>
{
freecui's avatar
freecui committed
25
    
freecui's avatar
freecui committed
26 27 28 29 30 31 32 33 34
    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) GXFProcessMaterial *d_processMaterial;
@property (nonatomic, strong) NSIndexPath *d_dateIndexPath;
freecui's avatar
freecui committed
35 36 37
@property (nonatomic, assign) BOOL d_hasSaved;
@property (nonatomic, strong) GXFBottomView *c_bottomV;

freecui's avatar
freecui committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
@end
@implementation GXFPopNewMaterialViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"新增原料明细";
    [self initData];
    [self initSubViews];
}



- (void)initData {
    self.d_leftArr = @[@"原料商品:",@"入库日期:",@"产地:",@"品质描述:",@"基础数量",@"基础单价:",@"总金额:",@"备注:",];
    self.d_rightArr = @[@"选择商品",@"",@"输入产地",@"输入品质描述",@"基础数量",@"基础单价",@"总金额",@"输入备注内容"];
    self.d_lableTextArr = @[@"斤",@"元",@"元"];
    self.d_processMaterial = [[GXFProcessMaterial alloc]init];
}
- (void)initSubViews {
    //self.view.backgroundColor =  RGBA(0, 0, 0, 0.5);
    
//    CGFloat tableVH =  GXF_TABLEVIEW_FOOT_HEITHT + GXF_TABLEVIEW_HEADER_HEITHT + GXF_TABLEVIEW_NOMALCELL_HEIGHT * _d_leftArr.count;
    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
68
    GXFBottomView *bottomV = [[GXFBottomView alloc]initWithFrame:CGRectMake(0, _c_tableView.bottom, self.view.width, BottomViewHeight) leftButtonColor:GXF_ORIGIN_COLOR rightButtonColor:GXF_GREEN_COLOR LeftBtnTitle:@"删除" rightBtnTitle:@"保存"];// [[GXFBottomView alloc]initWithFrame:CGRectMake(0, _c_tableView.bottom, self.view.width, BottomViewHeight) LeftBtnTitle:@"删除" rightBtnTitle:@"保存"];
freecui's avatar
freecui committed
69
    bottomV.delegate = self;
freecui's avatar
freecui committed
70 71
    self.c_bottomV = bottomV;
    [self.view addSubview:_c_bottomV];
freecui's avatar
freecui committed
72 73 74 75 76 77 78 79 80 81

    
    
    
}

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

//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
//    return GXF_TABLEVIEW_HEADER_HEITHT;
//}
//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
//    return GXF_TABLEVIEW_FOOT_HEITHT;
//}
//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
//    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _c_tableView.width, GXF_TABLEVIEW_HEADER_HEITHT)];
//    IBTUILabel *lbl = [[IBTUILabel alloc]initWithFrame:headerView.frame Text:@"新增原料明细" textAligment:NSTextAlignmentCenter backgroundColor:GXF_LABLE_BG_COLOR textColor:GXF_LABLE_TINT_COLOR font:GXF_LABLE_FONT];
//    UIButton *btn = [IBTCustomButtom creatButtonWithFrame:CGRectMake(_c_tableView.width - GXF_TABLEVIEW_HEADER_HEITHT, 0, GXF_TABLEVIEW_HEADER_HEITHT, GXF_TABLEVIEW_HEADER_HEITHT) target:self sel:@selector(closeClicked) tag:0 image:nil title:@"关闭" titleColor:[UIColor blackColor] isCorner:NO corner:0 bgColor:nil];
//   
//    [headerView addSubview:lbl];
//     [headerView addSubview:btn];
//    return headerView;
//}
//- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
//    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _c_tableView.width, GXF_TABLEVIEW_HEADER_HEITHT )];
//    GXFBottomView *bottomV = [[GXFBottomView alloc]initWithFrame:footView.frame LeftBtnTitle:@"删除" rightBtnTitle:@"保存"];
//    [footView addSubview:bottomV];
//    return footView;
//}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    GXFTableViewCell *xfCell ;
        xfCell.width = _c_tableView.width;
freecui's avatar
freecui committed
113
    if (indexPath.row == 0 || indexPath.row == 1) {
freecui's avatar
freecui committed
114 115 116 117 118 119
        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;
       
        }
freecui's avatar
freecui committed
120
    } else if ( indexPath.row == 2 || indexPath.row == 3 || indexPath.row == 7) {
freecui's avatar
freecui committed
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
        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 == 4 || indexPath.row == 5 || indexPath.row == 6) {
        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 - 4]];
        
        }
        
    }
    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];
    return xfCell;

}
#pragma UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
freecui's avatar
freecui committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159
     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_processMaterial.productUuid = product.uuid;
                _d_processMaterial.productCode = product.code;
                _d_processMaterial.productName = product.name;
            }
        };
        [self PushViewController:vc animated:YES];
    }
freecui's avatar
freecui committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 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
    if (indexPath.row == 1) {
        [self startDatePickView];
        self.d_dateIndexPath = indexPath;
        
    }
}


#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_processMaterial.instockDate = 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)textFieldDidBeginEditing:(UITextField *)textField {
//    if (textField.tag == 1) {
//        [textField resignFirstResponder];
//    }
//    CGFloat texfFiledH = GXF_TABLEVIEW_NOMALCELL_HEIGHT * (textField.tag + 1) + 64;
//    CGFloat offset = KeyboardHeight - (ScreenSize.height - texfFiledH) ;
//    if (offset > 0) {
//        [self setTableFrame: offset];
//        
//    }
//  
//}
- (void)textFieldDidEndEditing:(UITextField *)textField {
    [self textFieldShouldReturn:textField];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
   // [self recoverTableViewFrame];
    [textField resignFirstResponder];
    switch (textField.tag) {
        case 0:
            self.d_processMaterial.productName = textField.text;
            break;
        case 1:
           // self.d_processMaterial.productName = textField.text;
            break;
        case 2:
            self.d_processMaterial.place = textField.text;
            break;
        case 3:
            self.d_processMaterial.quality = textField.text;
            break;
        case 4:
            self.d_processMaterial.baseQty = [NSNumber numberWithFloat:[textField.text floatValue]];
            break;
        case 5:
            self.d_processMaterial.basePrice = [NSNumber numberWithFloat:[textField.text floatValue]];;
            break;
        case 6:
            self.d_processMaterial.total = [NSNumber numberWithFloat:[textField.text floatValue]];;
            break;
        case 7:
            self.d_processMaterial.remark = textField.text;
            break;
        default:
            break;
    }
    return YES;
freecui's avatar
freecui committed
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
}


#pragma GXFBottomViewDelegate
- (void)bottomViewleftButtonClicked:(UIButton *)leftBtn {

}
- (void)bottomViewRightButtonClicked:(UIButton *)rightBtn {
    self.d_hasSaved = YES;
    [self.c_bottomV.f_rightBtn setBackgroundColor:GXF_GRAY_COLOR];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_saveMaterial object:_d_processMaterial];
    
    

freecui's avatar
freecui committed
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
}
//- (void)setTableFrame: (CGFloat)tableOffset {
//    [UIView animateWithDuration:0.25 animations:^{
//        CGRect tableFrame = _c_tableView.frame;
//        tableFrame.origin.y -=  tableOffset;
//        self.c_tableView.frame = tableFrame;
//    }];
//}
//- (void)recoverTableViewFrame {
//    [UIView animateWithDuration:0.25 animations:^{
//        CGRect tableFrame = _c_tableView.frame;
//        tableFrame.origin.y = 0;
//        self.c_tableView.frame = tableFrame;
//    }];
//}

////注册通知观察者
//- (void)registerForKeyboardNotifications {
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
//    
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
//}
//
//- (void)keyboardWasShown: (NSNotification *)aNotification {
//    NSDictionary *info = [aNotification userInfo];
//    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
//    
//    [UIView animateWithDuration:0.25 animations:^{
//        CGRect tableFrame = _c_tableView.frame;
//        tableFrame.origin.y = kbSize.height;
//    }];
//}
@end