// // PBChooseView.m // IphoneBIMe // // Created by zjf on 2018/8/15. // Copyright © 2018年 ProBIM. All rights reserved. // #import "PBChooseView.h" #import "PBIssueAddModel.h" @interface PBChooseView() @property (nonatomic, strong) UIView *bgView; @property (nonatomic, strong) UIPickerView *pickerView; @property (nonatomic, strong) NSArray *dataArr; @property (nonatomic, weak) UIView *topView; @property (nonatomic, weak) UILabel *statusTitleL; @property (nonatomic, weak) UILabel *typeTitleL; @property (nonatomic, weak) UILabel *statusSelectL; @property (nonatomic, weak) UILabel *typeSelectL; @property (nonatomic, weak) UILabel *promptL; @property (nonatomic, strong) PBIssueNavModel *selectNavModel; @property (nonatomic, assign) BOOL isSelectStatus; @property (nonatomic, assign) BOOL isSelectType; @end @implementation PBChooseView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0]; [self addSubview:self.bgView]; [self setupUI]; } return self; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint point = [[touches anyObject]locationInView:self]; CALayer *layer = [self.layer hitTest:point]; if (layer == self.layer) { [self hidden]; } } - (void)hidden { if (self.ChooseCompleteBlock) { self.ChooseCompleteBlock(_isSelectStatus, _isSelectType); } [UIView animateWithDuration:0.3 animations:^{ self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0]; self.bgView.y = PBScreenHeight; }completion:^(BOOL finished) { for (UIView *cover in PBKeyWindow.subviews) { if ([cover isKindOfClass:[PBChooseView class]]) { [cover removeFromSuperview]; } } }]; } - (void)show { [UIView animateWithDuration:0.3 animations:^{ self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5]; self.bgView.y = PBScreenHeight - self.visualViewHeight; }]; } #pragma mark - 懒加载 - (UIView *)bgView { if (_bgView == nil) { _bgView = [[UIView alloc]initWithFrame:CGRectMake(0, PBScreenHeight, PBScreenWidth, PBScreenHeight)]; _bgView.backgroundColor = [UIColor whiteColor]; } return _bgView; } - (void)setVisualViewHeight:(NSInteger)visualViewHeight { _visualViewHeight = visualViewHeight; } - (void)setupUI { UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width / 2, 3)]; topView.backgroundColor = WarningColor; [self.bgView addSubview:topView]; UIView *linView = [[UIView alloc] init]; linView.backgroundColor = [UIColor z_colorWithR:242 G:242 B:242]; [self.bgView addSubview:linView]; [linView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.bgView).offset(33); make.centerX.equalTo(self.bgView); make.width.equalTo(@1); make.height.equalTo(@55); }]; UIButton *statusBtn = [[UIButton alloc] init]; [statusBtn addTarget:self action:@selector(statusBtnAction) forControlEvents:UIControlEventTouchUpInside]; [self.bgView addSubview:statusBtn]; [statusBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(topView.mas_bottom); make.left.equalTo(self.bgView); make.right.equalTo(linView.mas_left); make.height.equalTo(@129); }]; UIButton *typeBtn = [[UIButton alloc] init]; [typeBtn addTarget:self action:@selector(typeBtnAction) forControlEvents:UIControlEventTouchUpInside]; [self.bgView addSubview:typeBtn]; [typeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(topView.mas_bottom); make.right.equalTo(self.bgView); make.left.equalTo(linView.mas_right); make.height.equalTo(@129); }]; UILabel *statusTieleL = [UILabel z_labelWithText:@"状态" Color:PromptColor isBold:NO Font:DescFontSize]; [self.bgView addSubview:statusTieleL]; [statusTieleL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(statusBtn).offset(31); make.centerX.equalTo(statusBtn); make.height.equalTo(@20); }]; UILabel *typeTieleL = [UILabel z_labelWithText:@"类型" Color:PromptColor isBold:NO Font:DescFontSize]; [self.bgView addSubview:typeTieleL]; [typeTieleL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(typeBtn).offset(31); make.centerX.equalTo(typeBtn); make.height.equalTo(@20); }]; UILabel *statusSelectL = [UILabel z_labelWithText:@"请选择" Color:WarningColor isBold:NO Font:MarkedFontSize]; statusSelectL.textAlignment = NSTextAlignmentCenter; [self.bgView addSubview:statusSelectL]; [statusSelectL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(statusTieleL.mas_bottom).offset(14); make.left.equalTo(statusBtn).offset(16); make.right.equalTo(statusBtn).offset(-16); make.height.equalTo(@25); }]; UILabel *typeSelectL = [UILabel z_labelWithText:@"请选择" Color:IgnoreColor isBold:NO Font:MarkedFontSize]; typeSelectL.textAlignment = NSTextAlignmentCenter; [self.bgView addSubview:typeSelectL]; [typeSelectL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(typeTieleL.mas_bottom).offset(14); make.left.equalTo(typeBtn).offset(16); make.right.equalTo(typeBtn).offset(-16); make.height.equalTo(@25); }]; UIView *lin1View = [[UIView alloc] init]; lin1View.backgroundColor = [UIColor z_colorWithR:242 G:242 B:242]; [self.bgView addSubview:lin1View]; [lin1View mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(statusBtn.mas_bottom); make.left.right.equalTo(self.bgView); make.height.equalTo(@1); }]; UILabel *promptL = [UILabel z_labelWithText:@"请选择状态" Color:PromptColor isBold:NO Font:MarkedFontSize]; promptL.textAlignment = NSTextAlignmentCenter; [self.bgView addSubview:promptL]; [promptL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(lin1View).offset(15); make.size.mas_equalTo(CGSizeMake(120, 25)); make.centerX.equalTo(self.bgView); }]; UIButton *determineBtn = [UIButton z_textButton:@"确定" fontSize:MarkedFontSize normalColor:WarningColor]; [self.bgView addSubview:determineBtn]; [determineBtn addTarget:self action:@selector(determineBtnActio) forControlEvents:UIControlEventTouchUpInside]; [determineBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(promptL); make.right.equalTo(self.bgView).offset(-16); make.size.mas_equalTo(CGSizeMake(52, 50)); }]; UIView *lin2View = [[UIView alloc] init]; lin2View.backgroundColor = [UIColor z_colorWithR:242 G:242 B:242]; [self.bgView addSubview:lin2View]; [lin2View mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(promptL.mas_bottom).offset(13); make.left.right.equalTo(self.bgView); make.height.equalTo(@1); }]; self.pickerView = [[UIPickerView alloc]init]; self.pickerView.backgroundColor = [UIColor whiteColor]; self.pickerView.delegate = self; self.pickerView.dataSource = self; [self.bgView addSubview:self.pickerView]; [self.pickerView reloadAllComponents];//刷新UIPickerView [self.pickerView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(lin2View.mas_bottom); make.right.equalTo(self.bgView).offset(-44); make.left.equalTo(self.bgView).offset(44); make.height.equalTo(@282); }]; self.topView = topView; self.statusTitleL = statusTieleL; self.typeTitleL = typeTieleL; self.statusSelectL = statusSelectL; self.typeSelectL = typeSelectL; self.promptL = promptL; } - (void)determineBtnActio { if (self.index == 0) { self.isSelectStatus = YES; self.leftIssueAddModel.navModel = self.selectNavModel.copy; self.statusSelectL.text = self.leftIssueAddModel.navModel.ItemName; if (self.rightIssueAddModel.roleType != CREATOR) { [self hidden]; }else { if(self.rightIssueAddModel.navModel) { [self hidden]; }else { self.index = 1; } } }else { self.isSelectType = YES; self.rightIssueAddModel.navModel = self.selectNavModel.copy; self.typeSelectL.text = self.rightIssueAddModel.navModel.ItemName; if(self.leftIssueAddModel.navModel) { [self hidden]; }else { self.index = 0; } } } - (void)statusBtnAction { if (self.isAdd) { return; } self.index = 0; } - (void)typeBtnAction { if (self.rightIssueAddModel.roleType != CREATOR) { return; } self.index = 1; } #pragma mark UIPickerViewDelegate && UIPickerViewDataSource - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{ return 1; } - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ return self.dataArr.count; } - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{ return 60.f; } - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ self.selectNavModel = self.dataArr[row]; } - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { for(UIView *singleLine in pickerView.subviews){ if (singleLine.frame.size.height < 1){ singleLine.backgroundColor = [UIColor z_colorWithR:242 G:242 B:242]; } } UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width / 2, 30)]; label.textAlignment = NSTextAlignmentCenter; label.font = [UIFont systemFontOfSize:20]; PBIssueNavModel *navModel = self.dataArr[row]; label.text = navModel.ItemName; return label; } - (void)setIndex:(NSInteger)index { _index = index; if (index == 0) { [UIView animateWithDuration:0.2 animations:^{ self.topView.x = 0; }]; self.statusSelectL.textColor = WarningColor; if (self.rightIssueAddModel.navModel) { self.typeSelectL.textColor = TitleColor; }else { self.typeSelectL.textColor = IgnoreColor; } if (self.rightIssueAddModel.roleType != CREATOR) { self.typeSelectL.textColor = IgnoreColor; } self.promptL.text = self.leftIssueAddModel.prompt; self.dataArr = [self.statusAndTypeData valueForKey:@"IssueStatus"]; [self.pickerView reloadAllComponents]; [self.pickerView selectRow:0 inComponent:0 animated:NO]; self.selectNavModel = self.dataArr[0]; }else { [UIView animateWithDuration:0.2 animations:^{ self.topView.x = self.bgView.width / 2; }]; if (self.rightIssueAddModel.roleType != CREATOR) { self.typeSelectL.textColor = IgnoreColor; }else { self.typeSelectL.textColor = WarningColor; } if (self.leftIssueAddModel.navModel) { self.statusSelectL.textColor = TitleColor; }else { self.statusSelectL.textColor = IgnoreColor; } self.promptL.text = self.rightIssueAddModel.prompt; self.dataArr = [self.statusAndTypeData valueForKey:@"IssueTypes"]; [self.pickerView reloadAllComponents]; [self.pickerView selectRow:0 inComponent:0 animated:NO]; self.selectNavModel = self.dataArr[0]; } } - (void)setLeftIssueAddModel:(PBIssueAddModel *)leftIssueAddModel { _leftIssueAddModel = leftIssueAddModel; self.statusTitleL.text = leftIssueAddModel.title; if (leftIssueAddModel.navModel) { self.statusSelectL.text = leftIssueAddModel.navModel.ItemName; }else { self.statusSelectL.text = @"请选择"; } } - (void)setRightIssueAddModel:(PBIssueAddModel *)rightIssueAddModel { _rightIssueAddModel = rightIssueAddModel; self.typeTitleL.text = rightIssueAddModel.title; if (rightIssueAddModel.navModel) { self.typeSelectL.text = rightIssueAddModel.navModel.ItemName; }else { self.typeSelectL.text = @"请选择"; } } - (void)setStatusAndTypeData:(NSDictionary *)statusAndTypeData { _statusAndTypeData = statusAndTypeData; } - (void)setIsAdd:(BOOL)isAdd { _isAdd = isAdd; } @end