//
|
// PBModelListViewController.m
|
// IphoneBIMe
|
//
|
// Created by zjf on 2018/7/18.
|
// Copyright © 2018年 ProBIM. All rights reserved.
|
//
|
|
#import "PBModelListViewController.h"
|
#import "PBProjectModel.h"
|
#import "PBPhaseLabel.h"
|
#import "PBModelsModel.h"
|
#import "PBModelsTableViewCell.h"
|
#import "PBModelCategoryViewController.h"
|
#import "PBLoadModelDisplayController.h"
|
#import "PBPromptView.h"
|
#import "PBProjectPower.h"
|
#import "PBShareView.h"
|
#define ModelModuleName @"BIMModel"
|
static NSString *const CellID = @"CellID";
|
@interface PBModelListViewController ()<UITableViewDataSource, UITableViewDelegate>
|
@property (nonatomic, strong) UIScrollView *phaseScrollView;
|
@property (nonatomic,strong) NSArray *phaseArr;
|
@property (nonatomic,strong) NSMutableArray *labelM;
|
@property (nonatomic,strong) UITableView *tableView;
|
@property (nonatomic,strong) NSMutableArray *listArrM;
|
@property (nonatomic,copy) NSString *firstValue;
|
@property (nonatomic, strong) PBPromptView *promptView;
|
@property (nonatomic, strong) PBShareView *shareView;
|
@end
|
@implementation PBModelListViewController
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.f) {
|
self.edgesForExtendedLayout = UIRectEdgeNone;
|
self.navigationController.interactivePopGestureRecognizer.enabled = NO; //让rootView禁止滑动
|
}
|
[self setupNav];
|
[self setupUI];
|
}
|
- (void)loadProjectConfig {
|
[YJProgressHUD showProgress:@"" inView:self.view];
|
// [YJProgressHUD showCustomAnimation:@"" inview:self.view];
|
[[PBNetworkTools sharedTools] RequestGetProjectConfigWithProjectID:_projectModel.bimcomposerid andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
|
if (error) {
|
NSLog(@"%@",error);
|
[YJProgressHUD showMessage:@"加载失败" inView:self.view];
|
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"];
|
self.firstValue = [arr[0] valueForKey:@"value"];
|
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.phaseArr = arr_M.copy;
|
[self loadAllMode];
|
[self createChannelLabel];
|
}];
|
}
|
|
/// 创建频道标签
|
- (void)createChannelLabel{
|
CGFloat labelW = 130;
|
CGFloat labelH = self.phaseScrollView.bounds.size.height;
|
for (int i = 0; i < self.phaseArr.count; i++) {
|
PBPhaseLabel *label = [[PBPhaseLabel alloc] init];
|
[self.phaseScrollView addSubview:label];
|
CGFloat labelX = labelW * i;
|
label.frame = CGRectMake(labelX, 0, labelW, labelH);
|
self.phaseScrollView.contentSize = CGSizeMake(labelW * self.phaseArr.count, 0);
|
label.text = [self.phaseArr[i] valueForKey:@"name"];
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTapClick:)];
|
[label addGestureRecognizer:tap];
|
label.tag = i;
|
label.userInteractionEnabled = YES;
|
[self.labelM addObject:label];
|
if (i == 0) {
|
// label.scale = 1.0;
|
label.isSelectLabel = YES;
|
}else {
|
label.isSelectLabel = NO;
|
}
|
}
|
}
|
|
#pragma mark - 频道标签的点击事件
|
- (void)labelTapClick:(UITapGestureRecognizer *)tap {
|
PBPhaseLabel *selected_label = (PBPhaseLabel *)tap.view;
|
CGFloat labelOffsetX = selected_label.center.x - (self.view.bounds.size.width * 0.5);
|
CGFloat minOffsetX = 0;
|
CGFloat maxOffsetX = self.phaseScrollView.contentSize.width - self.view.bounds.size.width;
|
if (maxOffsetX > minOffsetX) {
|
if (labelOffsetX < minOffsetX) {
|
labelOffsetX = 0;
|
} else if (labelOffsetX > maxOffsetX) {
|
labelOffsetX = maxOffsetX;
|
}
|
[self.phaseScrollView setContentOffset:CGPointMake(labelOffsetX, 0) animated:YES];
|
}
|
#pragma mark - 点击频道标签剧中时,更新模型
|
[self retrieveModelsWithIndex:selected_label.tag];
|
#pragma mark - 点击label时选中的缩放比例最大,其余的保持
|
NSInteger index = selected_label.tag;
|
for (int i = 0; i < self.labelM.count; ++i) {
|
PBPhaseLabel *label = self.labelM[i];
|
if (index == i) {
|
// label.scale = 1.0;
|
label.isSelectLabel = YES;
|
} else {
|
// label.scale = 0;
|
label.isSelectLabel = NO;
|
}
|
}
|
}
|
|
- (void)setupUI {
|
self.view.backgroundColor = [UIColor z_colorWithR:239 G:239 B:239];
|
self.phaseScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 43)];
|
self.phaseScrollView.backgroundColor = [UIColor whiteColor];
|
self.phaseScrollView.showsHorizontalScrollIndicator = NO;
|
[self.view addSubview:self.phaseScrollView];
|
self.tableView = [[UITableView alloc] init];
|
self.tableView.dataSource = self;
|
self.tableView.delegate = self;
|
self.tableView.rowHeight = 70.f;
|
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
[self.tableView registerClass:[PBModelsTableViewCell class] forCellReuseIdentifier:CellID];
|
[self.view addSubview:self.tableView];
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.phaseScrollView.mas_bottom).offset(1);
|
make.left.right.bottom.equalTo(self.view);
|
}];
|
[self.view addSubview:self.promptView];
|
[self.promptView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.bottom.left.right.equalTo(self.tableView);
|
}];
|
for (PBProjectPower *power in self.powerArr) {
|
if ([power.Bm_EnCode isEqualToString:ModelModuleName]) {
|
if ([power.checkstate isEqualToString:@"1"]) {
|
//有权限
|
self.promptView.hidden = YES;
|
[self loadProjectConfig];
|
return;
|
}else {
|
//无权限
|
self.promptView.textL.text = @"暂无权限";
|
self.promptView.hidden = NO;
|
return;
|
}
|
}
|
}
|
//无权限
|
self.promptView.textL.text = @"暂无权限";
|
self.promptView.hidden = NO;
|
}
|
|
- (void)loadAllMode {
|
[[PBNetworkTools sharedTools] RequestGetProjectAllModelsWithProjectID:_projectModel.bimcomposerid andKeyword:@"" andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
|
if (error) {
|
NSLog(@"%@",error);
|
[YJProgressHUD showMessage:@"加载失败" inView:self.view];
|
return;
|
}
|
[YJProgressHUD hide];
|
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)];
|
NSArray *modelsArr = [NSArray yy_modelArrayWithClass:[PBModelsModel class] json:mString.copy];
|
for (int i = 0; i < self.phaseArr.count; i++) {
|
NSMutableArray *arrM = [[NSMutableArray alloc] init];
|
NSMutableArray *noBelongArrM = [[NSMutableArray alloc] init];
|
for (int j = 0; j < modelsArr.count; j++) {
|
PBModelsModel *modelsModel = modelsArr[j];
|
if([[self.phaseArr[i] valueForKey:@"value"] isEqualToString:modelsModel.Phase]) {
|
[arrM addObject:modelsModel];
|
}else {
|
[noBelongArrM addObject:modelsModel];
|
}
|
}
|
modelsArr = noBelongArrM.copy;
|
[self.listArrM addObject:arrM];
|
if (i == self.phaseArr.count - 1) {
|
[self.listArrM addObject:noBelongArrM];
|
}
|
}
|
[self.modelsArrM addObjectsFromArray:self.listArrM[0]];
|
if ([[self.phaseArr[0] valueForKey:@"value"] isEqualToString:self.firstValue]) {
|
[self.modelsArrM addObjectsFromArray:self.listArrM[self.phaseArr.count]];
|
}
|
if (self.modelsArrM.count == 0) {
|
self.promptView.hidden = NO;
|
}else {
|
self.promptView.hidden = YES;
|
}
|
[self.tableView reloadData];
|
}];
|
}
|
|
- (void)retrieveModelsWithIndex:(NSInteger)index {
|
[self.modelsArrM removeAllObjects];
|
[self.modelsArrM addObjectsFromArray:self.listArrM[index]];
|
if ([[self.phaseArr[index] valueForKey:@"value"] isEqualToString:self.firstValue]) {
|
[self.modelsArrM addObjectsFromArray:self.listArrM[self.phaseArr.count]];
|
}
|
if (self.modelsArrM.count == 0) {
|
self.promptView.hidden = NO;
|
}else {
|
self.promptView.hidden = YES;
|
}
|
[self.tableView reloadData];
|
}
|
|
- (NSMutableArray *)labelM {
|
if (_labelM == nil) {
|
_labelM = [NSMutableArray array];
|
}
|
return _labelM;
|
}
|
|
- (void)setupNav {
|
PBBackNavItem *backNav = [PBBackNavItem backNacItem];
|
backNav.title = @"项目";
|
[backNav addTarget:self action:@selector(backItemAction) forControlEvents:UIControlEventTouchUpInside];
|
UIBarButtonItem *backNavItem = [[UIBarButtonItem alloc] initWithCustomView:backNav];
|
self.navigationItem.leftBarButtonItem = backNavItem;
|
}
|
- (void)backItemAction {
|
[PBNoteCenter postNotificationName: PBNoteCenterDismissTabBarController object:nil];
|
}
|
- (void)setProjectModel:(PBProjectModel *)projectModel {
|
_projectModel = projectModel;
|
}
|
- (void)setPowerArr:(NSArray *)powerArr {
|
_powerArr = powerArr;
|
}
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
return self.modelsArrM.count;
|
}
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
PBModelsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath];
|
cell.modelsModel = self.modelsArrM[indexPath.row];
|
return cell;
|
}
|
|
- (NSMutableArray<PBModelsModel *> *)modelsArrM {
|
if (_modelsArrM == nil) {
|
_modelsArrM = [[NSMutableArray alloc] init];
|
}
|
return _modelsArrM;
|
}
|
- (NSMutableArray *)listArrM {
|
if (_listArrM == nil) {
|
_listArrM = [[NSMutableArray alloc] init];
|
}
|
return _listArrM;
|
}
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
// PBModelsModel *modelsModel = self.modelsArrM[indexPath.row];
|
// PBModelCategoryViewController *modelCategoryVC = [[PBModelCategoryViewController alloc] init];
|
// modelCategoryVC.hidesBottomBarWhenPushed = YES;
|
// modelCategoryVC.projectModel = _projectModel;
|
// modelCategoryVC.modelsModel = modelsModel;
|
// [self.navigationController pushViewController:modelCategoryVC animated:YES];
|
PBLoadModelDisplayController *modelDisplayVC = [[PBLoadModelDisplayController alloc] init];
|
modelDisplayVC.hidesBottomBarWhenPushed = YES;
|
modelDisplayVC.projectModel = self.projectModel;
|
modelDisplayVC.projectIID = self.projectModel.bimcomposerid;
|
modelDisplayVC.modelID = self.modelsArrM[indexPath.row].ID;
|
[self.navigationController pushViewController:modelDisplayVC animated:YES];
|
}
|
|
|
//- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
|
// UITableViewRowAction *shareAction = [UITableViewRowAction rowActionWithStyle:(UITableViewRowActionStyleDestructive) title:@"分享" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
|
// [self shareWithModelsModel:self.modelsArrM[indexPath.row]];
|
// }];
|
// shareAction.backgroundColor = WarningColor;
|
//
|
// UITableViewRowAction *loadAction =[UITableViewRowAction rowActionWithStyle:(UITableViewRowActionStyleDestructive) title:@"加载" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
|
// PBLoadModelDisplayController *modelDisplayVC = [[PBLoadModelDisplayController alloc] init];
|
// modelDisplayVC.hidesBottomBarWhenPushed = YES;
|
// modelDisplayVC.projectModel = self.projectModel;
|
// modelDisplayVC.projectIID = self.projectModel.bimcomposerid;
|
// modelDisplayVC.modelID = self.modelsArrM[indexPath.row].ID;
|
// [self.navigationController pushViewController:modelDisplayVC animated:YES];
|
// }];
|
// loadAction.backgroundColor = IndicatedColor;
|
// return @[shareAction, loadAction];
|
//}
|
- (void)shareWithModelsModel:(PBModelsModel *)model {
|
[PBKeyWindow addSubview:self.shareView];
|
self.shareView.modelID = model.ID;
|
self.shareView.desc = model.Name;
|
UIImage *image;
|
if([model.Thumbnail isEqualToString:@""]) {
|
image = [UIImage imageNamed:@"logo_unknown"];
|
}else {
|
image = [NSString imageDecoding:model.Thumbnail];
|
}
|
self.shareView.image = image;
|
[self.shareView show];
|
}
|
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
return YES;
|
}
|
- (PBShareView *)shareView {
|
if (_shareView == nil) {
|
_shareView = [[PBShareView alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
CGFloat height;
|
if (IS_IPHONE_X) {
|
height = 290.f + 34.f;
|
}else {
|
height = 290.f;
|
}
|
_shareView.visualViewHeight = height;
|
_shareView.viewController = self;
|
_shareView.projectID = self.projectModel.organizeid;
|
_shareView.viewID = @"";
|
_shareView.viewPointID = @"";
|
_shareView.title = @"模型";
|
}
|
return _shareView;
|
}
|
|
- (PBPromptView *)promptView {
|
if (_promptView == nil) {
|
_promptView = [[PBPromptView alloc] init];
|
_promptView.imageV.image = [UIImage imageNamed:@"Model_category_empty"];
|
_promptView.textL.text = @"此阶段无模型数据";
|
}
|
return _promptView;
|
}
|
|
- (void)didReceiveMemoryWarning {
|
[super didReceiveMemoryWarning];
|
// Dispose of any resources that can be recreated.
|
}
|
|
/*
|
#pragma mark - Navigation
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
// Get the new view controller using [segue destinationViewController].
|
// Pass the selected object to the new view controller.
|
}
|
*/
|
|
@end
|