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
//
//  PBPanoramaBaseController.m
//  IphoneBIMe
//
//  Created by ZhangJF on 2022/10/18.
//  Copyright © 2022 ProBIM. All rights reserved.
//
 
#import "PBPanoramaBaseController.h"
#import "PBPanoramaTableViewCell.h"
#import "PBPanoramaModel.h"
#import "PBPanoramaViewController.h"
 
static NSString *const CellID = @"CellID";
@interface PBPanoramaBaseController ()<UITableViewDataSource, UITableViewDelegate>
 
@end
 
@implementation PBPanoramaBaseController
 
- (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(248, 248, 248);
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.rowHeight = 114.f;
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[PBPanoramaTableViewCell 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.panoramaArrM removeAllObjects];
        [self loadPanoramaList];
    }];
    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;
}
- (void)loadPanoramaList {
    NSString *statusId = @""; NSString *searText = @"";
    if (self.dropdownMenuArrM.count == 1) {
        PBIssueNavModel *statusNavModel = self.dropdownMenuArrM[0][self.statusSelectIndex];
        statusId = statusNavModel.ItemDetailId;
    };
    searText = self.searchText == nil? @"" : self.searchText;
    [[PBNetworkTools sharedTools] GetListByLabelGroupWithOrganizeId:self.projectModel.organizeid andLabelId:statusId andPbName:searText  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) {
            NSMutableArray *arrM = [[NSMutableArray alloc] init];
            for (NSDictionary *obj in networkModel.Data) {
                NSArray *arr =  [obj valueForKey:@"Panoramas"];
                [arrM addObjectsFromArray:arr];
            }
            NSMutableArray *modelArrM = [[NSMutableArray alloc] init];
            for (NSDictionary *dict in arrM) {
                PBPanoramaModel *panoramaModel = [PBPanoramaModel yy_modelWithDictionary:dict];
                [modelArrM addObject:panoramaModel];
            }
            self.panoramaArrM = modelArrM;
            [self.tableView reloadData];
        } else {
            [YJProgressHUD showMessage:@"加载列表失败" inView:self.view];
        }
    }];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.panoramaArrM.count;
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PBPanoramaTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath];
    cell.panoramaModel = self.panoramaArrM[indexPath.row];
    return cell;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    PBPanoramaModel *panoramaModel = self.panoramaArrM[indexPath.row];
    PBPanoramaViewController *panoramaVC = [[PBPanoramaViewController alloc] init];
    panoramaVC.projectModel = self.projectModel;
    panoramaVC.panoramaModel = panoramaModel;
    [self.navigationController pushViewController:panoramaVC animated:YES];
}
 
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    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 delPanoramaGroupWith:indexPath];
        }];
        [alertVC addAction:cancelAction];
        [alertVC addAction:determineAction];
        [self presentViewController:alertVC animated:YES completion:nil];
    }];
 
    return @[deleteAction];
}
                                         
- (void)delPanoramaGroupWith:(NSIndexPath *)indexPath {
    [YJProgressHUD showProgress:@"" inView:self.view];
    PBPanoramaModel *panoramaModel = self.panoramaArrM[indexPath.row];
    [[PBNetworkTools sharedTools] RemoveItemWithPbGuid:panoramaModel.PbGuid 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.panoramaArrM removeObjectAtIndex:indexPath.row];
            [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [self.tableView reloadData];
        }else {
            [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
        }
    }];
}
- (NSMutableArray *)panoramaArrM {
    if (_panoramaArrM == nil) {
        _panoramaArrM = [[NSMutableArray alloc] init];
    }
    return _panoramaArrM;
}
- (void)setProjectModel:(PBProjectModel *)projectModel {
    _projectModel = projectModel;
}
- (NSMutableArray *)dropdownMenuArrM {
    if (_dropdownMenuArrM == nil) {
        _dropdownMenuArrM = [[NSMutableArray alloc] init];
    }
    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