//
|
// 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
|