zjf
2023-03-13 881f0da670f20c401c1e1d08b36253abb28f72d2
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
//
//  PBIssueBaseController.m
//  IphoneBIMe
//
//  Created by zjf on 2018/8/13.
//  Copyright © 2018年 ProBIM. All rights reserved.
//
 
#import "PBIssueBaseController.h"
#import "PBIssueListTableViewCell.h"
#import "PBIssueListModel.h"
#import "PBAddIssueController.h"
#import "PBNavigationController.h"
#import "PBRefreshGifHeader.h"
#define pageSize 20
 
static NSString *const CellID = @"CellID";
@interface PBIssueBaseController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, assign) NSInteger pageIndex;
@property (nonatomic, strong) PBRefreshGifHeader *headerView;
@end
 
@implementation PBIssueBaseController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.f) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    [self setupUI];
    [self setupRefresh];
}
- (void)setupUI {
    self.tableView = [[UITableView alloc] init];
    self.tableView.backgroundColor = PBColor(244, 245, 246);
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.rowHeight = 120.f;
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.tableView registerClass:[PBIssueListTableViewCell class] forCellReuseIdentifier:CellID];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(41);
        make.left.right.bottom.equalTo(self.view);
    }];
    
    [self.view addSubview:self.promptView];
    self.promptView.hidden = YES;
}
- (void)setupRefresh {
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        self.pageIndex = 0;
        [self.issueArrM removeAllObjects];
        [self loadIssueList];
    }];
    header.lastUpdatedTimeLabel.hidden = YES;
    header.stateLabel.textColor = TitleColor;
    [header setTitle:@"下拉刷新" forState:MJRefreshStateIdle];
    [header setTitle:@"释放更新" forState:MJRefreshStatePulling];
    [header setTitle:@"加载中..." forState:MJRefreshStateRefreshing];
    self.tableView.mj_header = header;
 
//    MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
//        [self loadIssueList];
//    }];
//    self.tableView.mj_footer = footer;
 
//    self.tableView.mj_header = self.headerView;
}
 
