//
|
// 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
|