// // PBModelViewController.m // IphoneBIMe // // Created by zjf on 2020/7/28. // Copyright © 2020 ProBIM. All rights reserved. // #import "PBModelViewController.h" #import "PBProjectModel.h" #import "PBModelsModel.h" #import "PBModelLeftTableViewCell.h" #import "PBRightTableViewCell.h" #import "PBBlankTableViewCell.h" #import "PBModelSearchController.h" #import "PBLoadModelDisplayController.h" #import "PBShareView.h" static NSString *const LeftCellID = @"LeftCellID"; static NSString *const RightCellID = @"RightCellID"; static NSString *const BlackCellID = @"BlackCellID"; @interface PBModelViewController () { NSInteger _leftIndex;//左边被选中的索引值 // BOOL _isSelectSlide;//是点击leftTableView,还是拖拽右边的滑动视图 } @property (nonatomic,strong) NSArray *phaseArr; @property (nonatomic,strong) NSMutableArray *listArrM; //左视图-->标签tableView @property (nonatomic , strong)UITableView *leftTabView; //右视图-->列表样式or卡片样式 @property (nonatomic , strong)UITableView *rightTabView; @property (nonatomic, strong) PBShareView *shareView; @end @implementation PBModelViewController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault; } - (void)viewDidLoad { [super viewDidLoad]; _leftIndex = 0; [self setupUI]; [self loadProjectConfig]; } - (void)setupUI { PBBackNavItem *backNav = [PBBackNavItem backNacItem]; backNav.title = @" "; [backNav addTarget:self action:@selector(backItemAction) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *backNavItem = [[UIBarButtonItem alloc] initWithCustomView:backNav]; self.navigationItem.leftBarButtonItem = backNavItem; // UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search_background"]]; // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(searchAction:)]; // imageV.userInteractionEnabled = YES; // [imageV addGestureRecognizer:tap]; // self.navigationItem.titleView = imageV; self.leftTabView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped]; self.leftTabView.dataSource = self; self.leftTabView.delegate = self; self.leftTabView.backgroundColor = [UIColor whiteColor]; self.leftTabView.tableFooterView = [UIView new]; self.leftTabView.showsVerticalScrollIndicator = NO; self.leftTabView.rowHeight = 62.f; [self.leftTabView registerClass:[PBModelLeftTableViewCell class] forCellReuseIdentifier:LeftCellID]; self.leftTabView.separatorStyle = UITableViewCellSeparatorStyleNone; [self.view addSubview:self.leftTabView]; [self.leftTabView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.bottom.equalTo(self.view); make.width.equalTo(@(takeawayLeft_W)); }]; self.rightTabView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; self.rightTabView.dataSource = self; self.rightTabView.delegate = self; self.rightTabView.backgroundColor = PBColor(245, 244, 247); self.rightTabView.tableFooterView = [UIView new]; self.rightTabView.separatorStyle = UITableViewCellSeparatorStyleNone; self.rightTabView.showsVerticalScrollIndicator = NO; self.rightTabView.rowHeight = UITableViewAutomaticDimension; self.rightTabView.estimatedRowHeight = 100.f; [self.rightTabView registerClass:[PBRightTableViewCell class] forCellReuseIdentifier:RightCellID]; [self.rightTabView registerClass:[PBBlankTableViewCell class] forCellReuseIdentifier:BlackCellID]; [self.view addSubview:self.rightTabView]; [self.rightTabView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.leftTabView.mas_right); make.top.bottom.right.equalTo(self.view); }]; if (@available(iOS 15.0, *)) { self.rightTabView.sectionHeaderTopPadding = 0; } // self.rightTabView.contentInset = UIEdgeInsetsMake(0, 0, 0, 10 ); } - (void)backItemAction { [PBNoteCenter postNotificationName: PBNoteCenterDismissTabBarController object:nil]; } - (void)searchAction:(UITapGestureRecognizer *)tap { PBModelSearchController *searchVC = [[PBModelSearchController alloc] init]; searchVC.projectModel = self.projectModel; searchVC.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:searchVC animated:YES]; } - (void)loadProjectConfig { // [YJProgressHUD showCustomAnimation:@"" inview:self.view]; [YJProgressHUD showProgress:@"" 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]; }]; } - (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]; } [self.leftTabView reloadData]; [self.rightTabView reloadData]; }]; } #pragma mark - FSBaseTableViewDataSource & FSBaseTableViewDelegate 委托方法 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if (tableView == self.leftTabView) { return 1; } return self.listArrM.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (tableView == self.leftTabView) { return self.phaseArr.count; } NSArray *arr = self.listArrM[section]; if (arr.count == 0) { return 1; }else { return arr.count; } } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (tableView == _rightTabView) { return 26; }else{ return 0.01; } } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { //最后一个 return 0.01; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return nil; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if (tableView == _rightTabView) { UIView *bgView = [[UIView alloc]init]; bgView.backgroundColor = PBColor(245, 244, 247); NSDictionary *dict = self.phaseArr[section]; UILabel *nameL = [UILabel z_labelWithText:[dict valueForKey:@"name"] Color:PBColor(97, 111, 125) isBold:YES Font:12]; [bgView addSubview:nameL]; [nameL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(bgView).offset(10); make.left.equalTo(bgView).offset(10); make.height.equalTo(@16); }]; return bgView; } return nil; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView == _leftTabView) { PBModelLeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LeftCellID forIndexPath:indexPath]; cell.dict = self.phaseArr[indexPath.row]; UIView *selectView = [[UIView alloc]initWithFrame:cell.frame]; selectView.backgroundColor = PBColor(245, 244, 247); UIView *linV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 4, 62.f)]; linV.backgroundColor = PBColor(0, 122, 255); [selectView addSubview:linV]; cell.selectedBackgroundView = selectView; if (indexPath.row == _leftIndex) { [_leftTabView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; } return cell; }else { NSArray *arr = self.listArrM[indexPath.section]; if (arr.count == 0) { PBBlankTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:BlackCellID forIndexPath:indexPath]; return cell; }else { PBRightTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:RightCellID forIndexPath:indexPath]; cell.modelsModel = arr[indexPath.row]; return cell; } } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (_leftTabView == tableView) { // //选中_leftTabView而不是拖拽右边的滑动视图 // _isSelectSlide = YES; [_rightTabView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:indexPath.row] atScrollPosition:UITableViewScrollPositionTop animated:YES]; [_leftTabView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle]; _leftIndex = indexPath.row; }else{ PBLoadModelDisplayController *modelDisplayVC = [[PBLoadModelDisplayController alloc] init]; modelDisplayVC.hidesBottomBarWhenPushed = YES; modelDisplayVC.projectModel = self.projectModel; modelDisplayVC.projectIID = self.projectModel.bimcomposerid; NSArray *arr = self.listArrM[indexPath.section]; PBModelsModel *modelsModel = arr[indexPath.row]; modelDisplayVC.modelID = modelsModel.ID; [self.navigationController pushViewController:modelDisplayVC animated:YES]; } } - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { if (_rightTabView == tableView){ // UITableViewRowAction *shareAction = [UITableViewRowAction rowActionWithStyle:(UITableViewRowActionStyleDestructive) title:@"分享" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { // NSArray *arr = self.listArrM[indexPath.section]; // PBModelsModel *modelsModel = arr[indexPath.row]; // [self shareWithModelsModel:modelsModel]; // }]; // 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; NSArray *arr = self.listArrM[indexPath.section]; PBModelsModel *modelsModel = arr[indexPath.row]; modelDisplayVC.modelID = modelsModel.ID; [self.navigationController pushViewController:modelDisplayVC animated:YES]; }]; loadAction.backgroundColor = IndicatedColor; return @[loadAction]; }else { return @[]; } } - (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:@"Project_list_cellImg_bg"]; }else { image = [NSString imageDecoding:model.Thumbnail]; } self.shareView.image = image; [self.shareView show]; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView != _leftTabView) { if (!(scrollView.isTracking || scrollView.isDecelerating)) { }else { NSArray *array; array = _rightTabView.indexPathsForVisibleRows; if (array.count > 0) { //1:找到indexPath NSIndexPath *indexPath = array[0]; //2:可见的第一个section位置 NSInteger section = indexPath.section; //3: // if (!_isSelectSlide) { NSLog(@"section:--------%zd",section); //只有拖拽的时候,才执行该方法 [_leftTabView selectRowAtIndexPath:[NSIndexPath indexPathForRow:section inSection:0] animated:NO scrollPosition:UITableViewScrollPositionMiddle]; // } } } } } - (void)setProjectModel:(PBProjectModel *)projectModel { _projectModel = projectModel; } - (void)setPowerArr:(NSArray *)powerArr { _powerArr = powerArr; } - (NSMutableArray *)listArrM { if (_listArrM == nil) { _listArrM = [[NSMutableArray alloc] init]; } return _listArrM; } - (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; } /* #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