- (void)loadIssueList {
    self.promptView.hidden = YES;
    NSString *statusId = @""; NSString *typeId = @""; NSString *archiveId = @""; NSString *search = @"";
    if (self.dropdownMenuArrM.count == 3) {
        PBIssueNavModel *statusNavModel = self.dropdownMenuArrM[0][self.statusSelectIndex];
        PBIssueNavModel *typeNavModel = self.dropdownMenuArrM[1][self.typeSelectIndex];
        PBIssueNavModel *archiveTypeNavModel = self.dropdownMenuArrM[2][self.archiveSelectIndex];
        statusId = statusNavModel.ItemDetailId;
        typeId = typeNavModel.ItemDetailId;
        archiveId = archiveTypeNavModel.ItemDetailId;
    };
    if (self.searchText == nil) {
        if ([statusId isEqualToString:@""] & [typeId isEqualToString:@""]) {
            self.promptView.textL.text = @"暂无问题点击右上角加号新增问题";
//            NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:_promptView.textL.text];
//            NSRange redRange = NSMakeRange([[noteStr string] rangeOfString:@"加号"].location, [[noteStr string] rangeOfString:@"加号"].length);
//            //需要设置的位置
//            [noteStr addAttribute:NSForegroundColorAttributeName value:IndicatedColor range:redRange];
//            //设置颜色
//            [_promptView.textL setAttributedText:noteStr];
            
        }else {
            self.promptView.textL.text = @"无筛选结果";
        }
    }else {
        search = self.searchText;
        self.promptView.textL.text = @"暂无相关问题,请换关键字搜索";
        if ([search isEqualToString:@""]) {
            [self.tableView.mj_header endRefreshing];
            self.promptView.hidden = NO;
            self.countL.text = @"搜索结果(0)";
            return;
        }
    }
    [[PBNetworkTools sharedTools] getIssueListWithOrganizeId:_projectModel.organizeid andIssueStatusId:statusId andIssueTypeId:typeId andArchiveId:archiveId andKeyword:search andUserType:@"" andPageIndex:++self.pageIndex andPageSize:pageSize andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        if (error) {
            [YJProgressHUD showMessage:@"加载问题列表失败" inView:self.view];
            --self.pageIndex;
            return;
        }
        NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
        PBNetworkModel *networkModel = [PBNetworkModel yy_modelWithJSON:str];
        if ([networkModel.Msg isEqualToString:@"OK"]) {
            if (self.countL) {
                self.countL.hidden = NO;
                NSInteger count = [[networkModel.Data valueForKey:@"TotalCount"] integerValue];
                self.countL.text = [NSString stringWithFormat:@"搜索结果(%zd)",count];
            }
            NSMutableArray *arrM = [[NSMutableArray alloc] init];
            for (NSDictionary *obj in [networkModel.Data valueForKey:@"Items"]) {
                PBIssueListModel *issueListModel = [PBIssueListModel yy_modelWithDictionary:obj];
                [arrM addObject:issueListModel];
            }
            [self.issueArrM addObjectsFromArray:arrM.copy];
            [self.tableView reloadData];
            if (arrM.count < pageSize) {
                self.tableView.mj_footer.hidden = YES;
            }else {
                self.tableView.mj_footer.hidden = NO;
            }
            if (self.issueArrM.count == 0) {
                self.promptView.hidden = NO;
            }else {
                self.promptView.hidden = YES;
            }
        }else {
            --self.pageIndex;
            [YJProgressHUD showMessage:@"加载问题列表失败" inView:self.view];
        }
    }];
}
 
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.issueArrM.count;
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PBIssueListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath];
    cell.projectModel = self.projectModel;
    cell.issueListModel = self.issueArrM[indexPath.row];
    return cell;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    PBAddIssueController *detailsVC = [[PBAddIssueController alloc] init];
    detailsVC.isAddIssue = NO;
    detailsVC.projectModel = self.projectModel;
    detailsVC.issueListModel = self.issueArrM[indexPath.row];
    detailsVC.statusAndTypeData = self.statusAndTypeData;
    PBNavigationController *nav = [[PBNavigationController alloc] initWithRootViewController:detailsVC];
    nav.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:nav animated:YES completion:nil];
    
}
 
 
//- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {
//    [self customDeleteBtnAfteriOS11:tableView];
//}
//- (void)customDeleteBtnAfteriOS11:(UITableView *)tableView {
//    NSLog(@"yyyyyyy");
//    for (UIView *subview in tableView.subviews) {
//        NSLog(@"======%@",NSStringFromClass([subview class]));
//
//        if ([NSStringFromClass([subview class]) isEqualToString:@"UISwipeActionPullView"]) {
//            UIButton *btn = [subview.subviews objectAtIndex:0];
//            [btn setImage:[UIImage imageNamed:@"Issue_problem_list_delete"] forState:UIControlStateNormal];
//        }
//    }
//}
 
//- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
//    NSLog(@"===bbbbb");
//    return UITableViewCellEditingStyleDelete;
//}
//- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
//    PBIssueListModel *issueListModel = self.issueArrM[indexPath.row];
//    NSString *userId = [[NSString getLoginData] valueForKey:@"UserId"];
//    if (![userId isEqualToString:issueListModel.CreateUserId]) {
//        return @[];
//    }
//
//    UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
//        NSLog(@"点击了删除");
//        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"您确定要删除吗?" preferredStyle:UIAlertControllerStyleAlert];
//        UIAlertAction *cancelAction  = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
//        UIAlertAction *determineAction  = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
//            [self deleteIssueWith:indexPath];
//        }];
//        [alertVC addAction:cancelAction];
//        [alertVC addAction:determineAction];
//        [self presentViewController:alertVC animated:YES completion:nil];
//     }];
//    rowAction.backgroundColor = [UIColor whiteColor];
//    return @[rowAction];
//}
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    PBIssueListModel *issueListModel = self.issueArrM[indexPath.row];
    if (!issueListModel.isIssueManager) {
        return @[];
    }
    UITableViewRowAction *shareAction = [UITableViewRowAction rowActionWithStyle:(UITableViewRowActionStyleDestructive) title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"您确定要删除吗?" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancelAction  = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *determineAction  = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            [self deleteIssueWith:indexPath];
        }];
        [alertVC addAction:cancelAction];
        [alertVC addAction:determineAction];
        [self presentViewController:alertVC animated:YES completion:nil];
    }];
