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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
//
//  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