// // PBChooseOneTaskViewController.m // IphoneBIMe // // Created by ZhangJF on 2022/8/26. // Copyright © 2022 ProBIM. All rights reserved. // #import "PBChooseOneTaskViewController.h" #import "PBSchedulePlanModel.h" #import "PBChooseTasksCell.h" #import "PBTaskScheduleViewController.h" static NSString *const tasksCellID = @"tasksCellID"; @interface PBChooseOneTaskViewController () @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSArray *dataList; @property (nonatomic, weak) UIView *bottomV; @property (nonatomic, weak) UIButton *determineBtn; @end @implementation PBChooseOneTaskViewController - (void)viewWillAppear:(BOOL)animated { [super viewDidAppear:animated]; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.f) { self.edgesForExtendedLayout = UIRectEdgeNone; self.navigationController.interactivePopGestureRecognizer.enabled = NO; //让rootView禁止滑动 } } - (void)viewDidLoad { [super viewDidLoad]; [self setupNav]; [self setupUI]; } - (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:[PBChooseTasksCell class] forCellReuseIdentifier:tasksCellID]; 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)); }]; // 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 *determineBtn = [UIButton z_textButton:@"确定" 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.bottomV = bottomV; // self.determineBtn = determineBtn; } - (void)determineBtnAction:(PBSchedulePlanModel *)planModel { [PBNoteCenter postNotificationName:PBNoteCenterChooseTask object:planModel]; [self backAction]; } - (void)backAction{ UINavigationController *navVC = self.navigationController; NSMutableArray *viewControllers = [[NSMutableArray alloc] init]; for (UIViewController *vc in [navVC viewControllers]) { [viewControllers addObject:vc]; if ([vc isKindOfClass:[PBTaskScheduleViewController 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 { PBSchedulePlanModel *taskInfoModel = [PBSchedulePlanModel yy_modelWithDictionary:self.dataList[indexPath.row]]; PBChooseTasksCell *cell = [tableView dequeueReusableCellWithIdentifier:tasksCellID forIndexPath:indexPath]; cell.planModel = taskInfoModel; cell.saveBlock = ^(BOOL isSave) { NSString *planStr = @""; if (self.planModel.mobilePlan == nil || [self.planModel.mobilePlan isEqualToString: @""]){ planStr = taskInfoModel.Name; }else { planStr = [NSString stringWithFormat:@"%@-->%@",self.planModel.mobilePlan ,taskInfoModel.Name]; } taskInfoModel.mobilePlan = planStr; [self determineBtnAction:taskInfoModel]; }; cell.nextBlock = ^{ PBChooseOneTaskViewController *vc = [[PBChooseOneTaskViewController alloc] init]; NSString *planStr = @""; if (self.planModel.mobilePlan == nil || [self.planModel.mobilePlan isEqualToString: @""]){ planStr = taskInfoModel.Name; }else { planStr = [NSString stringWithFormat:@"%@-->%@",self.planModel.mobilePlan ,taskInfoModel.Name]; } taskInfoModel.mobilePlan = planStr; vc.planModel = taskInfoModel; [self.navigationController pushViewController:vc animated:YES]; }; return cell; } - (void)setPlanModel:(PBSchedulePlanModel *)planModel { _planModel = planModel; self.dataList = planModel.children; [self.tableView reloadData]; } /* #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