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
//
//  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 ()<UITableViewDataSource, UITableViewDelegate>
@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