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
//
//  PBExamineBaseController.m
//  IphoneBIMe
//
//  Created by zjf on 2018/11/26.
//  Copyright © 2018 ProBIM. All rights reserved.
//
 
#import "PBExamineBaseController.h"
#import "PBExamineListTableViewCell.h"
#import "PBExamineListToCheckCell.h"
#import "PBExamineListPicCell.h"
#import "PBExamineListTwoPicCell.h"
#import "PBExamineListMorePicCell.h"
#import "PBResultModel.h"
#import "PBExamineListModel.h"
#import "PBIssueNavModel.h"
#import "PBCheckTaskViewController.h"
#import "PBExamineDetailController.h"
#import "PBRefreshGifHeader.h"
#import "PBVideoPlayViewController.h"
#define pageSize 15
 
static NSString *const CellID = @"CellID";
static NSString *const ToCheckCellID = @"ToCheckCellID";
static NSString *const CheckPicCellID = @"CheckPicCellID";
static NSString *const TwoPicCellID = @"TwoPicCellID";
static NSString *const MorePicCellID = @"MorePicCellID";
@interface PBExamineBaseController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, assign) NSInteger pageIndex;
@property (nonatomic, strong) NSMutableArray *examineDictArr;
@property (nonatomic, strong) PBRefreshGifHeader *headerView;
@end
 
@implementation PBExamineBaseController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.f) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    self.view.backgroundColor = [UIColor whiteColor];
    [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 = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 200.f;
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[PBExamineListTableViewCell class] forCellReuseIdentifier:CellID];
    [self.tableView registerClass:[PBExamineListToCheckCell class] forCellReuseIdentifier:ToCheckCellID];
    [self.tableView registerClass:[PBExamineListPicCell class] forCellReuseIdentifier:CheckPicCellID];
    [self.tableView registerClass:[PBExamineListTwoPicCell class] forCellReuseIdentifier:TwoPicCellID];
    [self.tableView registerClass:[PBExamineListMorePicCell class] forCellReuseIdentifier:MorePicCellID];
    [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.examineArrM removeAllObjects];
        [self.examineDictArr removeAllObjects];
        [self loadExamineList];
    }];
    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 loadExamineList];
//    }];
//    self.tableView.mj_footer = footer;
    
