//
|
// PBScheduleBaseController.m
|
// IphoneBIMe
|
//
|
// Created by ZhangJF on 2022/8/18.
|
// Copyright © 2022 ProBIM. All rights reserved.
|
//
|
|
#import "PBScheduleBaseController.h"
|
#import "PBScheduleTableViewCell.h"
|
#import "PBScheduleListModel.h"
|
#import "PBAddIssueController.h"
|
#import "PBNavigationController.h"
|
#import "PBRefreshGifHeader.h"
|
#import "PBScheduleModuleViewController.h"
|
#import "PBPreScheduleViewController.h"
|
#define pageSize 20
|
|
static NSString *const CellID = @"CellID";
|
@interface PBScheduleBaseController ()<UITableViewDataSource, UITableViewDelegate>
|
@property (nonatomic, assign) NSInteger pageIndex;
|
@property (nonatomic, strong) PBRefreshGifHeader *headerView;
|
|
@end
|
|
@implementation PBScheduleBaseController
|
|
- (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 = 112.f;
|
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
[self.tableView registerClass:[PBScheduleTableViewCell 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 *archiveId = @"";
|
if (self.dropdownMenuArrM.count == 2) {
|
PBIssueNavModel *statusNavModel = self.dropdownMenuArrM[0][self.statusSelectIndex];
|
PBIssueNavModel *archiveTypeNavModel = self.dropdownMenuArrM[1][self.archiveSelectIndex];
|
statusId = statusNavModel.ItemDetailId;
|
archiveId = archiveTypeNavModel.ItemDetailId;
|
};
|
|
[[PBNetworkTools sharedTools] GetMobilePASONWithOrganizeId:self.projectModel.organizeid andMobilePA_ProjectID:archiveId andMobilePA_state:statusId 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.Ret == 1) {
|
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) {
|
PBScheduleListModel *scheduleListModel = [PBScheduleListModel yy_modelWithDictionary:obj];
|
[arrM addObject:scheduleListModel];
|
}
|
[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 = YES;
|
}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 {
|
PBScheduleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath];
|
cell.projectModel = self.projectModel;
|
cell.scheduleListModel = self.issueArrM[indexPath.row];
|
return cell;
|
}
|
#pragma mark - UITableViewDelegate
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
PBScheduleListModel *model = self.issueArrM[indexPath.row];
|
// if ([model.MobilePA_state isEqualToString:@"待提交"] || [model.MobilePA_state isEqualToString:@"驳回待提交"]){
|
// PBScheduleModuleViewController *moduleVC = [[PBScheduleModuleViewController alloc] init];
|
// moduleVC.isAdd = false;
|
// moduleVC.projectModel = self.projectModel;
|
// moduleVC.scheduleListModel = model;
|
// [self.navigationController pushViewController:moduleVC animated:YES];
|
// }else {
|
// PBPreScheduleViewController *preVC = [[PBPreScheduleViewController alloc] init];
|
// preVC.projectModel = self.projectModel;
|
// preVC.scheduleListModel = model;
|
// [self.navigationController pushViewController:preVC animated:YES];
|
// }
|
|
}
|
|
|
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
|
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 delMobilePAWith:indexPath];
|
}];
|
[alertVC addAction:cancelAction];
|
[alertVC addAction:determineAction];
|
[self presentViewController:alertVC animated:YES completion:nil];
|
}];
|
|
return @[shareAction];
|
}
|
|
- (void)delMobilePAWith:(NSIndexPath *)indexPath {
|
[YJProgressHUD showProgress:@"" inView:self.view];
|
PBScheduleListModel *scheduleListModel = self.issueArrM[indexPath.row];
|
[[PBNetworkTools sharedTools] DelMobilePAWithPlanId:scheduleListModel.MobilePA_ProjectID andCreateuserId:scheduleListModel.MobilePA_Createuserid andUnittime:scheduleListModel.MobilePA_Unittime andOrganizeId:self.projectModel.organizeid 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)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
|