// // PBScheduleModuleViewController.m // IphoneBIMe // // Created by ZhangJF on 2022/8/23. // Copyright © 2022 ProBIM. All rights reserved. // #import "PBScheduleModuleViewController.h" #import "PBProjectModel.h" #import "PBSchedulePlanModel.h" #import "PBModuleTableViewCell.h" #import "PBTaskScheduleViewController.h" #import "PBSitePerViewController.h" #import "PBSiteMechanicalViewController.h" #import "PBSiteMaterialViewController.h" #import "PBSafetyViewController.h" #import "PBSuperviseViewController.h" #import "PBScheduleListModel.h" #import "PBPreScheduleViewController.h" static NSString *const CellID = @"CellID"; @interface PBScheduleModuleViewController () @property (nonatomic, strong) NSArray *dataList; @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSDictionary *completeState; @property (nonatomic, weak) UIButton *previewBtn; @end @implementation PBScheduleModuleViewController - (void)viewDidAppear:(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.completeState = @{ @"Progress_MobileState": @"未提交", @"MobileUserDetial_state": @"未提交", @"MaterialsDetial_state": @"未提交", @"MachineDetial_State": @"未提交", @"MobileSafe_state": @"未提交", @"MobileSupervise_state": @"未提交" }; if (self.isAdd) { [self loadData]; }else { [self loadData]; [self loadStatus]; } [self setupUI]; [self setupNav]; } - (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)loadData { self.dataList = @[ @{@"key": @"schedule", @"icon": @"schedule", @"name": @"任务进度", @"completeKey": @"Progress_MobileState", @"complete": @"未提交"}, // @{@"key": @"personnel", @"icon": @"personnel", @"name": @"现场人员", @"completeKey": @"MobileUserDetial_state", @"complete": @"未提交"}, // @{@"key": @"mechanical", @"icon": @"mechanical", @"name": @"现场机械", @"completeKey": @"MaterialsDetial_state", @"complete": @"未提交"}, // @{@"key": @"Material", @"icon": @"Material", @"name": @"现场材料", @"completeKey": @"MachineDetial_State", @"complete": @"未提交"}, // @{@"key": @"safety", @"icon": @"safety", @"name": @"质量安全", @"completeKey": @"MobileSafe_state", @"complete": @"未提交"}, // @{@"key": @"supervise", @"icon": @"supervise", @"name": @"督导会", @"completeKey": @"MobileSupervise_state", @"complete": @"未提交"}, ]; } - (void)loadStatus { [[PBNetworkTools sharedTools] GetSearchstateWithPlanId:self.scheduleListModel.MobilePA_ProjectID andUnittime:self.scheduleListModel.MobilePA_Unittime andCreateuserid:self.scheduleListModel.MobilePA_Createuserid 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.Ret == 1) { self.completeState = networkModel.Data; [self.tableView reloadData]; }else { [YJProgressHUD showMessage:networkModel.Msg inView:self.view]; } }]; } - (void)setupUI { self.view.backgroundColor = [UIColor z_colorWithR:243 G:243 B:244]; self.tableView = [[UITableView alloc] init]; self.tableView.backgroundColor = PBColor(243, 243, 244); self.tableView.dataSource = self; self.tableView.delegate = self; self.tableView.rowHeight = 88.f; self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [self.tableView registerClass:[PBModuleTableViewCell class] forCellReuseIdentifier:CellID]; [self.view addSubview:self.tableView]; CGFloat bottomH = 64.f; if (IS_IPHONE_X) { bottomH = 64.f + IPHONE_X_BOTTOM; } [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.left.right.equalTo(self.view); make.bottom.equalTo(self.view).offset(-bottomH); }]; // UIButton *previewBtn = [[UIButton alloc] init]; // [previewBtn setImage:[UIImage imageNamed:@"preview_dis"] forState:UIControlStateDisabled]; // [previewBtn setImage:[UIImage imageNamed:@"preview"] forState:UIControlStateNormal]; // [previewBtn addTarget:self action:@selector(previewAction) forControlEvents:UIControlEventTouchUpInside]; // [self.view addSubview:previewBtn]; // [previewBtn mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(self.tableView.mas_bottom).offset(7); // make.left.equalTo(self.view).offset(10); // make.right.equalTo(self.view).offset(-10); // make.height.equalTo(@48); // }]; // if (self.isAdd) { // previewBtn.enabled = NO; // }else { // previewBtn.enabled = YES; // } // self.previewBtn = previewBtn; } - (void)previewAction { PBPreScheduleViewController * preVC = [[PBPreScheduleViewController alloc] init]; preVC.projectModel = self.projectModel; preVC.scheduleListModel = self.scheduleListModel; [self.navigationController pushViewController:preVC animated:YES]; } #pragma mark - Table view data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataList.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { PBModuleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath]; NSDictionary *dict = self.dataList[indexPath.row]; NSMutableDictionary *dictM = dict.mutableCopy; NSString *iscomplete = [self.completeState valueForKey:[dict valueForKey:@"completeKey"]]; [dictM setValue:iscomplete forKey:@"complete"]; cell.dict = dictM.copy; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *dict = self.dataList[indexPath.row]; NSString *type = [dict valueForKey:@"key"]; if ([type isEqualToString:@"schedule"]) { // 任务进度 PBTaskScheduleViewController *moduleVC = [[PBTaskScheduleViewController alloc] init]; moduleVC.projectModel = self.projectModel; if (self.isAdd) { moduleVC.schedulePlanModel = self.schedulePlanModel; }else { moduleVC.scheduleListModel = self.scheduleListModel; } moduleVC.AddSuccessBlock = ^(PBScheduleListModel * _Nonnull listModel) { if (self.isAdd) { self.isAdd = false; self.scheduleListModel = listModel; // self.previewBtn.enabled = YES; } [self loadStatus]; }; [self.navigationController pushViewController:moduleVC animated:YES]; } else if ([type isEqualToString:@"personnel"]) { // 现场人员 PBSitePerViewController *moduleVC = [[PBSitePerViewController alloc] init]; moduleVC.projectModel = self.projectModel; if (self.isAdd) { moduleVC.schedulePlanModel = self.schedulePlanModel; }else { moduleVC.scheduleListModel = self.scheduleListModel; } // moduleVC.AddSuccessBlock = ^(PBScheduleListModel * _Nonnull listModel) { // if (self.isAdd) { // self.isAdd = false; // self.scheduleListModel = listModel; // self.previewBtn.enabled = YES; // } // [self loadStatus]; // }; [self.navigationController pushViewController:moduleVC animated:YES]; } else if ([type isEqualToString:@"mechanical"]) { // 现场机械 PBSiteMechanicalViewController *moduleVC = [[PBSiteMechanicalViewController alloc] init]; moduleVC.projectModel = self.projectModel; if (self.isAdd) { moduleVC.schedulePlanModel = self.schedulePlanModel; }else { moduleVC.scheduleListModel = self.scheduleListModel; } moduleVC.AddSuccessBlock = ^(PBScheduleListModel * _Nonnull listModel) { if (self.isAdd) { self.isAdd = false; self.scheduleListModel = listModel; // self.previewBtn.enabled = YES; } [self loadStatus]; }; [self.navigationController pushViewController:moduleVC animated:YES]; } else if ([type isEqualToString:@"Material"]) { // 现场材料 PBSiteMaterialViewController *moduleVC = [[PBSiteMaterialViewController alloc] init]; moduleVC.projectModel = self.projectModel; if (self.isAdd) { moduleVC.schedulePlanModel = self.schedulePlanModel; }else { moduleVC.scheduleListModel = self.scheduleListModel; } moduleVC.AddSuccessBlock = ^(PBScheduleListModel * _Nonnull listModel) { if (self.isAdd) { self.isAdd = false; self.scheduleListModel = listModel; // self.previewBtn.enabled = YES; } [self loadStatus]; }; [self.navigationController pushViewController:moduleVC animated:YES]; } else if ([type isEqualToString:@"safety"]) { // 质量安全 PBSafetyViewController *moduleVC = [[PBSafetyViewController alloc] init]; moduleVC.projectModel = self.projectModel; if (self.isAdd) { moduleVC.schedulePlanModel = self.schedulePlanModel; }else { moduleVC.scheduleListModel = self.scheduleListModel; } moduleVC.AddSuccessBlock = ^(PBScheduleListModel * _Nonnull listModel) { if (self.isAdd) { self.isAdd = false; self.scheduleListModel = listModel; // self.previewBtn.enabled = YES; } [self loadStatus]; }; [self.navigationController pushViewController:moduleVC animated:YES]; } else if ([type isEqualToString:@"supervise"]) { // 督导会 PBSuperviseViewController *moduleVC = [[PBSuperviseViewController alloc] init]; moduleVC.projectModel = self.projectModel; if (self.isAdd) { moduleVC.schedulePlanModel = self.schedulePlanModel; }else { moduleVC.scheduleListModel = self.scheduleListModel; } moduleVC.AddSuccessBlock = ^(PBScheduleListModel * _Nonnull listModel) { if (self.isAdd) { self.isAdd = false; self.scheduleListModel = listModel; // self.previewBtn.enabled = YES; } [self loadStatus]; }; [self.navigationController pushViewController:moduleVC animated:YES]; } } - (void)setScheduleModel:(PBSchedulePlanModel *)schedulePlanModel { _schedulePlanModel = schedulePlanModel; } - (void)setProjectModel:(PBProjectModel *)projectModel { _projectModel = projectModel; } - (void)setScheduleListModel:(PBScheduleListModel *)scheduleListModel { _scheduleListModel = scheduleListModel; } - (void)setIsAdd:(BOOL)isAdd { _isAdd = isAdd; } /* #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