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