// // PBPositioningTypeViewController.m // IphoneBIMe // // Created by zjf on 2018/12/17. // Copyright © 2018 ProBIM. All rights reserved. // #import "PBPositioningTypeViewController.h" #import "PBModelsModel.h" #import "PBViewPointModel.h" #import "PBPromptView.h" #import "PBTextTableViewCell.h" #import "PBImageTableViewCell.h" #import "PBDrawingsModel.h" #import "PBEViewPointDetailsController.h" #import "PBEDrawingsShowController.h" #import "PBExamineAddModel.h" static NSString *const TextCellID = @"TextCellID"; static NSString *const ImageCellID = @"ImageCellID"; @interface PBPositioningTypeViewController () @property (nonatomic, assign) BOOL isDraw; @property (nonatomic, strong) NSMutableArray *dataList; @property (nonatomic, strong) PBPromptView *promptView; @property (nonatomic, strong) UITableView *tableView; @end @implementation PBPositioningTypeViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupNav]; [self setupUI]; [self loadViewPoint]; } - (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 { [self.navigationController popViewControllerAnimated:YES]; } - (void)setupUI { self.view.backgroundColor = [UIColor whiteColor]; NSArray * _titles = @[@"模型定位", @"图纸定位"]; UISegmentedControl * segmentedControl = [[UISegmentedControl alloc] initWithItems:_titles]; segmentedControl.size = CGSizeMake(200, 32); segmentedControl.selectedSegmentIndex = 0; segmentedControl.tintColor = TitleColor; [segmentedControl addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged]; self.navigationItem.titleView = segmentedControl; self.tableView = [[UITableView alloc] init]; self.tableView.dataSource = self; self.tableView.delegate = self; self.tableView.rowHeight = 70; self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; [self.tableView registerClass:[PBTextTableViewCell class] forCellReuseIdentifier:TextCellID]; [self.tableView registerClass:[PBImageTableViewCell class] forCellReuseIdentifier:ImageCellID]; [self.view addSubview:self.tableView]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.bottom.equalTo(self.view); }]; [self.view addSubview:self.promptView]; [self.promptView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.tableView); make.bottom.left.right.equalTo(self.view); }]; self.promptView.hidden = YES; } - (void)segmentValueChanged:(UISegmentedControl *)segment { switch (segment.selectedSegmentIndex) { case 0: { self.isDraw = NO; [self loadViewPoint]; break; } case 1: { self.isDraw = YES; [self loadDraw]; break; } default: break; } } - (void)loadViewPoint { [YJProgressHUD showProgress:@"" inView:self.view]; self.dataList = nil; [self.tableView reloadData]; self.promptView.hidden = YES; [[PBNetworkTools sharedTools] RequestGetAllViewpointWithProjectId:_modelsModel.ProjectID andModelId:_modelsModel.ID 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]; 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.dataList = arrM; if (self.dataList.count == 0) { self.promptView.hidden = NO; }else { [self.tableView reloadData]; } }]; } - (void)loadDraw { [YJProgressHUD showProgress:@"" inView:self.view]; self.dataList = nil; [self.tableView reloadData]; self.promptView.hidden = YES; [[PBNetworkTools sharedTools] RequestGetFIleWithProjectID:_modelsModel.ProjectID andModelID:_modelsModel.ID andVersionNO:@"" andFileType:@"PlanView" andFileName:@"sheets" 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]; NSDictionary *dict = [NSString convertTodictionaryOrArr:str]; NSMutableArray *arrM = [[NSMutableArray alloc] init]; for (NSDictionary *obj in [dict valueForKey:@"sheets"]) { PBDrawingsModel *model = [PBDrawingsModel yy_modelWithDictionary:obj]; [arrM addObject:model]; } self.dataList = arrM; if (self.dataList.count == 0) { self.promptView.hidden = NO; }else { [self.tableView reloadData]; } }]; } #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataList.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { id model = self.dataList[indexPath.row]; PBImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ImageCellID forIndexPath:indexPath]; if (self.isDraw) { cell.drawingsModel = (PBDrawingsModel *)model; }else { cell.viewPointModel = (PBViewPointModel *)model; } return cell; } #pragma mark - UITableViewDelegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (self.isDraw) { // 图纸选择 PBDrawingsModel *drawingsModel = self.dataList[indexPath.row]; PBEDrawingsShowController *drawingsShowVC = [[PBEDrawingsShowController alloc] init]; drawingsShowVC.modelsModel = _modelsModel; drawingsShowVC.drawingsModel = drawingsModel; drawingsShowVC.examineAddModel = self.examineAddModel; [self.navigationController pushViewController:drawingsShowVC animated:YES]; }else { // 视点选择 PBViewPointModel *viewPointModel = self.dataList[indexPath.row]; PBEViewPointDetailsController *viewPointDetailsVC = [[PBEViewPointDetailsController alloc] init]; viewPointDetailsVC.updataDefaultViewPointBlock = ^{ // [self loadData:self.index]; }; viewPointDetailsVC.projectModel = _projectModel; viewPointDetailsVC.modelsModel = _modelsModel; viewPointDetailsVC.viewPointModel = viewPointModel; viewPointDetailsVC.isExamineShow = YES; viewPointDetailsVC.examineAddModel = self.examineAddModel; [self.navigationController pushViewController:viewPointDetailsVC animated:YES]; } } - (PBPromptView *)promptView { if (_promptView == nil) { _promptView = [[PBPromptView alloc] init]; _promptView.imageV.image = [UIImage imageNamed:@"Model_category_empty"]; _promptView.textL.text = @"暂无数据"; _promptView.hidden = YES; } return _promptView; } - (void)setModelsModel:(PBModelsModel *)modelsModel { _modelsModel = modelsModel; } - (void)setProjectModel:(PBProjectModel *)projectModel { _projectModel = projectModel; } - (void)setExamineAddModel:(PBExamineAddModel *)examineAddModel { _examineAddModel = examineAddModel; } /* #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