// // PBDivisionViewController.m // IphoneBIMe // // Created by zjf on 2018/12/20. // Copyright © 2018 ProBIM. All rights reserved. // #import "PBDivisionViewController.h" #import "PBItemizedViewController.h" #import "PBExamineAddModel.h" static NSString *const cellID = @"cellID"; @interface PBDivisionViewController () @property (nonatomic, strong) UITableView *tableView; @end @implementation PBDivisionViewController - (void)viewDidLoad { [super viewDidLoad]; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.f) { self.edgesForExtendedLayout = UIRectEdgeNone; } [self setupNav]; [self setupUI]; } - (void)setupNav { self.title = @"分部工程"; 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 { UILabel *titleL = [UILabel z_labelWithText:@"请选择分部工程" Color:DescColor isBold:NO Font:12]; titleL.backgroundColor = PBColor(242, 242, 242); [self.view addSubview:titleL]; [titleL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.right.equalTo(self.view); make.left.equalTo(self.view).offset(16); make.height.equalTo(@24); }]; self.view.backgroundColor = [UIColor whiteColor]; self.tableView = [[UITableView alloc] init]; self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; self.tableView.dataSource = self; self.tableView.delegate = self; self.tableView.rowHeight = 42; [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID]; [self.view addSubview:self.tableView]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view).offset(24); make.right.bottom.equalTo(self.view); make.left.equalTo(self.view).offset(16); }]; } #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _dataList.count + 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath]; if (indexPath.row == 0) { cell.textLabel.text = @"无分部工程"; }else { NSDictionary *dict = self.dataList[indexPath.row - 1]; cell.textLabel.text = [dict valueForKey:@"name"]; } return cell; } #pragma mark - UITableViewDelegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) { [self setupData]; [PBNoteCenter postNotificationName:PBNoteCenterUpdateDivision object:nil]; [self.navigationController popToRootViewControllerAnimated:YES]; }else { PBItemizedViewController *itemizedVC = [[PBItemizedViewController alloc] init]; NSArray *arr = [self.dataList[indexPath.row - 1] valueForKey:@"children"]; for (NSDictionary *dict in arr) { NSString *title = [dict valueForKey:@"title"]; if ([title isEqualToString:@"分项工程"]) { itemizedVC.dataList = [dict valueForKey:@"items"]; } } itemizedVC.divisionDict = self.dataList[indexPath.row - 1]; itemizedVC.examineArr = self.examineArr; [self.navigationController pushViewController:itemizedVC animated:YES]; } } - (void)setupData { NSDictionary *dict = @{ @"name" : @"<无分部工程>", @"value" : @"", @"children" : @[] }; NSDictionary *dict1 = @{ @"name" : @"<无分项工程>", @"value" : @"", @"children" : @[] }; NSDictionary *dict2 = @{ @"name" : @"<无检验批>", @"value" : @"", @"children" : @[] }; self.examineArr[0].dataDict = dict; self.examineArr[1].dataDict = dict1; self.examineArr[2].dataDict = dict2; } - (void)setDataList:(NSArray *)dataList { _dataList = dataList; } - (void)setExamineArr:(NSArray *)examineArr { _examineArr = examineArr; } /* #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