// // PBItemizedViewController.m // IphoneBIMe // // Created by zjf on 2018/12/21. // Copyright © 2018 ProBIM. All rights reserved. // #import "PBItemizedViewController.h" #import "PBTestViewController.h" #import "PBExamineAddModel.h" static NSString *const cellID = @"cellID"; @interface PBItemizedViewController () @property (nonatomic, strong) UITableView *tableView; @end @implementation PBItemizedViewController - (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 { PBTestViewController *testVC = [[PBTestViewController alloc] init]; NSArray *arr = [self.dataList[indexPath.row - 1] valueForKey:@"children"]; for (NSDictionary *dict in arr) { NSString *title = [dict valueForKey:@"title"]; if ([title isEqualToString:@"检验批"]) { testVC.dataList = [dict valueForKey:@"items"]; } } testVC.examineArr = self.examineArr; testVC.divisionDict = self.divisionDict; testVC.itemizedDict = self.self.dataList[indexPath.row - 1]; [self.navigationController pushViewController:testVC animated:YES]; } } - (void)setupData { NSDictionary *dict1 = @{ @"name" : @"<无分项工程>", @"value" : @"", @"children" : @[] }; NSDictionary *dict2 = @{ @"name" : @"<无检验批>", @"value" : @"", @"children" : @[] }; self.examineArr[0].dataDict = self.divisionDict; self.examineArr[1].dataDict = dict1; self.examineArr[2].dataDict = dict2; } - (void)setDataList:(NSArray *)dataList { _dataList = dataList; } - (void)setExamineArr:(NSArray *)examineArr { _examineArr = examineArr; } - (void)setDivisionDict:(NSDictionary *)divisionDict { _divisionDict = divisionDict; } /* #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