//    self.tableView.mj_header = self.headerView;
}
- (void)loadExamineList {
    NSString *search = @"";
    if (self.searchText == nil) {
        self.promptView.textL.text = @"暂无检查数据";
        self.promptView.imageV.image = [UIImage imageNamed:@"Examine_ security_list_empty"];
//        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 {
        search = self.searchText;
        self.promptView.textL.text = @"暂无相关检查数据,请换关键字搜索";
        self.promptView.imageV.image = [UIImage imageNamed:@"Examine_quality_list_empty"];
        if ([search isEqualToString:@""]) {
            [self.tableView.mj_header endRefreshing];
            self.promptView.hidden = NO;
            return;
        }
    }
    NSString *relatedID;
    NSString *levelID;
    NSString *stateID;
    NSString *typeID;
    NSString *SortField;
    NSString *SortIsAsc;
    if (![self.searchText isEqualToString:@""] && self.searchText != nil) {
        relatedID = @"";
        levelID = @"";
        stateID = @"";
        typeID = @"";
        SortField = @"";
        SortIsAsc = @"";
    }else {
        relatedID = self.relatedId == nil? @"" : self.relatedId;
        levelID = self.levelId == nil? @"" : self.levelId;
        stateID = self.stateId == nil? @"" : self.stateId;
        typeID = self.typeId == nil? @"" : self.typeId;
        SortField = self.sortingArr[self.sortingSelect];
        SortIsAsc = self.sortingAse == 0? @"0" : @"1";
//        PBIssueNavModel *resultNavModel = _dropdownMenuArrM[0][_resultSelectIndex];
//        PBIssueNavModel *typeNavModel = _dropdownMenuArrM[1][_typeSelectIndex];
//        PBIssueNavModel *levelNavModel = _dropdownMenuArrM[2][_levelSelectIndex];
//        PBIssueNavModel *relatedModel = _dropdownMenuArrM[3][_relatedSelectIndex];
 
//        StateType = resultNavModel.ItemDetailId;
//        AuthorType = relatedModel.ItemDetailId;
//        Severitylevel = levelNavModel.ItemDetailId;
//        Types = typeNavModel.ItemDetailId;
    }
    [[PBNetworkTools sharedTools] RequestExamineListWithBIMComposerId:self.projectModel.bimcomposerid andSearchValue:search andStateType:stateID andAuthorType:relatedID andSeveritylevel:levelID andTypes:typeID andSortField:SortField andSortIsAsc:SortIsAsc andPageIndex:0 andPageSize:1000 andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
        [self.tableView.mj_header endRefreshing];
        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) {
            for (NSDictionary *obj in [networkModel.Data valueForKey:@"List"]) {
                PBExamineListModel *examineListModel = [PBExamineListModel yy_modelWithDictionary:obj];
                [self.examineArrM addObject:examineListModel];
            }
            [self.examineDictArr addObjectsFromArray:[networkModel.Data valueForKey:@"List"]];
            if (self.examineArrM.count == 0) {
                self.promptView.hidden = NO;
            }else {
                self.promptView.hidden = YES;
                [self.tableView reloadData];
            }
        }else {
           [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
           [self.tableView reloadData];
        }
    }];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.examineArrM.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PBExamineListModel *examineListModel = self.examineArrM[indexPath.row];
    NSString *flagStr = [examineListModel.ExamineResult substringToIndex:1];
    if ([flagStr isEqualToString:@"A"]) {
        PBExamineListToCheckCell *cell = [tableView dequeueReusableCellWithIdentifier:ToCheckCellID forIndexPath:indexPath];
        cell.examineListModel = examineListModel;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    } else {
        //列表不显示图片视频
//        if (examineListModel.FirstCheck_Attachments.count >= 3) {
//            PBExamineListMorePicCell *cell = [tableView dequeueReusableCellWithIdentifier:MorePicCellID forIndexPath:indexPath];
//            cell.examineListModel = examineListModel;
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            return cell;
//        }else if (examineListModel.FirstCheck_Attachments.count == 2) {
//            PBExamineListTwoPicCell *cell = [tableView dequeueReusableCellWithIdentifier:TwoPicCellID forIndexPath:indexPath];
//            cell.examineListModel = examineListModel;
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            return cell;
//        }else if (examineListModel.FirstCheck_Attachments.count == 1) {
//            PBExamineListPicCell *cell = [tableView dequeueReusableCellWithIdentifier:CheckPicCellID forIndexPath:indexPath];
//            cell.examineListModel = examineListModel;
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            cell.PlayVideoBlock = ^(NSString * _Nonnull url) {
//                PBVideoPlayViewController *playVC = [[PBVideoPlayViewController alloc] init];
//                playVC.url = url;
//                playVC.hidesBottomBarWhenPushed = YES;
//                [self.navigationController pushViewController:playVC animated:YES];
//            };
//            return cell;
//        }else {
            PBExamineListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath];
            cell.examineListModel = examineListModel;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
//        }
    }
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    PBExamineListModel *examineListModel = self.examineArrM[indexPath.row];
    NSString *flagStr = [examineListModel.ExamineResult substringToIndex:1];
    if ([flagStr isEqualToString:@"A"]) {
        PBCheckTaskViewController *addExamineVC = [[PBCheckTaskViewController alloc] init];
        addExamineVC.projectModel = self.projectModel;
        addExamineVC.stateArr = self.stateArr;
        addExamineVC.levelArr = self.levelArr;
        addExamineVC.typeArr = self.typeArr;
        addExamineVC.examineListModel = examineListModel;
        addExamineVC.examineListDict = self.examineDictArr[indexPath.row];
        addExamineVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:addExamineVC animated:YES];
    }else {
        PBExamineDetailController *vc = [[PBExamineDetailController alloc] init];
        vc.projectModel = self.projectModel;
        vc.stateArr = self.stateArr;
        vc.levelArr = self.levelArr;
        vc.examineListModel = examineListModel;
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
    }
}
 
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    PBExamineListModel *examineListModel = self.examineArrM[indexPath.row];
//    if (!examineListModel.IsExamineMgr) {
//        return @[];
//    }
    UITableViewRowAction *deleteAction =[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 deleteExamineWith:indexPath];
        }];
        [alertVC addAction:cancelAction];
        [alertVC addAction:determineAction];
        [self presentViewController:alertVC animated:YES completion:nil];
    }];
    deleteAction.backgroundColor = ErrorColor;
 
    UITableViewRowAction *closeAction = [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 closeExamineWith:indexPath];
        }];
        [alertVC addAction:cancelAction];
        [alertVC addAction:determineAction];
        [self presentViewController:alertVC animated:YES completion:nil];
    }];
    closeAction.backgroundColor = PBColor(40, 58, 79);
    //判断权限
    NSString *flagStr = [examineListModel.ExamineResult substringToIndex:1];
    if ([UserID isEqualToString:examineListModel.ExaminerID]) {
        if ([flagStr isEqualToString:@"E"]){
            return @[deleteAction];
        }else {
            return @[closeAction, deleteAction];
        }
    }else {
        return nil;
    }
}
//关闭
- (void)closeExamineWith:(NSIndexPath *)indexPath {
    [YJProgressHUD showProgress:@"" inView:self.view];
    PBExamineListModel *examienListModel = self.examineArrM[indexPath.row];
    [[PBNetworkTools sharedTools] RequestCloseItemsWithId:examienListModel.ExamineID 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.examineArrM removeObjectAtIndex:indexPath.row];
            [self.examineDictArr removeObjectAtIndex:indexPath.row];
            [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [self.tableView reloadData];
        }else {
            [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
        }
    }];
}
//删除
- (void)deleteExamineWith:(NSIndexPath *)indexPath {
    [YJProgressHUD showProgress:@"" inView:self.view];
    PBExamineListModel *examienListModel = self.examineArrM[indexPath.row];
    [[PBNetworkTools sharedTools] RequestRemoveItemsWithId:examienListModel.ExamineID 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.examineArrM removeObjectAtIndex:indexPath.row];
            [self.examineDictArr removeObjectAtIndex:indexPath.row];
            [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [self.tableView reloadData];
        }else {
            [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
        }
    }];
}
 
