// // TransportBoltView.m // XFFruit // // Created by 陈俊俊 on 15/9/7. // Copyright (c) 2015年 Xummer. All rights reserved. // #import "TransportBoltView.h" #import "MaskCell.h" #define TableHeight 45 #define LeftMargin 80 #define TotalHeight 224 #define LeftHeight 44 #define BottomHeight 50 @interface TransportBoltView () { UIView *_leftView; UIButton *_currentBtn; NSIndexPath *_currentIndexPath; NSString *_state; NSString *_billNumber; NSString *_title; UIButton *_clearBtn; } @property (nonatomic,strong)NSString *state; @property (nonatomic,strong)NSString *billNumber; @property (nonatomic,strong)NSString *userNumber; @end @implementation TransportBoltView - (instancetype)initWithFrame:(CGRect)frame state:(NSString *)state userNumber:(NSString *)userNumber billNumber:(NSString *)billNumber{ self = [super initWithFrame:frame]; if (self) { self.userNumber = userNumber; self.billNumber = billNumber; self.state = state; [self createView]; [self createRightView]; [self preferData]; } return self; } - (void)preferData{ if ([self.state isEqualToString:TRANSPORT_STATE_INITIAL]) { _currentIndexPath = [NSIndexPath indexPathForRow:0 inSection:0]; }else if ([self.state isEqualToString:TRANSPORT_STATE_UNRECEIVED]) { _currentIndexPath = [NSIndexPath indexPathForRow:1 inSection:0]; }else if ([self.state isEqualToString:TRANSPORT_STATE_RECEIVED]) { _currentIndexPath = [NSIndexPath indexPathForRow:2 inSection:0]; }else if ([self.state isEqualToString:TRANSPORT_STATE_ABORTED]) { _currentIndexPath = [NSIndexPath indexPathForRow:3 inSection:0]; } self.userFiled.hidden = YES; if(self.userNumber.length > 0){ self.userFiled.text = self.userNumber; } self.billFiled.hidden = YES; if (self.billNumber.length > 0) { self.billFiled.text = self.billNumber; } } #pragma mark - 创建视图 - (void)createView { _leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, LeftMargin,self.frame.size.height- BottomHeight)]; [self addSubview:_leftView]; NSArray *arr = @[@"按状态",@"创建人代码",@"调研单号"]; for (NSInteger i = 0; i 0) { _billFiled.text = @""; } if (_userFiled.text.length > 0) { _userFiled.text = @""; } if (_currentIndexPath) { _currentIndexPath = nil; [self.tableView reloadData]; } if ([self.delegate respondsToSelector:@selector(clearBoltInformation)]) { [self.delegate clearBoltInformation]; } } #pragma mark - 协议 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArr.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellID = @"MaskID"; MaskCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (cell == nil) { cell = [[MaskCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID totalWidth: ScreenSize.width - 80 totalHeight:TableHeight]; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone; } if (_dataArr.count > 0) { cell.Commitbtn.hidden = YES; [cell setTitleStr:self.dataArr[indexPath.row]]; } if (_currentIndexPath) { if (indexPath.row == _currentIndexPath.row) { cell.Commitbtn.hidden = NO; }else{ cell.Commitbtn.hidden = YES; } } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ //获取选中的cell MaskCell *currentCell = (MaskCell *)[tableView cellForRowAtIndexPath:_currentIndexPath]; currentCell.Commitbtn.hidden = YES; MaskCell *cell = (MaskCell *)[tableView cellForRowAtIndexPath:indexPath]; cell.Commitbtn.hidden = NO; _currentIndexPath = indexPath; //initial(未提交)submitted(已提交)rejected(已拒绝)approved(已审批)shipping(发运中)finished(已完成) NSString *stateStr = @""; if (indexPath.row == 0) { stateStr = TRANSPORT_STATE_INITIAL; }else if(indexPath.row == 1){ stateStr = TRANSPORT_STATE_UNRECEIVED; }else if(indexPath.row == 2){ stateStr = TRANSPORT_STATE_RECEIVED; }else if(indexPath.row == 3){ stateStr = TRANSPORT_STATE_ABORTED; } [self.delegate getBoltValueSelectRow:stateStr]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return TableHeight; } - (BOOL)textFieldShouldReturn:(UITextField *)textField{ [self keyBoardHidden]; return YES; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ [self keyBoardHidden]; } - (void)keyBoardHidden{ [self.userFiled resignFirstResponder]; [self.billFiled resignFirstResponder]; } - (void)textFieldDidEndEditing:(UITextField *)textField{ if (textField == self.userFiled) { if (self.userFiled.text.length > 0) { [self.delegate getuserLike:self.userFiled.text]; } }else if(textField == self.billFiled){ if (self.billFiled.text.length > 0) { [self.delegate getbillLike:self.billFiled.text]; } } } @end