123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- //
- // CarDetail.m
- // LNManager
- //
- // Created by EchoShacolee on 2017/4/10.
- // Copyright © 2017年 lee. All rights reserved.
- //
- #import "CarDetail.h"
- #import "LockCell.h"
- @interface CarDetail ()
- {
-
- BOOL _isLock;//锁定状态
- UIButton * _locakBtn;//锁定/解锁
- NSArray * _dataArr;//锁定记录
-
- HolderView * _holderV;
- }
- @end
- @implementation CarDetail
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.navigationItem.title = @"车辆详情";
-
- if (self.byWillDo) {
- [self createBottomBarWithtoolTitles:@[@"审核"]];
- [self setSegmentControllWithTitles:@[@"基本信息"]];
- }else{
- [self createBottomBarWithtoolTitles:@[@"锁定/解锁"]];
- [self setSegmentControllWithTitles:@[@"基本信息",@"锁定历史记录"]];
- [self getLockRecords];
- [self getRequsetData];
-
- UITableView * tabV = [_tableViews lastObject];
- _holderV = [[HolderView alloc] initWithFrame:tabV.frame];
- [_holderV freshBlock:^{
-
- [self getLockRecords];
- }];
- [_mainScroolView addSubview:_holderV];
- }
-
- }
- -(void)setData{
- _keysArr = @[@[@"培训机构编号",@"TCO_INSCODE"],
- @[@"车架号",@"TCO_FRANUM"],
- @[@"发动机号",@"TCO_ENGNUM"],
- @[@"车辆牌号",@"TCO_LICNUM"],
- @[@"车牌颜色",@"TCO_PLATECOLOR"],
- @[@"生产厂家",@"TCO_MANUFACTURE"],
- @[@"车辆品牌",@"TCO_BRAND"],
- @[@"车辆型号",@"TCO_MODEL"],
- @[@"培训车型 ",@"TCO_PERDRITYPE"],
- @[@"购买日期 ",@"TCO_BUYDATE"],
- @[@"备案状态",@"TCO_RECORD_STATUS"],
- @[@"备案日期",@"TCO_RECORD_DATE"],
- @[@"锁定状态",@"TCO_LOCK_STATUS"],
- @[@"锁定/解锁时间",@"TCO_LOCK_DATE"],
- @[@"教练车编号",@"TCO_CARNUM"]];
-
- [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];
-
- //
- if (self.lockBlock) {
- self.lockBlock(self.dataSource);
- }
- }];
- }
- -(void)getLockRecords{
-
- //判断网络是否连接
- if (![NetworkManager connectedToNetWork]) {
- [self showMsgByAlertVCWithString:@"网络连接异常"];
- return;
- }
-
- NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init];
- [mDic setObject:self.objNum forKey:@"objnum"];
- [mDic setObject:@"3" forKey:@"type"];
- [MBProgressHUD hideHUDForView:self.view animated:NO];
- [MBProgressHUD showHUDAddedTo:self.view animated:NO];
- [NetworkManager requestWithMethod:@"lockLogs" parameters:mDic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) {
-
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- _holderV.hidden = NO;
-
- if (failureStr) {
- [self showMsgByAlertVCWithString:failureStr];
- return;
- }
-
- if ([successDic[@"code"] isEqualToString:@"1"]) {
- [self showMsgByAlertVCWithString:successDic[@"msg"]];
- return;
- }
-
- _dataArr = successDic[@"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)createBottomBarWithtoolTitles:(NSArray *)toolTitles{
-
- float widthBtn = (kSize.width-1*toolTitles.count+1)/toolTitles.count;
- float HeightBth = JOb_DETAIL_BOTTOMBAR_HEIGHT;
- for (int i=0; i<toolTitles.count; i++) {
- UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
- button.frame = CGRectMake(i*(widthBtn+1), kSize.height-HeightBth-SafeAreaBottomHeight, widthBtn, HeightBth);
- if (i == 0 && self.byWillDo == NO) {
- [button setTitle:@"锁定" forState:UIControlStateNormal];
- _locakBtn = button;
- }else{
- [button setTitle:toolTitles[i] forState:UIControlStateNormal];
- }
-
- UIColor * color = COLOR_THEME;
- button.backgroundColor = color;
- [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(lockReason) forControlEvents:UIControlEventTouchUpInside];
- button.tag = 100+i;
-
- [self.view addSubview:button];
- }
- }
- -(void)lockReason{
-
- if (self.byWillDo && self.shenheBLock) {
- self.shenheBLock();
- return;
- }
-
- NSString * title = _isLock ? @"解锁":@"锁定";
- NSString *message = [NSString stringWithFormat:@"请输入%@理由:",title];
- UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
-
- [alertFind addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
- textField.placeholder = [NSString stringWithFormat:@"(必须填写,否则将无法完成%@)",title];
- }];
- [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
- [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
-
- UITextField *tf = alertFind.textFields[0];
- if (tf.text.length > 0) {
- [self lockCarWithReason:tf.text];
- }else{
- [self showMsgByMBWithString:@"操作失败,请输入锁定/解锁理由"];
- }
-
- }]];
- NSString *theID = _isLock?@"552":@"551";
-
- [Tools permissionValidationWithID:theID result:^(BOOL isCan, NSString *failureStr) {
- if (!isCan) {
- if (failureStr) {
- [self showMsgByMBWithString:failureStr];
- }
- return;
- }
-
- [self presentViewController:alertFind animated:true completion:nil];
-
- }];
-
- }
- -(void)lockCarWithReason:(NSString *)reason{
- NSMutableDictionary * mdic = [NSMutableDictionary new];
- [mdic setValue:MYAPPDELEGATE.userDic[@"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{
- NSInteger index = [_tableViews indexOfObject:tableView];
- if (index == 1) {
- return _dataArr.count;
- }
- return [_keysArr count];
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- if ([_tableViews indexOfObject:tableView] == 1) {
- return [LockCell heightForDic:_dataArr[indexPath.row]];
- }
- 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;
- }
-
- //这里不想把父类搞得太复杂(else if key==xxx),就自己实现一次
- UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
-
- if (!cell) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"];
- }
-
- if ([_statusArr[indexPath.row] isEqualToNumber:@1]) {
- cell.detailTextLabel.numberOfLines = 0;
- cell.detailTextLabel.textAlignment = NSTextAlignmentLeft;
- }else{
- cell.detailTextLabel.numberOfLines = 1;
- cell.detailTextLabel.textAlignment = NSTextAlignmentRight;
- }
-
- NSString * key = _keysArr[indexPath.row][1];
- cell.textLabel.text = _keysArr[indexPath.row][0];
- cell.detailTextLabel.numberOfLines = 0;
- if ([key isEqualToString:@"TCO_RECORD_STATUS"]){
- NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
-
- cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"已备案" : @"未备案" ;
- }else if ([key isEqualToString:@"TCO_PLATECOLOR"]){
- NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
- //车牌颜色(1:蓝色; 2:黄色; 3:黑色; 4:白色; 5:绿色; 9:其他;)
- switch ([status integerValue]) {
- case 1:
- cell.detailTextLabel.text = @"蓝色";
- break;
- case 2:
- cell.detailTextLabel.text = @"黄色";
- break;
- case 3:
- cell.detailTextLabel.text = @"黑色";
- break;
- case 4:
- cell.detailTextLabel.text = @"白色";
- break;
- case 5:
- cell.detailTextLabel.text = @"绿色";
- break;
- case 9:
- cell.detailTextLabel.text = @"其它";
- break;
- default:
- break;
- }
- }else if ([key isEqualToString:@"TCO_LOCK_STATUS"]){
- NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
-
- cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"已锁定" : @"未锁定" ;
- }else{
- cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[key]];
- }
-
- return cell;
-
- }
- - (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
|