BPositionCell.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. //
  2. // BPositionCell.m
  3. // HappyJob
  4. //
  5. // Created by 张晓光 on 2019/7/1.
  6. // Copyright © 2019 Bob. All rights reserved.
  7. //
  8. #import "BPositionCell.h"
  9. #import "BPositonModel.h"
  10. @interface BPositionCell ()
  11. @property (nonatomic, strong) UIView *bgView;
  12. @property (nonatomic, strong) UILabel *updateTimelabel;
  13. @property (nonatomic, strong) UILabel *nameLabel;
  14. @property (nonatomic, strong) UIButton *stateBtn;
  15. @property (nonatomic, strong) UILabel *countlabel;
  16. @property (nonatomic, strong) UILabel *addressLabel;
  17. @property (nonatomic, strong) UILabel *timeLabel;
  18. @property (nonatomic, strong) UIButton *refreshBtn;
  19. @property (nonatomic, strong) UIButton *stopBtn;
  20. @property (nonatomic, strong) UIButton *endBtn;
  21. @property (nonatomic, strong) UIButton *editBtn;
  22. @property (nonatomic, strong) UIButton *resumeBtn;//简历
  23. @property (nonatomic, strong) UIView *lineView;
  24. @end
  25. @implementation BPositionCell
  26. - (void)awakeFromNib {
  27. [super awakeFromNib];
  28. // Initialization code
  29. }
  30. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  31. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
  32. {
  33. self.selectionStyle = UITableViewCellSelectionStyleNone;
  34. self.backgroundColor = COLOR_GRAYFA;
  35. [self initViews];
  36. [self autoLayOutViews];
  37. }
  38. return self;
  39. }
  40. - (void)initViews {
  41. [self.contentView addSubview:self.bgView];
  42. [self.bgView addSubview:self.updateTimelabel];
  43. [self.bgView addSubview:self.nameLabel];
  44. [self.bgView addSubview:self.stateBtn];
  45. [self.bgView addSubview:self.resumeBtn];
  46. [self.resumeBtn addSubview:self.countlabel];
  47. [self.bgView addSubview:self.addressLabel];
  48. [self.bgView addSubview:self.timeLabel];
  49. [self.bgView addSubview:self.refreshBtn];
  50. [self.bgView addSubview:self.stopBtn];
  51. [self.bgView addSubview:self.endBtn];
  52. [self.bgView addSubview:self.editBtn];
  53. [self.bgView addSubview:self.lineView];
  54. }
  55. - (void)BPositionCellArray:(NSArray *)array andIndexPath:(NSIndexPath *)indexPath {
  56. NSDictionary *dict = [array objectAtIndex:indexPath.row];
  57. BPositonModel *model = [BPositonModel yy_modelWithJSON:dict];
  58. //更新时间
  59. NSString *updateDate = [HJAppService compareCurrentTimeDayAndMonth:[NSString stringWithFormat:@"%ld",(long)[HJAppService timeSwitchTimestamp:model.updateDate]]];
  60. self.updateTimelabel.text = [NSString stringWithFormat:@"最后更新于:%@",updateDate];
  61. //职位名称
  62. self.nameLabel.text = model.positionName;
  63. _nameLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 150;
  64. //地址
  65. if (model.hpPositionAddressList.count == 0)
  66. {
  67. self.addressLabel.text = [NSString stringWithFormat:@"工作地点:%@",@"全国"];
  68. }
  69. else
  70. {
  71. self.addressLabel.text = [NSString stringWithFormat:@"工作地点:%@ %@",model.hpPositionAddressList[0].adname ? [[model.hpPositionAddressList[0].adname componentsSeparatedByString:@"-"] componentsJoinedByString:@" "] :@"",model.hpPositionAddressList[0].address ? model.hpPositionAddressList[0].address:@""];
  72. }
  73. if ([model.positionCategory isEqualToString:@"8"])
  74. { //8全职
  75. if ([model.recruitNumber integerValue] > 0 )
  76. {
  77. self.timeLabel.text = [NSString stringWithFormat:@"招聘人数:%@",[NSString stringWithFormat:@"%@人 (全职工作)",model.recruitNumber]];
  78. }
  79. else
  80. {
  81. self.timeLabel.text = [NSString stringWithFormat:@"招聘人数:%@",@"若干人 (全职工作)"];
  82. }
  83. }
  84. else
  85. { //9兼职
  86. if (model.workDate == nil || [model.workDate isEqualToString:@""])
  87. {
  88. self.timeLabel.text = [NSString stringWithFormat:@"工作时间:%@",@"(兼职工作)"];
  89. }
  90. else
  91. {
  92. NSArray *timeArray = [model.workDate componentsSeparatedByString:@","];
  93. NSString *startTime = [HJAppService compareCurrentTimeDayAndMonth:[NSString stringWithFormat:@"%ld",(long)[HJAppService timeSwitchTimestamp:[NSString stringWithFormat:@"%@ 00:00:00",timeArray[0]]]]];
  94. NSString *endTime = [HJAppService compareCurrentTimeDayAndMonth:[NSString stringWithFormat:@"%ld",(long)[HJAppService timeSwitchTimestamp:[NSString stringWithFormat:@"%@ 00:00:00",[timeArray lastObject]]]]];
  95. self.timeLabel.text = [NSString stringWithFormat:@"工作时间:%@",[NSString stringWithFormat:@"%@-%@(兼职工作)",startTime,endTime]];
  96. }
  97. }
  98. //职位审核状态
  99. if ([model.authenticationStatus integerValue] == 1)
  100. {//审核中
  101. _stateBtn.hidden = NO;
  102. self.updateTimelabel.hidden = YES;
  103. [_stateBtn setTitle:@"审核中" forState:UIControlStateNormal];
  104. [_stateBtn setImage:[UIImage imageNamed:@"b_position_ing"] forState:UIControlStateNormal];
  105. [_stateBtn setTitleColor:COLOR_GRAY9 forState:UIControlStateNormal];
  106. }
  107. else if ([model.authenticationStatus integerValue] == 2)
  108. {//审核驳回
  109. _stateBtn.hidden = NO;
  110. self.updateTimelabel.hidden = YES;
  111. [_stateBtn setTitle:@"审核驳回" forState:UIControlStateNormal];
  112. [_stateBtn setImage:[UIImage imageNamed:@"position_audit_rejected"] forState:UIControlStateNormal];
  113. [_stateBtn setTitleColor:COLOR_READFF forState:UIControlStateNormal];
  114. }
  115. else
  116. {
  117. _stateBtn.hidden = YES;
  118. self.updateTimelabel.hidden = NO;
  119. }
  120. //简历数量
  121. if ([model.count integerValue] > 0)
  122. {
  123. self.countlabel.hidden = NO;
  124. }
  125. else
  126. {
  127. self.countlabel.hidden = YES;
  128. }
  129. //是否结束 0下架 1未下架
  130. if ([model.isOn boolValue])
  131. {//未下架
  132. self.editBtn.selected = YES;
  133. if ([self isTimeEnd:model.endDate])
  134. {//时间结束
  135. if ([model.isPause boolValue])
  136. {
  137. [self.stopBtn setTitle:@"开始" forState:UIControlStateNormal];
  138. }
  139. else
  140. {
  141. [self.stopBtn setTitle:@"暂停" forState:UIControlStateNormal];
  142. }
  143. self.refreshBtn.selected = NO;
  144. self.stopBtn.selected = NO;
  145. self.resumeBtn.selected = NO;
  146. }
  147. else
  148. {//时间未结束
  149. self.refreshBtn.selected = YES;
  150. self.stopBtn.selected = YES;
  151. self.resumeBtn.selected = YES;
  152. //是否暂停 1:暂停
  153. if ([model.isPause boolValue])
  154. {
  155. [self.stopBtn setTitle:@"开始" forState:UIControlStateNormal];
  156. }
  157. else
  158. {
  159. [self.stopBtn setTitle:@"暂停" forState:UIControlStateNormal];
  160. }
  161. }
  162. }
  163. else
  164. {//下架
  165. //是否暂停 1:暂停
  166. if ([model.isPause boolValue])
  167. {
  168. [self.stopBtn setTitle:@"开始" forState:UIControlStateNormal];
  169. }
  170. else
  171. {
  172. [self.stopBtn setTitle:@"暂停" forState:UIControlStateNormal];
  173. }
  174. self.stopBtn.selected = NO;
  175. self.refreshBtn.selected = NO;
  176. self.endBtn.selected = NO;
  177. self.editBtn.selected = NO;
  178. self.resumeBtn.selected = NO;
  179. self.stateBtn.hidden = YES;
  180. }
  181. }
  182. /* 判断时间是否结束 */
  183. - (BOOL)isTimeEnd:(NSString *)endTimeStr {
  184. if (endTimeStr)
  185. {
  186. //yes结束
  187. NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
  188. [formatter setDateFormat:@"yyyy-MM-dd"];
  189. NSString *todayDate=[formatter stringFromDate:[NSDate date]];
  190. NSDate *today = [formatter dateFromString:todayDate];
  191. NSDate *endTime = [formatter dateFromString:endTimeStr];
  192. NSComparisonResult result = [endTime compare:today];
  193. if (result == NSOrderedDescending)
  194. {
  195. return NO;
  196. }
  197. else if (result == NSOrderedSame)
  198. {
  199. return NO;
  200. }
  201. else
  202. {
  203. return YES;
  204. }
  205. }
  206. else
  207. {
  208. return NO;
  209. }
  210. }
  211. #pragma mark - 布局
  212. - (void)autoLayOutViews {
  213. __weak typeof(self) weakSelf = self;
  214. [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  215. make.leading.equalTo(weakSelf.contentView.mas_leading).offset(0);
  216. make.trailing.equalTo(weakSelf.contentView.mas_trailing).offset(0);
  217. make.top.equalTo(weakSelf.contentView.mas_top).offset(0);
  218. make.bottom.equalTo(weakSelf.contentView.mas_bottom).offset(-10);
  219. }];
  220. [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  221. make.leading.equalTo(weakSelf.bgView.mas_leading).offset(15);
  222. make.top.equalTo(weakSelf.bgView.mas_top).offset(20);
  223. }];
  224. [_updateTimelabel mas_makeConstraints:^(MASConstraintMaker *make) {
  225. make.right.equalTo(weakSelf.bgView).offset(-15);
  226. make.centerY.equalTo(weakSelf.nameLabel);
  227. }];
  228. [_stateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  229. make.right.equalTo(weakSelf.bgView).offset(-15);
  230. make.centerY.equalTo(weakSelf.nameLabel);
  231. }];
  232. [_addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  233. make.leading.equalTo(weakSelf.bgView.mas_leading).offset(15);
  234. make.trailing.equalTo(weakSelf.bgView.mas_trailing).offset(-15);
  235. make.top.equalTo(weakSelf.nameLabel.mas_bottom).offset(20);
  236. }];
  237. [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  238. make.leading.equalTo(weakSelf.bgView.mas_leading).offset(15);
  239. make.trailing.equalTo(weakSelf.bgView.mas_trailing).offset(-15);
  240. make.top.equalTo(weakSelf.addressLabel.mas_bottom).offset(5);
  241. }];
  242. [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  243. make.left.right.offset(0);
  244. make.top.equalTo(self.timeLabel.mas_bottom).offset(10);
  245. make.height.mas_equalTo(1);
  246. }];
  247. [_refreshBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  248. make.leading.equalTo(weakSelf.bgView.mas_leading).offset(15);
  249. make.top.equalTo(weakSelf.timeLabel.mas_bottom).offset(20);
  250. make.bottom.equalTo(weakSelf.bgView.mas_bottom).offset(-20);
  251. make.size.mas_offset(CGSizeMake(HJHorizontalScale(53), HJHorizontalScale(26)));
  252. }];
  253. [_stopBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  254. make.leading.equalTo(weakSelf.refreshBtn.mas_trailing).offset(15);
  255. make.centerY.equalTo(weakSelf.refreshBtn);
  256. make.size.mas_offset(CGSizeMake(HJHorizontalScale(53), HJHorizontalScale(26)));
  257. }];
  258. [_endBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  259. make.leading.equalTo(weakSelf.stopBtn.mas_trailing).offset(15);
  260. make.centerY.equalTo(weakSelf.refreshBtn);
  261. make.size.mas_offset(CGSizeMake(HJHorizontalScale(53), HJHorizontalScale(26)));
  262. }];
  263. [_editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  264. make.leading.equalTo(weakSelf.endBtn.mas_trailing).offset(15);
  265. make.centerY.equalTo(weakSelf.refreshBtn);
  266. make.size.mas_offset(CGSizeMake(HJHorizontalScale(53), HJHorizontalScale(26)));
  267. }];
  268. [_resumeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  269. make.trailing.equalTo(weakSelf.bgView.mas_trailing).offset(-15);
  270. make.centerY.equalTo(weakSelf.refreshBtn);
  271. make.size.mas_offset(CGSizeMake(HJHorizontalScale(69), HJHorizontalScale(27)));
  272. }];
  273. [_countlabel mas_makeConstraints:^(MASConstraintMaker *make) {
  274. make.right.top.offset(0);
  275. make.size.mas_offset(CGSizeMake(10, 10));
  276. }];
  277. }
  278. #pragma mark - event response
  279. /* 简历 */
  280. - (void)resumeButtonClick:(UIButton *)btn {
  281. self.resumeBlock(btn.selected);
  282. }
  283. /* 刷新 */
  284. - (void)refreshButtonClick:(UIButton *)btn {
  285. self.refreshButtonBlock(btn.selected);
  286. }
  287. /* 暂停 */
  288. - (void)stopButtonClick:(UIButton *)btn {
  289. self.stopButtonBlock(btn.selected);
  290. }
  291. /* 结束 */
  292. - (void)endButtonClick:(UIButton *)btn {
  293. self.endButtonBlock(btn.selected);
  294. }
  295. /* 编辑 */
  296. - (void)editButtonClick:(UIButton *)btn {
  297. self.editButtonBlock(btn.selected);
  298. }
  299. #pragma mark - getter and setter
  300. - (UIView *)bgView {
  301. if (_bgView == nil)
  302. {
  303. _bgView = [[UIView alloc]init];
  304. _bgView.backgroundColor = [UIColor whiteColor];
  305. }
  306. return _bgView;
  307. }
  308. - (UILabel *)updateTimelabel {
  309. if (_updateTimelabel == nil)
  310. {
  311. _updateTimelabel = [[UILabel alloc]init];
  312. _updateTimelabel.textColor = COLOR_GRAY9;
  313. _updateTimelabel.font = [UIFont systemFontOfSize:12];
  314. }
  315. return _updateTimelabel;
  316. }
  317. - (UILabel *)nameLabel {
  318. if (_nameLabel == nil)
  319. {
  320. _nameLabel = [[UILabel alloc]init];
  321. _nameLabel.textColor = COLOR_BACK3;
  322. _nameLabel.font = [UIFont systemFontOfSize:17];
  323. }
  324. return _nameLabel;
  325. }
  326. - (UIButton *)stateBtn {
  327. if (_stateBtn == nil)
  328. {
  329. _stateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  330. _stateBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  331. [_stateBtn setTitleColor:COLOR_GRAY9 forState:UIControlStateNormal];
  332. [_stateBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:3];
  333. }
  334. return _stateBtn;
  335. }
  336. - (UILabel *)addressLabel {
  337. if (_addressLabel == nil)
  338. {
  339. _addressLabel = [[UILabel alloc]init];
  340. _addressLabel.textColor = COLOR_BACK6;
  341. _addressLabel.font = [UIFont systemFontOfSize:12];
  342. }
  343. return _addressLabel;
  344. }
  345. - (UILabel *)timeLabel {
  346. if (_timeLabel == nil)
  347. {
  348. _timeLabel = [[UILabel alloc]init];
  349. _timeLabel.textColor = COLOR_BACK6;
  350. _timeLabel.font = [UIFont systemFontOfSize:12];
  351. }
  352. return _timeLabel;
  353. }
  354. - (UIButton *)refreshBtn {
  355. if (_refreshBtn == nil)
  356. {
  357. _refreshBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  358. [_refreshBtn setTitle:@"刷新" forState:UIControlStateNormal];
  359. _refreshBtn.selected = YES;
  360. [_refreshBtn setTitleColor:COLOR_BACK3 forState:UIControlStateSelected];
  361. [_refreshBtn setTitleColor:COLOR_GRAY9 forState:UIControlStateNormal];
  362. _refreshBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  363. _refreshBtn.layer.borderWidth = 1;
  364. _refreshBtn.layer.borderColor = COLOR_GRAY9.CGColor;
  365. _refreshBtn.layer.cornerRadius = 5;
  366. _refreshBtn.layer.masksToBounds = YES;
  367. [_refreshBtn addTarget:self action:@selector(refreshButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  368. }
  369. return _refreshBtn;
  370. }
  371. - (UIButton *)stopBtn {
  372. if (_stopBtn == nil)
  373. {
  374. _stopBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  375. [_stopBtn setTitle:@"暂停" forState:UIControlStateNormal];
  376. _stopBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  377. _stopBtn.selected = YES;
  378. [_stopBtn setTitleColor:COLOR_BACK3 forState:UIControlStateSelected];
  379. [_stopBtn setTitleColor:COLOR_GRAY9 forState:UIControlStateNormal];
  380. _stopBtn.layer.borderWidth = 1;
  381. _stopBtn.layer.borderColor = COLOR_GRAY9.CGColor;
  382. _stopBtn.layer.cornerRadius = 5;
  383. _stopBtn.layer.masksToBounds = YES;
  384. [_stopBtn addTarget:self action:@selector(stopButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  385. }
  386. return _stopBtn;
  387. }
  388. - (UIButton *)endBtn {
  389. if (_endBtn == nil)
  390. {
  391. _endBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  392. [_endBtn setTitle:@"下架" forState:UIControlStateNormal];
  393. _endBtn.selected = YES;
  394. [_endBtn setTitleColor:COLOR_BACK3 forState:UIControlStateSelected];
  395. [_endBtn setTitleColor:COLOR_GRAY9 forState:UIControlStateNormal];
  396. _endBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  397. _endBtn.layer.borderWidth = 1;
  398. _endBtn.layer.borderColor = COLOR_GRAY9.CGColor;
  399. _endBtn.layer.cornerRadius = 5;
  400. _endBtn.layer.masksToBounds = YES;
  401. [_endBtn addTarget:self action:@selector(endButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  402. }
  403. return _endBtn;
  404. }
  405. - (UIButton *)editBtn {
  406. if (_editBtn == nil)
  407. {
  408. _editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  409. [_editBtn setTitle:@"编辑" forState:UIControlStateNormal];
  410. _endBtn.selected = YES;
  411. [_editBtn setTitleColor:COLOR_BACK3 forState:UIControlStateSelected];
  412. [_editBtn setTitleColor:COLOR_GRAY9 forState:UIControlStateNormal];
  413. _editBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  414. _editBtn.layer.borderWidth = 1;
  415. _editBtn.layer.borderColor = COLOR_GRAY9.CGColor;
  416. _editBtn.layer.cornerRadius = 5;
  417. _editBtn.layer.masksToBounds = YES;
  418. [_editBtn addTarget:self action:@selector(editButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  419. }
  420. return _editBtn;
  421. }
  422. - (UIButton *)resumeBtn {
  423. if (_resumeBtn == nil)
  424. {
  425. _resumeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  426. _resumeBtn.selected = YES;
  427. [_resumeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  428. [_resumeBtn setTitleColor:COLOR_BACK3 forState:UIControlStateSelected];
  429. [_resumeBtn setTitle:@"简历管理" forState:UIControlStateNormal];
  430. _resumeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  431. _resumeBtn.layer.borderColor = COLOR_GRAY9.CGColor;
  432. _resumeBtn.layer.cornerRadius = 5;
  433. _resumeBtn.backgroundColor = COLOR_BACKE;
  434. [_resumeBtn addTarget:self action:@selector(resumeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  435. }
  436. return _resumeBtn;
  437. }
  438. - (UILabel *)countlabel {
  439. if (_countlabel == nil)
  440. {
  441. _countlabel = [[UILabel alloc]init];
  442. _countlabel.backgroundColor = COLOR_READFF;
  443. _countlabel.layer.cornerRadius = 5;
  444. _countlabel.layer.masksToBounds = YES;
  445. }
  446. return _countlabel;
  447. }
  448. - (UIView *)lineView {
  449. if (_lineView == nil)
  450. {
  451. _lineView = [[UIView alloc]init];
  452. _lineView.backgroundColor = COLOR_BACKE;
  453. }
  454. return _lineView;
  455. }
  456. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  457. [super setSelected:selected animated:animated];
  458. // Configure the view for the selected state
  459. }
  460. @end