// // RepairViewController.m // LN_School // // Created by EchoShacolee on 2017/6/15. // Copyright © 2017年 Danson. All rights reserved. // #import "RepairViewController.h" #import "STSegView.h" #import "Rep_DetailCell.h" #import "RepDetailVC.h" #import "RepairApplyVC.h" @interface RepairViewController () { STSegView *seg; UIScrollView *scroll; UITableView *mainTableView; HolderView *holder; NSInteger currentPage; NSString *orderState; NSMutableArray *dataArray; } @end @implementation RepairViewController - (void)viewDidLoad { [super viewDidLoad]; [self myInit]; [self getRepairs]; } -(void)myInit { [self.view setBackgroundColor:[UIColor whiteColor]]; [self setTitle:@"设备报修"]; [self goBackByNavigation]; currentPage = 1; orderState = @"0"; dataArray = [NSMutableArray array]; CGFloat x,y,w,h; x = y = 0; w = kSize.width; h = 50; seg = [[STSegView alloc] initWithFrame:CGRectMake(x, y, w, h)]; [seg setTitles:@[@"待处理",@"已派单",@"已完成"]]; seg.font = 20; seg.selectedIndex = 0; [self.view addSubview:seg]; [seg click:^(NSString* sInd) { currentPage = 1; orderState = sInd; [self getRepairs]; }]; y += h; h = kSize.height - y - kNavOffSet; mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(x, y, w, h) style:UITableViewStyleGrouped]; mainTableView.delegate = self; mainTableView.dataSource = self; mainTableView.estimatedRowHeight = 85; mainTableView.estimatedSectionHeaderHeight = 0; mainTableView.estimatedSectionFooterHeight = 0; [self.view addSubview:mainTableView]; holder = [[HolderView alloc] initWithFrame:mainTableView.frame]; [holder freshBlock:^{ currentPage = 1; [self getRepairs]; }]; [self.view addSubview:holder]; //报修 UIButton *bxBtn = [UIButton buttonWithType:UIButtonTypeCustom]; bxBtn.frame = CGRectMake(kSize.width - 80, kSize.height - 80 -kNavOffSet-SafeAreaBottomHeight, 60, 60); bxBtn.backgroundColor = defGreen; [bxBtn setTitle:@"申请" textColor:[UIColor whiteColor] font:25 fotState:UIControlStateNormal]; bxBtn.clipsToBounds = YES; bxBtn.layer.cornerRadius = bxBtn.width/2; [bxBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:bxBtn]; } -(void)btnClick{ RepairApplyVC * vc = [[RepairApplyVC alloc]init]; vc.type = @"1"; vc.blcok = ^{ currentPage = 1; [self getRepairs]; }; [self navPushHideTabbarToVC:vc]; } #pragma mark tableView -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return dataArray.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { Rep_DetailCell *cell = [Rep_DetailCell cellForTableView:tableView]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; [cell setDic:dataArray[indexPath.section]]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ RepDetailVC * vc = [[RepDetailVC alloc]init]; vc.dic = dataArray[indexPath.section]; vc.blcok = ^{ currentPage = 1; [self getRepairs]; }; [self navPushHideTabbarToVC:vc]; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 15; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return .1f; } -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ CGFloat offset_y = scrollView.contentOffset.y; CGFloat x = scrollView.contentSize.height < scrollView.frame.size.height ? scrollView.contentSize.height:scrollView.frame.size.height; if (offset_y<-70) { currentPage = 1; [self getRepairs]; }else if(offset_y+x>scrollView.contentSize.height+70){ [self getRepairs]; } } #pragma mark 数据请求 -(void)getRepairs { if (![NetManager connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableDictionary *mdic = [[NSMutableDictionary alloc]init]; [mdic setValue:@"" forKey:@"coachOutId"]; [mdic setValue:orderState forKey:@"status"]; [mdic setValue:@"1" forKey:@"isPage"]; [mdic setValue:@"10" forKey:@"pageSize"]; [mdic setValue:[NSString stringWithFormat:@"%d",(int)currentPage] forKey:@"currentPage"]; NSString *method = @"getRepairs"; [MBProgressHUD showLoadToView:self.view]; [NetManager requestAnythingWithURL:method dictionary:mdic dataArray:nil completion:^(NSDictionary *root) { [MBProgressHUD hideHUDForView:self.view]; if (currentPage == 1) { holder.hidden = NO; [dataArray removeAllObjects]; } if (!root) { ShowErrorMsg(@"请求失败!"); return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowErrorMsg(root[@"msg"]); return; } NSArray *array = root[@"body"]; if ([array count] < 1) { ShowMsg(@"已加载全部"); [mainTableView reloadData]; return; } [dataArray addObjectsFromArray:array]; currentPage += 1; holder.hidden = YES; [mainTableView reloadData]; }]; } - (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