//    shareAction.backgroundColor = WarningColor;
    
    UITableViewRowAction *loadAction =[UITableViewRowAction rowActionWithStyle:(UITableViewRowActionStyleDestructive) title:@"归档" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"您确定要归档吗?" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancelAction  = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        UIAlertAction *determineAction  = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            [self archiveWith:indexPath];
        }];
        [alertVC addAction:cancelAction];
        [alertVC addAction:determineAction];
        [self presentViewController:alertVC animated:YES completion:nil];
    }];
    loadAction.backgroundColor = IndicatedColor;
    return @[shareAction];
}
                                         
- (void)deleteIssueWith:(NSIndexPath *)indexPath {
    [YJProgressHUD showProgress:@"" inView:self.view];
    PBIssueListModel *issueListModel = self.issueArrM[indexPath.row];
    [[PBNetworkTools sharedTools] RequestDeleteIssueWithIssueID:issueListModel.IssueId 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];
            [self.issueArrM removeObjectAtIndex:indexPath.row];
            [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [self.tableView reloadData];
        }else {
            [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
        }
    }]; 
}
- (void)archiveWith:(NSIndexPath *)indexPath {
    PBIssueListModel *issueListModel = self.issueArrM[indexPath.row];
    if (![issueListModel.IssueStatusText isEqualToString:@"关闭"]) {
        [YJProgressHUD showMessage:@"该问题未关闭,不能归档" inView:self.view];
        return;
    }
    [YJProgressHUD showProgress:@"" inView:self.view];
    [[PBNetworkTools sharedTools] SetIssueDeleteMarkWithIssueID:issueListModel.IssueId 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];
            //判断是否隐藏归档
            PBIssueNavModel *archiveTypeNavModel = self.dropdownMenuArrM[3][self.archiveSelectIndex];
            NSString *archiveId = archiveTypeNavModel.ItemDetailId;
            if ([archiveId isEqualToString:@"0"]) {//隐藏
                [self.issueArrM removeObjectAtIndex:indexPath.row];
                [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
                [self.tableView reloadData];
            }else {
                PBIssueListModel *issueModel = self.issueArrM[indexPath.row];
                issueModel.DeleteMark = @"2";
                [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
            }
        }else {
            [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
        }
    }];
}
 
- (void)setProjectModel:(PBProjectModel *)projectModel {
    _projectModel = projectModel;
}
- (void)setPowerArr:(NSArray *)powerArr {
    _powerArr = powerArr;
}
 
- (NSMutableArray *)issueArrM {
    if (_issueArrM == nil) {
        _issueArrM = [[NSMutableArray alloc] init];
    }
    return _issueArrM;
}
- (NSMutableArray *)dropdownMenuArrM {
    if (_dropdownMenuArrM == nil) {
        _dropdownMenuArrM = [[NSMutableArray alloc] init];
    }
    return _dropdownMenuArrM;
}
 
- (PBPromptView *)promptView {
    if (_promptView == nil) {
        _promptView = [[PBPromptView alloc] initWithFrame:self.view.bounds];
        _promptView.imageV.image = [UIImage imageNamed:@"Issue_list_empty"];
    }
    return _promptView;
}
 
- (PBRefreshGifHeader *)headerView {
    if(_headerView == nil) {
        _headerView = [[PBRefreshGifHeader alloc] init];
        __weak typeof(self) weakSelf = self;
        [self.headerView setRefreshingBlock:^{
            weakSelf.pageIndex = 0;
            [weakSelf.issueArrM removeAllObjects];
            [weakSelf loadIssueList];
//            [weakSelf.tableView.mj_header endRefreshing];
        }];
    }
    return _headerView;
}
 
- (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