zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
113
114
115
116
117
118
119
120
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//
//  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