Job_Detail_base.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. //
  2. // Job_Detail_base.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/4/9.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "Job_Detail_base.h"
  9. #import <TZImageManager.h>
  10. #import <TZImagePickerController.h>
  11. @interface Job_Detail_base ()<UIScrollViewDelegate>
  12. @end
  13. @implementation Job_Detail_base
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. _tableViews = [[NSMutableArray alloc]init];
  17. _heightsArr = [[NSMutableArray alloc]init];
  18. _statusArr = [[NSMutableArray alloc]init];
  19. _keysArr = [[NSMutableArray alloc]init];
  20. [self setData];
  21. }
  22. -(void)setData{
  23. for (int i=0; i<_keysArr.count; i++) {
  24. [_statusArr addObject:@0];
  25. [_heightsArr addObject:@normalCellH];
  26. }
  27. }
  28. #pragma mark SegmentControll
  29. -(void)setCurrentIndex:(NSInteger)currentIndex{
  30. if (_currentIndex != currentIndex) {
  31. //_currentIndex = currentIndex;
  32. _seg.selectedSegmentIndex = currentIndex;
  33. [self changeTableview:_seg];
  34. }
  35. }
  36. -(void)setSegmentControllWithTitles:(NSArray *)dataArr isBttomBar:(BOOL)isBttombar{
  37. //
  38. CGRect frame;
  39. if (dataArr.count == 1) {
  40. frame = CGRectMake(0, 0, kSize.width, 0);
  41. }else{
  42. frame = CGRectMake(10, 0, kSize.width - 20, JOb_DETAIL_SEGBAR_HEIGHT);
  43. }
  44. _seg = [[UISegmentedControl alloc]initWithItems:dataArr];
  45. _seg.frame = frame;
  46. _seg.selectedSegmentIndex = 0;
  47. self.currentIndex = 0;
  48. _seg.tintColor = defGreen;
  49. // _seg.apportionsSegmentWidthsByContent = YES;
  50. [_seg addTarget:self action:@selector(changeTableview:) forControlEvents:UIControlEventValueChanged];
  51. [self.view addSubview:_seg];
  52. //1+n
  53. //
  54. CGFloat bottomBarH = 0;
  55. //判断是否需要底部处理button
  56. if (isBttombar) {
  57. bottomBarH = JOb_DETAIL_BOTTOMBAR_HEIGHT+SafeAreaBottomHeight;
  58. }
  59. _mainScroolView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_seg.frame), kSize.width, kSize.height-CGRectGetMaxY(_seg.frame)-bottomBarH-kNavOffSet)];//导航栏不透明
  60. _mainScroolView.pagingEnabled = YES;
  61. _mainScroolView.bounces = NO;
  62. _mainScroolView.showsVerticalScrollIndicator = NO;
  63. _mainScroolView.showsHorizontalScrollIndicator = NO;
  64. _mainScroolView.delegate = self;
  65. [self.view addSubview:_mainScroolView];
  66. for (int i=0; i<dataArr.count; i++) {
  67. UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectMake(i*kSize.width, 0, kSize.width, _mainScroolView.frame.size.height) style:UITableViewStylePlain];
  68. tableview.tableFooterView = [UIView new];
  69. tableview.delegate = self;
  70. tableview.dataSource = self;
  71. [_tableViews addObject:tableview];
  72. [_mainScroolView addSubview:tableview];
  73. }
  74. _mainScroolView.contentSize = CGSizeMake(kSize.width*_tableViews.count, 0);
  75. }
  76. - (void)changeTableview:(UISegmentedControl *)sender{
  77. [_mainScroolView setContentOffset:CGPointMake(kSize.width*sender.selectedSegmentIndex, 0) animated:NO];//yes的话会导致相互影响卡顿
  78. _currentIndex = _seg.selectedSegmentIndex;//这个不会触发set方法,触发set方法需要.语法
  79. }
  80. #pragma mark scroollViewDetagate
  81. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  82. {
  83. if ([scrollView isKindOfClass:[UITableView class]]) {
  84. return;
  85. }
  86. _seg.selectedSegmentIndex = scrollView.contentOffset.x/kSize.width;
  87. _currentIndex = _seg.selectedSegmentIndex;
  88. }
  89. //头视图不停留
  90. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  91. if (![scrollView isEqual:_tableViews[0]]) {
  92. return;
  93. }
  94. CGFloat sectionHeaderHeight = 120;
  95. if(scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
  96. scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
  97. } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
  98. scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
  99. }
  100. }
  101. #pragma mark tableviewDe
  102. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  103. return _keysArr.count;
  104. }
  105. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  106. if ([_statusArr[indexPath.row] isEqualToNumber:@1]) {
  107. //缓存高度
  108. NSNumber *cellHeight = [_heightsArr objectAtIndex:indexPath.row];
  109. if ([cellHeight isEqualToNumber:@normalCellH]) {
  110. CGFloat fontSize = 17;
  111. NSString *detail = [NSString stringWithFormat:@"%@",self.dataSource[_keysArr[indexPath.row][1]]];
  112. CGFloat wid = kSize.width - [_keysArr[indexPath.row][0] widthForFont:fontSize] - 46;//46是cell边距20+20+间距6 plus
  113. CGFloat h1 = [self getHeightWithWidth:wid Font:fontSize String:detail]+1+16;//+1 cell与content 16是上下间距
  114. CGFloat H = h1>normalCellH?h1:normalCellH;
  115. [_heightsArr replaceObjectAtIndex:indexPath.row withObject:[NSNumber numberWithFloat:H]];
  116. return H;
  117. }else{
  118. return [cellHeight floatValue];
  119. }
  120. }
  121. return normalCellH;
  122. }
  123. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  124. //这里返回的cell是第一个tableview的。下面对于key的判定isequal和contains的区别在于 一个是独有,一个是共有
  125. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
  126. if (!cell) {
  127. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellId"];
  128. }
  129. NSString * key = _keysArr[indexPath.row][1];
  130. cell.textLabel.text = _keysArr[indexPath.row][0];
  131. if ([key containsString:@"_SEX"]) {
  132. NSString *sex = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  133. cell.detailTextLabel.text = [sex isEqualToString:@"1"] ? @"男" : @"女" ;
  134. }else if ([key containsString:@"_EMPLOYSTATUS"]){
  135. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  136. cell.detailTextLabel.text = [status isEqualToString:@"0"] ? @"在职" : @"离职" ;
  137. }else if ([key containsString:@"_RECORD_STATUS"]){
  138. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  139. cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"已备案" : @"未备案" ;
  140. }else if ([key containsString:@"_LOCK_STATUS"]){
  141. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  142. cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"已锁定" : @"解除锁定" ;
  143. }else if ([key containsString:@"_OCCUPATIONLEVEL"]){
  144. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  145. switch ([status integerValue]) {
  146. case 1:
  147. cell.detailTextLabel.text = @"一级";
  148. break;
  149. case 2:
  150. cell.detailTextLabel.text = @"二级";
  151. break;
  152. case 3:
  153. cell.detailTextLabel.text = @"三级";
  154. break;
  155. case 4:
  156. cell.detailTextLabel.text = @"四级";
  157. break;
  158. default:
  159. break;
  160. }
  161. }else if ([key isEqualToString:@"TCO_PLATECOLOR"]){
  162. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  163. //车牌颜色(1:蓝色; 2:黄色; 3:黑色; 4:白色; 5:绿色; 9:其他;)
  164. switch ([status integerValue]) {
  165. case 1:
  166. cell.detailTextLabel.text = @"蓝色";
  167. break;
  168. case 2:
  169. cell.detailTextLabel.text = @"黄色";
  170. break;
  171. case 3:
  172. cell.detailTextLabel.text = @"黑色";
  173. break;
  174. case 4:
  175. cell.detailTextLabel.text = @"白色";
  176. break;
  177. case 5:
  178. cell.detailTextLabel.text = @"绿色";
  179. break;
  180. case 9:
  181. cell.detailTextLabel.text = @"其它";
  182. break;
  183. default:
  184. break;
  185. }
  186. }else if ([key isEqualToString:@"AUDITSTUATS"]){
  187. NSString *status = [NSString stringWithFormat:@"%@",self.dataSource[key]];
  188. cell.detailTextLabel.text = @"审核中";
  189. switch ([status integerValue]) {
  190. case 1:
  191. cell.detailTextLabel.text = @"审核通过";
  192. break;
  193. case 2:
  194. cell.detailTextLabel.text = @"审核拒绝";
  195. break;
  196. default:
  197. break;
  198. }
  199. cell.detailTextLabel.text = [status isEqualToString:@"1"] ? @"审核通过" : @"未备案" ;
  200. }else{
  201. cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.dataSource[_keysArr[indexPath.row][1]]];
  202. }
  203. if ([_statusArr[indexPath.row] isEqualToNumber:@1]) {
  204. cell.detailTextLabel.numberOfLines = 0;
  205. cell.detailTextLabel.textAlignment = NSTextAlignmentLeft;
  206. }else{
  207. cell.detailTextLabel.numberOfLines = 1;
  208. cell.detailTextLabel.textAlignment = NSTextAlignmentRight;
  209. }
  210. return cell;
  211. }
  212. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  213. if ([_tableViews indexOfObject:tableView] == 0) {
  214. if ([_statusArr[indexPath.row] isEqualToNumber:@1]) {
  215. [_statusArr replaceObjectAtIndex:indexPath.row withObject:@0];
  216. }else{
  217. [_statusArr replaceObjectAtIndex:indexPath.row withObject:@1];
  218. }
  219. [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  220. }
  221. }
  222. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  223. if ([tableView isEqual:_tableViews[0]] && self.headImgStr) {
  224. return 120;
  225. }
  226. return 0;
  227. }
  228. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  229. UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kSize.width, 120)];
  230. UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100*5/6, 100)];//标准一寸照295/413
  231. imageV.contentMode = UIViewContentModeScaleAspectFit;
  232. imageV.center = view.center;
  233. NSString *imgPath = @"";
  234. #pragma clang diagnostic push
  235. #pragma clang diagnostic ignored"-Wcompare-distinct-pointer-types"
  236. //写在这个中间的代码,都不会被编译器提示-Wcompare-distinct-pointer-types类型的警告
  237. if (self.headImgStr != [NSNull null]) {
  238. imgPath = self.headImgStr;
  239. }
  240. #pragma clang diagnostic po
  241. [imageV sd_setImageWithURL:[NSURL URLWithString:imgPath] placeholderImage:[UIImage imageNamed:@"default_headImg"]];
  242. imageV.layer.masksToBounds = YES;
  243. imageV.layer.cornerRadius = 5;
  244. [view addSubview:imageV];
  245. //
  246. imageV.userInteractionEnabled = YES;
  247. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectHeadImg)];
  248. [imageV addGestureRecognizer:tap];
  249. return view;
  250. }
  251. -(void)selectHeadImg{
  252. TZImagePickerController *imagePickerVC = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:nil];
  253. imagePickerVC.allowCrop = YES;
  254. CGFloat width = kSize.width*2/3;
  255. imagePickerVC.cropRect = CGRectMake(kSize.width/6, kSize.height/2-width*3/5, width, width*6/5);
  256. // 通过block(或者代理),来得到用户选择的照片.
  257. [imagePickerVC setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets,BOOL isSelectOriginalPhoto) {
  258. [self uploadHeadImg:photos[0]];
  259. }];
  260. [self presentViewController:imagePickerVC animated:YES completion:nil];
  261. }
  262. -(void)uploadHeadImg:(UIImage*)image{
  263. //交给具体的子类去实现
  264. }
  265. #pragma mark - 返回合适lable的高度
  266. -(CGFloat)getHeightWithWidth:(CGFloat)wid Font:(CGFloat)fontSize String:(NSString *)str
  267. {
  268. if (str.length == 0) {
  269. return 0;
  270. }
  271. UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
  272. lab.text = str;
  273. lab.numberOfLines = 0;
  274. lab.font = [UIFont systemFontOfSize:fontSize];
  275. return [lab sizeThatFits:CGSizeMake(wid, MAXFLOAT)].height;
  276. }
  277. - (void)didReceiveMemoryWarning {
  278. [super didReceiveMemoryWarning];
  279. // Dispose of any resources that can be recreated.
  280. }
  281. /*
  282. #pragma mark - Navigation
  283. // In a storyboard-based application, you will often want to do a little preparation before navigation
  284. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  285. // Get the new view controller using [segue destinationViewController].
  286. // Pass the selected object to the new view controller.
  287. }
  288. */
  289. @end