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
//
//  PBRecordViewController.m
//  IphoneBIMe
//
//  Created by zjf on 2019/1/31.
//  Copyright © 2019 ProBIM. All rights reserved.
//
 
#import "PBRecordViewController.h"
#import "PBExamineListModel.h"
#import "PBResultModel.h"
#import "PBRecordModel.h"
#import "PBRecordTableViewCell.h"
#import "PBAddRecordViewController.h"
#import "PBApplyInspectionViewController.h"
#import "PBRoleModel.h"
#import "PBVideoPlayViewController.h"
#import "PBRecordImageTableViewCell.h"
static NSString *const CellID = @"CellID";
static NSString *const attachmentCellID = @"CeattachmentCellIDllID";
@interface PBRecordViewController ()<UIGestureRecognizerDelegate, UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSIndexPath *indexPath;
@property (nonatomic, assign) BOOL acceptance;
@property (nonatomic, assign) BOOL rectification;
@property (nonatomic, strong) NSMutableArray *recordListM;
@property (nonatomic, weak) UIButton *functionBtn;
@end
 
@implementation PBRecordViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.f) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
        self.navigationController.interactivePopGestureRecognizer.delegate = self;
    }
    [self setupNav];
    [self setupUI];
    [self loadDetail];
}
 
- (void)setupNav {
    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];
}
 
#pragma mark - 验收
- (void)acceptanceAction {
    PBAddRecordViewController *addRecordVC = [[PBAddRecordViewController alloc] init];
    addRecordVC.examineListModel = self.examineListModel;
    addRecordVC.projectModel = self.projectModel;
    addRecordVC.UpdateRecordListBlock = ^(BOOL isQualified) {
        [self loadDetail];
    };
    [self presentViewController:addRecordVC animated:YES completion:nil];
}
#pragma mark - 申请复检
- (void)apply {
    PBApplyInspectionViewController *applyInspectionVC = [[PBApplyInspectionViewController alloc] init];
    applyInspectionVC.examineListModel = self.examineListModel;
    applyInspectionVC.projectModel = self.projectModel;
    applyInspectionVC.UpdateRecordListBlock = ^{
        [self loadDetail];
    };
    [self presentViewController:applyInspectionVC animated:YES completion:nil];
}
- (void)loadDetail {
    [YJProgressHUD showProgress:@"" inView:self.view];
    [[PBNetworkTools sharedTools] RequestGetItemWithExamineID:self.examineListModel.ExamineID andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
        if (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) {
            [YJProgressHUD hide];
           self.examineDetailDic = networkModel.Data;
           NSString *flagStr = [[self.examineDetailDic valueForKey:@"ExamineResult"] substringToIndex:1];
           self.recordListM = [[NSMutableArray alloc] init];
           [self.recordListM addObjectsFromArray:[self.examineDetailDic valueForKey:@"RecordWithAttachments"]];
           NSDictionary *dict = @{
                               @"RectificationOperator" : self.examineListModel.bu_examiner_name,
                               @"RectificationRemark" : [self.examineDetailDic valueForKey:@"ExamineRemark"],
                               @"CreateDate": self.examineListModel.CreateDate,
                               @"indexFlag": @"0"
           };
            [self.recordListM addObject:dict];
            self.title = [NSString stringWithFormat:@"全部 %zd 条记录",self.recordListM.count];
//           if (self.UpdateRecordCountBlock) {
//               self.UpdateRecordCountBlock(self.examineDetailDic);
//           }
            [self.tableView reloadData];
            [self setBottomBtnWithFlag:flagStr];
        }else {
            [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
        }
    }];
}
- (void)setBottomBtnWithFlag:(NSString *)flagStr {
    if (self.roleModel.User_InRelation == NO && self.roleModel.User_InPrincipal == NO) {
        self.functionBtn.hidden = YES;
        return;
    }
    if (self.functionBtn == nil) {
        UIButton *functionBtn = [[UIButton alloc] init];
        self.functionBtn = functionBtn;
        [self.view addSubview:functionBtn];
        [functionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.tableView.mas_bottom).offset(7);
            make.left.equalTo(self.view).offset(10);
            make.right.equalTo(self.view).offset(-10);
            make.height.equalTo(@50);
        }];
    }
    if ([flagStr isEqualToString:@"B"]) {
        //申请复检
        [self.functionBtn setImage:[UIImage imageNamed:@"apply_reinspection_nor"] forState:UIControlStateNormal];
        [self.functionBtn setImage:[UIImage imageNamed:@"apply_reinspection_dis-1"] forState:UIControlStateDisabled];
        [self.functionBtn addTarget:self action:@selector(apply) forControlEvents:UIControlEventTouchUpInside];
        if (self.roleModel.User_InRelation) {
            self.functionBtn.enabled = YES;
        }else {
            self.functionBtn.enabled = NO;
        }
    }else if ([flagStr isEqualToString:@"C"]) {
        //验收
        [self.functionBtn setImage:[UIImage imageNamed:@"acceptance_nor"] forState:UIControlStateNormal];
        [self.functionBtn setImage:[UIImage imageNamed:@"acceptance_dis-1"] forState:UIControlStateDisabled];
        [self.functionBtn addTarget:self action:@selector(acceptanceAction) forControlEvents:UIControlEventTouchUpInside];
        if (self.roleModel.User_InPrincipal) {
            self.functionBtn.enabled = YES;
        }else {
            self.functionBtn.enabled = NO;
        }
    }else if ([flagStr isEqualToString:@"D"]) {
        self.functionBtn.hidden = YES;
    }
    if (self.ModifyStateBlock) {
        self.ModifyStateBlock(flagStr);
    }
}
- (void)setupUI {
    self.view.backgroundColor = PBColor(244, 245, 246);
//    self.view.backgroundColor = [UIColor blackColor];
//    UIView *bgView = [[UIView alloc] init];
//    bgView.backgroundColor = PBColor(244, 245, 246);
//    [self.view addSubview:bgView];
//    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.view).offset(70);
//        make.left.right.bottom.equalTo(self.view);
//    }];
    self.tableView = [[UITableView alloc] init];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView registerClass:[PBRecordTableViewCell class] forCellReuseIdentifier:CellID];
    [self.tableView registerClass:[PBRecordImageTableViewCell class] forCellReuseIdentifier:attachmentCellID];
    self.tableView.estimatedRowHeight = 80.f;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.bounces = NO;
    self.tableView.backgroundColor = PBColor(244, 245, 246);
    [self.view addSubview:self.tableView];
    CGFloat bottomH = 64.f;
    if (IS_IPHONE_X) {
        bottomH = 64.f + IPHONE_X_BOTTOM;
    }
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view);
        make.left.equalTo(self.view).offset(10);
        make.right.equalTo(self.view).offset(-10);
        make.bottom.equalTo(self.view).offset(-(bottomH));
    }];
    UIView *linV = [[UIView alloc] init];
    linV.backgroundColor = PBColor(246, 246, 247);
    [self.view addSubview:linV];
    [linV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tableView.mas_bottom);
        make.left.right.equalTo(self.view);
        make.height.equalTo(@1);
    }];
}
 
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.recordListM.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PBRecordModel *recordModel = [PBRecordModel yy_modelWithDictionary:self.recordListM[indexPath.section]];
    if (indexPath.section == 0) {
        recordModel.isOneIndex = NO;
    }else {
        recordModel.isOneIndex = NO;
    }
    if (indexPath.section == self.recordListM.count - 2) {
        recordModel.indexFlag = @"1";
    }
    if (indexPath.row == 0) {
        PBRecordTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath];
        cell.recordModel = recordModel;
        cell.PlayVideoBlock = ^(NSString * _Nonnull videoUrl) {
            NSLog(@"打开视频");
            PBVideoPlayViewController *playVC = [[PBVideoPlayViewController alloc] init];
            playVC.url = videoUrl;
            [self.navigationController pushViewController:playVC animated:YES];
        };
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else {
        PBRecordImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:attachmentCellID forIndexPath:indexPath];
        cell.recordModel = recordModel;
        cell.PlayVideoBlock = ^(NSString * _Nonnull videoUrl) {
            NSLog(@"打开视频");
            PBVideoPlayViewController *playVC = [[PBVideoPlayViewController alloc] init];
            playVC.url = videoUrl;
            [self.navigationController pushViewController:playVC animated:YES];
        };
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}
 
