// // PBRoleViewController.m // IphoneBIMe // // Created by zjf on 2021/1/6. // Copyright © 2021 ProBIM. All rights reserved. // #import "PBRoleViewController.h" #import "PBProjectModel.h" #import "PBPersonRoleTableViewCell.h" #import "PBRolePersonViewController.h" static NSString *const CellID = @"CellID"; @interface PBRoleViewController () @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSArray *dataList; @end @implementation PBRoleViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupNav]; [self setupUI]; [self loadData]; } - (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 = 56; 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:[PBPersonRoleTableViewCell class] forCellReuseIdentifier:CellID]; [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 *)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)loadData { [YJProgressHUD showProgress:@"" inView:self.view]; [[PBNetworkTools sharedTools] GetProjectRolesAndUsersOrganizeID:self.projectModel.organizeid andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) { if (error) { [YJProgressHUD showMessage:@"加载失败" inView:self.view]; NSLog(@"%@",error); return; } NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; NSLog(@"%@",str); PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str]; if (networkModel.Ret == 1) { [YJProgressHUD hide]; self.dataList = [networkModel.Data valueForKey:@"List"]; [self.tableView reloadData]; }else { [YJProgressHUD showMessage:networkModel.Msg inView:self.view]; } }]; } #pragma mark - UITableViewDelegate, UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataList.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { PBPersonRoleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath]; cell.selectionStyle = UITableViewCellSelectionStyleNone; NSDictionary *dict = self.dataList[indexPath.row]; cell.roleDict = dict; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *dict = self.dataList[indexPath.row]; NSString *roleId = [dict valueForKey:@"RoleId"]; PBRolePersonViewController *personListVC = [[PBRolePersonViewController alloc] init]; personListVC.roleID = roleId; personListVC.projectModel = self.projectModel; personListVC.isMultiSelect = self.isMultiSelect; personListVC.selectList = self.selectList; [self.navigationController pushViewController:personListVC animated:YES]; } - (void)setProjectModel:(PBProjectModel *)projectModel { _projectModel = projectModel; } - (void)setIsMultiSelect:(BOOL)isMultiSelect { _isMultiSelect = isMultiSelect; } - (void)setSelectList:(NSMutableArray *)selectList { _selectList = selectList; } /* #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