123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- //
- // Job_Detail_base.m
- // LNManager
- //
- // Created by EchoShacolee on 2017/4/9.
- // Copyright © 2017年 lee. All rights reserved.
- //
- #import "Job_Detail_base.h"
- #import <TZImageManager.h>
- #import <TZImagePickerController.h>
- @interface Job_Detail_base ()<UIScrollViewDelegate>
- @end
- @implementation Job_Detail_base
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- _tableViews = [[NSMutableArray alloc]init];
-
- _heightsArr = [[NSMutableArray alloc]init];
- _statusArr = [[NSMutableArray alloc]init];
- _keysArr = [[NSMutableArray alloc]init];
- [self setData];
- }
- -(void)setData{
-
- for (int i=0; i<_keysArr.count; i++) {
- [_statusArr addObject:@0];
- [_heightsArr addObject:@normalCellH];
- }
- }
- #pragma mark SegmentControll
- -(void)setCurrentIndex:(NSInteger)currentIndex{
- if (_currentIndex != currentIndex) {
- //_currentIndex = currentIndex;
- _seg.selectedSegmentIndex = currentIndex;
- [self changeTableview:_seg];
- }
- }
- -(void)setSegmentControllWithTitles:(NSArray *)dataArr isBttomBar:(BOOL)isBttombar{
- //
- CGRect frame;
- if (dataArr.count == 1) {
- frame = CGRectMake(0, 0, kSize.width, 0);
- }else{
- frame = CGRectMake(10, 0, kSize.width - 20, JOb_DETAIL_SEGBAR_HEIGHT);
- }
- _seg = [[UISegmentedControl alloc]initWithItems:dataArr];
- _seg.frame = frame;
- _seg.selectedSegmentIndex = 0;
- self.currentIndex = 0;
- _seg.tintColor = defGreen;
- // _seg.apportionsSegmentWidthsByContent = YES;
- [_seg addTarget:self action:@selector(changeTableview:) forControlEvents:UIControlEventValueChanged];
- [self.view addSubview:_seg];
-
- //1+n
- //
- CGFloat bottomBarH = 0;
-
- //判断是否需要底部处理button
- if (isBttombar) {
- bottomBarH = JOb_DETAIL_BOTTOMBAR_HEIGHT+SafeAreaBottomHeight;
- }
- _mainScroolView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_seg.frame), kSize.width, kSize.height-CGRectGetMaxY(_seg.frame)-bottomBarH-kNavOffSet)];//导航栏不透明
- _mainScroolView.pagingEnabled = YES;
- _mainScroolView.bounces = NO;
- _mainScroolView.showsVerticalScrollIndicator = NO;
- _mainScroolView.showsHorizontalScrollIndicator = NO;
- _mainScroolView.delegate = self;
-
- [self.view addSubview:_mainScroolView];
-
- for (int i=0; i<dataArr.count; i++) {
- UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectMake(i*kSize.width, 0, kSize.width, _mainScroolView.frame.size.height) style:UITableViewStylePlain];
- tableview.tableFooterView = [UIView new];
- tableview.delegate = self;
- tableview.dataSource = self;
- [_tableViews addObject:tableview];
- [_mainScroolView addSubview:tableview];
- }
-
- _mainScroolView.contentSize = CGSizeMake(kSize.width*_tableViews.count, 0);
-
- }
- - (void)changeTableview:(UISegmentedControl *)sender{
-
- [_mainScroolView setContentOffset:CGPointMake(kSize.width*sender.selectedSegmentIndex, 0) animated:NO];//yes的话会导致相互影响卡顿
- _currentIndex = _seg.selectedSegmentIndex;//这个不会触发set方法,触发set方法需要.语法
- }
- #pragma mark scroollViewDetagate
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
- {
-
- if ([scrollView isKindOfClass:[UITableView class]]) {
- return;
- }
-
- _seg.selectedSegmentIndex = scrollView.contentOffset.x/kSize.width;
- _currentIndex = _seg.selectedSegmentIndex;
- }
- //头视图不停留
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- if (![scrollView isEqual:_tableViews[0]]) {
- return;
- }
- CGFloat sectionHeaderHeight = 120;
- if(scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
- scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
- } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
- scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
- }
- }
- #pragma mark tableviewDe
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
-
- return _keysArr.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- if ([_statusArr[indexPath.row] isEqualToNumber:@1]) {
- //缓存高度
- NSNumber *cellHeight = [_heightsArr objectAtIndex:indexPath.row];
-
- if ([cellHeight isEqualToNumber:@normalCellH]) {
-
- CGFloat fontSize = 17;
- NSString *detail = [NSString stringWithFormat:@"%@",self.dataSource[_keysArr[indexPath.row][1]]];
- CGFloat wid = kSize.width - [_keysArr[indexPath.row][0] widthForFont:fontSize] - 46;//46是cell边距20+20+间距6 plus
-
- CGFloat h1 = [self getHeightWithWidth:wid Font:fontSize String:detail]+1+16;//+1 cell与content 16是上下间距
- CGFloat H = h1>normalCellH?h1:normalCellH;
-
- [_heightsArr replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithFloat:H]];
- return H;
-
-
- }else{
-
- return [cellHeight floatValue];
- }
- }
- return normalCellH;
-
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- //这里返回的cell是第一个tableview的。下面对于key的判定isequal和contains的区别在于 一个是独有,一个是共有
-
- UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
-
- if (!cell) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"];
- }
-
-
- NSString * key = _keysArr[indexPath.row][1];
- cell.textLabel.text = _keysArr[indexPath.row][0];
- if ([key containsString:@"_SEX"]) {
- NSString *sex = [NSString stringWithFormat:@"%@",self.dataSource[key]];
-
- cell.detailTextLabel.text = [sex isEqualToString:@"1"] ? @"男" : @"女" ;
- }else if ([key containsString:@"_EMPLOYSTATUS"]){
- NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
-
- cell.detailTextLabel.text = [status isEqualToString:@"0"] ? @"在职" : @"离职" ;
- }else if ([key containsString:@"_RECORD_STATUS"]){
- NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
-
- cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"已备案" : @"未备案" ;
- }else if ([key containsString:@"_LOCK_STATUS"]){
- NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
-
- cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"已锁定" : @"解除锁定" ;
- }else if ([key containsString:@"_OCCUPATIONLEVEL"]){
-
- NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
-
- 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;
-
- default:
- break;
- }
-
- }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:@"AUDITSTUATS"]){
- NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
-
- cell.detailTextLabel.text = @"审核中";
- switch ([status integerValue]) {
- case 1:
- cell.detailTextLabel.text = @"审核通过";
- break;
- case 2:
- cell.detailTextLabel.text = @"审核拒绝";
- break;
-
- default:
- break;
- }
-
- cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"审核通过" : @"未备案" ;
- }else{
- cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[_keysArr[indexPath.row][1]]];
- }
-
- if ([_statusArr[indexPath.row] isEqualToNumber:@1]) {
- cell.detailTextLabel.numberOfLines = 0;
- cell.detailTextLabel.textAlignment = NSTextAlignmentLeft;
-
- }else{
- cell.detailTextLabel.numberOfLines = 1;
- cell.detailTextLabel.textAlignment = NSTextAlignmentRight;
- }
-
- return cell;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
-
- if ([_tableViews indexOfObject:tableView] == 0) {
-
- if ([_statusArr[indexPath.row] isEqualToNumber:@1]) {
- [_statusArr replaceObjectAtIndex:indexPath.row withObject:@0];
- }else{
- [_statusArr replaceObjectAtIndex:indexPath.row withObject:@1];
- }
-
- [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
- }
-
-
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
-
- if ([tableView isEqual:_tableViews[0]] && self.headImgStr) {
- return 120;
- }
- return 0;
- }
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
-
- UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, 120)];
- UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100*5/6, 100)];//标准一寸照295/413
- imageV.contentMode = UIViewContentModeScaleAspectFit;
- imageV.center = view.center;
-
- NSString *imgPath = @"";
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored"-Wcompare-distinct-pointer-types"
- //写在这个中间的代码,都不会被编译器提示-Wcompare-distinct-pointer-types类型的警告
- if (self.headImgStr != [NSNull null]) {
- imgPath = self.headImgStr;
- }
- #pragma clang diagnostic po
-
- [imageV sd_setImageWithURL:[NSURL URLWithString:imgPath] placeholderImage:[UIImage imageNamed:@"default_headImg"]];
- imageV.layer.masksToBounds = YES;
- imageV.layer.cornerRadius = 5;
- [view addSubview:imageV];
-
- //
- imageV.userInteractionEnabled = YES;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectHeadImg)];
- [imageV addGestureRecognizer:tap];
-
- return view;
- }
- -(void)selectHeadImg{
-
- TZImagePickerController *imagePickerVC = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:nil];
- imagePickerVC.allowCrop = YES;
- CGFloat width = kSize.width*2/3;
- imagePickerVC.cropRect = CGRectMake(kSize.width/6, kSize.height/2-width*3/5, width, width*6/5);
-
- // 通过block(或者代理),来得到用户选择的照片.
- [imagePickerVC setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets,BOOL isSelectOriginalPhoto) {
-
- [self uploadHeadImg:photos[0]];
- }];
- [self presentViewController:imagePickerVC animated:YES completion:nil];
- }
- -(void)uploadHeadImg:(UIImage*)image{
- //交给具体的子类去实现
- }
- #pragma mark - 返回合适lable的高度
- -(CGFloat)getHeightWithWidth:(CGFloat)wid Font:(CGFloat)fontSize String:(NSString *)str
- {
- if (str.length == 0) {
- return 0;
- }
-
- UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
- lab.text = str;
- lab.numberOfLines = 0;
- lab.font = [UIFont systemFontOfSize:fontSize];
-
- return [lab sizeThatFits:CGSizeMake(wid, MAXFLOAT)].height;
- }
- - (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
|