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
//
//  PBTaskScheduleViewController.m
//  IphoneBIMe
//
//  Created by ZhangJF on 2022/8/24.
//  Copyright © 2022 ProBIM. All rights reserved.
//
 
#import "PBTaskScheduleViewController.h"
#import "PBProjectModel.h"
#import "PBSchedulePlanModel.h"
#import "PBTaskHeaderView.h"
#import "PBPlanTaskTableViewCell.h"
#import "PBunPlanTaskTableViewCell.h"
#import "PBScheduleImgTableViewCell.h"
#import "PBTaskScheduleModel.h"
#import "PBChooseOneTaskViewController.h"
#import "PBEditTimeView.h"
#import "PBScheduleListModel.h"
#import "PBImageModel.h"
 
static NSString *const ImageCellID = @"ImageCellID";
static NSString *const PlanCellID = @"PlanCellID";
static NSString *const unPlanCellID = @"unPlanCellID";
@interface PBTaskScheduleViewController ()<UITableViewDataSource, UITableViewDelegate, LFImagePickerControllerDelegate>
@property (nonatomic, strong) NSArray *dataList;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSIndexPath *currentIndexPath;
@property (nonatomic, strong) PBEditTimeView *editTimeView;
@property (nonatomic, strong) PBTaskHeaderView *headerView;
@property (nonatomic, strong) NSMutableArray *imageArrM;
@property (nonatomic, strong) NSMutableArray *planTaskArrM;
@property (nonatomic, strong) NSMutableArray *unplanTaskArrM;
@property (nonatomic, copy) NSString *unitText;
@property (nonatomic, copy) NSString *fillDate;
@property (nonatomic, copy) NSString *creatName;
@property (nonatomic, copy) NSString *creatId;
@property (nonatomic, assign) BOOL isAdd;
@end
 
@implementation PBTaskScheduleViewController
- (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];
    [PBNoteCenter addObserver:self selector:@selector(updateTask:) name:PBNoteCenterChooseTask object:nil];
    [self setupUI];
    [self loadTask];
    [self loadData];
    [self setupNav];
}
- (void)processingRatio:(PBTaskScheduleModel *)model andFillDate:(NSString *)fillDate {
    if (model.Progress_Name){
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"yyyy-MM-dd"];
        NSDate *startDate = [formatter dateFromString:model.Progress_planstarttime];
        NSDate *finshDate = [formatter dateFromString:model.Progress_plannendtime];
        NSDate *filDate = [formatter dateFromString:fillDate];
        NSTimeInterval planTime = [finshDate timeIntervalSinceDate:startDate];
    //    NSInteger planDay = (NSInteger)planTime/(3600*24);
        NSTimeInterval time = [filDate timeIntervalSinceDate:startDate];
    //    NSInteger day = (NSInteger)time/(3600*24);
        // 计划
        NSString *planString = @"0";
        float planP = time / planTime;
        if(planP >= 1) {
            planString = @"100";
        } else if(planP < 0) {
            planString = @"0"; 
        } else {
           NSInteger num = planP * 100;
           planString = [NSString stringWithFormat:@"%zd", num];
        }
        NSLog(@"计划所得:%f,%@",planP, planString);
        model.Progress_planratio = planString;
        // 累计
        
        // 状态
        NSInteger planProgress = [planString integerValue];
        NSInteger mobileProgress = [model.Progress_MobileAddratio integerValue];
        if (mobileProgress > planProgress) {
            model.Progress_state = @"超前";
        }else if(mobileProgress == planProgress){
            model.Progress_state = @"正常";
        } else {
            model.Progress_state = @"滞后";
        }
    }
}
- (void)updateTask:(NSNotification *)noti {
    NSDictionary *item = self.dataList[self.currentIndexPath.section];
    NSArray *arr = [item valueForKey:@"child"];
    PBTaskScheduleModel *model = arr[self.currentIndexPath.row];
    PBSchedulePlanModel *planModel = noti.object;
    model.Progress_Name = planModel.Name;
    model.Progress_treeID = planModel.UID;
    model.Progress_MobilePlan = planModel.mobilePlan;
    model.Progress_MobileTomorrowratio = @"";
    model.Progress_actualratio = @"";
    NSRange range = [planModel.Start rangeOfString:@"T"];
    NSString *start = [planModel.Start substringToIndex:range.location];
    NSRange range1 = [planModel.Finish rangeOfString:@"T"];
    NSString *finish = [planModel.Finish substringToIndex:range1.location];
    model.Progress_planstarttime = start;
    model.Progress_plannendtime = finish;
    //获取累计
    [self getTaskAddWithModel:model];
}
- (void)getTaskAddWithModel:(PBTaskScheduleModel *)model {
    [[PBNetworkTools sharedTools] GetMobileAddWithTreeID:model.Progress_treeID andPlanId:self.schedulePlanModel.UID 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) {
            model.Progress_MobileAddratio = networkModel.Data;
            model.MobileAddratio = networkModel.Data;
            [self processingRatio:model andFillDate:self.fillDate];
            [self.tableView reloadRowsAtIndexPaths:@[self.currentIndexPath] withRowAnimation:UITableViewRowAnimationFade];
        }else {
            [YJProgressHUD showFailed:@"获取累计失败" inview:self.view];
        }
    }];
}
 