- (void)setExamineListModel:(PBExamineListModel *)examineListModel {
    _examineListModel = examineListModel;
}
- (void)setProjectModel:(PBProjectModel *)projectModel {
    _projectModel = projectModel;
}
 
//- (void)setRecordListM:(NSMutableArray *)recordListM {
//    _recordListM = recordListM;
//    /**
//     RectificationID : "3b0b0ac2-86f4-4da1-8af1-072fb00cc1ed"
//     RectificationOperatorID : "9d9ca069-af5a-4564-9999-591b16560332"
//     RectificationOperator : "zjf"
//     RectificationOperateFlag : 1
//     RectificationCheckDate : "2020-08-19T14:29:35"
//     RectificationCheckResult : "整改"
//     RectificationRemark : "Djfkejkfjekljfkejlkfjelkjllsleifiejiijkdsnfklffjeh"
//     IsDel : null
//     ExamineID : "9578d162-aef6-4a99-92c2-d5b6048651b7"
//     CreateDate : "2020-08-19T14:29:35"
//     aer_counterpart : null
//     */
//    NSDictionary *dict = @{
//        @"RectificationOperator" : self.examineListModel.bu_examiner_name,
//        @"RectificationRemark" : [self.examineDetailDic valueForKey:@"ExamineRemark"],
//        @"CreateDate": self.examineListModel.CreateDate,
//        @"indexFlag": @"0"
//    };
//    [_recordListM addObject:dict];
//}
 
- (void)setExamineDetailDic:(NSDictionary *)examineDetailDic {
    _examineDetailDic = examineDetailDic;
}
- (void)setRoleType:(RoleType)roleType {
    _roleType = roleType;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/
 
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/
 
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
 
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/
 
/*
#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