//
|
// PBChooseType.m
|
// IphoneBIMe
|
//
|
// Created by ZhangJF on 2022/8/30.
|
// Copyright © 2022 ProBIM. All rights reserved.
|
//
|
|
#import "PBChooseType.h"
|
#import "PBSitePerModel.h"
|
#import "PBPerPlanModel.h"
|
#import "PBSiteMaterialModel.h"
|
#import "PBMaterialPlanModel.h"
|
#import "PBMechanicalPlanModel.h"
|
#import "PBSiteMechanicalModel.h"
|
#import "PBPanoramaModel.h"
|
|
@interface PBChooseType()<UITableViewDelegate, UITableViewDataSource>
|
@property (nonatomic, strong) UIView *bgView;
|
@property (nonatomic, strong) UITableView *tableView;
|
@property (nonatomic, assign) BOOL isSelsected;
|
@property (nonatomic, weak) UILabel *promptL;
|
@property (nonatomic, assign) NSInteger index;
|
@end
|
@implementation PBChooseType
|
- (instancetype)initWithFrame:(CGRect)frame {
|
if (self = [super initWithFrame:frame]) {
|
self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0];
|
[self addSubview:self.bgView];
|
|
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bgView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
|
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
|
maskLayer.frame = self.bgView.bounds;
|
maskLayer.path = maskPath.CGPath;
|
self.bgView.layer.mask = maskLayer;
|
[self setupUI];
|
}
|
return self;
|
}
|
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
CGPoint point = [[touches anyObject]locationInView:self];
|
CALayer *layer = [self.layer hitTest:point];
|
if (layer == self.layer) {
|
self.isSelsected = NO;
|
[self hidden];
|
}
|
}
|
- (void)hidden {
|
if (self.ChooseCompleteBlock) {
|
self.ChooseCompleteBlock(self.isSelsected, self.index);
|
}
|
[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:[PBChooseType 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 {
|
UILabel *promptL =[UILabel z_labelWithText:@"" Color:PBColor(40, 58, 79) isBold:YES Font:16];
|
promptL.textAlignment = NSTextAlignmentCenter;
|
[self.bgView addSubview:promptL];
|
[promptL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.bgView).offset(12);
|
make.left.equalTo(self.bgView).offset(20);
|
make.right.equalTo(self.bgView).offset(-20);
|
make.height.equalTo(@18);
|
}];
|
UIView *linView = [[UIView alloc] init];
|
linView.backgroundColor = PBColor(244, 245, 246);
|
[self.bgView addSubview:linView];
|
[linView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.bgView).offset(42);
|
make.left.equalTo(self.bgView).offset(25);
|
make.right.equalTo(self.bgView).offset(-25);
|
make.height.equalTo(@1);
|
}];
|
|
self.tableView = [[UITableView alloc] init];
|
self.tableView.dataSource = self;
|
self.tableView.delegate = self;
|
self.tableView.backgroundColor = [UIColor whiteColor];
|
self.tableView.tableFooterView = [UIView new];
|
// self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
self.tableView.showsVerticalScrollIndicator = NO;
|
self.tableView.rowHeight = 44;
|
[self.bgView addSubview:self.tableView];
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(linView.mas_bottom);
|
make.right.equalTo(self.bgView).offset(-10);
|
make.left.equalTo(self.bgView).offset(10);
|
make.height.equalTo(@220);
|
}];
|
self.promptL = promptL;
|
}
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
return self.dateList.count;
|
}
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
if(self.sitePerModel) {
|
PBPerPlanModel *planModel = self.dateList[indexPath.row];
|
UITableViewCell *cell = [[UITableViewCell alloc] init];
|
cell.textLabel.text = planModel.Mobile_UserType;
|
return cell;
|
}else if(self.siteMaterialModel){
|
PBMaterialPlanModel *planModel = self.dateList[indexPath.row];
|
UITableViewCell *cell = [[UITableViewCell alloc] init];
|
cell.textLabel.text = planModel.Materials_Name;
|
return cell;
|
}else if (self.siteMechanicalModel) {
|
PBMechanicalPlanModel *planModel = self.dateList[indexPath.row];
|
UITableViewCell *cell = [[UITableViewCell alloc] init];
|
cell.textLabel.text = planModel.Machine_Name;
|
return cell;
|
}else if (self.panoramaModel) {
|
NSDictionary *dict = self.dateList[indexPath.row];
|
UITableViewCell *cell = [[UITableViewCell alloc] init];
|
cell.textLabel.text = [dict valueForKey:@"LabelName"];
|
return cell;
|
} else {
|
UITableViewCell *cell = [[UITableViewCell alloc] init];
|
return cell;
|
}
|
}
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
self.index = indexPath.row;
|
self.isSelsected = YES;
|
[self hidden];
|
}
|
- (void)setDateList:(NSArray *)dateList {
|
_dateList = dateList;
|
[self.tableView reloadData];
|
}
|
- (void)setSitePerModel:(PBSitePerModel *)sitePerModel{
|
_sitePerModel = sitePerModel;
|
self.promptL.text = @"请选择工种";
|
}
|
- (void)setSiteMaterialModel:(PBSiteMaterialModel *)siteMaterialModel {
|
_siteMaterialModel = siteMaterialModel;
|
self.promptL.text = @"请选择机械";
|
}
|
- (void)setSiteMechanicalModel:(PBSiteMechanicalModel *)siteMechanicalModel {
|
_siteMechanicalModel = siteMechanicalModel;
|
self.promptL.text = @"请选择材料";
|
}
|
- (void)setPanoramaModel:(PBPanoramaModel *)panoramaModel {
|
_panoramaModel = panoramaModel;
|
self.promptL.text = @"请选择标签";
|
}
|
/*
|
// Only override drawRect: if you perform custom drawing.
|
// An empty implementation adversely affects performance during animation.
|
- (void)drawRect:(CGRect)rect {
|
// Drawing code
|
}
|
*/
|
|
@end
|