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
//
//  PBViewPointScrollView.m
//  IphoneBIMe
//
//  Created by ZhangJF on 2022/10/20.
//  Copyright © 2022 ProBIM. All rights reserved.
//
 
#import "PBViewPointScrollView.h"
#import "PBScrollVpView.h"
#import "PBScrollModelView.h"
#import "PBScrollStageView.h"
#import "PBProjectModel.h"
#import "PBModelsModel.h"
#import "PBViewPointModel.h"
@interface PBViewPointScrollView()<UIScrollViewDelegate>
@property (nonatomic, weak) UIView *menuView;
@property (nonatomic, weak) UIView *menuTextView;
@property (nonatomic, weak) UILabel *scrollLab;
@property (nonatomic, assign) NSInteger lastIndex;
@property (nonatomic, assign) NSInteger currentIndex;
@property (nonatomic, strong) UIScrollView *subScrollView;
@property (nonatomic , strong) PBScrollStageView *stageView;//阶段
@property (nonatomic , strong) PBScrollModelView *modelView;//模型
@property (nonatomic , strong) PBScrollVpView *vpView;//空间视点
@property (nonatomic , strong) PBProjectModel *projectModel;
@property (nonatomic , strong) NSArray *stageArr;
@property (nonatomic , strong) NSArray *modelArr;
@property (nonatomic , strong) NSArray *vpArr;
@property (nonatomic, weak) UILabel *stageL;
@property (nonatomic, weak) UILabel *modelL;
@property (nonatomic, weak) UILabel *viewPointL;
@end
@implementation PBViewPointScrollView
- (instancetype)initWithFrame:(CGRect)frame withProjectModel:(nonnull PBProjectModel *)projectModel {
    if (self = [super initWithFrame:frame]) {
        self.projectModel = projectModel;
        [self loadProjectConfig];
        [self setupUI];
    }
    return self;
}
- (void)loadProjectConfig {
    [YJProgressHUD showProgress:@"" inView:self];
    [[PBNetworkTools sharedTools] RequestGetProjectConfigWithProjectID:_projectModel.bimcomposerid andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
        if (error) {
            NSLog(@"%@",error);
            [YJProgressHUD showMessage:@"加载失败" inView:self];
            return;
        }
        NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
        NSDictionary *dict = [NSString convertTodictionaryOrArr:str];
        NSArray *projectDictData = [dict valueForKey:@"ProjectDictData"];
        NSArray *arr = [projectDictData[0] valueForKey:@"children"];
        NSMutableArray *arr_M = arr.mutableCopy;
        for (int i = 0; i < arr_M.count; ++i) {
            for (int  j = 0; j < arr_M.count-1; ++j) {
                NSInteger sort1 = [[arr_M[j] valueForKey:@"sort"] intValue];
                NSInteger sort2 = [[arr_M[j + 1] valueForKey:@"sort"] intValue];
                if (sort1 > sort2) {
                    [arr_M exchangeObjectAtIndex:j withObjectAtIndex:j+1];
                }
            }
        }
        self.stageArr = arr_M.copy;
        self.stageView.stageArr = self.stageArr;
    }];
}
- (void)loadModels {
    self.modelL.text = @"请选择";
    self.viewPointL.text = @"请选择";
    self.modelData = nil;
    self.vpData = nil;
    self.vpArr = @[];
    self.vpView.vpArr = self.vpArr;
    
    [[PBNetworkTools sharedTools] RequestGetProjectStageAllModelsWithProjectID:_projectModel.bimcomposerid andPhase:[self.stageData valueForKey:@"value"] andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
        if (error) {
            NSLog(@"%@",error);
            return;
        }
        NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
        str = [str stringByReplacingOccurrencesOfString:@"\\" withString:@""];
        NSMutableString *mString = [NSMutableString stringWithString:str];
        [mString deleteCharactersInRange:NSMakeRange(0, 1)];
        [mString deleteCharactersInRange:NSMakeRange(mString.length-1, 1)];
        self.modelArr = [NSArray yy_modelArrayWithClass:[PBModelsModel class] json:mString.copy];
        self.modelView.modelArr = self.modelArr;
    }];
}
 
