// // CoachDetail.m // LNManager // // Created by EchoShacolee on 2017/4/10. // Copyright © 2017年 lee. All rights reserved. // #import "CoachDetail.h" #import "LockCell.h" #import "UploadCoachContractVC.h" #import "TileViewController.h" @interface CoachDetail () { BOOL _isLock;//锁定状态 UIButton * _locakBtn;//锁定/解锁 NSArray * _dataArr; HolderView *_holderV; NSMutableArray *_dataImgs; HolderView *_holderV2; BOOL _isPermission;//上传合同权限 } @end @implementation CoachDetail - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"教练详情"; _dataArr = [[NSArray alloc]init]; _dataImgs = [[NSMutableArray alloc]init]; [Tools permissionValidationWithID:@"1187" view:self.view result:^(BOOL isCan, NSString *failureStr) { _isPermission = isCan; if (isCan) { [self setSegmentControllWithTitles:@[@"基本信息",@"锁定历史记录",@"合同"] isBttomBar:YES]; [self createBottomBarWithtoolTitle:@"上传教练合同"]; }else{ [self setSegmentControllWithTitles:@[@"基本信息",@"锁定历史记录",@"合同"] isBttomBar:NO]; } [self getRequsetData]; [self getLockRecords]; UITableView * tabV = _tableViews[1]; _holderV = [[HolderView alloc] initWithFrame:tabV.frame]; [_holderV freshBlock:^{ [self getLockRecords]; }]; [_mainScroolView addSubview:_holderV]; UITableView *tableV = _tableViews[2]; _holderV2 = [[HolderView alloc]initWithFrame:tableV.frame]; _holderV2.y -= JOb_DETAIL_BOTTOMBAR_HEIGHT; [_holderV2 freshBlock:^{ [self getRequsetData]; }]; [_mainScroolView addSubview:_holderV2]; }]; } -(void)setData{ _keysArr = @[ // @[@"培训机构编号",@"TCI_INSCODE"],培训机构编号 @[@"姓名",@"TCI_NAME"], @[@"性别",@"TCI_SEX"], @[@"证件号",@"TCI_IDCARD"], @[@"手机号码",@"TCI_MOBILE"], @[@"联系地址",@"TCI_ADDRESS"], @[@"供职状态",@"TCI_EMPLOYSTATUS"], @[@"驾驶证号",@"TCI_DRILICENCE"], @[@"驾驶证初领日期",@"TCI_FSTDRILICDATE"], @[@"职业资格证号",@"TCI_OCCUPATIONNO"], @[@"职业资格等级",@"TCI_OCCUPATIONLEVEL"], @[@"准驾车型",@"TCI_DRIPERMITTED"], @[@"准教车型",@"TCI_TEACHPERMITTED"], @[@"入职日期",@"TCI_HIREDATE"], @[@"离职日期",@"TCI_LEAVEDATE"], @[@"全国统一编号",@"TCI_COACHNUM"], @[@"备案时间",@"TCI_RECORD_DATE"]]; [super setData]; } -(void)getRequsetData{ [self getDataWithDic:self.requesetDic method:@"coachs" block:^(NSDictionary *successDic) { self.dataSource = [NSMutableDictionary dictionaryWithDictionary:successDic[@"body"][0]]; self.headImgStr = self.dataSource[@"TCI_PHOTO_PATH"]; [_tableViews[0] reloadData]; [_dataImgs removeAllObjects]; _dataImgs = [NSMutableArray arrayWithArray:[self.dataSource[@"TCI_PROTOCOL_PATH"] componentsSeparatedByString:@","]]; if (_dataImgs.count > 0) { _holderV2.hidden = YES; } [_tableViews[2] reloadData]; _isLock = [[NSString stringWithFormat:@"%@",self.dataSource[@"TCI_LOCK_STATUS"]] isEqualToString:@"1"]; [_locakBtn setTitle:_isLock ? @"解锁" : @"锁定" forState:UIControlStateNormal]; }]; } -(void)getLockRecords{ //判断网络是否连接 if (![NetManager connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableDictionary * mDic = [[NSMutableDictionary alloc]init]; [mDic setObject:self.coachNum forKey:@"qgcode"]; [mDic setObject:@"2" 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(goToUploadCoachContractVC) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; } -(void)goToUploadCoachContractVC { // NSLog(@"coachNum--->%@-----dataSource------>%@",self.coachNum,self.dataSource); UploadCoachContractVC *uploadVC = [[UploadCoachContractVC alloc] init]; uploadVC.coachID = [NSString stringWithFormat:@"%@",self.dataSource[@"TCI_ID"]]; uploadVC.imgPaths = self.dataSource[@"TCI_PROTOCOL_PATH"]; uploadVC.block = ^{ [self getRequsetData]; self.currentIndex = 2; }; [self navPushHideTabbarToVC:uploadVC]; } -(void)lockCoachWithReason:(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[@"TCI_COACHNUM"] forKey:@"coachnum"]; [self getDataWithDic:mdic method:@"lockCoach" 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) { CGFloat height = _isPermission ? JOb_DETAIL_BOTTOMBAR_HEIGHT : 0; return kSize.height-kNavOffSet-height-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:@"LockCellId"]; 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"]; } if (cell.contentView.subviews.count != 0) { [[cell.contentView.subviews lastObject] removeFromSuperview]; } TileViewController *vc = [[TileViewController alloc]initWithImageNames:_dataImgs]; CGFloat height = _isPermission ? JOb_DETAIL_BOTTOMBAR_HEIGHT : 0; vc.view.height -= 64+JOb_DETAIL_SEGBAR_HEIGHT+height; [self addChildViewController:vc]; [cell.contentView addSubview:vc.view]; return cell; } return [super tableView:tableView cellForRowAtIndexPath:indexPath]; } #pragma mark - 上传头像 -(void)uploadHeadImg:(UIImage*)image { NSData *data = UIImagePNGRepresentation([image scaledToWid:100]); NSString *imgString = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]; NSMutableDictionary *dic = [NSMutableDictionary dictionary]; [dic setObject:imgString forKey:@"content"]; [dic setObject:self.dataSource[@"TCI_ID"] forKey:@"coachId"];//这个值新增不要,此处修改要 NSString *method = @"uploadCoachPhoto"; [MBProgressHUD showLoadToView:self.view]; [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root) { [MBProgressHUD hideHUDForView:self.view]; if (!root) { ShowMsg(@"上传头像失败!"); return; } if ([root[@"code"] isEqualToString:@"1"]) { ShowErrorMsg(root[@"msg"]); return; } //上传照片成功 self.headImgStr = root[@"body"]; ShowMsg(root[@"msg"]); [_tableViews[0] reloadData]; }]; } - (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