CarList.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // CarList.m
  3. // LN_School
  4. //
  5. // Created by EchoShacolee on 2017/4/17.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "CarList.h"
  9. #import "CarDetail.h"
  10. @interface CarList ()<UITableViewDelegate,UITableViewDataSource>
  11. {
  12. UITableView * _tableView;
  13. NSArray *_dataSurce;
  14. NSMutableDictionary * _requestDic;
  15. HolderView * holderV;
  16. }
  17. @end
  18. @implementation CarList
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.navigationItem.title = @"车辆列表";
  22. self.navigationController.navigationBar.translucent = NO;
  23. self.view.backgroundColor = KBackGroundColor;
  24. [self goBackByNavigation];
  25. _dataSurce = [NSArray new];
  26. [self myInit];
  27. [self getData];
  28. }
  29. -(void)myInit{
  30. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height-kNavOffSet)];
  31. _tableView.dataSource = self;
  32. _tableView.delegate = self;
  33. _tableView.tableFooterView = [UIView new];
  34. [self.view addSubview:_tableView];
  35. holderV = [[HolderView alloc]initWithFrame:_tableView.frame];
  36. [holderV freshBlock:^{
  37. [self getData];
  38. }];
  39. [self.view addSubview:holderV];
  40. }
  41. -(void)getData{
  42. //判断网络是否连接
  43. if (![NetManager connectedToNetWork]) {
  44. showMsgUnconnect();
  45. return;
  46. }
  47. NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init];
  48. [mDic setValue:defUser.userDict[@"dqbh"] forKey:@"dqbh"];
  49. [mDic setValue:defUser.userDict[@"qxbh"] forKey:@"qxbh"];
  50. [mDic setValue:defUser.userDict[@"school"] forKey:@"schoolId"];
  51. [mDic setValue:@"" forKey:@"licnum"];
  52. [mDic setValue:@"" forKey:@"isPage"];
  53. [mDic setValue:@"" forKey:@"pageSize"];
  54. [mDic setValue:@"" forKey:@"currentPage"];
  55. _requestDic = mDic;
  56. [NetManager requestAnythingWithURL:@"cars" dictionary:mDic dataArray:nil completion:^(NSDictionary *root) {
  57. holderV.hidden = NO;
  58. if (!root) {
  59. ShowMsg(@"数据请求失败,请重试");
  60. return;
  61. }
  62. if ([root[@"code"] integerValue] == 1) {
  63. ShowMsg(root[@"msg"]);
  64. return;
  65. }
  66. _dataSurce = root[@"body"];
  67. if (_dataSurce.count > 0) {
  68. holderV.hidden = YES;
  69. }
  70. [_tableView reloadData];
  71. }];
  72. }
  73. #pragma mark tableview代理方法
  74. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  75. return _dataSurce.count;
  76. }
  77. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  78. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  79. if (!cell) {
  80. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellId"];
  81. }
  82. NSDictionary *dic = _dataSurce[indexPath.row];
  83. cell.textLabel.text = [NSString stringWithFormat:@"%@ %@",dic[@"TCO_LICNUM"],dic[@"TCO_COACH_NAME"]];
  84. return cell;
  85. }
  86. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  87. [ _requestDic setValue:_dataSurce[indexPath.row][@"TCO_LICNUM"] forKey:@"licnum"];
  88. CarDetail * vc = [[CarDetail alloc]init];
  89. vc.carNum = _dataSurce[indexPath.row][@"TCO_CARNUM"];
  90. vc.requesetDic = _requestDic;
  91. [self navPushHideTabbarToVC:vc];
  92. }
  93. - (void)didReceiveMemoryWarning {
  94. [super didReceiveMemoryWarning];
  95. // Dispose of any resources that can be recreated.
  96. }
  97. /*
  98. #pragma mark - Navigation
  99. // In a storyboard-based application, you will often want to do a little preparation before navigation
  100. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  101. // Get the new view controller using [segue destinationViewController].
  102. // Pass the selected object to the new view controller.
  103. }
  104. */
  105. @end