// // CarList.m // LN_School // // Created by EchoShacolee on 2017/4/17. // Copyright © 2017年 Danson. All rights reserved. // #import "CarList.h" #import "CarDetail.h" @interface CarList () { UITableView * _tableView; NSArray *_dataSurce; NSMutableDictionary * _requestDic; HolderView * holderV; } @end @implementation CarList - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"车辆列表"; self.navigationController.navigationBar.translucent = NO; self.view.backgroundColor = KBackGroundColor; [self goBackByNavigation]; _dataSurce = [NSArray new]; [self myInit]; [self getData]; } -(void)myInit{ _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height-kNavOffSet)]; _tableView.dataSource = self; _tableView.delegate = self; _tableView.tableFooterView = [UIView new]; [self.view addSubview:_tableView]; holderV = [[HolderView alloc]initWithFrame:_tableView.frame]; [holderV freshBlock:^{ [self getData]; }]; [self.view addSubview:holderV]; } -(void)getData{ //判断网络是否连接 if (![NetManager connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init]; [mDic setValue:defUser.userDict[@"dqbh"] forKey:@"dqbh"]; [mDic setValue:defUser.userDict[@"qxbh"] forKey:@"qxbh"]; [mDic setValue:defUser.userDict[@"school"] forKey:@"schoolId"]; [mDic setValue:@"" forKey:@"licnum"]; [mDic setValue:@"" forKey:@"isPage"]; [mDic setValue:@"" forKey:@"pageSize"]; [mDic setValue:@"" forKey:@"currentPage"]; _requestDic = mDic; [NetManager requestAnythingWithURL:@"cars" dictionary:mDic dataArray:nil completion:^(NSDictionary *root) { holderV.hidden = NO; if (!root) { ShowMsg(@"数据请求失败,请重试"); return; } if ([root[@"code"] integerValue] == 1) { ShowMsg(root[@"msg"]); return; } _dataSurce = root[@"body"]; if (_dataSurce.count > 0) { holderV.hidden = YES; } [_tableView reloadData]; }]; } #pragma mark tableview代理方法 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _dataSurce.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"]; if (!cell) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellId"]; } NSDictionary *dic = _dataSurce[indexPath.row]; cell.textLabel.text = [NSString stringWithFormat:@"%@ %@",dic[@"TCO_LICNUM"],dic[@"TCO_COACH_NAME"]]; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [ _requestDic setValue:_dataSurce[indexPath.row][@"TCO_LICNUM"] forKey:@"licnum"]; CarDetail * vc = [[CarDetail alloc]init]; vc.carNum = _dataSurce[indexPath.row][@"TCO_CARNUM"]; vc.requesetDic = _requestDic; [self navPushHideTabbarToVC:vc]; } - (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