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