CarList.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. #import "NewCar.h"
  11. @interface CarList ()<UITableViewDelegate,UITableViewDataSource>
  12. {
  13. UITableView * _tableView;
  14. NSArray *_dataSurce;
  15. NSMutableDictionary * _requestDic;
  16. HolderView * holderV;
  17. }
  18. @end
  19. @implementation CarList
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. self.navigationItem.title = @"车辆列表";
  23. self.navigationController.navigationBar.translucent = NO;
  24. self.view.backgroundColor = KBackGroundColor;
  25. [self goBackByNavigation];
  26. _dataSurce = [NSArray new];
  27. [self myInit];
  28. [Tools permissionValidationWithID:@"28" view:self.view result:^(BOOL isCan, NSString *failureStr) {
  29. if (isCan) {
  30. UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
  31. btn.frame = CGRectMake(0, 0, 43, 44);
  32. btn.titleLabel.font = [UIFont systemFontOfSize:17];
  33. [btn setTitle:@"新增" forState:UIControlStateNormal];
  34. [btn setTitleColor:defGreen forState:UIControlStateNormal];
  35. [btn addTarget:self action:@selector(addMoreAction) forControlEvents:UIControlEventTouchUpInside];
  36. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  37. }
  38. }];
  39. }
  40. - (void)viewWillAppear:(BOOL)animated {
  41. [super viewWillAppear:animated];
  42. [self getData];
  43. }
  44. -(void)myInit{
  45. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height-kNavOffSet)];
  46. _tableView.dataSource = self;
  47. _tableView.delegate = self;
  48. _tableView.tableFooterView = [UIView new];
  49. [self.view addSubview:_tableView];
  50. holderV = [[HolderView alloc]initWithFrame:_tableView.frame];
  51. [holderV freshBlock:^{
  52. [self getData];
  53. }];
  54. [self.view addSubview:holderV];
  55. }
  56. - (void)addMoreAction {
  57. // if (!myDelegate.isSchool) {
  58. // ShowMsg(@"驾校管理员才可以新增操作");
  59. // return;
  60. // }
  61. NewCar *vc = [[NewCar alloc] init];
  62. [self.navigationController pushViewController:vc animated:YES];
  63. }
  64. -(void)getData{
  65. //判断网络是否连接
  66. if (![NetManager connectedToNetWork]) {
  67. showMsgUnconnect();
  68. return;
  69. }
  70. NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init];
  71. [mDic setValue:defUser.userDict[@"dqbh"] forKey:@"dqbh"];
  72. [mDic setValue:defUser.userDict[@"qxbh"] forKey:@"qxbh"];
  73. [mDic setValue:defUser.userDict[@"school"] forKey:@"schoolId"];
  74. [mDic setValue:@"" forKey:@"licnum"];
  75. [mDic setValue:@"" forKey:@"isPage"];
  76. [mDic setValue:@"" forKey:@"pageSize"];
  77. [mDic setValue:@"" forKey:@"currentPage"];
  78. _requestDic = mDic;
  79. [MBProgressHUD showLoadToView:self.view];
  80. [NetManager requestAnythingWithURL:@"cars" dictionary:mDic dataArray:nil completion:^(NSDictionary *root) {
  81. [MBProgressHUD hideHUDForView:self.view];
  82. holderV.hidden = NO;
  83. if (!root) {
  84. ShowMsg(@"数据请求失败,请重试");
  85. return;
  86. }
  87. if ([root[@"code"] integerValue] == 1) {
  88. ShowMsg(root[@"msg"]);
  89. return;
  90. }
  91. _dataSurce = root[@"body"];
  92. if (_dataSurce.count > 0) {
  93. holderV.hidden = YES;
  94. }
  95. [_tableView reloadData];
  96. }];
  97. }
  98. #pragma mark tableview代理方法
  99. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  100. return _dataSurce.count;
  101. }
  102. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  103. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  104. if (!cell) {
  105. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellId"];
  106. }
  107. NSDictionary *dic = _dataSurce[indexPath.row];
  108. NSString *str = dic[@"TCO_COACH_NAME"];
  109. cell.textLabel.text = [NSString stringWithFormat:@"%@ %@",dic[@"TCO_LICNUM"],str];
  110. return cell;
  111. }
  112. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  113. [ _requestDic setValue:_dataSurce[indexPath.row][@"TCO_LICNUM"] forKey:@"licnum"];
  114. CarDetail * vc = [[CarDetail alloc]init];
  115. vc.carNum = _dataSurce[indexPath.row][@"TCO_CARNUM"];
  116. vc.requesetDic = _requestDic;
  117. vc.dataSource = _dataSurce[indexPath.row];
  118. [self navPushHideTabbarToVC:vc];
  119. }
  120. - (void)didReceiveMemoryWarning {
  121. [super didReceiveMemoryWarning];
  122. // Dispose of any resources that can be recreated.
  123. }
  124. /*
  125. #pragma mark - Navigation
  126. // In a storyboard-based application, you will often want to do a little preparation before navigation
  127. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  128. // Get the new view controller using [segue destinationViewController].
  129. // Pass the selected object to the new view controller.
  130. }
  131. */
  132. @end