//
|
// PBArtifactsViewController.m
|
// IphoneBIMe
|
//
|
// Created by zjf on 2020/9/11.
|
// Copyright © 2020 ProBIM. All rights reserved.
|
//
|
|
#import "PBArtifactsViewController.h"
|
#import "PBStructureTableViewCell.h"
|
#import "PBProjectModel.h"
|
#import "PBArtifactsModel.h"
|
#import "PBChooseArtifactsCell.h"
|
#import "PBArtifactsInfoModel.h"
|
#import "PBAddExamineViewController.h"
|
#import "PBSiteMaterialViewController.h"
|
#import "PBSeleceArtifactsViewController.h"
|
#import "PBExamineAddModel.h"
|
#import "PBSiteMechanicalModel.h"
|
static NSString *const cellID = @"cellID";
|
static NSString *const artifactsCellID = @"artifactsCellID";
|
@interface PBArtifactsViewController ()<UITableViewDataSource, UITableViewDelegate, UIGestureRecognizerDelegate>
|
@property (nonatomic, strong) UITableView *tableView;
|
@property (nonatomic, strong) NSArray *dataList;
|
@property (nonatomic, weak) UIView *bottomV;
|
@property (nonatomic, weak) UIButton *determineBtn;
|
@property (nonatomic, weak) UIButton *arrowBtn;
|
@property (nonatomic, weak) UILabel *selectCountL;
|
@end
|
|
@implementation PBArtifactsViewController
|
- (void)viewWillAppear:(BOOL)animated {
|
[super viewWillAppear:animated];
|
NSLog(@"============%zd",self.selectList.count);
|
if ([self.artifactsModel.DirectChildrenCount isEqualToString:@"0"] && ![self.artifactsModel.ChildrenItemCount isEqualToString:@"0"]) {
|
for (PBArtifactsInfoModel *model in self.dataList) {
|
for (PBArtifactsInfoModel *selectModel in self.selectList) {
|
if ([model.bm_guid isEqualToString:selectModel.bm_guid]) {
|
model.isSelected = YES;
|
break;
|
}else {
|
model.isSelected = NO;
|
}
|
}
|
}
|
[self.tableView reloadData];
|
}
|
if (self.selectList.count > 0) {
|
self.bottomV.hidden = NO;
|
self.arrowBtn.hidden = NO;
|
self.selectCountL.hidden = NO;
|
self.determineBtn.hidden = NO;
|
self.selectCountL.text = [NSString stringWithFormat:@"已选择%zd个构件",self.selectList.count];
|
[self.determineBtn setTitle:[NSString stringWithFormat:@"确定(%zd)",self.selectList.count] forState:UIControlStateNormal];
|
}else {
|
// self.bottomV.hidden = YES;
|
// self.arrowBtn.hidden = YES;
|
// self.selectCountL.hidden = YES;
|
// self.determineBtn.hidden = YES;
|
self.bottomV.hidden = NO;
|
self.arrowBtn.hidden = NO;
|
self.selectCountL.hidden = NO;
|
self.determineBtn.hidden = NO;
|
self.selectCountL.text = [NSString stringWithFormat:@"已选择%zd个构件",self.selectList.count];
|
[self.determineBtn setTitle:[NSString stringWithFormat:@"确定(%zd)",self.selectList.count] forState:UIControlStateNormal];
|
}
|
}
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.f) {
|
self.edgesForExtendedLayout = UIRectEdgeNone;
|
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
|
self.navigationController.interactivePopGestureRecognizer.delegate = self;
|
}
|
[self setupNav];
|
[self setupUI];
|
[self loadArtifactsData];
|
}
|
- (void)loadArtifactsData {
|
[YJProgressHUD showProgress:@"" inView:self.view];
|
NSString *code;
|
if (self.artifactsModel == nil) {
|
code = @"";
|
[[PBNetworkTools sharedTools] GetCategoriesWithOrganizeId:self.projectModel.organizeid andBaseCode:code andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
|
if (error) {
|
[YJProgressHUD showMessage:@"加载失败" inView:self.view];
|
return;
|
}
|
NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
|
PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
|
if (networkModel.Ret == 1) {
|
[YJProgressHUD hide];
|
self.dataList = [networkModel.Data valueForKey:@"list"];
|
[self.tableView reloadData];
|
if (self.dataList.count == 0) {
|
[YJProgressHUD showMessage:@"暂无内容,请返回上级选择" inView:self.view];
|
}
|
}else {
|
[YJProgressHUD showMessage:networkModel.Msg inView:self.view];
|
}
|
}];
|
}else {
|
if ([self.artifactsModel.DirectChildrenCount isEqualToString:@"0"]) {
|
if ([self.artifactsModel.ChildrenItemCount isEqualToString:@"0"]) {
|
[YJProgressHUD showMessage:@"暂无数据" inView:self.view];
|
return;
|
}
|
[[PBNetworkTools sharedTools] GetMaterialListWithOrganizeId:self.projectModel.organizeid andBc_guid:self.artifactsModel.bmc_guid andCallBack:^(NSURLResponse *response, id responseObject, NSError *error) {
|
if (error) {
|
[YJProgressHUD showMessage:@"加载失败" inView:self.view];
|
return;
|
}
|
NSString *str = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
|
PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
|
if (networkModel.Ret == 1) {
|
[YJProgressHUD hide];
|
NSMutableArray *arrM = [[NSMutableArray alloc] init];
|
NSArray *list = [networkModel.Data valueForKey:@"List"];
|
for (NSDictionary *obj in list) {
|
PBArtifactsInfoModel *model = [PBArtifactsInfoModel yy_modelWithDictionary:obj];
|
for (PBArtifactsInfoModel *selectModel in self.selectList) {
|
if ([model.bm_guid isEqualToString:selectModel.bm_guid]) {
|
model.isSelected = YES;
|
break;
|
}else {
|
model.isSelected = NO;
|
}
|
}
|
[arrM addObject:model];
|
}
|
self.dataList = arrM.copy;
|
[self.tableView reloadData];
|
if (self.dataList.count == 0) {
|
[YJProgressHUD showMessage:@"暂无内容,请返回上级选择" inView:self.view];
|
}
|
}else {
|
[YJProgressHUD showMessage:networkModel.Msg inView:self.view];
|
}
|
}];
|
}else {
|
code = self.artifactsModel.bmc_code;
|
[[PBNetworkTools sharedTools] GetCategoriesWithOrganizeId:self.projectModel.organizeid andBaseCode:code andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
|
if (error) {
|
[YJProgressHUD showMessage:@"加载失败" inView:self.view];
|
return;
|
}
|
NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
|
PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
|
if (networkModel.Ret == 1) {
|
[YJProgressHUD hide];
|
self.dataList = [networkModel.Data valueForKey:@"list"];
|
[self.tableView reloadData];
|
if (self.dataList.count == 0) {
|
[YJProgressHUD showMessage:@"暂无内容,请返回上级选择" inView:self.view];
|
}
|
}else {
|
[YJProgressHUD showMessage:networkModel.Msg inView:self.view];
|
}
|
}];
|
}
|
}
|
}
|
- (void)setupNav {
|
self.title = @"关联构件";
|
UIBarButtonItem *backNavItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Doc_preview_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backItemAction)];
|
self.navigationItem.leftBarButtonItem = backNavItem;
|
}
|
|
- (void)backItemAction {
|
[self.navigationController popViewControllerAnimated:YES];
|
}
|
- (void)setupUI {
|
self.view.backgroundColor = PBColor(244, 245, 246);
|
self.tableView = [[UITableView alloc] init];
|
self.tableView.backgroundColor = [UIColor whiteColor];
|
self.tableView.dataSource = self;
|
self.tableView.delegate = self;
|
self.tableView.bounces = NO;
|
self.tableView.rowHeight = 47;
|
self.tableView.sectionIndexColor = PBColor(97, 111, 125);
|
UITableView *footerV = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
if (@available(iOS 15.0, *)) {
|
footerV.sectionHeaderTopPadding = 0;
|
};
|
self.tableView.tableFooterView = footerV;
|
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
[self.tableView registerClass:[PBStructureTableViewCell class] forCellReuseIdentifier:cellID];
|
[self.tableView registerClass:[PBChooseArtifactsCell class] forCellReuseIdentifier:artifactsCellID];
|
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 56, 0);
|
[self.view addSubview:self.tableView];
|
CGFloat bottomH = 0.f;
|
if (IS_IPHONE_X) {
|
bottomH = 0.f + IPHONE_X_BOTTOM;
|
}
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.view);
|
make.left.right.equalTo(self.view);
|
make.bottom.equalTo(self.view).offset(-(bottomH));
|
}];
|
// self.tableView.tableHeaderView = [self setupTableHearderView];
|
|
UIView *bottomV = [[UIView alloc] init];
|
bottomV.backgroundColor = [UIColor whiteColor];
|
[self.view addSubview:bottomV];
|
[bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.left.bottom.right.equalTo(self.tableView);
|
make.height.equalTo(@54);
|
}];
|
UIButton *arrowBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"arrow_top"]];
|
[arrowBtn addTarget:self action:@selector(arrowTopActon) forControlEvents:UIControlEventTouchUpInside];
|
[self.view addSubview:arrowBtn];
|
[arrowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(bottomV).offset(15);
|
make.left.equalTo(bottomV).offset(12);
|
make.size.mas_equalTo(CGSizeMake(24, 24));
|
}];
|
UILabel *selectCountL = [UILabel z_labelWithText:[NSString stringWithFormat:@"已选择%zd个构件",self.selectList.count] Color:PBColor(40, 58, 79) isBold:YES Font:14];
|
[self.view addSubview:selectCountL];
|
[selectCountL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.centerY.equalTo(arrowBtn);
|
make.height.equalTo(@20);
|
make.left.equalTo(arrowBtn.mas_right).offset(15);
|
make.right.equalTo(self.view).offset(-120);
|
}];
|
UIButton *determineBtn = [UIButton z_textButton:[NSString stringWithFormat:@"确定(%zd)",self.selectList.count] boldFontSize:14 normalColor:[UIColor whiteColor]];
|
[determineBtn addTarget:self action:@selector(determineBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
determineBtn.backgroundColor = PBColor(0, 122, 255);
|
[self.view addSubview:determineBtn];
|
[determineBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(bottomV).offset(9);
|
make.right.equalTo(bottomV).offset(-20);
|
make.size.mas_equalTo(CGSizeMake(89, 34));
|
}];
|
[determineBtn circleViewWithRadius:6];
|
self.arrowBtn = arrowBtn;
|
self.bottomV = bottomV;
|
self.selectCountL = selectCountL;
|
self.determineBtn = determineBtn;
|
if (self.selectList.count > 0) {
|
self.bottomV.hidden = NO;
|
self.arrowBtn.hidden = NO;
|
self.selectCountL.hidden = NO;
|
self.determineBtn.hidden = NO;
|
}else {
|
// self.bottomV.hidden = YES;
|
// self.arrowBtn.hidden = YES;
|
// self.selectCountL.hidden = YES;
|
// self.determineBtn.hidden = YES;
|
self.bottomV.hidden = NO;
|
self.arrowBtn.hidden = NO;
|
self.selectCountL.hidden = NO;
|
self.determineBtn.hidden = NO;
|
}
|
}
|
- (void)determineBtnAction {
|
[PBNoteCenter postNotificationName:PBNoteCenterUpdateArtifacts object:self.selectList.copy];
|
if (self.examineAddModel) {
|
[self backAction];
|
}else if (self.siteMechanicalModel) {
|
[self backAction1];
|
}
|
}
|
- (UIView *)setupTableHearderView {
|
UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 52)];
|
bgV.backgroundColor = PBColor(244, 245, 246);
|
UIButton *searchBtn = [UIButton z_bgImageButton:[UIImage imageNamed:@"Examine_search_background"]];
|
[searchBtn addTarget:self action:@selector(searchAction) forControlEvents:UIControlEventTouchUpInside];
|
[bgV addSubview:searchBtn];
|
[searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(bgV).offset(8);
|
make.left.equalTo(bgV).offset(10);
|
make.right.equalTo(bgV).offset(-10);
|
make.height.equalTo(@36);
|
}];
|
return bgV;
|
}
|
- (void)searchAction {
|
|
}
|
- (void)arrowTopActon {
|
PBSeleceArtifactsViewController *selectArtifactsVC = [[PBSeleceArtifactsViewController alloc] init];
|
selectArtifactsVC.type = @"Artifacts";
|
selectArtifactsVC.selectList = self.selectList;
|
[self.navigationController pushViewController:selectArtifactsVC animated:YES];
|
}
|
- (void)backAction{
|
UINavigationController *navVC = self.navigationController;
|
NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
|
for (UIViewController *vc in [navVC viewControllers]) {
|
[viewControllers addObject:vc];
|
if ([vc isKindOfClass:[PBAddExamineViewController class]]) {
|
break;
|
}
|
}
|
[navVC setViewControllers:viewControllers animated:YES];
|
}
|
- (void)backAction1{
|
UINavigationController *navVC = self.navigationController;
|
NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
|
for (UIViewController *vc in [navVC viewControllers]) {
|
[viewControllers addObject:vc];
|
if ([vc isKindOfClass:[PBSiteMaterialViewController class]]) {
|
break;
|
}
|
}
|
[navVC setViewControllers:viewControllers animated:YES];
|
}
|
#pragma mark - UITableViewDataSource
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
return self.dataList.count;
|
}
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
if ([self.artifactsModel.DirectChildrenCount isEqualToString:@"0"] && ![self.artifactsModel.ChildrenItemCount isEqualToString:@"0"]) {
|
PBChooseArtifactsCell *cell = [tableView dequeueReusableCellWithIdentifier:artifactsCellID forIndexPath:indexPath];
|
PBArtifactsInfoModel *infoModel = self.dataList[indexPath.row];
|
cell.artifactsInfoModel = infoModel;
|
__weak typeof(cell) weakCell = cell;
|
cell.saveBlock = ^(BOOL isSave) {
|
if (isSave) {
|
[self.selectList addObject:infoModel];
|
}else {
|
for (PBArtifactsInfoModel *model in self.selectList) {
|
if ([model.bm_guid isEqualToString:infoModel.bm_guid]) {
|
[self.selectList removeObject:model];
|
break;
|
}
|
}
|
}
|
if (self.selectList.count > 0) {
|
self.bottomV.hidden = NO;
|
self.arrowBtn.hidden = NO;
|
self.selectCountL.hidden = NO;
|
self.determineBtn.hidden = NO;
|
self.selectCountL.text = [NSString stringWithFormat:@"已选择%zd个构件",self.selectList.count];
|
[self.determineBtn setTitle:[NSString stringWithFormat:@"确定(%zd)",self.selectList.count] forState:UIControlStateNormal];
|
}else {
|
// self.bottomV.hidden = YES;
|
// self.arrowBtn.hidden = YES;
|
// self.selectCountL.hidden = YES;
|
// self.determineBtn.hidden = YES;
|
self.bottomV.hidden = NO;
|
self.arrowBtn.hidden = NO;
|
self.selectCountL.hidden = NO;
|
self.determineBtn.hidden = NO;
|
self.selectCountL.text = [NSString stringWithFormat:@"已选择%zd个构件",self.selectList.count];
|
[self.determineBtn setTitle:[NSString stringWithFormat:@"确定(%zd)",self.selectList.count] forState:UIControlStateNormal];
|
}
|
};
|
return cell;
|
}else {
|
PBStructureTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
|
NSDictionary *dict = self.dataList[indexPath.row];
|
PBArtifactsModel *artifactsModel = [PBArtifactsModel yy_modelWithDictionary:dict];
|
cell.artifactsModel = artifactsModel;
|
cell.NextLevelBlock = ^{
|
PBArtifactsViewController *vc = [[PBArtifactsViewController alloc] init];
|
vc.projectModel = self.projectModel;
|
if (self.examineAddModel) {
|
vc.examineAddModel = self.examineAddModel;
|
} else if (self.siteMechanicalModel){
|
vc.siteMechanicalModel = self.siteMechanicalModel;
|
}
|
vc.artifactsModel = artifactsModel;
|
vc.selectList = self.selectList;
|
[self.navigationController pushViewController:vc animated:YES];
|
};
|
return cell;
|
}
|
}
|
#pragma mark - UITableViewDelegate
|
- (void)setArtifactsModel:(PBArtifactsModel *)artifactsModel {
|
_artifactsModel = artifactsModel;
|
}
|
- (void)setProjectModel:(PBProjectModel *)projectModel {
|
_projectModel = projectModel;
|
}
|
|
- (NSMutableArray *)selectList {
|
if (_selectList == nil) {
|
_selectList = [[NSMutableArray alloc] init];
|
}
|
return _selectList;;
|
}
|
- (void)setExamineAddModel:(PBExamineAddModel *)examineAddModel {
|
_examineAddModel = examineAddModel;
|
}
|
- (void)setSiteMechanicalModel:(PBSiteMechanicalModel *)siteMechanicalModel {
|
_siteMechanicalModel = siteMechanicalModel;
|
}
|
/*
|
#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
|