- (void)loadVierPoint {
    self.viewPointL.text = @"请选择";
    self.vpData = nil;
    [[PBNetworkTools sharedTools] RequestGetAllViewpointWithProjectId:_projectModel.bimcomposerid andModelId:_modelData.ID andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
        if (error) {
            NSLog(@"%@",error);
            return;
        }
        NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
        NSArray *arr = [NSArray yy_modelArrayWithClass:[PBViewPointModel class] json:str];
        NSMutableArray *arrM = [[NSMutableArray alloc] init];
        for (PBViewPointModel *viewPointModel in arr) {
            if ([viewPointModel.Type isEqualToString:@"0"] || [viewPointModel.Type isEqualToString:@"1"]) {
                [arrM addObject:viewPointModel];
            }
        }
        self.vpArr = arrM;
        self.vpView.vpArr = self.vpArr;
    }];
    
}
- (void)setupUI {
    self.backgroundColor = [UIColor whiteColor];
    //创建顶部tap
    [self createTopMenuView];
    [self addSubview:self.subScrollView];
    [self.subScrollView addSubview:self.stageView];//阶段
    [self.subScrollView addSubview:self.modelView];//模型
    [self.subScrollView addSubview:self.vpView];//空间视点
}
 
- (void)createTopMenuView {
    UIView *menuView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, 40)];
    [self addSubview:menuView];
//    _menuView = menuView;
    //商品
    CGFloat button_W = self.width/3;
    UIButton *stageBT = [UIButton z_textButton:@"阶段" boldFontSize:14 normalColor:PBColor(24, 24, 24)];
    [stageBT addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    stageBT.frame = CGRectMake(0, 0, button_W, menuView.height);
    stageBT.tag = 1;
    [menuView addSubview:stageBT];
    
    UIButton *modelBT = [UIButton z_textButton:@"模型" boldFontSize:14 normalColor:PBColor(24, 24, 24)];
    [modelBT addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    modelBT.frame = CGRectMake(button_W, 0, button_W, menuView.height);
    modelBT.tag = 2;
    [menuView addSubview:modelBT];
    
    UIButton *viewPointBT = [UIButton z_textButton:@"空间视点" boldFontSize:14 normalColor:PBColor(24, 24, 24)];
    [viewPointBT addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    viewPointBT.frame = CGRectMake(button_W*2, 0, button_W, menuView.height);
    viewPointBT.tag = 3;
    [menuView addSubview:viewPointBT];
 
    UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, menuView.height-1, self.width, 1)];
    line.backgroundColor = PBColor(216, 216, 216);
    [menuView addSubview:line];
//    //4:可移动的底部滑竿
    UILabel *scrollLab = [[UILabel alloc]init];
    scrollLab.frame = CGRectMake(stageBT.center.x-15, menuView.height-8, 30, 2);
    scrollLab.backgroundColor = PBColor(0, 122, 255);
    [menuView addSubview:scrollLab];
    self.menuView = menuView;
    self.scrollLab = scrollLab;
    
    
    UIView *menuTextView = [[UIView alloc]initWithFrame:CGRectMake(0, menuView.height, self.width, 40)];
    [self addSubview:menuTextView];
    
    UILabel *stageL = [UILabel z_labelWithText:@"请选择" Color:PBColor(24, 24, 24) isBold:NO Font:13];
    stageL.numberOfLines = 1;
    stageL.textAlignment = NSTextAlignmentCenter;
    stageL.frame = CGRectMake(0, 0, button_W, menuTextView.height);
    stageL.tag = 10;
    [menuTextView addSubview:stageL];
    
    UILabel *modelL = [UILabel z_labelWithText:@"请选择" Color:PBColor(24, 24, 24) isBold:NO Font:13];
    modelL.numberOfLines = 1;
    modelL.textAlignment = NSTextAlignmentCenter;
    modelL.frame = CGRectMake(button_W, 0, button_W, menuTextView.height);
    modelL.tag = 11;
    [menuTextView addSubview:modelL];
    
    UILabel *viewPointL = [UILabel z_labelWithText:@"请选择" Color:PBColor(24, 24, 24) isBold:NO Font:13];
    viewPointL.numberOfLines = 1;
    viewPointL.textAlignment = NSTextAlignmentCenter;
    viewPointL.frame = CGRectMake(button_W*2, 0, button_W, menuTextView.height);
    viewPointL.tag = 12;
    [menuTextView addSubview:viewPointL];
 
    UILabel *line1 = [[UILabel alloc] initWithFrame:CGRectMake(0, menuTextView.height-1, self.width, 1)];
    line1.backgroundColor = PBColor(216, 216, 216);
    [menuTextView addSubview:line1];
    self.menuTextView = menuTextView;
    self.stageL = stageL;
    self.modelL = modelL;
    self.viewPointL = viewPointL;
}
#pragma mark - 控制事件
- (void)btnClick:(UIButton *)btn {
    NSInteger tag = btn.tag;
    _currentIndex = tag;
 
    [self.subScrollView setContentOffset:CGPointMake((_currentIndex-1)*self.subScrollView.width, 0) animated:YES];
 
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat scorllOffsetW = self.subScrollView.width*2;
    CGFloat currentOffsetX =  self.subScrollView.contentOffset.x;
    CGFloat rate = currentOffsetX/scorllOffsetW;//速率
    CGFloat offset_X = self.width/3 * rate*2;
    CGRect frame = _scrollLab.frame;
    frame.origin.x = offset_X+(self.width/3/2-15);;
    _scrollLab.frame = frame;
    
}
 
