// // PBAddExamineController.m // IphoneBIMe // // Created by zjf on 2018/11/28. // Copyright © 2018 ProBIM. All rights reserved. // #import "PBAddExamineController.h" #import "PBProjectModel.h" #import "PBExamineTableHeaderView.h" #import "PBExamineAddModel.h" #import "PBExamineInputTableViewCell.h" #import "PBOneChooseTableViewCell.h" #import "PBTwoChooseTableViewCell.h" #import "PBMoreChooseTableViewCell.h" #import "PBEditTimeTableViewCell.h" #import "PBPersonTableViewCell.h" #import "PBTextShowTableViewCell.h" #import "PBEditTextController.h" #import "PBChooseModelViewController.h" #import "AppDelegate.h" #import "PBOneChooseView.h" #import "PBDivisionViewController.h" #import "PBTwoChooseView.h" #import "PBEditPersonView.h" #import "PBPersonModel.h" #import "PBTimeChooseView.h" #import "PBModelsModel.h" #import "PBViewPointModel.h" #import "PBDrawingposModel.h" #import "PBDrawingsInfoModel.h" #import "PBResultModel.h" #import "PBExamineListModel.h" #import "PBRecordViewController.h" #import "PBOpenDrawController.h" #import "PBOpenViewPointController.h" #import "PBRecordModel.h" #import "PBStructureViewController.h" static NSString *const inputCellID = @"InputCellID"; static NSString *const positioningCellID = @"positioningCellID"; static NSString *const oneChooseCellID = @"oneChooseCellID"; static NSString *const twoChooseCellID = @"twoChooseCellID"; static NSString *const moreChooseCellID = @"moreChooseCellID"; static NSString *const personCellID = @"personCellID"; static NSString *const textCellID = @"textCellID"; static NSString *const timeCellID = @"timeCellID"; @interface PBAddExamineController () @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) PBExamineTableHeaderView *tableheaderView; @property (nonatomic, strong) NSMutableArray *dataListM; @property (nonatomic, strong) NSMutableArray *selectedPhotos; @property (nonatomic, assign) NSInteger mandatoryCount;//必填项个数 @property (nonatomic, strong) PBOneChooseView *oneChooseView; @property (nonatomic, strong) PBTwoChooseView *twoChooseView; @property (nonatomic, strong) PBTimeChooseView *timeChooseView; @property (nonatomic, strong) PBEditPersonView *editPersonView; @property (nonatomic, strong) NSArray *engineeringArr;//单位工程数据 @property (nonatomic, strong) NSArray *professionalArr;//专业数据 @property (nonatomic, strong) NSArray *teamArr;//施工班组数据 @property (nonatomic, copy) NSString *recordingName;//本地录音name @property (nonatomic, strong) PBModelsModel *modelsModel;//定位选择的模型信息 @property (nonatomic, strong) NSMutableArray *imageArr;//详情图片信息 @property (nonatomic, strong) NSDictionary *audioData;//详情音频信息 @property (nonatomic, strong) PBViewPointModel *viewPointModel;//定位视点信息 @property (nonatomic, strong) PBDrawingposModel *drawingposModel;//定位图纸点信息 @property (nonatomic, strong) PBDrawingsInfoModel *drawingsInfoModel;//定位图纸点信息 @property (nonatomic, assign) RoleType roleType; @property (nonatomic, weak) UIView *linView; @property (nonatomic, strong) NSMutableArray *recordListM; @property (nonatomic, strong) NSDictionary *examinDetailDic; @property (nonatomic, assign) BOOL isIssueManage; @end @implementation PBAddExamineController - (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.view.backgroundColor = [UIColor whiteColor]; //工程结构 选择后更新数据通知 [PBNoteCenter addObserver:self selector:@selector(updateDivision:) name:PBNoteCenterUpdateDivision object:nil]; //复检为合格后 [PBNoteCenter addObserver:self selector:@selector(reInspectionQualified:) name:PBNoteCenterReInspectionQualified object:nil]; // if (self.examineListModel.IsExamineMgr) { // self.isIssueManage = YES; // }else { // self.isIssueManage = NO; // } // [YJProgressHUD showCustomAnimation:@"" inview:self.view]; [YJProgressHUD showProgress:@"" inView:self.view]; [self loadData]; if (self.isAddExamine) { [self setupNav]; [self setupUI]; }else { [self loadRelevantData]; } } - (void)updateDivision:(NSNotification *)noti { NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0]; if (self.isAddExamine) { [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; }else { PBExamineAddModel *examineAddModel = self.dataListM[indexPath.row]; NSMutableDictionary *dictM = [[NSMutableDictionary alloc] init]; [dictM setValue:[examineAddModel.dataDict valueForKey:@"ec_guid"] forKey:examineAddModel.key]; [YJProgressHUD showProgress:@"" inView:self.view]; [self ModifyExamineTextDataWith:dictM andIndexPath:indexPath andIsDelete:NO]; } } - (void)reInspectionQualified:(NSNotification *)noti { self.dataListM[4].dataStr = @"合格"; self.dataListM[5].dataStr = nil; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:4 inSection:0]; [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone]; } - (void)loadData { NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"examineAdd3" ofType:@"plist"]; NSArray *list = [NSArray arrayWithContentsOfFile:plistPath]; NSMutableArray *listM = [[NSMutableArray alloc] init]; for (NSInteger i = 0; i < list.count; i++) { NSDictionary *dict = list[i]; PBExamineAddModel *model = [PBExamineAddModel yy_modelWithDictionary:dict]; model.isAddExamine = self.isAddExamine; model.isIssueManage = self.isIssueManage; if (model.isMandatory) { ++self.mandatoryCount; } [listM addObject:model]; } self.dataListM = listM; } #pragma mark - 加载检查相关数据 - (void)loadRelevantData { [YJProgressHUD showProgress:@"" inView:self.view]; [[PBNetworkTools sharedTools] RequestGetItemWithExamineID:self.examineListModel.ExamineID andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) { if (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.examinDetailDic = networkModel.Data; [self collatingDetailedData]; }else { [YJProgressHUD showMessage:networkModel.Msg inView:self.view]; } }]; } - (void)collatingDetailedData { for (PBExamineAddModel *examineAddModel in self.dataListM) { if ([examineAddModel.cellType isEqualToString:@"text"] || [examineAddModel.cellType isEqualToString:@"time"] || [examineAddModel.cellType isEqualToString:@"input"]){ NSString *dataStr = [self.examinDetailDic valueForKey:examineAddModel.key]; if ([dataStr isKindOfClass:[NSNull class]]) { examineAddModel.dataStr = nil; }else { if ([examineAddModel.cellType isEqualToString:@"time"]) { NSRange range = [dataStr rangeOfString:@"T"]; dataStr = [dataStr substringToIndex:range.location]; examineAddModel.dataStr = dataStr; }else { examineAddModel.dataStr = dataStr; } } }else if ([examineAddModel.cellType isEqualToString:@"choose"]) { if ([examineAddModel.key isEqualToString:@"CategoryID"]) { if ([self.examinDetailDic valueForKey:@"ec_name"]) { NSDictionary *dic = @{ @"ec_name":[self.examinDetailDic valueForKey:@"ec_name"] }; examineAddModel.dataDict = dic; } }else if ([examineAddModel.key isEqualToString:@"aedt_guid"]) { if ([self.examinDetailDic valueForKey:@"aedt_name"]) { NSDictionary *dic = @{ @"aedt_name":[self.examinDetailDic valueForKey:@"aedt_name"] }; examineAddModel.dataDict = dic; } }else { if ([self.examinDetailDic valueForKey:examineAddModel.key]) { NSDictionary *dic = @{ @"aedt_name":[self.examinDetailDic valueForKey:examineAddModel.key] }; examineAddModel.dataDict = dic; } } }else if ([examineAddModel.cellType isEqualToString:@"person"]) { NSMutableArray *arrM = [[NSMutableArray alloc] init]; NSArray *personArr; if ([examineAddModel.key isEqualToString:@"PrincipalID"]) { personArr = [self.examinDetailDic valueForKey:@"PrincipalObjs"]; }else { personArr = [self.examinDetailDic valueForKey:@"aede_checkeruserobjs"]; } for (NSDictionary *obj in personArr) { PBPersonModel *personModel = [PBPersonModel yy_modelWithDictionary:obj]; [arrM addObject:personModel]; } examineAddModel.personArr = arrM.copy; } // else if ([examineAddModel.cellType isEqualToString:@"text"]) { // if ([self.examinDetailDic valueForKey:@"Examiner"]) { // NSDictionary *dic = @{ // @"RealName":[self.examinDetailDic valueForKey:@"Examiner"], // @"UserID":@"" // }; // examineAddModel.dataDict = dic; // } // } } // self.imageArr = [[self.examinDetailDic valueForKey:@"Attachments"] mutableCopy]; // [self setupNav]; [self setupUI]; // [self setTableHeaderViewImage]; } - (void)updateCompletionIndicator { if (!self.isAddExamine) { return; } CGFloat oneWidth = PBScreenWidth / self.mandatoryCount; NSInteger completedCount = 0; for (PBExamineAddModel *examineAddModel in self.dataListM) { if (examineAddModel.isMandatory) { if ([examineAddModel.cellType isEqualToString:@"input"]) { if (examineAddModel.dataStr != nil && ![examineAddModel.dataStr isEqualToString:@""]) { ++completedCount; } }else if ([examineAddModel.cellType isEqualToString:@"choose"]) { if (examineAddModel.dataDict){ ++completedCount; } }else if ([examineAddModel.cellType isEqualToString:@"person"]) { if (examineAddModel.personArr.count != 0) { ++completedCount; } }else if ([examineAddModel.cellType isEqualToString:@"time"]) { PBExamineAddModel *resultExamineModel = self.dataListM[4]; if ([resultExamineModel.dataStr isEqualToString:@"合格"]) { ++completedCount; }else { if (examineAddModel.dataStr != nil && ![examineAddModel.dataStr isEqualToString:@""]) { ++completedCount; } } } } } CGFloat linViewW = oneWidth *completedCount; [UIView animateWithDuration:0.2 animations:^{ self.linView.width = linViewW; } completion:^(BOOL finished) { if (completedCount == self.mandatoryCount) { self.navigationItem.rightBarButtonItem.enabled = YES; }else { self.navigationItem.rightBarButtonItem.enabled = NO; } }]; } - (void)setupUI { __weak typeof(self) weakSelf = self; if (_isAddExamine) { self.view.backgroundColor = [UIColor z_colorWithR:216 G:216 B:216]; }else { self.view.backgroundColor = [UIColor whiteColor]; } UIView *linView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 3)]; linView.backgroundColor = WarningColor; [self.view addSubview:linView]; self.linView = linView; self.tableView = [[UITableView alloc] init]; self.tableView.dataSource = self; self.tableView.delegate = self; self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.estimatedRowHeight = 100.f; [self.tableView registerClass:[PBExamineInputTableViewCell class] forCellReuseIdentifier:inputCellID]; [self.tableView registerClass:[PBOneChooseTableViewCell class] forCellReuseIdentifier:oneChooseCellID]; [self.tableView registerClass:[PBTwoChooseTableViewCell class] forCellReuseIdentifier:twoChooseCellID]; [self.tableView registerClass:[PBMoreChooseTableViewCell class] forCellReuseIdentifier:moreChooseCellID]; [self.tableView registerClass:[PBPersonTableViewCell class] forCellReuseIdentifier:personCellID]; [self.tableView registerClass:[PBTextShowTableViewCell class] forCellReuseIdentifier:textCellID]; [self.tableView registerClass:[PBEditTimeTableViewCell class] forCellReuseIdentifier:timeCellID]; [self.view addSubview:self.tableView]; NSInteger topH = 0; if (self.isAddExamine) { topH = 3; }else { topH = 0; } [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view).offset(topH); make.left.right.bottom.equalTo(self.view); }]; // self.tableheaderView = [[PBExamineTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 200)]; // self.tableheaderView.ChooseImageBlock = ^{ // if (weakSelf.isAddExamine) { // [weakSelf takePhotoLibrary]; // }else if (weakSelf.isIssueManage) { // if ([[[weakSelf.examinDetailDic valueForKey:@"BasicInfo"] valueForKey:@"ExamineResult"] isEqualToString:@"合格"]) { // [YJProgressHUD showMessage:@"已合格,无法修改" inView:weakSelf.view]; // }else { // [weakSelf takePhotoLibrary]; // } // } // }; // self.tableheaderView.DeleteImageBlock = ^(NSInteger index) { // if (weakSelf.isAddExamine) { // [weakSelf.selectedPhotos removeObjectAtIndex:index]; // [weakSelf setTableHeaderViewImage]; // }else { // if (weakSelf.isIssueManage) { // if ([[[weakSelf.examinDetailDic valueForKey:@"BasicInfo"] valueForKey:@"ExamineResult"] isEqualToString:@"合格"]) { // [YJProgressHUD showMessage:@"已合格,无法修改" inView:weakSelf.view]; // }else { // [weakSelf deleteRelationImageWithIndex:index andIsIamge:YES]; // } // }else { // [YJProgressHUD showMessage:@"没有删除权限" inView:weakSelf.view]; // } // } // }; // self.tableheaderView.projectModel = self.projectModel; // self.tableheaderView.isAddExamine = self.isAddExamine; // self.tableheaderView.roleType = self.roleType; // self.tableView.tableHeaderView = self.tableheaderView; } - (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; if (self.isAddExamine) { UIBarButtonItem *saveNavItem = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(saveExamine)]; self.navigationItem.rightBarButtonItem = saveNavItem; self.navigationItem.rightBarButtonItem.enabled = NO; }else { UIBarButtonItem *commentsItem = [[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:@"记录(%zd)",[[self.examinDetailDic valueForKey:@"Rectifications"] count]] style:UIBarButtonItemStylePlain target:self action:@selector(recordAction)]; self.navigationItem.rightBarButtonItem = commentsItem; } } - (void)saveImageWithImage:(NSArray *)files { [[PBNetworkTools sharedTools] UploadImagesWithFiles:files andIssueID:nil andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) { if (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) { NSMutableString *strM = [[NSMutableString alloc] init]; NSString *fileID = @""; for (NSDictionary *obj in networkModel.Data) { [strM appendFormat:@"%@,",[obj valueForKey:@"bf_guid"]]; } if([strM length] > 0){ fileID = [strM substringToIndex:([strM length]-1)]; [self creatTextDataWithFileIDs:fileID]; }else { [YJProgressHUD showMessage:@"上传图片返回数据错误" inView:self.view]; } }else { [YJProgressHUD showMessage:networkModel.Msg inView:self.view]; } }]; } - (void)addIamgeWithFiles:(NSArray *)files { [YJProgressHUD showProgress:@"" inView:self.view]; NSMutableDictionary *dictM = [[NSMutableDictionary alloc] init]; [dictM setValue:self.examineListModel.ExamineID forKey:@"ExamineID"]; [[PBNetworkTools sharedTools] RequestExam_AddAttachmentsWithData:dictM andIamges:files andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) { if (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) { [YJProgressHUD hide]; [self loadRelevantData]; }else { [YJProgressHUD showMessage:networkModel.Msg inView:self.view]; } }]; } #pragma mark - 保存方法 - (void)saveExamine { [self.view endEditing:NO]; [YJProgressHUD showProgress:@"" inView:self.view]; if (self.selectedPhotos.count > 0) { [self saveImageWithImage:self.selectedPhotos.copy]; }else { [self creatTextDataWithFileIDs:@""]; } } - (void)creatTextDataWithFileIDs:(NSString *)fileIDs { NSMutableDictionary *dictM = [[NSMutableDictionary alloc] init]; for (PBExamineAddModel *examineAddModel in self.dataListM) { if ([examineAddModel.cellType isEqualToString:@"input"]) { NSString *inputStr = examineAddModel.dataStr == nil ? @"" : examineAddModel.dataStr; [dictM setObject:inputStr forKey:examineAddModel.key]; }else if ([examineAddModel.cellType isEqualToString:@"choose"]){ if (examineAddModel.dataDict) { NSString *chooseValue = @""; if ([examineAddModel.key isEqualToString:@"CategoryID"]) { chooseValue = [examineAddModel.dataDict valueForKey:@"ec_guid"]; }else if ([examineAddModel.key isEqualToString:@"aedt_guid"]){ chooseValue = [examineAddModel.dataDict valueForKey:@"aedt_guid"]; }else if ([examineAddModel.key isEqualToString:@"aede_severitylevel"]) { chooseValue = [examineAddModel.dataDict valueForKey:@"aedt_name"]; } if (chooseValue == nil) { chooseValue = @""; } [dictM setObject:chooseValue forKey:examineAddModel.key]; }else { [dictM setObject:@"" forKey:examineAddModel.key]; } }else if ([examineAddModel.cellType isEqualToString:@"person"]) { NSMutableString *userIdStrM = [[NSMutableString alloc] init]; for (PBPersonModel *obj in examineAddModel.personArr) { [userIdStrM appendString:[NSString stringWithFormat:@"%@,",obj.UserId]]; } if (userIdStrM.length == 0) { [dictM setObject:@"" forKey:examineAddModel.key]; }else { [dictM setObject:userIdStrM.copy forKey:examineAddModel.key]; } }else if ([examineAddModel.cellType isEqualToString:@"text"]) { [dictM setObject:[examineAddModel.dataDict valueForKey:@"UserID"] forKey:examineAddModel.key]; }else if ([examineAddModel.cellType isEqualToString:@"result"]) { [dictM setObject:examineAddModel.dataStr forKey:examineAddModel.key]; }else if ([examineAddModel.cellType isEqualToString:@"time"]) { NSString *timeStr = (examineAddModel.dataStr == nil) ? @"" : examineAddModel.dataStr; [dictM setObject:timeStr forKey:examineAddModel.key]; } } [dictM setObject:self.projectModel.bimcomposerid forKey:@"bimcomposerId"]; [dictM setObject:fileIDs forKey:@"bf_guids"]; [self addExamineWithData:dictM]; } #pragma mark - 提交 质检/安检 数据 - (void)addExamineWithData:(NSMutableDictionary *)dictM { [[PBNetworkTools sharedTools] RequestAddItemsWithData:dictM andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) { if (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) { [YJProgressHUD showMessage:@"保存成功" inView:self.view]; [self createRecordWithDict:networkModel.Data]; // [self dismissViewControllerAnimated:YES completion:nil]; }else { [YJProgressHUD showMessage:networkModel.Msg inView:self.view]; } }]; } #pragma mark - 创建整改记录 //生成整改记录 - (void)createRecordWithDict:(NSString *)str { [YJProgressHUD showProgress:@"添加记录" inView:self.view]; [[PBNetworkTools sharedTools] RequestExam_AddRecordWithExamineID:str andResult:@"整改" andRemark:@"整改" andFlag:@"1" andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) { if (error) { [YJProgressHUD showProgress:@"添加记录失败" inView:self.view]; [self dismissViewControllerAnimated:YES completion:nil]; return; } NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str]; if (networkModel.Ret == 1) { [YJProgressHUD showMessage:@"添加记录成功" inView:self.view]; [self dismissViewControllerAnimated:YES completion:nil]; }else { [YJProgressHUD showMessage:networkModel.Msg inView:self.view]; [self dismissViewControllerAnimated:YES completion:nil]; } }]; } #pragma mark - 修改检查文本数据 - (void)ModifyExamineTextDataWith:(NSMutableDictionary *)dictM andIndexPath:(NSIndexPath *)indexPath andIsDelete:(BOOL)isDelete { [dictM setObject:self.examineListModel.ExamineID forKey:@"ExamineId"]; [[PBNetworkTools sharedTools] RequestModifyItemWithData:dictM andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) { if (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) { [YJProgressHUD showMessage:@"修改成功" inView:self.view]; [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; }else { [YJProgressHUD showMessage:networkModel.Msg inView:self.view]; } }]; } #pragma mark - 记录 - (void)recordAction { [self.view endEditing:NO]; PBRecordViewController *recordVC = [[PBRecordViewController alloc] init]; recordVC.projectModel = self.projectModel; recordVC.examineListModel = self.examineListModel; recordVC.roleType = self.roleType; // recordVC.recordListM = [self.examinDetailDic valueForKey:@"Rectifications"]; recordVC.examineDetailDic = self.examinDetailDic; recordVC.UpdateRecordCountBlock = ^(NSDictionary * _Nonnull detailDic) { self.examinDetailDic = detailDic; self.recordListM = [self.examinDetailDic valueForKey:@"Rectifications"]; self.navigationItem.rightBarButtonItem.title = [NSString stringWithFormat:@"记录(%zd)",[[self.examinDetailDic valueForKey:@"Rectifications"] count]]; }; [self.navigationController pushViewController:recordVC animated:YES]; } #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 6; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { __weak typeof(self) weakSelf = self; if (indexPath.row == 0) { PBExamineInputTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:inputCellID forIndexPath:indexPath]; PBExamineAddModel *examineAddModel = self.dataListM[indexPath.row]; cell.examineAddModel = examineAddModel; cell.EditTextBlock = ^(NSString *text) { PBEditTextController *editTextVC = [[PBEditTextController alloc] init]; editTextVC.text = text; editTextVC.titleText = examineAddModel.title; editTextVC.prompt = examineAddModel.prompt; editTextVC.CompleteEditTextBlock = ^(NSString *text) { examineAddModel.dataStr = text; [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone]; [self updateCompletionIndicator]; }; [self.navigationController pushViewController:editTextVC animated:YES]; }; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; }else if (indexPath.row == 1) { PBExamineAddModel *examineAddModel = self.dataListM[indexPath.row]; PBOneChooseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:oneChooseCellID forIndexPath:indexPath]; cell.examineAddModel = examineAddModel; cell.ChooseBlock = ^{ if ([[[weakSelf.examinDetailDic valueForKey:@"BasicInfo"] valueForKey:@"ExamineResult"] isEqualToString:@"合格"]) { [YJProgressHUD showMessage:@"已合格,无法修改" inView:weakSelf.view]; }else { PBStructureViewController *structureVC = [[PBStructureViewController alloc] init]; structureVC.examineAddModel = examineAddModel; structureVC.projectModel = self.projectModel; [self.navigationController pushViewController:structureVC animated:YES]; } }; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; }else if (indexPath.row == 2 || indexPath.row == 3) { PBTextShowTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:textCellID forIndexPath:indexPath]; cell.examineAddModel = self.dataListM[indexPath.row]; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; }else if (indexPath.row == 4) { PBEditTimeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:timeCellID forIndexPath:indexPath]; PBExamineAddModel *leftExamineAddModel = self.dataListM[indexPath.row]; PBExamineAddModel *rightExamineAddModel = self.dataListM[indexPath.row + 1]; cell.leftExamineAddModel = leftExamineAddModel; cell.rightExamineAddModel = rightExamineAddModel; cell.ChooseBlock = ^(NSInteger index) { if (!self.isAddExamine) { return; } if ([leftExamineAddModel.dataStr isEqualToString:@"合格"] && index == 1) { [YJProgressHUD showMessage:@"整改结果已合格,无需填写整改时间" inView:self.view]; return; } [PBKeyWindow addSubview:self.timeChooseView]; self.timeChooseView.leftExamineAddModel = self.dataListM[indexPath.row]; self.timeChooseView.rightExamineAddModel = self.dataListM[indexPath.row + 1]; self.timeChooseView.index = index; self.timeChooseView.ChooseCompleteBlock = ^(BOOL isSelectLeft, BOOL isSelectRight) { if (isSelectLeft == NO && isSelectRight == NO) { return; } if (weakSelf.isAddExamine) { [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone]; [weakSelf updateCompletionIndicator]; }else { NSMutableDictionary *dictM = [[NSMutableDictionary alloc] init]; [dictM setObject:leftExamineAddModel.dataStr forKey:leftExamineAddModel.key]; NSString *timeStr = (rightExamineAddModel.dataStr == nil) ? @"" : rightExamineAddModel.dataStr; [dictM setObject:timeStr forKey:rightExamineAddModel.key]; [YJProgressHUD showProgress:@"" inView:weakSelf.view]; [weakSelf ModifyExamineTextDataWith:dictM andIndexPath:indexPath andIsDelete:NO]; } }; [self.timeChooseView show]; }; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; }else if (indexPath.row == 5 || indexPath.row == 6) { PBExamineAddModel *examineAddModel = self.dataListM[indexPath.row + 1]; PBPersonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:personCellID forIndexPath:indexPath]; cell.examineAddModel = examineAddModel; cell.EditPersonBlock = ^{ if ([[[weakSelf.examinDetailDic valueForKey:@"BasicInfo"] valueForKey:@"ExamineResult"] isEqualToString:@"合格"]) { [YJProgressHUD showMessage:@"已合格,无法修改" inView:weakSelf.view]; }else { [PBKeyWindow addSubview:self.editPersonView]; self.editPersonView.projectModel = self.projectModel; self.editPersonView.examineAddModel = examineAddModel; self.editPersonView.EditCompleteBlock = ^{ if (weakSelf.isAddExamine) { [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone]; [weakSelf updateCompletionIndicator]; }else { NSMutableDictionary *dictM = [[NSMutableDictionary alloc] init]; NSMutableString *strM = [[NSMutableString alloc] init]; for (PBPersonModel *personModel in examineAddModel.personArr) { [strM appendFormat:@"%@,",personModel.UserId]; } if (strM.length > 0) { NSString *userIDs = [strM substringToIndex:([strM length]-1)]; [dictM setValue:userIDs forKey:examineAddModel.key]; [YJProgressHUD showProgress:@"" inView:weakSelf.view]; [weakSelf ModifyExamineTextDataWith:dictM andIndexPath:indexPath andIsDelete:NO]; } } }; [self.editPersonView show]; } }; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; }else if (indexPath.row == 7) { PBTwoChooseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:twoChooseCellID forIndexPath:indexPath]; PBExamineAddModel *leftExamineModel;PBExamineAddModel *rightExamineModel; leftExamineModel = self.dataListM[indexPath.row + 1]; rightExamineModel = self.dataListM[indexPath.row + 2]; cell.leftExamineAddModel = leftExamineModel; cell.rightExamineAddModel = rightExamineModel; cell.ChooseBlock = ^(NSInteger index) { if ([[[weakSelf.examinDetailDic valueForKey:@"BasicInfo"] valueForKey:@"ExamineResult"] isEqualToString:@"合格"]) { [YJProgressHUD showMessage:@"已合格,无法修改" inView:weakSelf.view]; }else { [PBKeyWindow addSubview:self.twoChooseView]; self.twoChooseView.leftData = self.typeArr; self.twoChooseView.rightData = self.levelArr; self.twoChooseView.leftExamineAddModel = leftExamineModel; self.twoChooseView.rightExamineAddModel = rightExamineModel; self.twoChooseView.index = index; self.twoChooseView.ChooseCompleteBlock = ^(BOOL isSelectLeft, BOOL isSelectRight) { if (isSelectLeft == NO && isSelectRight == NO) { return; } if (weakSelf.isAddExamine) { [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone]; [weakSelf updateCompletionIndicator]; }else { NSMutableDictionary *dictM = [[NSMutableDictionary alloc] init]; [dictM setValue:[leftExamineModel.dataDict valueForKey:@"aedt_guid"] forKey:@"aede_examinetype"]; [dictM setValue:[rightExamineModel.dataDict valueForKey:@"aedt_name"] forKey:rightExamineModel.key]; [YJProgressHUD showProgress:@"" inView:weakSelf.view]; [weakSelf ModifyExamineTextDataWith:dictM andIndexPath:indexPath andIsDelete:NO]; } }; [self.twoChooseView show]; } }; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; }else { return nil; } } - (void)takePhotoLibrary { PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus]; if (status == PHAuthorizationStatusNotDetermined) {//未作出回应 [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { if(status == PHAuthorizationStatusAuthorized) { dispatch_async(dispatch_get_main_queue(), ^{//用户点击ok [self pushLFImagePickerController]; }); } else { dispatch_async(dispatch_get_main_queue(), ^{//点击不允许访问 NSLog(@"点击不允许访问"); }); } }]; }else if (status == PHAuthorizationStatusRestricted) {//没有被授权访问 可能家长控制 }else if (status == PHAuthorizationStatusDenied) {//已明确否认相册权限 UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"无法访问相册" message:@"请在iPhone的""设置-隐私-相册""中允许访问相册" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { if (@available(iOS 10.0, *)) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil]; } else { NSLog(@"选择取消"); } }]; [alertController addAction:cancelAction]; [alertController addAction:okAction]; [self presentViewController:alertController animated:YES completion:nil]; }else if (status == PHAuthorizationStatusAuthorized){//有权限访问 [self pushLFImagePickerController]; } } - (void)pushLFImagePickerController { NSInteger maxImageCount = 3 - self.selectedPhotos.count; LFImagePickerController *imagePicker = [[LFImagePickerController alloc] initWithMaxImagesCount:maxImageCount delegate:self]; imagePicker.allowTakePicture = YES;//内部显示相机 imagePicker.isSelectOriginalPhoto = YES;//是否选择原图 imagePicker.allowPickingType = LFPickingMediaTypePhoto;//用户是否可以选择视频 imagePicker.allowPickingOriginalPhoto = NO;//原图按钮将隐藏,用户将不能发送原图 imagePicker.maxPhotoBytes = 1024 * 1024 * 100;//最大图片所选字节大小 if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0f) { imagePicker.syncAlbum = YES; /** 实时同步相册 */ } [self presentViewController:imagePicker animated:YES completion:nil]; } #pragma mark - LFImagePickerControllerDelegate - (void)lf_imagePickerController:(LFImagePickerController *)picker didFinishPickingResult:(NSArray */*> *)results { NSMutableArray *imageArrM = [[NSMutableArray alloc] init]; for (NSInteger i = 0; i < results.count; i++) { LFResultObject *result = results[i]; if ([result isKindOfClass:[LFResultImage class]]){ LFResultImage *resultImage = (LFResultImage *)result; NSData *imageData = UIImageJPEGRepresentation(resultImage.originalImage, 0.5); UIImage *originalImage = [UIImage imageWithData:imageData]; [imageArrM addObject:originalImage]; } } if (self.isAddExamine) { [self.selectedPhotos addObjectsFromArray:imageArrM.copy]; [self setTableHeaderViewImage]; }else { [self addIamgeWithFiles:imageArrM.copy]; } } #pragma mark - 删除附件 - (void)deleteRelationImageWithIndex:(NSInteger )index andIsIamge:(BOOL)isImage{ [YJProgressHUD showProgress:@"" inView:self.view]; NSDictionary *dict = self.imageArr[index]; [[PBNetworkTools sharedTools] RequestExam_RmAttachmentsWithAttachmentIDs:[dict valueForKey:@"ExamineAttachmentID"] andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) { if (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) { [YJProgressHUD hide]; [self.imageArr removeObjectAtIndex:index]; [self setTableHeaderViewImage]; }else { [YJProgressHUD showMessage:networkModel.Msg inView:self.view]; } }]; } //新增图片选择图片后填充 - (void)setTableHeaderViewImage { if (self.isAddExamine) { self.tableheaderView.imageArr = self.selectedPhotos; }else { self.tableheaderView.detailsImageArr = self.imageArr; } } - (NSMutableArray *)selectedPhotos { if (_selectedPhotos == nil) { _selectedPhotos = [[NSMutableArray alloc] init]; } return _selectedPhotos; } - (PBOneChooseView *)oneChooseView { if (_oneChooseView == nil) { _oneChooseView = [[PBOneChooseView alloc] initWithFrame:[UIScreen mainScreen].bounds]; _oneChooseView.visualViewHeight = 468.f; _oneChooseView.dataArr = self.engineeringArr; } return _oneChooseView; } - (PBTwoChooseView *)twoChooseView { if (_twoChooseView == nil) { _twoChooseView = [[PBTwoChooseView alloc] initWithFrame:[UIScreen mainScreen].bounds]; _twoChooseView.visualViewHeight = 468.f; // _twoChooseView.unitDict = self.engineeringArr; } return _twoChooseView; } - (PBTimeChooseView *)timeChooseView { if (_timeChooseView == nil) { _timeChooseView = [[PBTimeChooseView alloc] initWithFrame:[UIScreen mainScreen].bounds]; _timeChooseView.visualViewHeight = 468.f; } return _timeChooseView; } - (PBEditPersonView *)editPersonView { if (_editPersonView == nil) { _editPersonView = [[PBEditPersonView alloc] initWithFrame:[UIScreen mainScreen].bounds]; CGFloat bottomH = 0.f; if (IS_IPHONE_X) { bottomH = 34.f; } _editPersonView.visualViewHeight = 468.f + bottomH; _editPersonView.isExamineChoose = YES; } return _editPersonView; } - (void)backItemAction { PBExamineAddModel *examineAddModel = self.dataListM[2]; if (examineAddModel.recordingType == PLAY) { [[PBAVPlayerManager sharedManager] stopPlay]; } self.recordingName = examineAddModel.recordingName; [PBNoteCenter removeObserver:self]; [self dismissViewControllerAnimated:YES completion:nil]; } - (void)setProjectModel:(PBProjectModel *)projectModel { _projectModel = projectModel; } - (void)setIsAddExamine:(BOOL)isAddExamine { _isAddExamine = isAddExamine; } - (void)setExamineListModel:(PBExamineListModel *)examineListModel { _examineListModel = examineListModel; } - (void)setExamineListDict:(NSDictionary *)examineListDict { _examineListDict = examineListDict; } - (void)dealloc { [PBNoteCenter removeObserver:self]; } - (NSMutableArray *)imageArr { if (_imageArr == nil) { _imageArr = [[NSMutableArray alloc] init]; } return _imageArr; } - (void)setTypeArr:(NSArray *)typeArr { _typeArr = typeArr; } - (void)setLevelArr:(NSArray *)levelArr { _levelArr = levelArr; } /* #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