HJClockInStateView.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. //
  2. // HJClockInStateView.m
  3. // HappyJob
  4. //
  5. // Created by 张晓光 on 2020/8/24.
  6. // Copyright © 2020 Bob. All rights reserved.
  7. //
  8. #import "HJClockInStateView.h"
  9. @implementation HJClockInStateView
  10. - (instancetype)initWithFrame:(CGRect)frame {
  11. if (self = [super initWithFrame:frame])
  12. {
  13. [self initSubViews];
  14. }
  15. return self;
  16. }
  17. - (void)initSubViews {
  18. [self addSubview:self.bgView];
  19. [self.bgView addSubview:self.goWorkView];
  20. [self.goWorkView addSubview:self.goWorkLabel];
  21. [self.goWorkView addSubview:self.goWorkStateView];
  22. [self.bgView addSubview:self.afterWorkView];
  23. [self.afterWorkView addSubview:self.afterWorkLabel];
  24. [self.afterWorkView addSubview:self.afterWorkStateView];
  25. [self.bgView addSubview:self.ruleLabel];
  26. [self.bgView addSubview:self.clockInButton];
  27. [self.bgView addSubview:self.promptView];
  28. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.left.equalTo(self.mas_left).offset(15);
  30. make.top.equalTo(self.mas_top).offset(10);
  31. make.right.equalTo(self.mas_right).offset(-15);
  32. make.bottom.equalTo(self.mas_bottom).offset(-10);
  33. }];
  34. //上班打卡
  35. [self.goWorkView mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.left.equalTo(self.bgView.mas_left).offset(13);
  37. make.top.equalTo(self.bgView.mas_top).offset(15);
  38. make.width.mas_equalTo((SCREEN_WIDTH - 15*2 - 13*2 - 6)/2);
  39. }];
  40. [self.goWorkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.left.equalTo(self.goWorkView.mas_left).offset(15);
  42. make.top.equalTo(self.goWorkView.mas_top).offset(5);
  43. }];
  44. [self.goWorkStateView mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.left.equalTo(self.goWorkView.mas_left).offset(15);
  46. make.top.equalTo(self.goWorkLabel.mas_bottom).offset(2);
  47. make.bottom.equalTo(self.goWorkView.mas_bottom).offset(-5);
  48. }];
  49. //下班打卡
  50. [self.afterWorkView mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.right.equalTo(self.bgView.mas_right).offset(-13);
  52. make.top.equalTo(self.bgView.mas_top).offset(15);
  53. make.width.mas_equalTo((SCREEN_WIDTH - 15*2 - 13*2 - 6)/2);
  54. }];
  55. [self.afterWorkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.left.equalTo(self.afterWorkView.mas_left).offset(15);
  57. make.top.equalTo(self.afterWorkView.mas_top).offset(5);
  58. }];
  59. [self.afterWorkStateView mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.left.equalTo(self.afterWorkView.mas_left).offset(15);
  61. make.top.equalTo(self.afterWorkLabel.mas_bottom).offset(2);
  62. make.bottom.equalTo(self.afterWorkView.mas_bottom).offset(-5);
  63. }];
  64. //规则
  65. [self.ruleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.left.equalTo(self.bgView.mas_left).offset(28);
  67. make.top.equalTo(self.goWorkView.mas_bottom).offset(10);
  68. }];
  69. //打卡
  70. [self.clockInButton mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.center.equalTo(self.bgView);
  72. make.size.mas_equalTo(CGSizeMake(140, 140));
  73. }];
  74. }
  75. - (void)setStateType:(HJClockInStateType)stateType {
  76. _stateType = stateType;
  77. switch (stateType) {
  78. case HJClockInStateTypeAuthing:
  79. {//审核中
  80. [self.clockInButton setImage:[UIImage imageNamed:@"clockin_audit"] forState:UIControlStateNormal];
  81. self.promptView.icon.image = [UIImage imageNamed:@"clockIn_state_warning"];
  82. self.promptView.textLabel.text = @"我们会尽快完成实名认证审核";
  83. [self goWork];
  84. }
  85. break;
  86. case HJClockInStateTypeGoWork:
  87. {//上班
  88. [self.clockInButton setImage:[UIImage imageNamed:@"clockIn_can"] forState:UIControlStateNormal];
  89. self.promptView.icon.image = [UIImage imageNamed:@"clockIn_state_can"];
  90. self.promptView.textLabel.text = @"已进入考勤打卡范围";
  91. [self goWork];
  92. }
  93. break;
  94. case HJClockInStateTypeGoWorkComplete:
  95. {//上班打卡完成,下班打卡还没开始
  96. [self.clockInButton setImage:[UIImage imageNamed:@"clockOut_disable"] forState:UIControlStateNormal];
  97. self.promptView.icon.image = [UIImage imageNamed:@"clockIn_state_warning"];
  98. [self afterWork];
  99. }
  100. break;
  101. case HJClockInStateTypeAfterWork:
  102. {//下班
  103. [self.clockInButton setImage:[UIImage imageNamed:@"clockOut_can"] forState:UIControlStateNormal];
  104. self.promptView.icon.image = [UIImage imageNamed:@"clockIn_state_can"];
  105. self.promptView.textLabel.text = @"已进入考勤打卡范围";
  106. [self afterWork];
  107. }
  108. break;
  109. case HJClockInStateTypeComplete:
  110. {//打卡完成
  111. [self.clockInButton setImage:[UIImage imageNamed:@"clockIn_done"] forState:UIControlStateNormal];
  112. self.promptView.icon.image = [UIImage imageNamed:@"clockIn_state_can"];
  113. self.promptView.textLabel.text = @"今日打卡已完成";
  114. [self complete];
  115. }
  116. break;
  117. case HJClockInStateTypeGoWorkOutOfRange:
  118. {//上班超出范围
  119. [self.clockInButton setImage:[UIImage imageNamed:@"clockin_beyond"] forState:UIControlStateNormal];
  120. self.promptView.icon.image = [UIImage imageNamed:@"clockIn_state_warning"];
  121. self.promptView.textLabel.text = @"请进入企业后再进行打卡";
  122. //从当前的下班打卡到下一个上班打卡
  123. self.goWorkStateView.icon.image = nil;
  124. [self.goWorkStateView.textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  125. make.left.equalTo(self.goWorkStateView.icon.mas_right).offset(0);
  126. }];
  127. [self outOfRange];
  128. }
  129. break;
  130. case HJClockInStateTypeAfterWorkOutOfRange:
  131. {//下班超出范围
  132. [self.clockInButton setImage:[UIImage imageNamed:@"clockin_beyond"] forState:UIControlStateNormal];
  133. self.promptView.icon.image = [UIImage imageNamed:@"clockIn_state_warning"];
  134. self.promptView.textLabel.text = @"请进入企业后再进行打卡";
  135. //上班已经完成了
  136. self.goWorkStateView.icon.image = [UIImage imageNamed:@"clockIn_icon"];
  137. [self.goWorkStateView.textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  138. make.left.equalTo(self.goWorkStateView.icon.mas_right).offset(3);
  139. }];
  140. [self outOfRange];
  141. }
  142. break;
  143. default:
  144. break;
  145. }
  146. }
  147. /* 上班 */
  148. - (void)goWork{
  149. [self.retryButton removeFromSuperview];
  150. [self.lineView removeFromSuperview];
  151. [self.wageView removeFromSuperview];
  152. //从当前的下班打卡到下一个上班打卡
  153. self.goWorkStateView.icon.image = nil;
  154. [self.goWorkStateView.textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  155. make.left.equalTo(self.goWorkStateView.icon.mas_right).offset(0);
  156. }];
  157. //下班打卡完成
  158. self.afterWorkStateView.icon.image = nil;
  159. [self.afterWorkStateView.textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  160. make.left.equalTo(self.afterWorkStateView.icon.mas_right).offset(0);
  161. }];
  162. [self.promptView mas_makeConstraints:^(MASConstraintMaker *make) {
  163. make.top.equalTo(self.clockInButton.mas_bottom).offset(25);
  164. make.centerX.equalTo(self.bgView);
  165. // make.bottom.equalTo(self.bgView.mas_bottom).offset(-HJXVerticalScale(50));
  166. }];
  167. [self.promptView.textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  168. make.left.equalTo(self.promptView.icon.mas_right).offset(6);
  169. }];
  170. }
  171. /* 下班 */
  172. - (void)afterWork {
  173. [self.retryButton removeFromSuperview];
  174. [self.lineView removeFromSuperview];
  175. [self.wageView removeFromSuperview];
  176. //上班打卡完成了
  177. self.goWorkStateView.icon.image = [UIImage imageNamed:@"clockIn_icon"];
  178. [self.goWorkStateView.textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  179. make.left.equalTo(self.goWorkStateView.icon.mas_right).offset(3);
  180. }];
  181. [self.promptView mas_makeConstraints:^(MASConstraintMaker *make) {
  182. make.top.equalTo(self.clockInButton.mas_bottom).offset(25);
  183. make.centerX.equalTo(self.bgView);
  184. // make.bottom.equalTo(self.bgView.mas_bottom).offset(-HJXVerticalScale(50));
  185. }];
  186. [self.promptView.textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  187. make.left.equalTo(self.promptView.icon.mas_right).offset(6);
  188. }];
  189. }
  190. /* 打卡完成 */
  191. - (void)complete {
  192. [self.retryButton removeFromSuperview];
  193. [self.bgView addSubview:self.lineView];
  194. [self.bgView addSubview:self.wageView];
  195. //上班打卡完成
  196. self.goWorkStateView.icon.image = [UIImage imageNamed:@"clockIn_icon"];
  197. [self.goWorkStateView.textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  198. make.left.equalTo(self.goWorkStateView.icon.mas_right).offset(3);
  199. }];
  200. //下班打卡完成
  201. self.afterWorkStateView.icon.image = [UIImage imageNamed:@"clockIn_icon"];
  202. [self.afterWorkStateView.textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  203. make.left.equalTo(self.afterWorkStateView.icon.mas_right).offset(3);
  204. }];
  205. [self.promptView mas_remakeConstraints:^(MASConstraintMaker *make) {
  206. make.top.equalTo(self.clockInButton.mas_bottom).offset(25);
  207. make.centerX.equalTo(self.bgView);
  208. // make.bottom.equalTo(self.bgView.mas_bottom).offset(-HJXVerticalScale(50));
  209. }];
  210. [self.promptView.textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  211. make.left.equalTo(self.promptView.icon.mas_right).offset(6);
  212. }];
  213. // [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
  214. //
  215. // make.left.right.equalTo(self.bgView).offset(0);
  216. // make.top.equalTo(self.promptView.mas_bottom).offset(HJXVerticalScale(50));
  217. // make.height.mas_equalTo(1);
  218. // }];
  219. // [self.wageView mas_remakeConstraints:^(MASConstraintMaker *make) {
  220. //
  221. // make.left.equalTo(self.bgView.mas_left).offset(15);
  222. // make.right.equalTo(self.bgView.mas_right).offset(-15);
  223. // make.top.equalTo(self.lineView.mas_bottom).offset(HJXVerticalScale(30));
  224. // make.bottom.equalTo(self.bgView.mas_bottom).offset(-HJXVerticalScale(25));
  225. // }];
  226. }
  227. /* 超出范围 */
  228. - (void)outOfRange {
  229. [self.bgView addSubview:self.retryButton];
  230. [self.lineView removeFromSuperview];
  231. [self.wageView removeFromSuperview];
  232. [self.promptView mas_remakeConstraints:^(MASConstraintMaker *make) {
  233. make.top.equalTo(self.clockInButton.mas_bottom).offset(25);
  234. make.centerX.equalTo(self.bgView);
  235. }];
  236. [self.promptView.textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
  237. make.left.equalTo(self.promptView.icon.mas_right).offset(6);
  238. }];
  239. [self.retryButton mas_remakeConstraints:^(MASConstraintMaker *make) {
  240. make.top.equalTo(self.promptView.mas_bottom).offset(40);
  241. make.centerX.equalTo(self.bgView);
  242. // make.bottom.equalTo(self.bgView.mas_bottom).offset(-HJVerticalScale(50));
  243. }];
  244. }
  245. #pragma mark - lazy
  246. - (UIView *)bgView {
  247. if (_bgView == nil)
  248. {
  249. _bgView = [[UIView alloc] init];
  250. _bgView.backgroundColor = [UIColor whiteColor];
  251. _bgView.layer.cornerRadius = 8;
  252. }
  253. return _bgView;
  254. }
  255. - (UIView *)goWorkView {
  256. if (_goWorkView == nil)
  257. {
  258. _goWorkView = [[UIView alloc] init];
  259. _goWorkView.backgroundColor = COLOR_F5F5F5;
  260. _goWorkView.layer.cornerRadius = 4;
  261. }
  262. return _goWorkView;
  263. }
  264. - (UILabel *)goWorkLabel {
  265. if (_goWorkLabel == nil)
  266. {
  267. _goWorkLabel = [[UILabel alloc] init];
  268. _goWorkLabel.textColor = COLOR_000000;
  269. _goWorkLabel.text = @"上班打卡";
  270. _goWorkLabel.font = [UIFont systemFontOfSize:14];
  271. }
  272. return _goWorkLabel;
  273. }
  274. - (HJClockInLabelImageView *)goWorkStateView {
  275. if (_goWorkStateView == nil)
  276. {
  277. _goWorkStateView = [[HJClockInLabelImageView alloc] init];
  278. _goWorkStateView.textLabel.text = @"未完成";
  279. _goWorkStateView.textLabel.textColor = COLOR_999999;
  280. _goWorkStateView.textLabel.font = [UIFont systemFontOfSize:13];
  281. }
  282. return _goWorkStateView;
  283. }
  284. - (UIView *)afterWorkView {
  285. if (_afterWorkView == nil)
  286. {
  287. _afterWorkView = [[UIView alloc] init];
  288. _afterWorkView.backgroundColor = COLOR_F5F5F5;
  289. _afterWorkView.layer.cornerRadius = 4;
  290. }
  291. return _afterWorkView;
  292. }
  293. - (UILabel *)afterWorkLabel {
  294. if (_afterWorkLabel == nil)
  295. {
  296. _afterWorkLabel = [[UILabel alloc] init];
  297. _afterWorkLabel.textColor = COLOR_000000;
  298. _afterWorkLabel.text = @"下班打卡";
  299. _afterWorkLabel.font = [UIFont systemFontOfSize:14];
  300. }
  301. return _afterWorkLabel;
  302. }
  303. - (HJClockInLabelImageView *)afterWorkStateView {
  304. if (_afterWorkStateView == nil)
  305. {
  306. _afterWorkStateView = [[HJClockInLabelImageView alloc] init];
  307. _afterWorkStateView.textLabel.text = @"未完成";
  308. _afterWorkStateView.textLabel.textColor = COLOR_999999;
  309. _afterWorkStateView.textLabel.font = [UIFont systemFontOfSize:13];
  310. }
  311. return _afterWorkStateView;
  312. }
  313. - (UILabel *)ruleLabel {
  314. if (_ruleLabel == nil)
  315. {
  316. _ruleLabel = [[UILabel alloc] init];
  317. _ruleLabel.text = @"请根据企业实际上下班时间打卡";
  318. _ruleLabel.font = [UIFont systemFontOfSize:12];
  319. _ruleLabel.textColor = COLOR_999999;
  320. }
  321. return _ruleLabel;
  322. }
  323. - (UIButton *)clockInButton {
  324. if (_clockInButton == nil)
  325. {
  326. _clockInButton = [UIButton buttonWithType:UIButtonTypeCustom];
  327. }
  328. return _clockInButton;
  329. }
  330. - (HJClockInLabelImageView *)promptView {
  331. if (_promptView == nil)
  332. {
  333. _promptView = [[HJClockInLabelImageView alloc] init];
  334. _promptView.textLabel.text = @"已进入考勤打卡范围";
  335. _promptView.textLabel.font = [UIFont systemFontOfSize:13];
  336. _promptView.icon.image = [UIImage imageNamed:@"clockIn_state_complete"];//clockIn_state_complete,clockIn_state_can
  337. }
  338. return _promptView;
  339. }
  340. - (UIButton *)retryButton {
  341. if (_retryButton == nil)
  342. {
  343. _retryButton = [UIButton buttonWithType:UIButtonTypeCustom];
  344. [_retryButton setTitle:@"重新定位" forState:UIControlStateNormal];
  345. [_retryButton setTitleColor:COLOR_0177FF forState:UIControlStateNormal];
  346. [_retryButton setImage:[UIImage imageNamed:@"retry_location"] forState:UIControlStateNormal];
  347. _retryButton.titleLabel.font = [UIFont boldSystemFontOfSize:13];
  348. [_retryButton layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:5];
  349. }
  350. return _retryButton;
  351. }
  352. - (UIView *)lineView {
  353. if (_lineView == nil)
  354. {
  355. _lineView = [[UIView alloc] init];
  356. _lineView.backgroundColor = COLOR_EEEEEE;
  357. }
  358. return _lineView;
  359. }
  360. - (HJClockInStatisticWageView *)wageView {
  361. if (_wageView == nil)
  362. {
  363. _wageView = [[HJClockInStatisticWageView alloc] init];
  364. }
  365. return _wageView;
  366. }
  367. @end