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