// // CustomerFilingSearchCell.m // IBOSS // // Created by 关宏厚 on 2020/8/28. // Copyright © 2020 elongtian. All rights reserved. // #import "CustomerFilingSearchCell.h" #import "BaseIDAndNameViewController.h" #import "UIColor+hexColor.h" #import "CustomerSearchModel.h" #import "SideSlipConfig.h" #import "BRDatePickerView.h" #import "BaseIDAndNameModel.h" #import "LogCommentVC.h" #import "LogShareAndCommentModel.h" @interface CustomerFilingSearchCell () // 抽屉model @property (strong,nonatomic) SideSlipModel *regionModel; // 日期对象 @property (strong,nonatomic) BRDatePickerView *dealDatePicker; // 临时开始日期 @property (copy, nonatomic) NSString *tempStartDate; // 临时结束日期 @property (copy, nonatomic) NSString *tempEndDate; @end @implementation CustomerFilingSearchCell /** 高度 @return return value description */ - (CGFloat)cellHeight { return 920.0f; } /** cell @param indexPath <#indexPath description#> @return <#return value description#> */ + (instancetype)createCellWithIndexPath:(NSIndexPath *)indexPath { CustomerFilingSearchCell *cell = [[NSBundle mainBundle] loadNibNamed:@"CustomerFilingSearchCell" owner:nil options:nil][0]; cell.txtCustomerName.delegate = cell; cell.txtTel.delegate = cell; cell.txtCustomerAddress.delegate = cell; cell.boolFlagValue = YES; cell.filedIntermediateCustomers.delegate = cell; [cell configureKeyboard]; return cell; } /** awakeFromNib */ - (void)awakeFromNib { [super awakeFromNib]; } /** Identifier @return <#return value description#> */ + (NSString *)cellReuseIdentifier { return @"CustomerFilingSearchCell"; } /** 有效无效标识 @return <#return value description#> */ - (NSMutableArray *)valueFlagArr{ if (_valueFlagArr == nil) { _valueFlagArr = [[NSMutableArray alloc]init]; BaseIDAndNameModel *m = [BaseIDAndNameModel new]; m.id = @"0"; m.name = @"有效"; [_valueFlagArr addObject:m]; m = [BaseIDAndNameModel new]; m.id = @"1"; m.name = @"无效"; [_valueFlagArr addObject:m]; } return _valueFlagArr; } /** 键盘配置 */ - (void)configureKeyboard { UIView *keyBoardAccessoryView = [self createKeyBoardAccessoryView]; _txtCustomerName.inputAccessoryView = keyBoardAccessoryView; _txtTel.inputAccessoryView = keyBoardAccessoryView; _txtCustomerAddress.inputAccessoryView = keyBoardAccessoryView; _filedIntermediateCustomers.inputAccessoryView = keyBoardAccessoryView; } /** 更新model @param model <#model description#> @param indexPath <#indexPath description#> */ - (void)updateCellWithModel:(SideSlipModel *__autoreleasing *)model indexPath:(NSIndexPath *)indexPath{ self.regionModel = *model; _isExistsSceneAttachment=NO; _isExistsDrawingAttachment=NO; _btnDrawingAttachment.layer.borderWidth=1; [ _btnDrawingAttachment setTitleColor:[UIColor colorWithRed:128/255 green:128/255 blue:128/255 alpha:1] forState:UIControlStateNormal]; _btnDrawingAttachment.layer.borderColor = [UIColor lightGrayColor].CGColor; _btnSceneAttachment.layer.borderWidth=1; [ _btnSceneAttachment setTitleColor:[UIColor colorWithRed:128/255 green:128/255 blue:128/255 alpha:1] forState:UIControlStateNormal]; _btnSceneAttachment.layer.borderColor = [UIColor lightGrayColor].CGColor; [self updateModel]; } /** 更新frame @param w <#w description#> */ - (void)updateFrame:(CGFloat)w{ } /** 重置按钮 事件 */ - (void)resetData { [_txtCustomerName setText:@""]; [_txtTel setText:@""]; [_txtCustomerAddress setText:@""]; [_btnFlagValue setTitle:@"请选择有效标识(默认有效)" forState:UIControlStateNormal]; _boolFlagValue = YES; [_btnStaDate setTitle:@"请选择开始日期" forState:UIControlStateNormal]; _sStartDate = @""; [_btnEndDate setTitle:@"请选择结束日期" forState:UIControlStateNormal]; _sEndDate = @""; [_filedIntermediateCustomers setText:@""]; _createUserID = @""; [_btnCreateUserName setTitle:@"请选择创建人" forState:UIControlStateNormal]; _isExistsDrawingAttachment=NO; _isExistsSceneAttachment=NO; [_btnSceneAttachment setTitle:@"全部" forState:UIControlStateNormal]; [_btnDrawingAttachment setTitle:@"全部" forState:UIControlStateNormal]; } /** 文本编辑时候 弹出取消完成按钮 @return <#return value description#> */ - (UIView *)createKeyBoardAccessoryView { UIView *keyBoardAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, ACCESSORY_VIEW_HEIGHT)]; [keyBoardAccessoryView setBackgroundColor:[UIColor hexColor:@"e1e1e1"]]; UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(ACCESSORY_BUTTON_LEADING_TRAILING, 0, ACCESSORY_BUTTON_WIDTH, ACCESSORY_VIEW_HEIGHT)]; [backButton setTitle:@"取消" forState:UIControlStateNormal]; [backButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; [backButton.titleLabel setFont:[UIFont systemFontOfSize:14.f]]; [backButton addTarget:self action:@selector(accessoryButtonBack) forControlEvents:UIControlEventTouchUpInside]; UIButton *doneButton = [[UIButton alloc] initWithFrame:CGRectMake(Screen_Width - ACCESSORY_BUTTON_LEADING_TRAILING - ACCESSORY_BUTTON_WIDTH, 0, ACCESSORY_BUTTON_WIDTH, ACCESSORY_VIEW_HEIGHT)]; [doneButton setTitle:@"完成" forState:UIControlStateNormal]; [doneButton setTitleColor:[UIColor hexColor:FILTER_RED_STRING] forState:UIControlStateNormal]; [doneButton.titleLabel setFont:[UIFont systemFontOfSize:14.f]]; [doneButton addTarget:self action:@selector(accessoryButtonDone) forControlEvents:UIControlEventTouchUpInside]; [keyBoardAccessoryView addSubview:backButton]; [keyBoardAccessoryView addSubview:doneButton]; return keyBoardAccessoryView; } /** 长度 @param textField <#textField description#> @param range <#range description#> @param string <#string description#> @return <#return value description#> */ - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { return YES; } /** 文本编辑结束事件 @param textField <#textField description#> */ - (void)textFieldDidEndEditing:(UITextField *)textField { [self updateModel]; } - (IBAction)clickSceneAttachmentAction:(id)sender { if(_isExistsSceneAttachment){ _isExistsSceneAttachment=NO; [_btnSceneAttachment setTitle:@"全部" forState:UIControlStateNormal]; _btnSceneAttachment.layer.borderWidth=1; [ _btnSceneAttachment setTitleColor:[UIColor colorWithRed:128/255 green:128/255 blue:128/255 alpha:1] forState:UIControlStateNormal]; _btnSceneAttachment.layer.borderColor = [UIColor lightGrayColor].CGColor; } else{ _isExistsSceneAttachment=YES; _btnSceneAttachment.layer.borderWidth=1; [_btnSceneAttachment setTitle:@"存在" forState:UIControlStateNormal]; [ _btnSceneAttachment setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; _btnSceneAttachment.layer.borderColor = [UIColor redColor].CGColor; } [self updateModel]; } - (IBAction)clickDrawingAttachmentAction:(id)sender { if(_isExistsDrawingAttachment){ _isExistsDrawingAttachment=NO; [_btnDrawingAttachment setTitle:@"全部" forState:UIControlStateNormal]; _btnDrawingAttachment.layer.borderWidth=1; [ _btnDrawingAttachment setTitleColor:[UIColor colorWithRed:128/255 green:128/255 blue:128/255 alpha:1] forState:UIControlStateNormal]; _btnDrawingAttachment.layer.borderColor = [UIColor lightGrayColor].CGColor; } else { _isExistsDrawingAttachment=YES; _btnDrawingAttachment.layer.borderWidth=1; [_btnDrawingAttachment setTitle:@"存在" forState:UIControlStateNormal]; [ _btnDrawingAttachment setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; _btnDrawingAttachment.layer.borderColor = [UIColor redColor].CGColor; } [self updateModel]; } /** 触摸事件 @param touches <#touches description#> @param event <#event description#> */ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self hideKey]; [_txtCustomerName resignFirstResponder]; [_txtCustomerAddress resignFirstResponder]; [_filedIntermediateCustomers resignFirstResponder]; [_txtTel resignFirstResponder]; } /** 有效标识 @param model <#model description#> @param value <#value description#> */ - (void)baseIDAndNameDoneDatas:(BaseIDAndNameModel *)model BaseIDAndName:(baseIdAndName)value{ if ([model.id isEqualToString:@"0"]) { self.boolFlagValue = YES; } if ([model.id isEqualToString:@"1"]) { self.boolFlagValue = NO; } [self.btnFlagValue setTitle:model.name forState:UIControlStateNormal]; [self updateModel]; } /** 取消文本 */ - (void)accessoryButtonBack { NSLog(@"accessoryButtonBack"); [self hideKey];} /** 确定文本 */ - (void)accessoryButtonDone { NSLog(@"accessoryButtonDone"); [_txtCustomerName resignFirstResponder]; [self hideKey]; } /** * 隐藏键盘 */ - (void)hideKey { [self.contentView endEditing:YES]; } /** 显示创建人列表 @param sender <#sender description#> */ - (IBAction)showCreateUserList:(id)sender { LogCommentVC *tc = [[LogCommentVC alloc] init]; tc.commentDelegate = self; tc.ispresentView = YES; if ([self.delegate respondsToSelector:@selector(sideSlipTableViewCellNeedsDismissViewController:animated:)]) { [self.delegate sideSlipTableViewCellNeedsDismissViewController:tc animated:YES]; } } /** 创建人回调 @param model <#model description#> */ - (void)reCommentData:(LogShareAndCommentInfoModel*)model { self.createUserID = model.userId; [_btnCreateUserName setTitle:model.userName forState:UIControlStateNormal]; [self updateModel]; } /** 开始日期 @param sender */ - (IBAction)showStaDate:(id)sender { __weak typeof(self) weakself=self; _dealDatePicker = [BRDatePickerView PickerAlertWithTitle:@""]; [_dealDatePicker configureSelectionBlock:^(NSString *date){ _tempStartDate=date; } andCompletionBlock:^(void){ weakself.sStartDate = _tempStartDate; [weakself.btnStaDate setTitle:weakself.sStartDate forState:UIControlStateNormal]; [self updateModel]; } andCancelBlock:^(void){ }]; [_dealDatePicker show]; } /** 结束日期 @param sender <#sender description#> */ - (IBAction)showEndDate:(id)sender { __weak typeof(self) weakself=self; _dealDatePicker = [BRDatePickerView PickerAlertWithTitle:@""]; [_dealDatePicker configureSelectionBlock:^(NSString *date){ self->_tempEndDate=date; } andCompletionBlock:^(void){ weakself.sEndDate = self->_tempEndDate; [weakself.btnEndDate setTitle:weakself.sEndDate forState:UIControlStateNormal]; [self updateModel]; } andCancelBlock:^(void){ }]; [_dealDatePicker show]; } /** 有效标识 @param sender <#sender description#> */ - (IBAction)showValueFlag:(id)sender { BaseIDAndNameViewController *tc = [[BaseIDAndNameViewController alloc ]init]; tc.bDelegate = self; tc.isPresentViewFlg = YES; tc.arrFilter = self.valueFlagArr; tc.arrSearch = self.valueFlagArr; tc.showDialogViewTag = baseIdAndNameValueFlag; if ([self.delegate respondsToSelector:@selector(sideSlipTableViewCellNeedsDismissViewController:animated:)]) { [self.delegate sideSlipTableViewCellNeedsDismissViewController:tc animated:YES]; } } /** 更新model */ - (void)updateModel{ CustomerSearchModel *model = [[CustomerSearchModel alloc] init]; model.customerName = [_txtCustomerName.text stringByReplacingOccurrencesOfString:@" " withString:@""]; model.customerTelephone = [_txtTel.text stringByReplacingOccurrencesOfString:@" " withString:@""]; model.customerAddress = [_txtCustomerAddress.text stringByReplacingOccurrencesOfString:@" " withString:@""]; model.IntermediateCustomers = [_filedIntermediateCustomers.text stringByReplacingOccurrencesOfString:@" " withString:@""];; model.createUserID = _createUserID; model.valueFlag = _boolFlagValue; model.customerStaDate = _sStartDate; model.customerEndDate = _sEndDate; model.isSceneAttachment=_isExistsSceneAttachment; model.isDrawingAttachment=_isExistsDrawingAttachment; NSMutableDictionary *mutDict = [NSMutableDictionary dictionaryWithDictionary:_regionModel.customDict]; [mutDict setValue:model forKey:CUSTOMER_SEARCH_RANGE_MODEL]; _regionModel.customDict = [mutDict copy]; } @end