// // 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; UITableView *mainTableView; HolderView *holder; NSInteger currentPage; NSString *orderState; NSMutableArray *dataArray; } @end @implementation RepairViewController - (void)viewDidLoad { [super viewDidLoad]; [self myInit]; [self getRepairs]; } -(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; self.navigationController.navigationBar.translucent = YES;//这里主要针对pop回来的时候 } -(void)myInit { self.view.backgroundColor = backGroundColor; currentPage = 1; orderState = @"0"; dataArray = [NSMutableArray array]; CGFloat x,y,w,h; x = 0; y = kNavOffSet; 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; mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(x, y, w, h) style:UITableViewStyleGrouped]; mainTableView.delegate = self; mainTableView.dataSource = self; mainTableView.estimatedRowHeight = 85; [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 -64, 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 = ^{ seg.selectedIndex = 0; }; [self.navigationController pushViewController:vc animated:YES]; } #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.block = ^{ currentPage = 1; [self getRepairs]; }; [self.navigationController pushViewController:vc animated:YES]; } -(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 { [LoadingView showHUD]; if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr = [[NSMutableArray alloc]init]; [arr addPro:@"coachOutId" Value:defUser.userDict[@"outId"]]; [arr addPro:@"status" Value:orderState]; [arr addPro:@"isPage" Value:@"1"]; [arr addPro:@"pageSize" Value:@"10"]; [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",(int)currentPage]]; NSString *method = @"getRepairs"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) { RemoveHUD(); if (currentPage == 1) { holder.hidden = NO; [dataArray removeAllObjects]; } if (!root) { ShowMsg(@"请求失败"); return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowMsg(root[@"body"]); return; } NSArray *array = root[@"body"]; if ([array count] < 1) { ShowMsg(@"已加载全部"); [mainTableView reloadData]; return; } static BOOL once = YES; if (once) { [dataArray addObjectsFromArray:array]; [dataArray addObjectsFromArray:array]; [dataArray addObjectsFromArray:array]; once = NO; } [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