// // CarDetail.m // LNManager // // Created by EchoShacolee on 2017/4/10. // Copyright © 2017年 lee. All rights reserved. // #import "CarDetail.h" #import "LockCell.h" #import "UploadCarCredentials.h" @interface CarDetail () { BOOL _isLock;//锁定状态 UIButton * _locakBtn;//锁定/解锁 NSArray * _dataArr; HolderView *_holderV; BOOL isPermission;//权限 } @end @implementation CarDetail - (void)viewDidLoad { [super viewDidLoad]; [Tools permissionValidationWithID:@"29" view:self.view result:^(BOOL isCan, NSString *failureStr) { isPermission = isCan; [self myInit]; }]; } -(void)myInit{ self.navigationItem.title = @"车辆详情"; _dataArr = [[NSArray alloc]init]; [self setSegmentControllWithTitles:@[@"基本信息",@"锁定历史记录",@"照片文件"] isBttomBar:NO]; // [self createBottomBarWithtoolTitles:@[@"锁定/解锁"]]; // [self createBottomBarWithtoolTitle:@"上传车辆行驶证"]; [self getRequsetData]; [self getLockRecords]; UITableView * tabV = _tableViews[1]; _holderV = [[HolderView alloc] initWithFrame:tabV.frame]; [_holderV freshBlock:^{ [self getLockRecords]; }]; [_mainScroolView addSubview:_holderV]; } -(void)setData{ _keysArr = @[ // @[@"培训机构编号",@"TCO_INSCODE"], @[@"车牌号",@"TCO_LICNUM"], @[@"车牌颜色",@"TCO_PLATECOLOR"], @[@"生产厂家",@"TCO_MANUFACTURE"], @[@"车辆品牌",@"TCO_BRAND"], @[@"培训车型",@"TCO_PERDRITYPE"], @[@"车辆型号",@"TCO_MODEL"], @[@"车架号",@"TCO_FRANUM"], @[@"发动机号",@"TCO_ENGNUM"], @[@"购买日期",@"TCO_BUYDATE"], @[@"保单号",@"BDH"], @[@"保险金额(元)",@"BXJE"], @[@"保险缴纳时间",@"BXJNSJ"], @[@"保险有效时间(年)",@"BXYXSJ"], @[@"年检时间",@"NJSH"], @[@"下次年检时间",@"XCNJSH"], @[@"创建时间",@"TCO_CREATE_DATE"], @[@"全国统一编号",@"TCO_CARNUM"], @[@"备案日期",@"TCO_RECORD_DATE"], @[@"锁定状态",@"TCO_LOCK_STATUS"], @[@"锁定/解锁时间",@"TCO_LOCK_DATE"], ]; [super setData]; } -(void)getRequsetData{ [self getDataWithDic:self.requesetDic method:@"cars" block:^(NSDictionary *successDic) { self.dataSource = [NSMutableDictionary dictionaryWithDictionary:successDic[@"body"][0]]; [_tableViews[0] reloadData]; _isLock = [[NSString stringWithFormat:@"%@",self.dataSource[@"TCO_LOCK_STATUS"]] isEqualToString:@"1"]; [_locakBtn setTitle:_isLock ? @"解锁" : @"锁定" forState:UIControlStateNormal]; [_tableViews[2] reloadData]; }]; } -(void)getLockRecords{ //判断网络是否连接 if (![NetManager connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init]; [mDic setObject:self.carNum forKey:@"qgcode"]; [mDic setObject:@"3" forKey:@"type"]; [MBProgressHUD showLoadToView:self.view]; [NetManager requestAnythingWithURL:@"getLockRecords" dictionary:mDic dataArray:nil completion:^(NSDictionary *root) { [MBProgressHUD hideHUDForView:self.view]; _holderV.hidden = NO; if (!root) { ShowMsg(@"数据请求失败,请重试"); return; } if ([root[@"code"] integerValue] == 1) { ShowMsg(root[@"msg"]); return; } _dataArr = root[@"body"]; if (_dataArr.count > 0) { _holderV.hidden = YES; } [_tableViews[1] reloadData]; _isLock = [[NSString stringWithFormat:@"%@",self.dataSource[@"TCI_LOCK_STATUS"]] isEqualToString:@"1"]; [_locakBtn setTitle:_isLock ? @"解锁" : @"锁定" forState:UIControlStateNormal]; }]; } #pragma mark 创建BottomBarButton -(void)createBottomBarWithtoolTitle:(NSString *)title{ UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; button.frame = CGRectMake(0, kSize.height-kNavOffSet-JOb_DETAIL_BOTTOMBAR_HEIGHT-SafeAreaBottomHeight, kSize.width, JOb_DETAIL_BOTTOMBAR_HEIGHT); button.backgroundColor = defGreen; [button setTitle:title textColor:[UIColor whiteColor] font:Font18 fotState:UIControlStateNormal]; [button addTarget:self action:@selector(goToUploadCarCredentials) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } -(void)goToUploadCarCredentials { // NSLog(@"carNum--->%@-----dataSource------>%@",self.carNum,self.dataSource); // UploadCarCredentials *uploadVC = [[UploadCarCredentials alloc] init]; // uploadVC.carID = [NSString stringWithFormat:@"%@",self.dataSource[@"TCO_ID"]]; // uploadVC.imgPath = self.dataSource[@"TCO_FILE_INFO"]; // [self navPushHideTabbarToVC:uploadVC]; [_seg setSelectedSegmentIndex:2]; } -(void)createBottomBarWithtoolTitles:(NSArray *)toolTitles{ float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count; float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT; for (int i=0; i 0) { [self lockCarWithReason:tf.text]; }else{ ShowMsg(@"操作失败,请输入锁定/解锁理由"); } }]]; [self presentViewController:alertFind animated:true completion:nil]; } -(void)lockCarWithReason:(NSString *)reason{ NSMutableDictionary * mdic = [NSMutableDictionary new]; [mdic setValue:defUser.userDict[@"id"] forKey:@"userId"]; [mdic setValue:reason forKey:@"reason"]; [mdic setValue:_isLock ? @"0" : @"1" forKey:@"status"];//类型 类型 1 锁定 0 解锁 [mdic setValue:self.dataSource[@"TCO_CARNUM"] forKey:@"carnum"]; [self getDataWithDic:mdic method:@"lockCar" block:^(NSDictionary *successdic) { //解锁成功,重新请求数据 [self getRequsetData]; [self getLockRecords]; }]; } #pragma mark 重写代理方法 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if ([_tableViews indexOfObject:tableView] == 1) { return _dataArr.count; } if ([_tableViews indexOfObject:tableView] == 2) { return 1; } return [super tableView:tableView numberOfRowsInSection:section]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if ([_tableViews indexOfObject:tableView] == 1) { return 44; } if ([_tableViews indexOfObject:tableView] == 2) { return kSize.height-kNavOffSet-JOb_DETAIL_SEGBAR_HEIGHT-SafeAreaBottomHeight; } return [super tableView:tableView heightForRowAtIndexPath:indexPath]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if ([_tableViews indexOfObject:tableView] == 1) { LockCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"]; if (!cell) { cell = [[[NSBundle mainBundle] loadNibNamed:@"LockCell" owner:nil options:nil]lastObject]; } [cell upDataWithDic:_dataArr[indexPath.row]]; return cell; } if ([_tableViews indexOfObject:tableView] == 2) { UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } if (cell.contentView.subviews.count != 0) { [[cell.contentView.subviews lastObject] removeFromSuperview]; } if (self.dataSource[@"TCO_ID"] == nil) { return cell; } UploadCarCredentials *uploadVC = [[UploadCarCredentials alloc] init]; uploadVC.isPermission = isPermission; uploadVC.carID = [NSString stringWithFormat:@"%@",self.dataSource[@"TCO_ID"]]; NSMutableArray *array = [NSMutableArray arrayWithCapacity:4]; NSString *path = @""; if (self.dataSource[@"TCO_PHOTO_PATH"]) { path = self.dataSource[@"TCO_PHOTO_PATH"]; } [array addObject:path]; path = @""; if (self.dataSource[@"TCO_FILE_INFO"]) { path = self.dataSource[@"TCO_FILE_INFO"]; } [array addObject:path]; path = @""; if (self.dataSource[@"TCO_FILE_INFO2"]) { path = self.dataSource[@"TCO_FILE_INFO2"]; } [array addObject:path]; path = @""; if (self.dataSource[@"TCO_FILE_INFO3"]) { path = self.dataSource[@"TCO_FILE_INFO3"]; } [array addObject:path]; uploadVC.imgPathArray = array; uploadVC.view.height -= 64 + JOb_DETAIL_SEGBAR_HEIGHT; [self addChildViewController:uploadVC]; [cell.contentView addSubview:uploadVC.view]; return cell; } return [super tableView:tableView cellForRowAtIndexPath:indexPath]; } - (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