- (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;
    
    UIBarButtonItem *saveNavItem = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(saveAction)];
    self.navigationItem.rightBarButtonItem = saveNavItem;
}
- (void)backItemAction {
    [PBNoteCenter removeObserver:self];
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)saveAction{
    // 先上传图片
    NSMutableArray *files = [[NSMutableArray alloc] init];
    NSMutableString *names = [[NSMutableString alloc] init];
    for (PBImageModel *imageModel in self.imageArrM) {
        if(imageModel.image){
            [files addObject:imageModel.image];
            [names appendString:[NSString stringWithFormat:@"%@,", imageModel.name]];
        }
    }
//    names = [names substringToIndex:([names length]-1)];
    if (files.count > 0){
        [[PBNetworkTools sharedTools] scheduleUploadImagesWithFiles:files andNames:names.copy andPlanID:self.schedulePlanModel.UID andUnittime:self.fillDate andorganizeId:self.projectModel.organizeid 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) {
                [self saveTask];
            }else {
                [YJProgressHUD showFailed:networkModel.Msg inview:self.view];
            }
        }];
    }else {
        [self saveTask];
    }
}
 
- (void)deleteImageWithIndex:(NSInteger)index {
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"确认删除图片" message:@"" preferredStyle:(UIAlertControllerStyleActionSheet)];
    UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"删除" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        PBImageModel *model = self.imageArrM[index];
        [[PBNetworkTools sharedTools] DelteImageWithGuid:model.bf_guid 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) {
                [self.imageArrM removeObjectAtIndex:index];
                NSIndexSet *set = [[NSIndexSet alloc] initWithIndex:0];
                [self.tableView reloadSections:set withRowAnimation:UITableViewRowAnimationFade];
            }else {
                [YJProgressHUD showFailed:networkModel.Msg inview:self.view];
            }
        }];
    }];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alertC addAction:alertA];
    [alertC addAction:cancel];
    [self presentViewController:alertC animated:YES completion:nil];
}
- (void)saveTask {
    [YJProgressHUD showProgress:@"正在保存..." inView:self.view];
    NSMutableArray *planArrM = [[NSMutableArray alloc] init];
    NSMutableArray *unPlanArrM = [[NSMutableArray alloc] init];
    for (PBTaskScheduleModel *obj in self.planTaskArrM) {
//        if (obj.MobileSafe_Name == nil || obj.MobileSafe_Measure == nil) {
//            [YJProgressHUD showMessage:@"请填写完整" inView:self.view];
//            return;
//        }
        
        NSDictionary *dict = @{
            @"Progress_MobilePlan": obj.Progress_MobilePlan == nil? @"" : obj.Progress_MobilePlan, //任务层级
            @"Progress_Name": obj.Progress_Name == nil? @"" : obj.Progress_Name,  // 任务项
            @"Progress_treeID": obj.Progress_treeID == nil? @"" : obj.Progress_treeID, //当前任务id
            @"Progress_planstarttime": obj.Progress_planstarttime == nil? @"" : obj.Progress_planstarttime, // 计划开始时间
            @"Progress_plannendtime": obj.Progress_plannendtime == nil? @"" : obj.Progress_plannendtime, //计划结束时间
            @"Progress_state": obj.Progress_state == nil? @"" : obj.Progress_state, //任务状态
            @"Progress_MobileReason": obj.Progress_MobileReason == nil? @"" : obj.Progress_MobileReason, //滞后原因
            @"Progress_planratio": obj.Progress_planratio == nil? @"" : obj.Progress_planratio, //计划完成比例
            @"Progress_actualratio": obj.Progress_actualratio == nil? @"" : obj.Progress_actualratio, //今日完成比例
            @"Progress_MobileTomorrowratio": obj.Progress_MobileTomorrowratio == nil? @"" : obj.Progress_MobileTomorrowratio, //明日完成比例
            @"Progress_MobileAddratio": obj.Progress_MobileAddratio == nil? @"" : obj.Progress_MobileAddratio, //累计完成比例
            @"Progress_MobileImageID": @"", // 图片id
            
            @"Progress_ProjectID": self.schedulePlanModel.UID == nil? @"" : self.schedulePlanModel.UID, // 进度计划id
            @"Progress_createuser": self.creatName == nil? @"" : self.creatName, //填报人 登录人
            @"Progress_unittime": self.fillDate == nil? @"" : self.fillDate, //填报时间
            @"organizeId": self.projectModel.organizeid == nil? @"" :self.projectModel.organizeid, //项目编码
            @"Progress_MobileCompany": self.unitText == nil? @"" : self.unitText //施工单位
        };
        [planArrM addObject:dict];
    }
    for (PBTaskScheduleModel *obj in self.unplanTaskArrM) {
        NSDictionary *dict = @{
            @"NoProgress_Name": obj.NoProgress_Name == nil? @"" : obj.NoProgress_Name, // 备注
            
            @"NoProgress_ProjectID": self.schedulePlanModel.UID == nil? @"" : self.schedulePlanModel.UID, // 进度计划id
            @"NoProgress_unittime": self.fillDate == nil? @"" : self.fillDate, //填报时间
            @"NoProgress_Username": self.creatName == nil? @"" : self.creatName, //填报人
            @"organizeId": self.projectModel.organizeid == nil? @"" : self.projectModel.organizeid, //填报人
            @"NoProgress_MobileCompany": self.unitText == nil? @"" : self.unitText
        };
        [unPlanArrM addObject:dict];
    }
    NSDictionary *mobile = @{
        @"Plan_json" : planArrM.copy,
        @"NoPlan_json" : unPlanArrM.copy
    };
    
    [[PBNetworkTools sharedTools] AddMobileJSONWithOrganizeId:self.projectModel.organizeid andMobile:mobile 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) {
            [YJProgressHUD hide];
            PBScheduleListModel *listModel = [[PBScheduleListModel alloc] init];
            listModel.MobilePA_ProjectID = self.schedulePlanModel.UID;
            listModel.MobilePA_ProjectName = self.schedulePlanModel.Name;
            listModel.MobilePA_Unittime = self.fillDate;
            listModel.MobilePA_CreateUser = self.creatName;
            listModel.MobilePA_Createuserid =  self.creatId;
            listModel.MobilePA_state = @"待提交";
            if (self.AddSuccessBlock) {
                self.AddSuccessBlock(listModel);
            }
            [PBNoteCenter removeObserver:self];
            [self.navigationController popViewControllerAnimated:YES];
        }else {
            [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
        }
 
    }];
}
- (void)loadTask{
    if (!self.isAdd) {
        [[PBNetworkTools sharedTools] GetSchedualTreeWithOrganizeId:self.projectModel.bimcomposerid andUid:self.schedulePlanModel.UID 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) {
                [YJProgressHUD hide];
                NSArray *arr = networkModel.Data;
                if (arr.count > 0){
                    NSDictionary *obj = arr[0];
                    self.schedulePlanModel = [PBSchedulePlanModel yy_modelWithDictionary:obj];
                    self.fillDate = self.scheduleListModel.MobilePA_Unittime;
                    self.creatName = self.scheduleListModel.MobilePA_CreateUser;
                    self.creatId = self.scheduleListModel.MobilePA_Createuserid;
                    self.isAdd = false;
                }
            }else {
                [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
            }
        }];
    }
}
- (void)loadData {
    self.dataList = @[@{@"type":@"image", @"name": @"进度形象照片", @"child": self.imageArrM}, @{@"type":@"planTask", @"name": @"计划任务完成情况", @"child": self.planTaskArrM}, @{@"type":@"unplanTask", @"name": @"非计划任务完成情况", @"child": self.unplanTaskArrM}];
    if(self.isAdd) {
        [self.tableView reloadData];
    }else {
        [[PBNetworkTools sharedTools] GetMobileJSONWithUnittime:self.fillDate andCreateuserId:self.creatId andPlanID:self.schedulePlanModel.UID 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) {
    //            [YJProgressHUD hide];
                NSArray *imageArr = [networkModel.Data valueForKey:@"Image_Json"];
                NSArray *planArr = [networkModel.Data valueForKey:@"Plan_json"];
                NSArray *unplanArr = [networkModel.Data valueForKey:@"NoPlan_json"];
                for (NSDictionary *obj in imageArr) {
                    PBImageModel *model = [PBImageModel yy_modelWithDictionary:obj];
                    [self.imageArrM addObject:model];
                }
                for (NSDictionary *obj in planArr) {
                    PBTaskScheduleModel *model = [PBTaskScheduleModel yy_modelWithDictionary:obj];
                    model.MobileAddratio = model.Progress_MobileAddratio;
                    [self.planTaskArrM addObject:model];
                }
                for (NSDictionary *obj in unplanArr) {
                    PBTaskScheduleModel *model = [PBTaskScheduleModel yy_modelWithDictionary:obj];
                    [self.unplanTaskArrM addObject:model];
                }
                [self.tableView reloadData];
                if (self.planTaskArrM.count > 0) {
                    PBTaskScheduleModel *model = self.planTaskArrM[0];
                    self.unitText = model.Progress_MobileCompany;
                } else if (self.unplanTaskArrM.count > 0){
                    PBTaskScheduleModel *model = self.unplanTaskArrM[0];
                    self.unitText = model.NoProgress_MobileCompany;
                } else {
                    self.unitText = nil;
                }
                self.headerView.unitText = self.unitText;
            }else {
                [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
            }
        }];
        
    }
}
- (void)setupUI {
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    
//    UITableViewController *tvc = [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];
//    [self addChildViewController:tvc];
//    self.tableView = tvc.tableView;
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.tableFooterView = [UIView new];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 100.f;
    [self.tableView registerClass:[PBPlanTaskTableViewCell class] forCellReuseIdentifier:PlanCellID];
    [self.tableView registerClass:[PBunPlanTaskTableViewCell class] forCellReuseIdentifier:unPlanCellID];
    [self.tableView registerClass:[PBScheduleImgTableViewCell class] forCellReuseIdentifier:ImageCellID];
    [self.view addSubview:self.tableView];
 
    if (@available(iOS 15.0, *)) {
        self.tableView.sectionHeaderTopPadding = 0;
    }
    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 *uploadImageBtn = [[UIButton alloc] init];
    [uploadImageBtn setImage:[UIImage imageNamed:@"uploadImage"] forState:UIControlStateNormal];
    [uploadImageBtn addTarget:self action:@selector(uploadImage) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:uploadImageBtn];
    [uploadImageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tableView.mas_bottom).offset(7);
        make.left.equalTo(self.view);
        make.width.equalTo(@140);
        make.height.equalTo(@48);
    }];
    
    UIButton *addTaskBtn = [[UIButton alloc] init];
    [addTaskBtn setImage:[UIImage imageNamed:@"add_task"] forState:UIControlStateNormal];
    [addTaskBtn addTarget:self action:@selector(addTaskAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addTaskBtn];
    [addTaskBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tableView.mas_bottom).offset(7);
        make.left.equalTo(uploadImageBtn.mas_right);
        make.right.equalTo(self.view);
        make.height.equalTo(@48);
    }];
    PBTaskHeaderView *headerV = [[PBTaskHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 186)];
    self.headerView = headerV;
    headerV.schedulePlanModel = self.schedulePlanModel;
    headerV.fillDate = self.fillDate;
    headerV.unitText = self.unitText;
    headerV.ChooseDate = ^{
        if (self.isAdd) {
            [self.view endEditing:YES];
            [PBKeyWindow addSubview:self.editTimeView];
            self.editTimeView.fillData = self.fillDate;
            self.editTimeView.ChooseCompleteBlock = ^(BOOL isSelsected, NSString *date){
                if (isSelsected) {
                    date = [date stringByReplacingOccurrencesOfString:@"年" withString:@"-"];
                    date = [date stringByReplacingOccurrencesOfString:@"月" withString:@"-"];
                    date = [date stringByReplacingOccurrencesOfString:@"日" withString:@""];
                    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
                    [formatter setDateFormat:@"yyyy-MM-dd"];
                    NSDate *newDate = [formatter dateFromString:date];
                    NSString * dateStr = [formatter stringFromDate:newDate];
                    self.fillDate = dateStr;
                    self.headerView.fillDate = self.fillDate;
                }
            };
            [self.editTimeView show];
        }else {
            [YJProgressHUD showMessage:@"无法修改日期" inView:self.view];
        }
    };
    headerV.textEditBlock = ^(NSString * _Nonnull text) {
        self.unitText = text;
    };
    self.tableView.tableHeaderView = headerV;
    
}
- (void)addTaskAction {
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"添加任务" message:@"" preferredStyle:(UIAlertControllerStyleActionSheet)];
    UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"计划任务" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        PBTaskScheduleModel *task = [[PBTaskScheduleModel alloc] init];
        [self.planTaskArrM addObject:task];
        [self.tableView reloadSections:[[NSIndexSet alloc] initWithIndex:1] withRowAnimation:UITableViewRowAnimationFade];
    }];
    UIAlertAction *alertA1 = [UIAlertAction actionWithTitle:@"非计划任务" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        PBTaskScheduleModel *task = [[PBTaskScheduleModel alloc] init];
        [self.unplanTaskArrM addObject:task];
        [self.tableView reloadSections:[[NSIndexSet alloc] initWithIndex:2] withRowAnimation:UITableViewRowAnimationFade];
    }];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alertC addAction:alertA];
    [alertC addAction:alertA1];
    [alertC addAction:cancel];
    [self presentViewController:alertC animated:YES completion:nil];
    
}
- (void)uploadImage {
    [self.view endEditing:YES];
    [self takePhotoLibrary];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataList.count;
}
 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSDictionary *item = self.dataList[section];
    NSArray *arr = [item valueForKey:@"child"];
    NSString *type = [item valueForKey:@"type"];
    if ([type isEqualToString:@"image"]){
        if (arr.count > 0) {
            return 1;
        }else {
            return 0;
        }
    }
    return arr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 52;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    //最后一个
    return 0.01;
}
 
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return nil;
}
 
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor = [UIColor whiteColor];
    UIView *iconV = [[UIView alloc] init];
    iconV.backgroundColor = PBColor(95, 158, 249);
    [bgView addSubview:iconV];
    [iconV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView).offset(20);
        make.size.mas_equalTo(CGSizeMake(6, 20));
        make.left.equalTo(bgView);
    }];
    NSDictionary *dict = self.dataList[section];
    UILabel *nameL = [UILabel z_labelWithText:[dict valueForKey:@"name"] Color:[UIColor z_colorWithR:95 G:158 B:249] isBold:YES Font:18];
    [bgView addSubview:nameL];
    [nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(iconV);
        make.left.equalTo(iconV.mas_right).offset(5);
    }];
    return bgView;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 
    NSDictionary *item = self.dataList[indexPath.section];
    NSString *type = [item valueForKey:@"type"];
    NSArray *arr = [item valueForKey:@"child"];
 
    if ([type isEqualToString:@"image"]) {
        PBScheduleImgTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ImageCellID forIndexPath:indexPath];
        cell.DeleteImageBlock = ^(NSInteger index) {
            [self deleteImageWithIndex:index];
        };
        cell.imageArr = self.imageArrM;
        return cell;
    }else if ([type isEqualToString:@"planTask"]){
        PBTaskScheduleModel *model = arr[indexPath.row];
        PBPlanTaskTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PlanCellID forIndexPath:indexPath];
        cell.taskScheduleModel = model;
        cell.taskIndex = indexPath.row + 1;
        cell.ChooseTaskBlock = ^{
            [self.view endEditing:YES];
            self.currentIndexPath = indexPath;
            PBChooseOneTaskViewController *taskVC = [[PBChooseOneTaskViewController alloc] init];
            taskVC.planModel = self.schedulePlanModel;
            [self.navigationController pushViewController:taskVC animated:YES];
        };
        cell.DeleteBlock = ^{
            [self.planTaskArrM removeObjectAtIndex:indexPath.row];
            [self.tableView reloadSections:[[NSIndexSet alloc] initWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
        };
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else {
        PBTaskScheduleModel *model = arr[indexPath.row];
        PBunPlanTaskTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:unPlanCellID forIndexPath:indexPath];
        cell.taskScheduleModel = model;
        cell.taskIndex = indexPath.row + 1;
        cell.DeleteBlock = ^{
            [self.unplanTaskArrM removeObjectAtIndex:indexPath.row];
            [self.tableView reloadSections:[[NSIndexSet alloc] initWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
        };
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}
- (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 {
    LFImagePickerController *imagePicker = [[LFImagePickerController alloc] initWithMaxImagesCount:9 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; /** 实时同步相册 */
    }
//    imagePicker.selectedAssets = self.selectAssetArr;
    [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];
            PBImageModel *imageModel = [[PBImageModel alloc] init];
            imageModel.image = originalImage;
            imageModel.name = @"";
            [imageArrM addObject:imageModel];
        }
    }
//    NSDictionary *dict = self.dataList[self.currentIndexPath.section];
//    NSArray *arr = [dict valueForKey:@"child"];
//    PBTaskScheduleModel *model = arr[self.currentIndexPath.row];
//    [model.imageArr addObjectsFromArray:imageArrM.copy];
//    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:self.currentIndexPath,nil] withRowAnimation:UITableViewRowAnimationFade];
    [self.imageArrM addObjectsFromArray:imageArrM];
    [self.tableView reloadSections:[[NSIndexSet alloc] initWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
}
- (void)setSchedulePlanModel:(PBSchedulePlanModel *)schedulePlanModel{
      _schedulePlanModel = schedulePlanModel;
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    self.fillDate = [formatter stringFromDate:[NSDate date]];
    self.creatName = Realname;
    self.creatId = UserID;
    self.isAdd = true;
}
- (void)setScheduleListModel:(PBScheduleListModel *)scheduleListModel {
    _scheduleListModel = scheduleListModel;
    PBSchedulePlanModel *planModel = [[PBSchedulePlanModel alloc] init];
    planModel.UID = scheduleListModel.MobilePA_ProjectID;
    planModel.Name = scheduleListModel.MobilePA_ProjectName;
    self.schedulePlanModel = planModel;
    self.fillDate = scheduleListModel.MobilePA_Unittime;
    self.creatName = scheduleListModel.MobilePA_CreateUser;
    self.creatId = scheduleListModel.MobilePA_Createuserid;
    self.isAdd = false;
}
- (void)setProjectModel:(PBProjectModel *)projectModel {
    _projectModel = projectModel;
}
- (PBEditTimeView *)editTimeView {
    if (_editTimeView == nil) {
        _editTimeView = [[PBEditTimeView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        _editTimeView.visualViewHeight = 300;
    }
    return _editTimeView;
}
-(NSMutableArray *)imageArrM {
    if (_imageArrM == nil) {
        _imageArrM = [[NSMutableArray alloc] init];
    }
    return _imageArrM;
}
- (NSMutableArray *)planTaskArrM {
    if (_planTaskArrM == nil) {
        _planTaskArrM = [[NSMutableArray alloc] init];
    }
    return _planTaskArrM;
}
 
- (NSMutableArray *)unplanTaskArrM {
    if (_unplanTaskArrM == nil) {
        _unplanTaskArrM = [[NSMutableArray alloc] init];
    }
    return _unplanTaskArrM;
}
- (void)dealloc {
    [PBNoteCenter removeObserver:self];
}
/*
#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