// // SchoolDetail.m // LNManager // // Created by EchoShacolee on 2017/4/9. // Copyright © 2017年 lee. All rights reserved. // #import "SchoolDetail.h" #import "LockCell.h" @interface SchoolDetail () { NSArray *_titles2;//_tableviews[1] 的相关key值 BOOL _isLock;//锁定状态 UIButton * _locakBtn;//锁定/解锁 NSArray * _dataArr;//锁定记录 HolderView * _holderV; } @end @implementation SchoolDetail - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"驾校详情"; if (self.byWillDo) { [self createBottomBarWithtoolTitles:@[@"审核"]]; [self setSegmentControllWithTitles:@[@"基本信息",@"场地信息"]]; }else{ [self createBottomBarWithtoolTitles:@[@"设置培训能力",@"锁定/解锁"]]; [self setSegmentControllWithTitles:@[@"基本信息",@"场地信息",@"锁定历史记录"]]; [self getLockLogs]; [self getRequsetData]; UITableView * tabV = [_tableViews lastObject]; _holderV = [[HolderView alloc] initWithFrame:tabV.frame]; [_holderV freshBlock:^{ [self getLockLogs]; }]; [_mainScroolView addSubview:_holderV]; } } -(void)setData{ _keysArr = @[@[@"地市名称",@"TSI_DQMC"], @[@"区县名称",@"TSI_QXMC"], @[@"机构名称",@"TSI_NAME"], @[@"机构简称",@"TSI_SHORTNAME"], @[@"培训机构地址",@"TSI_ADDRESS"], @[@"经营范围",@"TSI_BUSISCOPE"], @[@"经营状态",@"TSI_BUSISTATUS"], @[@"经营许可证编号",@"TSI_LICNUM"], @[@"经营许可日期",@"TSI_LICETIME"], @[@"营业执照注册号",@"TSI_BUSINESS"], @[@"统一社会信用代码",@"TSI_CREDITCODE"], @[@"法人代表",@"TSI_LEGAL"], @[@"联系人",@"TSI_CONTACT"], @[@"联系电话",@"TSI_PHONE"], @[@"分类等级",@"TSI_LEVEL"], @[@"全国编号",@"TSI_INSCODE"], @[@"邮政编码",@"TSI_POSTCODE"], @[@"备案时间",@"TSI_RECORD_DATE"], @[@"锁定状态",@"TSI_LOCK_STATUS"], @[@"锁定/解锁时间",@"TSI_LOCK_DATE"]]; _titles2 = @[@[@"教练员总数",@"TSI_COACHNUMBER"], @[@"考核员总数",@"TSI_GRASUPVNUM"], @[@"安全员总数",@"TSI_SAFMNGNUM"], @[@"教练车总数",@"TSI_TRACARNUM"], @[@"教室总面积(m2)",@"TSI_CLASSROOM"], @[@"理论教室面积(单位:m2)",@"TSI_THCLASSROOM"], @[@"教练场总面积(单位:m2)",@"TSI_PRATICEFIELD"]]; [super setData]; } -(void)getRequsetData{ [self getDataWithDic:self.requesetDic method:@"schools" block:^(NSDictionary *successDic) { self.dataSource = [NSMutableDictionary dictionaryWithDictionary:successDic[@"body"][0]]; for (UITableView * tableView in _tableViews) { [tableView reloadData]; } _isLock = [[NSString stringWithFormat:@"%@",self.dataSource[@"TSI_LOCK_STATUS"]] isEqualToString:@"1"]; [_locakBtn setTitle:_isLock ? @"解锁" : @"锁定" forState:UIControlStateNormal]; }]; } -(void)getLockLogs{ //判断网络是否连接 if (![NetworkManager connectedToNetWork]) { [self showMsgByAlertVCWithString:@"网络连接异常"]; return; } NSMutableDictionary * mdic = [[NSMutableDictionary alloc]init]; [mdic setValue:@"1" forKey:@"type"];//类型 1 培训机构 2 教练 3 教练车 4 学员 5 终端 [mdic setValue:self.requesetDic[@"inscode"] forKey:@"objnum"]; [MBProgressHUD hideHUDForView:self.view animated:NO];//强行先掉一次@lee [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 setHidden: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[2] reloadData]; }]; } #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 0) { [self lockSchoolWith:tf.text]; }else{ [self showMsgByMBWithString:@"操作失败,请输入锁定/解锁理由"]; } }]]; [self presentViewController:alertFind animated:true completion:nil]; } } -(void)setTrainability{ UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"设置培训能力" message:@"请选择设置方式" preferredStyle:UIAlertControllerStyleActionSheet]; //添加操作 [ac addAction:[UIAlertAction actionWithTitle:@"按车设置(每辆车最大带教人数)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self setCountWithType:@"1"]; }]]; [ac addAction:[UIAlertAction actionWithTitle:@"按月设置(每月最大允许招生量)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self setCountWithType:@"2"]; }]]; [ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]]; [self presentViewController:ac animated:YES completion:nil]; } - (void)setCountWithType:(NSString *)type { BOOL isCar = [type isEqualToString:@"1"]; NSString * title = isCar ? @"按车设置" : @"按月设置"; NSString * message = isCar ? @"请写入每辆车最大带教人数" : @"请写入每月最大允许招生量"; UIAlertController *ac = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert]; [ac addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { textField.placeholder = message; textField.keyboardType = UIKeyboardTypeNumberPad; }]; [ac addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSString *tfStr = [ac.textFields firstObject].text; NSMutableDictionary * mdic = [NSMutableDictionary new]; [mdic setValue:self.dataSource[@"TSI_INSCODE"] forKey:@"inscode"]; [mdic setValue:type forKey:@"type"];//类型 1 按车设置 2 按月设置 [mdic setValue:isCar ? tfStr : @"" forKey:@"limitCar"];//如果type=1 则不能为空 [mdic setValue:isCar ? @"" : tfStr forKey:@"limitMonth"];//如果type=2 则不能为空 [self getDataWithDic:mdic method:@"setSchoolTrain" block:^(NSDictionary *successdic) { if (isCar) { [self showMsgByAlertVCWithString:[NSString stringWithFormat:@"已成功设置该驾校每辆车最大带教人数为:%@个",tfStr]]; }else{ [self showMsgByAlertVCWithString:[NSString stringWithFormat:@"已成功设置该驾校每月最大允许招生量为:%@个",tfStr]]; } }]; }]]; [ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]]; [self presentViewController:ac animated:YES completion:nil]; } -(void)lockSchoolWith:(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"]; [mdic setValue:self.dataSource[@"TSI_INSCODE"] forKey:@"inscode"]; [self getDataWithDic:mdic method:@"lockSchool" block:^(NSDictionary *successdic) { //解锁成功,重新请求数据 [self getRequsetData]; [self getLockLogs]; }]; } #pragma mark 重写代理方法 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ NSInteger index = [_tableViews indexOfObject:tableView]; if (index == 2) { return _dataArr.count; } if (index == 1) { return _titles2.count; } if (self.dataSource == nil) { return 0; } return [_keysArr count]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if ([_tableViews indexOfObject:tableView] == 2) { return 85; }else if([_tableViews indexOfObject:tableView] == 1){ return 44; } return [super tableView:tableView heightForRowAtIndexPath:indexPath]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSInteger index = [_tableViews indexOfObject:tableView]; if (index == 2) { 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 (index == 1) { UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId2"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId2"]; } NSString * key = _titles2[indexPath.row][1]; cell.textLabel.text = _titles2[indexPath.row][0]; cell.detailTextLabel.numberOfLines = 0; cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[key]]; return cell; } //index == 0 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