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
//
//  PBChooseOneTaskViewController.m
//  IphoneBIMe
//
//  Created by ZhangJF on 2022/8/26.
//  Copyright © 2022 ProBIM. All rights reserved.
//
 
#import "PBChooseOneTaskViewController.h"
#import "PBSchedulePlanModel.h"
#import "PBChooseTasksCell.h"
#import "PBTaskScheduleViewController.h"
 
static NSString *const tasksCellID = @"tasksCellID";
@interface PBChooseOneTaskViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataList;
@property (nonatomic, weak) UIView *bottomV;
@property (nonatomic, weak) UIButton *determineBtn;
@end
 
@implementation PBChooseOneTaskViewController
- (void)viewWillAppear:(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 setupNav];
    [self setupUI];
}
 
- (void)setupNav {
    self.title = @"选择任务";
    UIBarButtonItem *backNavItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Doc_preview_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backItemAction)];
    self.navigationItem.leftBarButtonItem = backNavItem;
}
 
- (void)backItemAction {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)setupUI {
    self.view.backgroundColor = PBColor(244, 245, 246);
    self.tableView = [[UITableView alloc] init];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.bounces = NO;
    self.tableView.rowHeight = 47;
    self.tableView.sectionIndexColor = PBColor(97, 111, 125);
//    UITableView *footerV = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
//    if (@available(iOS 15.0, *)) {
//        footerV.sectionHeaderTopPadding = 0;
//    };
//    self.tableView.tableFooterView = footerV;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[PBChooseTasksCell class] forCellReuseIdentifier:tasksCellID];
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 56, 0);
    [self.view addSubview:self.tableView];
    CGFloat bottomH = 0.f;
    if (IS_IPHONE_X) {
        bottomH = 0.f + IPHONE_X_BOTTOM;
    }
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view);
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-(bottomH));
    }];
    
//    UIView *bottomV = [[UIView alloc] init];
//    bottomV.backgroundColor = [UIColor whiteColor];
//    [self.view addSubview:bottomV];
//    [bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.bottom.right.equalTo(self.tableView);
//        make.height.equalTo(@54);
//    }];
//
//    UIButton *determineBtn = [UIButton z_textButton:@"确定" boldFontSize:14 normalColor:[UIColor whiteColor]];
//    [determineBtn addTarget:self action:@selector(determineBtnAction) forControlEvents:UIControlEventTouchUpInside];
//    determineBtn.backgroundColor = PBColor(0, 122, 255);
//    [self.view addSubview:determineBtn];
//    [determineBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(bottomV).offset(9);
//        make.right.equalTo(bottomV).offset(-20);
//        make.size.mas_equalTo(CGSizeMake(89, 34));
//    }];
//    [determineBtn circleViewWithRadius:6];
//    self.bottomV = bottomV;
//    self.determineBtn = determineBtn;
}
- (void)determineBtnAction:(PBSchedulePlanModel *)planModel {
    [PBNoteCenter postNotificationName:PBNoteCenterChooseTask object:planModel];
    [self backAction];
}
- (void)backAction{
    UINavigationController *navVC = self.navigationController;
    NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
    for (UIViewController *vc in [navVC viewControllers]) {
        [viewControllers addObject:vc];
        if ([vc isKindOfClass:[PBTaskScheduleViewController class]]) {
            break;
         }
    }
    [navVC setViewControllers:viewControllers animated:YES];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    PBSchedulePlanModel *taskInfoModel = [PBSchedulePlanModel yy_modelWithDictionary:self.dataList[indexPath.row]];
    PBChooseTasksCell *cell = [tableView dequeueReusableCellWithIdentifier:tasksCellID forIndexPath:indexPath];
    cell.planModel = taskInfoModel;
    cell.saveBlock = ^(BOOL isSave) {
        NSString *planStr = @"";
        if (self.planModel.mobilePlan == nil || [self.planModel.mobilePlan isEqualToString: @""]){
            planStr = taskInfoModel.Name;
        }else {
            planStr = [NSString stringWithFormat:@"%@-->%@",self.planModel.mobilePlan ,taskInfoModel.Name];
        }
        
        taskInfoModel.mobilePlan = planStr;
        [self determineBtnAction:taskInfoModel];
    };
    cell.nextBlock = ^{
        PBChooseOneTaskViewController *vc = [[PBChooseOneTaskViewController alloc] init];
        NSString *planStr = @"";
        if (self.planModel.mobilePlan == nil || [self.planModel.mobilePlan isEqualToString: @""]){
            planStr = taskInfoModel.Name;
        }else {
            planStr = [NSString stringWithFormat:@"%@-->%@",self.planModel.mobilePlan ,taskInfoModel.Name];
        }
        
        taskInfoModel.mobilePlan = planStr;
        vc.planModel = taskInfoModel;
        [self.navigationController pushViewController:vc animated:YES];
    };
    return cell;
}
 
- (void)setPlanModel:(PBSchedulePlanModel *)planModel {
    _planModel = planModel;
    self.dataList = planModel.children;
    [self.tableView reloadData];
}
/*
#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