// // PBIssueListViewController.m // IphoneBIMe // // Created by zjf on 2018/7/18. // Copyright © 2018年 ProBIM. All rights reserved. // #import "PBIssueListViewController.h" #import "PBDropdownMenu.h" #import "PBIssueSearchController.h" #import "PBNavigationController.h" #import "PBAddIssueController.h" #import "PBProjectPower.h" #define IssueModuleName @"IssueTracking" @interface PBIssueListViewController () @property (nonatomic, strong) NSArray *roleArr; @property (nonatomic, strong) NSArray *archiveArr; @end @implementation PBIssueListViewController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault; } - (void)viewDidLoad { [super viewDidLoad]; [self setupNav]; for (PBProjectPower *power in self.powerArr) { if ([power.Bm_EnCode isEqualToString:IssueModuleName]) { if ([power.checkstate isEqualToString:@"1"]) { //有权限 self.promptView.hidden = YES; [self getProjectParentId]; // [self.tableView.mj_header beginRefreshing]; for (NSDictionary *obj in power.Bmbs) { if ([[obj valueForKey:@"Bmb_FullName"] isEqualToString:@"新增问题"]) { if ([[obj valueForKey:@"checkstate"] isEqualToString:@"1"]) { self.navigationItem.rightBarButtonItem.enabled = YES; } } } return; }else { //无权限 self.promptView.textL.text = @"暂无权限"; self.promptView.hidden = NO; return; } } } //无权限 self.promptView.textL.text = @"暂无权限"; self.promptView.hidden = NO; } #pragma mark - PBDropdownMenuDelegate - (void)dropdownMenu:(UIButton *)clickBtn selectedCellNumber:(NSInteger)number { NSInteger index = clickBtn.tag -100; switch (index) { case 0: self.statusSelectIndex = number; [self.tableView.mj_header beginRefreshing]; break; case 1: self.typeSelectIndex = number; [self.tableView.mj_header beginRefreshing]; break; // case 2: // self.userSelectIndex = number; // [self.tableView.mj_header beginRefreshing]; // break; case 2: self.archiveSelectIndex = number; [self.tableView.mj_header beginRefreshing]; break; default: break; } } - (void)getProjectParentId { // [YJProgressHUD showCustomAnimation:@"" inview:self.view]; [YJProgressHUD showProgress:@"" inView:self.view]; [[PBNetworkTools sharedTools] getProjectParentIDWithProjectID:self.projectModel.organizeid andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) { if (error) { NSLog(@"%@",error); [YJProgressHUD showMessage:@"加载状态、类型失败" inView:self.view]; return; } NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; NSLog(@"%@",str); PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str]; if (networkModel.Ret == 1){ [self loadTypeAndStatusWith:networkModel.Data]; }else { [YJProgressHUD showMessage:@"加载状态、类型失败" inView:self.view]; } }]; } - (void)loadTypeAndStatusWith:(NSString *)parentId { __block NSArray *statusArr; __block NSArray *typeArr; dispatch_semaphore_t sem = dispatch_semaphore_create(0); NSInteger commandCount = 2; __block NSInteger httpFinishCount = 0; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [[PBNetworkTools sharedTools] getIssueStatusWithCompanyId:parentId andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) { if (error) { NSLog(@"%@",error); [YJProgressHUD showMessage:@"加载状态失败" inView:self.view]; return; } NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str]; if ([networkModel.Msg isEqualToString:@"OK"]) { statusArr = networkModel.Data; if (++httpFinishCount == commandCount) { dispatch_semaphore_signal(sem); } }else { [YJProgressHUD showMessage:@"加载状态失败" inView:self.view]; return; } }]; [[PBNetworkTools sharedTools] getIssueTypesWithCompanyId:parentId andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) { if (error) { NSLog(@"%@",error); [YJProgressHUD showMessage:@"加载类型失败" inView:self.view]; return; } NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str]; if ([networkModel.Msg isEqualToString:@"OK"]) { typeArr = networkModel.Data; if (++httpFinishCount == commandCount) { dispatch_semaphore_signal(sem); } }else { [YJProgressHUD showMessage:@"加载类型失败" inView:self.view]; return; } }]; //如果全部请求没有返回则该线程会一直阻塞 dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); NSLog(@"全部加载完成==================: %@", [NSThread currentThread]); dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"更新视图UI update in main thread!:%@",[NSThread currentThread]); [YJProgressHUD hide]; NSMutableArray *statusArrM = [[NSMutableArray alloc] init]; for (NSDictionary *dict in statusArr) { PBIssueNavModel *issueNavModel = [PBIssueNavModel yy_modelWithDictionary:dict]; [statusArrM addObject:issueNavModel]; } NSMutableArray *typeArrM = [[NSMutableArray alloc] init]; for (NSDictionary *dict in typeArr) { PBIssueNavModel *issueNavModel = [PBIssueNavModel yy_modelWithDictionary:dict]; [typeArrM addObject:issueNavModel]; } self.statusAndTypeData = @{@"IssueStatus":statusArrM.mutableCopy, @"IssueTypes":typeArrM.mutableCopy}; PBIssueNavModel *statusNavModel = [[PBIssueNavModel alloc] init]; statusNavModel.ItemDetailId = @""; statusNavModel.ItemName = @"状态"; [statusArrM insertObject:statusNavModel atIndex:0]; PBIssueNavModel *typeNavModel = [[PBIssueNavModel alloc] init]; typeNavModel.ItemDetailId = @""; typeNavModel.ItemName = @"类型"; [typeArrM insertObject:typeNavModel atIndex:0]; [self.dropdownMenuArrM addObject:statusArrM]; [self.dropdownMenuArrM addObject:typeArrM]; // [self.dropdownMenuArrM addObject:self.roleArr];//去掉我相关检索 [self.dropdownMenuArrM addObject:self.archiveArr]; [self setupDropdownMenuView]; [self.tableView.mj_header beginRefreshing]; }); }); } - (void)setupDropdownMenuView { float dropdownMenuW = MainScreenWidth / (self.dropdownMenuArrM.count + 1); PBDropdownMenu *dropdownMenu = [[PBDropdownMenu alloc] initWithFrame:CGRectMake(0, 0, self.dropdownMenuArrM.count * dropdownMenuW, 40) andArr:self.dropdownMenuArrM]; dropdownMenu.delegate = self; [self.view addSubview:dropdownMenu]; UIButton *searchBtn = [[UIButton alloc] init]; [searchBtn setImage:[UIImage imageNamed:@"Doc_list_searchItem"] forState:UIControlStateNormal]; searchBtn.backgroundColor = [UIColor z_colorWithR:242 G:242 B:242]; searchBtn.frame = CGRectMake(dropdownMenuW * self.dropdownMenuArrM.count, 0, dropdownMenuW, 40); [searchBtn addTarget:self action:@selector(searchAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:searchBtn]; } - (void)searchAction { PBIssueSearchController *searchVC = [[PBIssueSearchController alloc] init]; searchVC.projectModel = self.projectModel; searchVC.hidesBottomBarWhenPushed = YES; searchVC.dropdownMenuArrM = self.dropdownMenuArrM; searchVC.statusSelectIndex = self.statusSelectIndex; searchVC.typeSelectIndex = self.typeSelectIndex; searchVC.userSelectIndex = self.userSelectIndex; searchVC.archiveSelectIndex = self.archiveSelectIndex; [self.navigationController pushViewController:searchVC animated:YES]; } - (void)setupNav { PBBackNavItem *backNav = [PBBackNavItem backNacItem]; backNav.title = @" "; [backNav addTarget:self action:@selector(backItemAction) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *backNavItem = [[UIBarButtonItem alloc] initWithCustomView:backNav]; self.navigationItem.leftBarButtonItem = backNavItem; UIBarButtonItem *addIssueItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Issue_list_add"] style:UIBarButtonItemStylePlain target:self action:@selector(addIssue)]; self.navigationItem.rightBarButtonItem = addIssueItem; self.navigationItem.rightBarButtonItem.enabled = YES; } - (void)addIssue { PBAddIssueController *addIssueVC = [[PBAddIssueController alloc] init]; addIssueVC.isAddIssue = YES; addIssueVC.projectModel = self.projectModel; addIssueVC.statusAndTypeData = self.statusAndTypeData; addIssueVC.SaveSuccessBlock = ^{ [self.tableView.mj_header beginRefreshing]; }; PBNavigationController *nav = [[PBNavigationController alloc] initWithRootViewController:addIssueVC]; nav.modalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:nav animated:YES completion:nil]; } - (void)backItemAction { [PBNoteCenter postNotificationName: PBNoteCenterDismissTabBarController object:nil]; } - (NSArray *)roleArr { if (_roleArr == nil) { PBIssueNavModel *issueNavModel = [[PBIssueNavModel alloc] init]; issueNavModel.ItemDetailId = @""; issueNavModel.ItemName = @"相关"; PBIssueNavModel *issueNavModel1 = [[PBIssueNavModel alloc] init]; issueNavModel1.ItemDetailId = @"Creator"; issueNavModel1.ItemName = @"我创建"; // PBIssueNavModel *issueNavModel2 = [[PBIssueNavModel alloc] init]; // issueNavModel2.ItemDetailId = @"Manager"; // issueNavModel2.ItemName = @"我负责"; PBIssueNavModel *issueNavModel3 = [[PBIssueNavModel alloc] init]; issueNavModel3.ItemDetailId = @"Joiner"; issueNavModel3.ItemName = @"我参与"; _roleArr = @[issueNavModel,issueNavModel1,issueNavModel3]; } return _roleArr; } - (NSArray *)archiveArr { if (_archiveArr == nil) { PBIssueNavModel *issueNavModel = [[PBIssueNavModel alloc] init]; issueNavModel.ItemDetailId = @"0"; issueNavModel.ItemName = @"归档/隐"; PBIssueNavModel *issueNavModel1 = [[PBIssueNavModel alloc] init]; issueNavModel1.ItemDetailId = @"1"; issueNavModel1.ItemName = @"归档/显"; _archiveArr = @[issueNavModel,issueNavModel1]; } return _archiveArr; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #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