// // 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 () @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