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
//
//  PBIssueListViewController.m
//  IphoneBIMe
//
//  Created by zjf on 2018/7/18.
//  Copyright © 2018年 ProBIM. All rights reserved.
//
 
#import "PBIssueListViewController.h"
#import "PBDropdownMenu.h"
#import "PBIssueSearchController.h"
#import "PBNavigationController.h"
#import "PBAddIssueController.h"
#import "PBProjectPower.h"
#define IssueModuleName @"IssueTracking"
@interface PBIssueListViewController ()<PBDropdownMenuDelegate>
@property (nonatomic, strong) NSArray *roleArr;
@property (nonatomic, strong) NSArray *archiveArr;
@end
 
@implementation PBIssueListViewController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNav];
    for (PBProjectPower *power in self.powerArr) {
        if ([power.Bm_EnCode isEqualToString:IssueModuleName]) {
            if ([power.checkstate isEqualToString:@"1"]) {
                //有权限
                self.promptView.hidden = YES;
                [self getProjectParentId];
//                [self.tableView.mj_header beginRefreshing];
                for (NSDictionary *obj in power.Bmbs) {
                    if ([[obj valueForKey:@"Bmb_FullName"] isEqualToString:@"新增问题"]) {
                        if ([[obj valueForKey:@"checkstate"] isEqualToString:@"1"]) {
                            self.navigationItem.rightBarButtonItem.enabled = YES;
                        }
                    }
                }
                return;
            }else {
                //无权限
                self.promptView.textL.text = @"暂无权限";
                self.promptView.hidden = NO;
                return;
            }
        }
    }
    //无权限
    self.promptView.textL.text = @"暂无权限";
    self.promptView.hidden = NO;
}
#pragma mark - PBDropdownMenuDelegate
- (void)dropdownMenu:(UIButton *)clickBtn selectedCellNumber:(NSInteger)number {
    NSInteger index = clickBtn.tag -100;
    switch (index) {
        case 0:
            self.statusSelectIndex = number;
            [self.tableView.mj_header beginRefreshing];
            break;
        case 1:
            self.typeSelectIndex = number;
            [self.tableView.mj_header beginRefreshing];
            break;
//        case 2:
//            self.userSelectIndex = number;
//            [self.tableView.mj_header beginRefreshing];
//            break;
        case 2:
            self.archiveSelectIndex = number;
            [self.tableView.mj_header beginRefreshing];
            break;
        default:
            break;
    }
}
- (void)getProjectParentId {
//    [YJProgressHUD showCustomAnimation:@"" inview:self.view];
    [YJProgressHUD showProgress:@"" inView:self.view];
    [[PBNetworkTools sharedTools] getProjectParentIDWithProjectID:self.projectModel.organizeid 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];
        NSLog(@"%@",str);
        PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
        if (networkModel.Ret == 1){
            [self loadTypeAndStatusWith:networkModel.Data];
        }else {
            [YJProgressHUD showMessage:@"加载状态、类型失败" inView:self.view];
        }
    }];
}
- (void)loadTypeAndStatusWith:(NSString *)parentId {
    __block NSArray *statusArr; __block NSArray *typeArr;
    dispatch_semaphore_t sem = dispatch_semaphore_create(0);
    NSInteger commandCount = 2;
    __block NSInteger httpFinishCount = 0;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [[PBNetworkTools sharedTools] getIssueStatusWithCompanyId:parentId 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.Msg isEqualToString:@"OK"]) {
                statusArr = networkModel.Data;
                if (++httpFinishCount == commandCount) {
                    dispatch_semaphore_signal(sem);
                }
            }else {
                [YJProgressHUD showMessage:@"加载状态失败" inView:self.view];
                return;
            }
        }];
        
        [[PBNetworkTools sharedTools] getIssueTypesWithCompanyId:parentId 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.Msg isEqualToString:@"OK"]) {
                typeArr = networkModel.Data;
                if (++httpFinishCount == commandCount) {
                    dispatch_semaphore_signal(sem);
                }
            }else {
                [YJProgressHUD showMessage:@"加载类型失败" inView:self.view];
                return;
            }
        }];
        //如果全部请求没有返回则该线程会一直阻塞
        dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
        NSLog(@"全部加载完成==================: %@", [NSThread currentThread]);
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"更新视图UI update in main thread!:%@",[NSThread currentThread]);
            [YJProgressHUD hide];
            NSMutableArray *statusArrM = [[NSMutableArray alloc] init];
            for (NSDictionary *dict in statusArr) {
                PBIssueNavModel *issueNavModel = [PBIssueNavModel yy_modelWithDictionary:dict];
                [statusArrM addObject:issueNavModel];
            }
            NSMutableArray *typeArrM = [[NSMutableArray alloc] init];
            for (NSDictionary *dict in typeArr) {
                PBIssueNavModel *issueNavModel = [PBIssueNavModel yy_modelWithDictionary:dict];
                [typeArrM addObject:issueNavModel];
            }
            self.statusAndTypeData = @{@"IssueStatus":statusArrM.mutableCopy, @"IssueTypes":typeArrM.mutableCopy};
            PBIssueNavModel *statusNavModel = [[PBIssueNavModel alloc] init];
            statusNavModel.ItemDetailId = @"";
            statusNavModel.ItemName = @"状态";
            [statusArrM insertObject:statusNavModel atIndex:0];
            
            PBIssueNavModel *typeNavModel = [[PBIssueNavModel alloc] init];
            typeNavModel.ItemDetailId = @"";
            typeNavModel.ItemName = @"类型";
            [typeArrM insertObject:typeNavModel atIndex:0];
            
            [self.dropdownMenuArrM addObject:statusArrM];
            [self.dropdownMenuArrM addObject:typeArrM];
