BHomeViewController.m 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. //
  2. // BHomeViewController.m
  3. // HappyJob
  4. //
  5. // Created by 张晓光 on 2019/7/1.
  6. // Copyright © 2019 Bob. All rights reserved.
  7. //
  8. #import "BHomeViewController.h"
  9. #import "BHomeListCell.h"
  10. #import "BHomeSearchView.h"
  11. #import "BHomeNoCertificationView.h"//认证结果
  12. #import "BHomeResumeDetailViewController.h"//简历详情
  13. #import "BHomeCertificationEnterpriseVC.h"//企业认证
  14. #import "BHomeEnterpriseAuthAPI.h"//查询企业认证结果
  15. #import "BHomeChangeIdentityAPI.h"//自发布切换身份
  16. #import "BHomeListAPI.h"//简历列表
  17. #import "BHomeDataBox.h"
  18. @interface BHomeViewController ()
  19. <
  20. UITableViewDelegate,
  21. UITextFieldDelegate,
  22. FBAPIManagerDelegate,
  23. FBAPIManagerInterceptor,
  24. UINavigationControllerDelegate,
  25. UIGestureRecognizerDelegate
  26. >
  27. @property (nonatomic, strong) BHomeNoCertificationView *certificationView;
  28. @property (nonatomic, strong) HJPageListView *tableView;
  29. @property (nonatomic, strong) BHomeSearchView *searchView;
  30. @property (nonatomic, strong) BHomeDataBox *dataBox;
  31. @property (nonatomic, strong) BHomeEnterpriseAuthAPI *authAPI;//查询企业认证结果
  32. @property (nonatomic, strong) BHomeChangeIdentityAPI *IDAPI;//自发布切换身份
  33. @property (nonatomic, strong) BHomeListAPI *listAPI;//简历列表
  34. @end
  35. @implementation BHomeViewController
  36. - (void)dealloc {
  37. [[NSNotificationCenter defaultCenter] removeObserver:self name:HJEnterpriseAuthResultNotification object:nil];
  38. }
  39. - (void)viewWillAppear:(BOOL)animated {
  40. [super viewWillAppear:animated];
  41. // [self.navigationController setNavigationBarHidden:YES animated:YES];
  42. self.navigationController.delegate = self;
  43. self.navigationController.interactivePopGestureRecognizer.delegate = self;
  44. }
  45. - (void)viewDidLoad {
  46. [super viewDidLoad];
  47. //认证成功通知回调
  48. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshEnterpriseAuthResult:) name:HJEnterpriseAuthResultNotification object:nil];
  49. // 错误页面刷新事件
  50. [self.view.errorView.refreshButton addTarget:self action:@selector(refreshButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  51. self.edgesForExtendedLayout = UIRectEdgeNone;
  52. [self.authAPI start];
  53. }
  54. #pragma mark - 导航栏的代理
  55. - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  56. // 判断要显示的控制器是否是自己
  57. // BOOL isPushSelfClass = [viewController isKindOfClass:[self class]];
  58. [self.navigationController setNavigationBarHidden:YES animated:animated];
  59. }
  60. #pragma mark - event response
  61. /* 认证成功回调(只有提交里信息) */
  62. - (void)refreshEnterpriseAuthResult:(NSNotificationCenter *)noti {
  63. [self.authAPI start];
  64. }
  65. /* 错误页面刷新事件 */
  66. - (void)refreshButtonClicked:(UIButton *)btn {
  67. [self.authAPI start];
  68. }
  69. #pragma mark - UITextFieldDelegate
  70. /* 当点击键盘上的return键*/
  71. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  72. {
  73. [self.searchView.searchTextField resignFirstResponder];
  74. self.listAPI.searchStr = textField.text;
  75. [self.listAPI start];
  76. return YES ;
  77. }
  78. #pragma mark - FBAPIManagerInterceptor
  79. - (BOOL)manager:(FBBaseAPIManager *)manager shouldStartCallAPIWithParams:(NSDictionary *)params {
  80. [self.view fb_showLoading];
  81. return YES;
  82. }
  83. - (void)managerShouldFinishCallAPI:(FBBaseAPIManager *)manager {
  84. [self.view fb_dismiss];
  85. }
  86. #pragma mark - FBPageableAPIManager
  87. - (void)managerCallAPIDidSuccess:(FBBaseAPIManager *)manager {
  88. [self.view dismissErrorView];
  89. if (manager == self.authAPI)
  90. {
  91. id fetchData = [manager fetchDataWithBox:self.dataBox];
  92. if ([[fetchData valueForKeyPath:@"data.isAuth"] boolValue] == NO)
  93. { //没有提交企业认证
  94. [self createCertificationView];
  95. }
  96. else if ([[fetchData valueForKeyPath:@"data.isAuth"] boolValue] == YES)
  97. { //有提交企业认证
  98. [self.IDAPI start];
  99. }
  100. }
  101. if (manager == self.IDAPI)
  102. {
  103. [manager fetchDataWithBox:self.dataBox];
  104. [self createTableView];
  105. [self.listAPI start];
  106. }
  107. if (manager == self.listAPI)
  108. {
  109. [self.tableView managerCallAPIDidSuccess:manager];
  110. }
  111. }
  112. - (void)managerCallAPIDidFailed:(FBBaseAPIManager *)manager {
  113. [self.view showErrorView];
  114. id fetchData = [manager fetchDataWithBox:self.dataBox];
  115. if ([fetchData isKindOfClass:[NSString class]])
  116. {
  117. [self.view fb_showFailureWithStatus:fetchData];
  118. }
  119. if (manager == self.listAPI)
  120. {
  121. [self.tableView managerCallAPIDidFailed:manager];
  122. }
  123. }
  124. #pragma mark - UItableView代理
  125. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  126. UIViewController *vc = [self.dataBox positionDetailViewControllerAtIndexPath:indexPath];
  127. vc.hidesBottomBarWhenPushed = YES;
  128. [self.navigationController pushViewController:vc animated:YES];
  129. }
  130. #pragma mark - private methods
  131. /* 创建TableView */
  132. - (void)createTableView {
  133. [self.view addSubview:self.searchView];
  134. [self.view addSubview:self.tableView];
  135. __weak typeof(self) weakSelf = self;
  136. [self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
  137. make.left.right.offset(0);
  138. make.top.offset(0);
  139. make.height.mas_equalTo(STATUS_H + NAVIGATION_H);
  140. }];
  141. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.top.equalTo(weakSelf.searchView.mas_bottom).offset(0);
  143. make.left.bottom.right.offset(0);
  144. }];
  145. }
  146. /* 没有认证页面 */
  147. - (void)createCertificationView {
  148. __weak typeof(self) weakSelf = self;
  149. [self.view addSubview:self.certificationView];
  150. [self.certificationView mas_makeConstraints:^(MASConstraintMaker *make) {
  151. make.left.right.offset(0);
  152. make.centerY.equalTo(weakSelf.view);
  153. }];
  154. _certificationView.certificationBlock = ^{
  155. BHomeCertificationEnterpriseVC *enterpriseVC = [[BHomeCertificationEnterpriseVC alloc]init];
  156. enterpriseVC.hidesBottomBarWhenPushed = YES;
  157. [weakSelf.navigationController pushViewController:enterpriseVC animated:YES];
  158. };
  159. }
  160. #pragma mark - event response
  161. - (void)searchButtonClick {
  162. [self.searchView.searchTextField resignFirstResponder];
  163. self.listAPI.searchStr = self.searchView.searchTextField.text;
  164. [self.listAPI start];
  165. }
  166. #pragma mark - setter and getter
  167. - (BHomeDataBox *)dataBox {
  168. if (_dataBox == nil)
  169. {
  170. _dataBox = [[BHomeDataBox alloc] init];
  171. }
  172. return _dataBox;
  173. }
  174. - (BHomeNoCertificationView *)certificationView {
  175. if (_certificationView == nil)
  176. {
  177. _certificationView = [[BHomeNoCertificationView alloc]init];
  178. }
  179. return _certificationView;
  180. }
  181. - (BHomeEnterpriseAuthAPI *)authAPI {
  182. if (_authAPI == nil)
  183. {
  184. _authAPI = [[BHomeEnterpriseAuthAPI alloc]init];
  185. _authAPI.APIManagerDelegate = self;
  186. _authAPI.APIManagerInterceptor = self;
  187. }
  188. return _authAPI;
  189. }
  190. - (BHomeChangeIdentityAPI *)IDAPI {
  191. if (_IDAPI == nil)
  192. {
  193. _IDAPI = [[BHomeChangeIdentityAPI alloc]init];
  194. _IDAPI.APIManagerDelegate = self;
  195. }
  196. return _IDAPI;
  197. }
  198. - (BHomeListAPI *)listAPI {
  199. if (_listAPI == nil)
  200. {
  201. _listAPI = [[BHomeListAPI alloc]init];
  202. _listAPI.APIManagerDelegate = self;
  203. _listAPI.APIManagerInterceptor = self.tableView;
  204. }
  205. return _listAPI;
  206. }
  207. - (BHomeSearchView *)searchView {
  208. if (_searchView == nil)
  209. {
  210. _searchView = [[BHomeSearchView alloc]init];
  211. _searchView.searchTextField.delegate = self;
  212. _searchView.searchTextField.placeholder = @"输入姓名或岗位等信息查找简历";
  213. [_searchView.cancelButton addTarget:self action:@selector(searchButtonClick) forControlEvents:UIControlEventTouchUpInside];
  214. }
  215. return _searchView;
  216. }
  217. - (HJPageListView *)tableView {
  218. if (_tableView == nil)
  219. {
  220. _tableView = [[HJPageListView alloc] init];
  221. _tableView.tableView.delegate = self;
  222. _tableView.tableView.dataSource = self.dataBox;
  223. _tableView.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  224. _tableView.APIManager = self.listAPI;
  225. _tableView.dataBox = self.dataBox;
  226. //自定义空白页
  227. _tableView.blankView.imageView.image = [UIImage imageNamed:@"b_home_empty"];
  228. NSMutableAttributedString *countAtt1 = [[NSMutableAttributedString alloc]initWithString:@"暂时还没有简历投递进来\n\n岗位信息内容填写越丰富\n越容易收到高质量的简历"];
  229. [countAtt1 addAttribute:NSForegroundColorAttributeName value:COLOR_BACK3 range:NSMakeRange(0, 11)];
  230. [countAtt1 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(0, 11)];
  231. _tableView.blankView.label.font = [UIFont systemFontOfSize:12];
  232. _tableView.blankView.label.attributedText = countAtt1;
  233. }
  234. return _tableView;
  235. }
  236. /*
  237. #pragma mark - Navigation
  238. // In a storyboard-based application, you will often want to do a little preparation before navigation
  239. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  240. // Get the new view controller using [segue destinationViewController].
  241. // Pass the selected object to the new view controller.
  242. }
  243. */
  244. @end