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