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
//
//  PBPanoramaViewController.m
//  IphoneBIMe
//
//  Created by ZhangJF on 2022/10/19.
//  Copyright © 2022 ProBIM. All rights reserved.
//
 
#import "PBPanoramaViewController.h"
#import "PBPanoramaTableViewCell.h"
#import "PBPanoramaModel.h"
#import "PBPanoramaItemModel.h"
#import "PBAddPanoramaViewController.h"
 
static NSString *const CellID = @"CellID";
@interface PBPanoramaViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *panoramas;
@end
 
@implementation PBPanoramaViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNav];
    [self setupUI];
    [self setupRefresh];
    [self.tableView.mj_header beginRefreshing];
}
- (void)setupNav {
    self.title = self.panoramaModel.PbName;
    PBBackNavItem *backNav = [PBBackNavItem backNacItem];
    backNav.title = @" ";
    [backNav addTarget:self action:@selector(backItemAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backNavItem = [[UIBarButtonItem alloc] initWithCustomView:backNav];
    self.navigationItem.leftBarButtonItem = backNavItem;
    UIBarButtonItem *addIssueItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Issue_list_add"] style:UIBarButtonItemStylePlain target:self action:@selector(addPanorama)];
    self.navigationItem.rightBarButtonItem = addIssueItem;
}
- (void)setupRefresh {
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self loadData];
    }];
    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)addPanorama {
    PBAddPanoramaViewController *addPanoramaVC = [[PBAddPanoramaViewController alloc] init];
    addPanoramaVC.projectModel = self.projectModel;
    addPanoramaVC.panoramaModel = self.panoramaModel;
    addPanoramaVC.SaveSuccessBlock = ^{
        [self.tableView.mj_header beginRefreshing];
    };
    [self.navigationController pushViewController:addPanoramaVC animated:YES];
}
- (void)backItemAction {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)loadData {
    [[PBNetworkTools sharedTools] GetPanoramaSceneListWithPb_guid:self.panoramaModel.PbGuid AndCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
        [self.tableView.mj_header endRefreshing];
        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){
            NSMutableArray *arrM = [[NSMutableArray alloc] init];
            for (NSDictionary *obj in networkModel.Data) {
                PBPanoramaItemModel *itemModel = [PBPanoramaItemModel yy_modelWithDictionary:obj];
                itemModel.PbUrl = self.panoramaModel.PbUrl;
                itemModel.LabelName = self.panoramaModel.LabelName;
                itemModel.pbName = self.panoramaModel.PbName;
                [arrM addObject:itemModel];
            }
            self.panoramas = arrM;
            [self.tableView reloadData];
        }else {
            [YJProgressHUD showFailed:networkModel.Msg inview:self.view];
        }
    }];
}
- (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.left.right.top.bottom.equalTo(self.view);
    }];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.panoramas.count;
}
 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PBPanoramaTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath];
    cell.panoramaItemModel = self.panoramas[indexPath.row];
    return cell;
}
#pragma mark - UITableViewDelegate
- (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 delPanoramaWith:indexPath];
        }];
        [alertVC addAction:cancelAction];
        [alertVC addAction:determineAction];
        [self presentViewController:alertVC animated:YES completion:nil];
    }];
 
    return @[deleteAction];
}
                                         
- (void)delPanoramaWith:(NSIndexPath *)indexPath {
    [YJProgressHUD showProgress:@"" inView:self.view];
    PBPanoramaItemModel *panoramaItemModel = self.panoramas[indexPath.row];
    [[PBNetworkTools sharedTools] RemoveSceneWithPbGuid:panoramaItemModel.PbGuid andSceneName:[NSString stringWithFormat:@"scene_%@",panoramaItemModel.PsScenename] 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.panoramas removeObjectAtIndex:indexPath.row];
            [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [self.tableView reloadData];
        }else {
            [YJProgressHUD showMessage:networkModel.Msg inView:self.view];
        }
    }];
}
 
 
 
- (void)setPanoramaModel:(PBPanoramaModel *)panoramaModel {
    _panoramaModel = panoramaModel;
}
/*
#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