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
364
365
366
//
//  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 ()<UITableViewDelegate,UITableViewDataSource>
{
    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