#pragma mark - 懒加载
- (UIScrollView *)subScrollView {
    if (_subScrollView == nil) {
        _subScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, _menuView.height + _menuTextView.height, self.width, self.height-_menuView.height - _menuTextView.height)];
        _subScrollView.contentSize = CGSizeMake(self.width * 3, _subScrollView.height);
        _subScrollView.pagingEnabled = YES;
        _subScrollView.scrollEnabled = YES;
        _subScrollView.showsHorizontalScrollIndicator = NO;
        _subScrollView.backgroundColor = [UIColor whiteColor];
        _subScrollView.delegate = self;
    }
    return _subScrollView;
}
 
- (PBScrollStageView *)stageView
{
    if (!_stageView) {
        _stageView = [[PBScrollStageView alloc]initWithFrame:CGRectMake(0, 0, self.width, _subScrollView.height)];
        _stageView.saveBlock = ^(NSDictionary * _Nonnull data) {
            _stageData = data;
            _stageL.text = [data valueForKey:@"name"];
            [self loadModels];
        };
    }
    return _stageView;
}
 
- (PBScrollModelView *)modelView
{
    if (!_modelView) {
        _modelView = [[PBScrollModelView alloc]initWithFrame:CGRectMake(self.width, 0, self.width, _subScrollView.height)];
        _modelView.saveBlock = ^(PBModelsModel * _Nonnull data) {
            _modelData = data;
            _modelL.text = data.Name;
            [self loadVierPoint];
        };
    }
    return _modelView;
}
 
- (PBScrollVpView *)vpView
{
    if (!_vpView) {
        _vpView = [[PBScrollVpView alloc]initWithFrame:CGRectMake(self.width*2, 0, self.width, _subScrollView.height)];
        _vpView.saveBlock = ^(PBViewPointModel * _Nonnull data) {
            _vpData = data;
            _viewPointL.text = data.Name;
        };
    }
    return _vpView;
}
- (void)setProjectModel:(PBProjectModel *)projectModel {
    _projectModel = projectModel;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
 
@end