zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
//
//  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 ()<UITableViewDataSource ,UITableViewDelegate, LFImagePickerControllerDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) PBExamineTableHeaderView *tableheaderView;
@property (nonatomic, strong) NSMutableArray<PBExamineAddModel *> *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 <LFResultObject /* <LFResultImage/LFResultVideo> */*> *)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