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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
//
//  PBTwoChooseView.m
//  IphoneBIMe
//
//  Created by zjf on 2018/12/24.
//  Copyright © 2018 ProBIM. All rights reserved.
//
 
#import "PBTwoChooseView.h"
#import "PBExamineAddModel.h"
@interface PBTwoChooseView()<UIPickerViewDelegate,UIPickerViewDataSource>
@property (nonatomic, strong)  UIView *bgView;
@property (nonatomic, strong) UIPickerView *pickerView;
 
@property (nonatomic, strong) NSArray *dataArr;
@property (nonatomic, weak) UIView *topView;
 
@property (nonatomic, weak) UILabel *leftTitleL;
@property (nonatomic, weak) UILabel *rightTitleL;
@property (nonatomic, weak) UILabel *leftSelectL;
@property (nonatomic, weak) UILabel *rightSelectL;
@property (nonatomic, weak) UILabel *promptL;
@property (nonatomic, strong) PBExamineAddModel *examineAddModel;
@property (nonatomic, assign) BOOL isSelectLeft;
@property (nonatomic, assign) BOOL isSelectRight;
@property (nonatomic, strong) NSDictionary *selectDict;
@end
@implementation PBTwoChooseView
- (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<UITouch *> *)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(_isSelectLeft, _isSelectRight);
    }
    [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:[PBTwoChooseView 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 *leftBtn = [[UIButton alloc] init];
    [leftBtn addTarget:self action:@selector(statusBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:leftBtn];
    [leftBtn 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 *rightBtn = [[UIButton alloc] init];
    [rightBtn addTarget:self action:@selector(typeBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:rightBtn];
    [rightBtn 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 *leftTieleL = [UILabel z_labelWithText:@"状态" Color:PromptColor isBold:NO Font:DescFontSize];
    [self.bgView addSubview:leftTieleL];
    [leftTieleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(leftBtn).offset(31);
        make.centerX.equalTo(leftBtn);
        make.height.equalTo(@20);
    }];
    
    UILabel *rightTieleL = [UILabel z_labelWithText:@"类型" Color:PromptColor isBold:NO Font:DescFontSize];
    [self.bgView addSubview:rightTieleL];
    [rightTieleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(rightBtn).offset(31);
        make.centerX.equalTo(rightBtn);
        make.height.equalTo(@20);
    }];
    
    UILabel *leftSelectL = [UILabel z_labelWithText:@"请选择" Color:WarningColor isBold:NO Font:MarkedFontSize];
    leftSelectL.textAlignment = NSTextAlignmentCenter;
    [self.bgView addSubview:leftSelectL];
    [leftSelectL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(leftTieleL.mas_bottom).offset(14);
        make.left.equalTo(leftBtn).offset(16);
        make.right.equalTo(leftBtn).offset(-16);
        make.height.equalTo(@25);
    }];
    
    UILabel *rightSelectL = [UILabel z_labelWithText:@"请选择" Color:IgnoreColor isBold:NO Font:MarkedFontSize];
    rightSelectL.textAlignment = NSTextAlignmentCenter;
    [self.bgView addSubview:rightSelectL];
    [rightSelectL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(rightTieleL.mas_bottom).offset(14);
        make.left.equalTo(rightBtn).offset(16);
        make.right.equalTo(rightBtn).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(leftBtn.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(130, 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.leftTitleL = leftTieleL;
    self.rightTitleL = rightTieleL;
    self.leftSelectL = leftSelectL;
    self.rightSelectL = rightSelectL;
    self.promptL = promptL;
}
 
- (void)determineBtnActio {
    if (self.index == 0) {
        self.isSelectLeft = YES;
        self.leftExamineAddModel.dataDict = self.selectDict.copy;
        self.leftSelectL.text = [self.leftExamineAddModel.dataDict valueForKey:@"aedt_name"];
        if(self.rightExamineAddModel.dataDict) {
            [self hidden];
        }else {
            self.index = 1;
        }
    }else {
        self.isSelectRight = YES;
        self.rightExamineAddModel.dataDict =  self.selectDict.copy;
        self.rightSelectL.text = [self.rightExamineAddModel.dataDict valueForKey:@"aedt_name"];
        if(self.leftExamineAddModel.dataDict) {
            [self hidden];
        }else {
            self.index = 0;
        }
    }
}
- (void)statusBtnAction {
    self.index = 0;
}
 
- (void)typeBtnAction {
    if (self.rightExamineAddModel.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.selectDict = 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];
    NSDictionary *dict = self.dataArr[row];
    label.text = [dict valueForKey:@"aedt_name"];
    return label;
}
- (void)setIndex:(NSInteger)index {
    _index = index;
    if (index == 0) {
        [UIView animateWithDuration:0.2 animations:^{
            self.topView.x = 0;
        }];
        self.leftSelectL.textColor = WarningColor;
        if (self.rightExamineAddModel.dataDict) {
            self.rightSelectL.textColor = TitleColor;
        }else {
            self.rightSelectL.textColor = IgnoreColor;
        }
        self.promptL.text = self.leftExamineAddModel.prompt;
        self.dataArr = self.leftData;
        [self.pickerView reloadAllComponents];
        [self.pickerView selectRow:0 inComponent:0 animated:NO];
        if (self.dataArr.count > 0) {
            self.selectDict = self.dataArr[0];
        }
    }else {
        [UIView animateWithDuration:0.2 animations:^{
            self.topView.x = self.bgView.width / 2;
        }];
        self.rightSelectL.textColor = WarningColor;
        if (self.leftExamineAddModel.dataDict) {
            self.leftSelectL.textColor = TitleColor;
        }else {
            self.leftSelectL.textColor = IgnoreColor;
        }
        self.promptL.text = self.rightExamineAddModel.prompt;
        self.dataArr = self.rightData;
        [self.pickerView reloadAllComponents];
        [self.pickerView selectRow:0 inComponent:0 animated:NO];
        self.selectDict = self.dataArr[0];
    }
}
 
- (void)setLeftExamineAddModel:(PBExamineAddModel *)leftExamineAddModel {
    _leftExamineAddModel = leftExamineAddModel;
    _leftTitleL.text = leftExamineAddModel.title;
    if (_leftExamineAddModel.dataDict) {
        _leftSelectL.text = [leftExamineAddModel.dataDict valueForKey:@"aedt_name"];
    }else {
        _leftSelectL.text = @"请选择";
    }
}
 
- (void)setRightExamineAddModel:(PBExamineAddModel *)rightExamineAddModel {
    _rightExamineAddModel = rightExamineAddModel;
    _rightTitleL.text = rightExamineAddModel.title;
    if (rightExamineAddModel.dataDict) {
        _rightSelectL.text = [rightExamineAddModel.dataDict valueForKey:@"aedt_name"];
    }else {
        _rightSelectL.text = @"请选择";
    }
}
- (void)setLeftData:(NSArray *)leftData {
    _leftData = leftData;
}
 
- (void)setRightData:(NSArray *)rightData {
    _rightData = rightData;
}
@end