//            [self.dropdownMenuArrM addObject:self.roleArr];//去掉我相关检索
            [self.dropdownMenuArrM addObject:self.archiveArr];
            [self setupDropdownMenuView];
            [self.tableView.mj_header beginRefreshing];
        });
    });
}
- (void)setupDropdownMenuView {
    float dropdownMenuW = MainScreenWidth / (self.dropdownMenuArrM.count + 1);
    PBDropdownMenu *dropdownMenu = [[PBDropdownMenu alloc] initWithFrame:CGRectMake(0, 0, self.dropdownMenuArrM.count * dropdownMenuW, 40) andArr:self.dropdownMenuArrM];
    dropdownMenu.delegate = self;
    [self.view addSubview:dropdownMenu];
 
    UIButton *searchBtn = [[UIButton alloc] init];
    [searchBtn setImage:[UIImage imageNamed:@"Doc_list_searchItem"] forState:UIControlStateNormal];
    searchBtn.backgroundColor = [UIColor z_colorWithR:242 G:242 B:242];
    searchBtn.frame = CGRectMake(dropdownMenuW * self.dropdownMenuArrM.count, 0, dropdownMenuW, 40);
    [searchBtn addTarget:self action:@selector(searchAction)  forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:searchBtn];
}
 
- (void)searchAction {
    PBIssueSearchController *searchVC = [[PBIssueSearchController alloc] init];
    searchVC.projectModel = self.projectModel;
    searchVC.hidesBottomBarWhenPushed = YES;
    searchVC.dropdownMenuArrM = self.dropdownMenuArrM;
    searchVC.statusSelectIndex = self.statusSelectIndex;
    searchVC.typeSelectIndex = self.typeSelectIndex;
    searchVC.userSelectIndex = self.userSelectIndex;
    searchVC.archiveSelectIndex = self.archiveSelectIndex;
    [self.navigationController pushViewController:searchVC animated:YES];
}
 
- (void)setupNav {
    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 *addIssueItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Issue_list_add"] style:UIBarButtonItemStylePlain target:self action:@selector(addIssue)];
    self.navigationItem.rightBarButtonItem = addIssueItem;
    self.navigationItem.rightBarButtonItem.enabled = YES;
}
- (void)addIssue {
    PBAddIssueController *addIssueVC = [[PBAddIssueController alloc] init];
    addIssueVC.isAddIssue = YES;
    addIssueVC.projectModel = self.projectModel;
    addIssueVC.statusAndTypeData = self.statusAndTypeData;
    addIssueVC.SaveSuccessBlock = ^{
        [self.tableView.mj_header beginRefreshing];
    };
    PBNavigationController *nav = [[PBNavigationController alloc] initWithRootViewController:addIssueVC];
    nav.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:nav animated:YES completion:nil];
}
- (void)backItemAction {
    [PBNoteCenter postNotificationName: PBNoteCenterDismissTabBarController object:nil];
}
 
- (NSArray *)roleArr {
    if (_roleArr == nil) {
        PBIssueNavModel *issueNavModel = [[PBIssueNavModel alloc] init];
        issueNavModel.ItemDetailId = @"";
        issueNavModel.ItemName = @"相关";
        
        PBIssueNavModel *issueNavModel1 = [[PBIssueNavModel alloc] init];
        issueNavModel1.ItemDetailId = @"Creator";
        issueNavModel1.ItemName = @"我创建";
        
//        PBIssueNavModel *issueNavModel2 = [[PBIssueNavModel alloc] init];
//        issueNavModel2.ItemDetailId = @"Manager";
//        issueNavModel2.ItemName = @"我负责";
        
        PBIssueNavModel *issueNavModel3 = [[PBIssueNavModel alloc] init];
        issueNavModel3.ItemDetailId = @"Joiner";
        issueNavModel3.ItemName = @"我参与";
        
        _roleArr = @[issueNavModel,issueNavModel1,issueNavModel3];
    }
    return _roleArr;
}
- (NSArray *)archiveArr {
    if (_archiveArr == nil) {
        PBIssueNavModel *issueNavModel = [[PBIssueNavModel alloc] init];
        issueNavModel.ItemDetailId = @"0";
        issueNavModel.ItemName = @"归档/隐";
        
        PBIssueNavModel *issueNavModel1 = [[PBIssueNavModel alloc] init];
        issueNavModel1.ItemDetailId = @"1";
        issueNavModel1.ItemName = @"归档/显";
        
        _archiveArr = @[issueNavModel,issueNavModel1];
    }
    return _archiveArr;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
/*
#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