HJPartTimeDetailViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. //
  2. // HJPartTimeDetailViewController.m
  3. // HappyJob
  4. //
  5. // Created by Bob on 2019/4/3.
  6. // Copyright © 2019 Bob. All rights reserved.
  7. //
  8. #import "HJPartTimeDetailViewController.h"
  9. #import "HJJobDetailForwardView.h"
  10. #import "HJJobDetailSelectiveBar.h"
  11. #import "HJWorkplaceViewController.h"
  12. #import "HJPositionDetailDataBox.h"
  13. #import "HJGetPositionDetailAPIManager.h"
  14. #import "HJLeftRightLabelView.h"
  15. #import "FBFlowLayoutView.h"
  16. #import "HJPositionDetailModel.h"
  17. #import "UIButton+HJTagButton.h"
  18. #import "HJPositionDetailCompanyView.h"
  19. #import "HJPositionDetailCompanyInfoVC.h"//公司信息
  20. #import "HJPartTimeDetailHeaderView.h"
  21. @interface HJPartTimeDetailViewController ()
  22. <
  23. HJJobDetailForwardViewDelegate,
  24. FBScrollLayoutViewDelegate,
  25. HJPositionDetailViewDelegate,
  26. FBFlowLayoutDelegate,
  27. FBFlowLayoutDataSource,
  28. UIScrollViewDelegate
  29. >
  30. @property (nonatomic, strong, readwrite) HJPositionDetailView *detailView;
  31. @property (nonatomic, strong) HJGetPositionDetailAPIManager *detailAPIManager;
  32. @property (nonatomic, strong) HJPositionDetailDataBox *detailDataBox;
  33. @property (nonatomic, strong) HJPartTimeDetailHeaderView *headerView;
  34. @property (nonatomic, strong) UIView *addressBgView;
  35. @property (nonatomic, strong) UIView *welfareBgView;
  36. @property (nonatomic, strong) UIView *workTimeBgView;
  37. @property (nonatomic, strong) HJJobDetailForwardView *addressView;
  38. @property (nonatomic, strong) UILabel *welfareLabel;
  39. @property (nonatomic, strong) FBFlowLayoutView *welfareView;
  40. @property (nonatomic, strong) HJLeftRightLabelView *workTimeLabel;
  41. @property (nonatomic, strong) UIView *baseInfoView;
  42. @property (nonatomic, strong) UIView *requireInfoView;
  43. @property (nonatomic, strong) HJPositionDetailCompanyView *companyInfoView;
  44. @property (nonatomic, copy) NSArray *welfareTagArray;
  45. @end
  46. @implementation HJPartTimeDetailViewController
  47. #pragma mark - life cycle
  48. - (void)dealloc {
  49. [[NSNotificationCenter defaultCenter] removeObserver:self name:HJLoginRefreshNotification object:nil];
  50. }
  51. - (void)viewWillAppear:(BOOL)animated {
  52. [super viewWillAppear:animated];
  53. [self hj_setupNavBar];
  54. }
  55. - (void)viewDidLoad {
  56. [super viewDidLoad];
  57. self.title = self.detailView.title;
  58. [self subViewsMakeConstraints];
  59. self.detailAPIManager.positionID = self.detailView.positionID;
  60. self.detailAPIManager.positionType = self.detailView.positionType;
  61. [self.detailAPIManager start];
  62. //添加登录刷新通知
  63. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginRefresh:) name:HJLoginRefreshNotification object:nil];
  64. }
  65. - (void)subViewsMakeConstraints {
  66. if (self.selfPublish)
  67. {
  68. self.detailView.customerServiceBtn.hidden = YES;
  69. }
  70. [self.view addSubview:self.detailView];
  71. [self.detailView mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.top.left.right.equalTo(self.view);
  73. if (self.selfPublish)
  74. {
  75. make.bottom.equalTo(self.view).offset(0);
  76. }
  77. else
  78. {
  79. make.bottom.equalTo(self.mas_bottomLayoutGuide).offset(0);
  80. }
  81. }];
  82. }
  83. #pragma mark - event response 通知
  84. - (void)loginRefresh:(NSNotification *)notification {
  85. [self.detailAPIManager start];
  86. }
  87. #pragma mark - FBScrollLayoutViewDelegate
  88. - (void)subviewsMakeConstraintsInScrollLayoutView:(FBScrollLayoutView *)scrollLayoutView contentView:(UIView *)contentView {
  89. [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.top.equalTo(contentView).offset(5);
  91. make.left.right.equalTo(contentView);
  92. }];
  93. [self.addressBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.top.equalTo(self.headerView.mas_bottom).with.offset(0);
  95. make.left.right.equalTo(contentView);
  96. }];
  97. if ([self.addressBgView.subviews indexOfObject:self.addressView] != NSNotFound)
  98. {
  99. [self.addressView mas_makeConstraints:^(MASConstraintMaker *make) {
  100. make.top.equalTo(self.addressBgView.mas_top).offset(0);
  101. make.bottom.equalTo(self.addressBgView.mas_bottom).offset(0);
  102. make.left.right.equalTo(self.addressBgView);
  103. make.height.mas_equalTo(75);
  104. }];
  105. }
  106. [self.welfareBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.top.equalTo(self.addressBgView.mas_bottom).offset(1);
  108. make.left.right.equalTo(contentView);
  109. }];
  110. if ([self.welfareBgView.subviews indexOfObject:self.welfareView] != NSNotFound)
  111. {
  112. [self.welfareLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.top.equalTo(self.welfareBgView.mas_top).with.offset(10);
  114. make.left.equalTo(self.welfareBgView).with.offset(15);
  115. make.width.mas_equalTo(80);
  116. }];
  117. [self.welfareView mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.top.equalTo(self.welfareLabel);
  119. make.left.equalTo(self.welfareLabel.mas_right).with.offset(12);
  120. make.right.equalTo(self.welfareBgView).with.offset(-15);
  121. make.bottom.equalTo(self.welfareBgView.mas_bottom).offset(-10);
  122. }];
  123. }
  124. [self.workTimeBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  125. make.top.equalTo(self.welfareBgView.mas_bottom).with.offset(0);
  126. make.left.right.equalTo(contentView);
  127. }];
  128. if ([self.workTimeBgView.subviews indexOfObject:self.workTimeLabel] != NSNotFound)
  129. {
  130. [self.workTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  131. make.top.equalTo(self.workTimeBgView.mas_top).offset(0);
  132. make.bottom.equalTo(self.workTimeBgView.mas_bottom).offset(0);
  133. make.left.right.equalTo(self.workTimeBgView);
  134. }];
  135. }
  136. [self.baseInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
  137. make.top.equalTo(self.workTimeBgView.mas_bottom).with.offset(5);
  138. make.left.right.equalTo(contentView);
  139. }];
  140. [self.requireInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
  141. make.top.equalTo(self.baseInfoView.mas_bottom).with.offset(5);
  142. make.left.right.equalTo(contentView);
  143. }];
  144. if (self.selfPublish)
  145. {
  146. // 这个一定要加,这样就可以确定内容的整体高度,UIScrollView就可以根据这个设置contentSize
  147. [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  148. make.bottom.equalTo(self.requireInfoView.mas_bottom).with.offset(0);
  149. }];
  150. }
  151. else
  152. {
  153. [self.companyInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
  154. make.top.equalTo(self.requireInfoView.mas_bottom).with.offset(5);
  155. make.left.right.equalTo(contentView);
  156. }];
  157. [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  158. make.bottom.equalTo(self.companyInfoView.mas_bottom).with.offset(0);
  159. }];
  160. }
  161. }
  162. - (void)subviewsMakeConstraintsInScrollLayoutView:(FBScrollLayoutView *)scrollLayoutView footerView:(UIView *)footerView {
  163. if (self.selfPublish)
  164. {
  165. [footerView mas_makeConstraints:^(MASConstraintMaker *make) {
  166. make.height.mas_equalTo(0.01);
  167. }];
  168. }
  169. else
  170. {
  171. [self.detailView.callButton mas_makeConstraints:^(MASConstraintMaker *make) {
  172. make.edges.equalTo(footerView).with.insets(UIEdgeInsetsMake(9, 15, 9, HJHorizontalScale(250)));
  173. make.height.mas_equalTo(44);
  174. }];
  175. [self.detailView.applyButton mas_makeConstraints:^(MASConstraintMaker *make) {
  176. make.edges.equalTo(footerView).with.insets(UIEdgeInsetsMake(9, HJHorizontalScale(135), 9, 15));
  177. }];
  178. }
  179. }
  180. #pragma mark - FBFlowLayoutDelegate
  181. - (CGFloat)estimateWidthInFlowLayoutView:(FBFlowLayoutView *)flowLayoutView {
  182. return (SCREEN_WIDTH - HJHorizontalScale(125));
  183. }
  184. - (CGFloat)subviewHorizontalSpacingInFlowLayoutView:(FBFlowLayoutView *)flowLayoutView {
  185. return 6;
  186. }
  187. - (CGFloat)subviewVerticalSpacingInFlowLayoutView:(FBFlowLayoutView *)flowLayoutView {
  188. return 6;
  189. }
  190. - (NSUInteger)numberInFlowLayoutView:(FBFlowLayoutView *)flowLayoutView {
  191. return self.welfareTagArray.count;
  192. }
  193. - (UIView *)flowLayoutView:(FBFlowLayoutView *)flowLayoutView subviewAtIndex:(NSUInteger)index {
  194. NSString *title = self.welfareTagArray[index];
  195. UIButton *tagButton = [UIButton hj_createWelfareTagButtonWithTitle:title maxSize:CGSizeMake(flowLayoutView.contentWidth, MAXFLOAT)];
  196. return tagButton;
  197. }
  198. #pragma mark - HJJobDetailForwardViewDelegate
  199. - (void)jobDetailForwardViewClicked:(HJJobDetailForwardView *)forwardView {
  200. HJWorkplaceViewController *vc = [[HJWorkplaceViewController alloc] init];
  201. vc.dataBox = self.detailDataBox;
  202. [self.navigationController pushViewController:vc animated:YES];
  203. }
  204. #pragma mark - HJPositionDetailViewDelegate
  205. - (void)positionDetailView:(HJPositionDetailView *)detailView configData:(NSDictionary *)data {
  206. if ([data[kHJDetailPositionIsShare] intValue] == 1)
  207. {
  208. //设置导航栏按钮
  209. if (!self.selfPublish)
  210. {
  211. [self fb_setupNavBarRightButtonItems:@[self.detailView.shareButton]];
  212. }
  213. }
  214. [self.headerView configurationPartTimeDetailHeaderViewData:data andCollectionButton:self.detailView.favoriteButton];
  215. self.baseInfoView = data[kHJPositionKeyBaseInfo];
  216. self.requireInfoView = data[kHJPositionKeyRequireInfo];
  217. self.companyInfoView = data[kHJPositionKeyCompanyNameInfo];
  218. //地址
  219. if (data[kHJPositionKeyAddress])
  220. {
  221. NSArray *addressArray = data[kHJPositionKeyAddress][kHJPositionKeyInnerValue];
  222. self.addressView.titleLabel.text = [NSString stringWithFormat:@"%@",addressArray[0][@"kHJWorkplaceKeyAddress"]];
  223. if (addressArray.count <= 1)
  224. {//如果地址数量为1个的时候隐藏地址数量和分割线同时titleLabel的布局修改
  225. self.addressView.allLabel.hidden = YES;
  226. self.addressView.lineView.hidden = YES;
  227. [self.addressView.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  228. make.left.equalTo(self.addressView.imageView.mas_right).offset(20);
  229. make.right.equalTo(self.addressView.mas_right).offset(-10);
  230. make.top.equalTo(self.addressView.mas_top).offset(15);
  231. }];
  232. }
  233. else
  234. {
  235. self.addressView.allLabel.hidden = NO;
  236. self.addressView.lineView.hidden = NO;
  237. self.addressView.allLabel.text = [NSString stringWithFormat:@"全部(%@)",@(addressArray.count)];
  238. }
  239. self.addressView.citylabel.text = [NSString stringWithFormat:@"%@",addressArray[0][@"kHJWorkplaceKeyArea"]];
  240. [self.addressBgView addSubview:self.addressView];
  241. }
  242. //福利
  243. HJPositionDetailModel *model = data[kHJPositionKeyDetailModel];
  244. NSArray *welfareTagArray = [model.position getWelfareArray];
  245. if (welfareTagArray.count > 0)
  246. {
  247. self.welfareTagArray = welfareTagArray;
  248. [self.welfareBgView addSubview:self.welfareLabel];
  249. [self.welfareBgView addSubview:self.welfareView];
  250. }
  251. //工作时间
  252. if (model.position.workDay.length > 0)
  253. {
  254. NSDictionary *workTimeDict = @{kHJLeftLabelText: @"工作时间:", kHJRightLabelText: [NSString stringWithFormat:@"%@\n%@", model.position.workDay, model.position.workTime ? model.position.workTime:@""]};
  255. self.workTimeLabel = [[HJLeftRightLabelView alloc] initWithTextArray:@[workTimeDict]];
  256. [self.workTimeBgView addSubview:self.workTimeLabel];
  257. }
  258. [detailView.scrollLayoutView.contentView addSubview:self.headerView];
  259. [detailView.scrollLayoutView.contentView addSubview:self.addressBgView];
  260. [detailView.scrollLayoutView.contentView addSubview:self.welfareBgView];
  261. [detailView.scrollLayoutView.contentView addSubview:self.workTimeBgView];
  262. [detailView.scrollLayoutView.contentView addSubview:self.baseInfoView];
  263. [detailView.scrollLayoutView.contentView addSubview:self.requireInfoView];
  264. if (!self.selfPublish)
  265. {
  266. [detailView.scrollLayoutView.contentView addSubview:self.companyInfoView];
  267. [detailView.scrollLayoutView.footerView addSubview:self.detailView.applyButton];
  268. [detailView.scrollLayoutView.footerView addSubview:self.detailView.callButton];
  269. }
  270. [detailView.scrollLayoutView makeConstraints];
  271. __weak typeof(self) weakSelf = self;
  272. self.companyInfoView.IntroductionButtonBlock = ^{
  273. HJPositionDetailCompanyInfoVC *vc = [[HJPositionDetailCompanyInfoVC alloc]init];
  274. vc.infoArray = data[kHJPositionKeyCompanyInfo];
  275. [weakSelf.navigationController pushViewController:vc animated:YES];
  276. };
  277. }
  278. #pragma mark - event response
  279. #pragma mark - private methods
  280. #pragma mark - getters and setters
  281. - (HJPartTimeDetailHeaderView *)headerView {
  282. if (_headerView == nil)
  283. {
  284. _headerView = [[HJPartTimeDetailHeaderView alloc]init];
  285. }
  286. return _headerView;
  287. }
  288. - (UIView *)addressBgView {
  289. if (_addressBgView == nil)
  290. {
  291. _addressBgView = [[UIView alloc]init];
  292. _addressBgView.backgroundColor = [UIColor whiteColor];
  293. }
  294. return _addressBgView;
  295. }
  296. - (UIView *)welfareBgView {
  297. if (_welfareBgView == nil)
  298. {
  299. _welfareBgView = [[UIView alloc]init];
  300. _welfareBgView.backgroundColor = [UIColor whiteColor];
  301. }
  302. return _welfareBgView;
  303. }
  304. - (UIView *)workTimeBgView {
  305. if (_workTimeBgView == nil)
  306. {
  307. _workTimeBgView = [[UIView alloc]init];
  308. _workTimeBgView.backgroundColor = [UIColor whiteColor];
  309. }
  310. return _workTimeBgView;
  311. }
  312. - (HJPositionDetailDataBox *)detailDataBox {
  313. if (_detailDataBox == nil)
  314. {
  315. _detailDataBox = [[HJPositionDetailDataBox alloc] init];
  316. }
  317. return _detailDataBox;
  318. }
  319. - (HJGetPositionDetailAPIManager *)detailAPIManager {
  320. if (_detailAPIManager == nil)
  321. {
  322. _detailAPIManager = [[HJGetPositionDetailAPIManager alloc] init];
  323. _detailAPIManager.APIManagerDelegate = self.detailView;
  324. _detailAPIManager.APIManagerInterceptor = self.detailView;
  325. }
  326. return _detailAPIManager;
  327. }
  328. - (HJPositionDetailView *)detailView {
  329. if (_detailView == nil)
  330. {
  331. _detailView = [[HJPositionDetailView alloc] init];
  332. _detailView.delegate = self;
  333. _detailView.scrollLayoutView.delegate = self;
  334. _detailView.APIManager = self.detailAPIManager;
  335. _detailView.dataBox = self.detailDataBox;
  336. _detailView.scrollLayoutView.scrollView.delegate = self;
  337. _detailView.scrollLayoutView.contentView.backgroundColor = COLOR_F5F5F5;
  338. }
  339. return _detailView;
  340. }
  341. - (UILabel *)welfareLabel {
  342. if (_welfareLabel == nil)
  343. {
  344. _welfareLabel = [[UILabel alloc] init];
  345. _welfareLabel.text = @"岗位福利:";
  346. _welfareLabel.textColor = COLOR_000000;
  347. _welfareLabel.font = [UIFont systemFontOfSize:14];
  348. _welfareLabel.textAlignment = NSTextAlignmentLeft;
  349. }
  350. return _welfareLabel;
  351. }
  352. - (FBFlowLayoutView *)welfareView {
  353. if (_welfareView == nil)
  354. {
  355. _welfareView = [[FBFlowLayoutView alloc] init];
  356. _welfareView.delegate = self;
  357. _welfareView.dataSource = self;
  358. _welfareView.numberOfLines = 0;
  359. }
  360. return _welfareView;
  361. }
  362. - (HJJobDetailForwardView *)addressView {
  363. if (_addressView == nil)
  364. {
  365. _addressView = [[HJJobDetailForwardView alloc] init];
  366. _addressView.imageView.image = [UIImage imageNamed:@"positiondetail_address"];
  367. _addressView.delegate = self;
  368. _addressView.backgroundColor = [UIColor whiteColor];
  369. }
  370. return _addressView;
  371. }
  372. @end