- (PBPromptView *)promptView {
    if (_promptView == nil) {
        _promptView = [[PBPromptView alloc] initWithFrame:self.view.bounds];
    }
    return _promptView;
}
- (void)setProjectModel:(PBProjectModel *)projectModel {
    _projectModel = projectModel;
}
 
- (void)setPowerArr:(NSArray *)powerArr {
    _powerArr = powerArr;
}
 
- (NSMutableArray *)examineArrM {
    if (_examineArrM == nil) {
        _examineArrM = [[NSMutableArray alloc] init];
    }
    return _examineArrM;
}
 
- (NSMutableArray *)examineDictArr {
    if (_examineDictArr == nil) {
        _examineDictArr = [[NSMutableArray alloc] init];
    }
    return _examineDictArr;
}
 
- (void)setSearchText:(NSString *)searchText {
    _searchText = searchText;
}
- (NSArray *)sortingArr {
    if (_sortingArr == nil) {
        _sortingArr = @[@"CreateDate", @"RectificateDate", @"State"];
    }
    return _sortingArr;
}
- (PBRefreshGifHeader *)headerView {
    if(_headerView == nil) {
        _headerView = [[PBRefreshGifHeader alloc] init];
        __weak typeof(self) weakSelf = self;
        [self.headerView setRefreshingBlock:^{
            weakSelf.pageIndex = 0;
            [weakSelf.examineArrM removeAllObjects];
            [weakSelf.examineDictArr removeAllObjects];
            [weakSelf loadExamineList];
        }];
    }
    return _headerView;
}
//- (NSMutableArray *)dropdownMenuArrM {
//    if (_dropdownMenuArrM == nil) {
//        _dropdownMenuArrM = [[NSMutableArray alloc] init];
//        
//        PBIssueNavModel *issueNavModel = [[PBIssueNavModel alloc] init];
//        issueNavModel.ItemDetailId = @"";
//        issueNavModel.ItemName = @"等级";
//        
//        PBIssueNavModel *issueNavModel1 = [[PBIssueNavModel alloc] init];
//        issueNavModel1.ItemDetailId = @"非常严重";
//        issueNavModel1.ItemName = @"非常严重";
//        
//        PBIssueNavModel *issueNavModel2 = [[PBIssueNavModel alloc] init];
//        issueNavModel2.ItemDetailId = @"严重";
//        issueNavModel2.ItemName = @"严重";
//        
//        PBIssueNavModel *issueNavModel3 = [[PBIssueNavModel alloc] init];
//        issueNavModel3.ItemDetailId = @"一般";
//        issueNavModel3.ItemName = @"一般";
//        NSArray *typeArr = @[issueNavModel, issueNavModel1, issueNavModel2, issueNavModel3];
//        
//        PBIssueNavModel *issueNavMode4 = [[PBIssueNavModel alloc] init];
//        issueNavMode4.ItemDetailId = @"";
//        issueNavMode4.ItemName = @"状态";
//        
//        PBIssueNavModel *issueNavModel5 = [[PBIssueNavModel alloc] init];
//        issueNavModel5.ItemDetailId = @"A_ToBeCheck";
//        issueNavModel5.ItemName = @"待检查";
//        
//        PBIssueNavModel *issueNavModel6 = [[PBIssueNavModel alloc] init];
//        issueNavModel6.ItemDetailId = @"B_ToBeRectified";
//        issueNavModel6.ItemName = @"待整改";
//        PBIssueNavModel *issueNavModel7 = [[PBIssueNavModel alloc] init];
//        issueNavModel7.ItemDetailId = @"C_ToBeRecheck";
//        issueNavModel7.ItemName = @"待验收";
//        PBIssueNavModel *issueNavModel8 = [[PBIssueNavModel alloc] init];
//        issueNavModel8.ItemDetailId = @"D_Qualified";
//        issueNavModel8.ItemName = @"已合格";
//        NSArray *stateArr = @[issueNavMode4, issueNavModel5, issueNavModel6, issueNavModel7, issueNavModel8];
//       
//        PBIssueNavModel *issueNavModel9 = [[PBIssueNavModel alloc] init];
//        issueNavModel9.ItemDetailId = @"";
//        issueNavModel9.ItemName = @"相关";
//        PBIssueNavModel *issueNavModel10 = [[PBIssueNavModel alloc] init];
//        issueNavModel10.ItemDetailId = @"AsChecker";
//        issueNavModel10.ItemName = @"我检查";
//        PBIssueNavModel *issueNavModel11 = [[PBIssueNavModel alloc] init];
//        issueNavModel11.ItemDetailId = @"AsRectifier";
//        issueNavModel11.ItemName = @"我整改";
//        PBIssueNavModel *issueNavModel12 = [[PBIssueNavModel alloc] init];
//        issueNavModel12.ItemDetailId = @"AsRechecker";
//        issueNavModel12.ItemName = @"我验收";
//        NSArray *relatedArr = @[issueNavModel9, issueNavModel10, issueNavModel11, issueNavModel12];
//
//        [_dropdownMenuArrM addObject:stateArr];
//        [_dropdownMenuArrM addObject:typeArr];
//        [_dropdownMenuArrM addObject:relatedArr];
//    }//传空字符串或以下其中之一,可选值:AsChecker(我检查)AsRechecker(我复检)AsRectifier(我整改)
//    return _dropdownMenuArrM;
//}
/*
#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