HJMyIntegralExchangeGiftDetailHeaderView.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //
  2. // HJMyIntegralExchangeGiftDetailHeaderView.m
  3. // HappyJob
  4. //
  5. // Created by 张晓光 on 2019/9/10.
  6. // Copyright © 2019 Bob. All rights reserved.
  7. //
  8. #import "HJMyIntegralExchangeGiftDetailHeaderView.h"
  9. #import "HJMyIntergralExchangeGiftDetailModel.h"
  10. @implementation HJMyIntegralExchangeGiftDetailHeaderView
  11. - (instancetype)initWithFrame:(CGRect)frame {
  12. if (self = [super initWithFrame:frame])
  13. {
  14. self.backgroundColor = COLOR_GRAYFA5;
  15. [self initSubViews];
  16. }
  17. return self;
  18. }
  19. - (void)initSubViews {
  20. [self addSubview:self.bgView];
  21. [self.bgView addSubview:self.titleLabel];
  22. [self.bgView addSubview:self.IntegralLabel];
  23. [self.bgView addSubview:self.conditionsLabel];
  24. [self.bgView addSubview:self.lineView];
  25. [self.bgView addSubview:self.inventoryLabel];
  26. [self.bgView addSubview:self.timeLabel];
  27. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.top.equalTo(self.mas_top).offset(10);
  29. make.left.equalTo(self.mas_left).offset(0);
  30. make.right.equalTo(self.mas_right).offset(0);
  31. make.bottom.equalTo(self.mas_bottom).offset(0);
  32. }];
  33. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.left.equalTo(self.bgView.mas_left).offset(15);
  35. make.top.equalTo(self.bgView.mas_top).offset(15);
  36. }];
  37. [self.IntegralLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.left.equalTo(self.bgView.mas_left).offset(15);
  39. make.top.equalTo(self.titleLabel.mas_bottom).offset(5);
  40. }];
  41. [self.conditionsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.right.equalTo(self.bgView.mas_right).offset(-15);
  43. make.centerY.equalTo(self.IntegralLabel);
  44. }];
  45. [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.equalTo(self.bgView.mas_left).offset(15);
  47. make.right.equalTo(self.bgView.mas_right).offset(-15);
  48. make.top.equalTo(self.IntegralLabel.mas_bottom).offset(20);
  49. make.height.mas_equalTo(1);
  50. }];
  51. [self.inventoryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.left.equalTo(self.bgView.mas_left).offset(15);
  53. make.top.equalTo(self.lineView.mas_bottom).offset(15);
  54. make.bottom.equalTo(self.bgView.mas_bottom).offset(-15);
  55. }];
  56. [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.right.equalTo(self.bgView.mas_right).offset(-15);
  58. make.centerY.equalTo(self.inventoryLabel);
  59. }];
  60. }
  61. - (void)configureHJMyIntegralExchangeGiftDetailHeaderViewDict:(NSDictionary *)dict {
  62. HJMyIntergralExchangeGiftDetailModel *model = [HJMyIntergralExchangeGiftDetailModel yy_modelWithDictionary:dict[@"data"]];
  63. self.titleLabel.text = model.mpCompaignsRewardSettingAPI.rewardName;
  64. if (model.mpCompaignsRewardSettingAPI.money)
  65. {
  66. self.IntegralLabel.text = [NSString stringWithFormat:@"%@积分 + %@元",model.mpCompaignsRewardSettingAPI.points,model.mpCompaignsRewardSettingAPI.money];
  67. }
  68. else
  69. {
  70. self.IntegralLabel.text = [NSString stringWithFormat:@"%@积分",model.mpCompaignsRewardSettingAPI.points];
  71. }
  72. if (model.mpCompaignsRewardSettingAPI.exchangeNumber)
  73. {
  74. self.conditionsLabel.text = [NSString stringWithFormat:@"每人限领%@份",model.mpCompaignsRewardSettingAPI.exchangeNumber];
  75. }
  76. //库存
  77. if (model.mpCompaignsRewardSettingAPI.rewardNumber)
  78. {
  79. self.inventoryLabel.text = [NSString stringWithFormat:@"库存:%ld 已领:%@",[model.mpCompaignsRewardSettingAPI.rewardNumber integerValue] - [model.mpCompaignsRewardSettingAPI.exchangeRewardNum integerValue],model.mpCompaignsRewardSettingAPI.exchangeRewardNum];
  80. }
  81. else
  82. {
  83. self.inventoryLabel.text = [NSString stringWithFormat:@"库存:不限 已领:%@",model.mpCompaignsRewardSettingAPI.exchangeRewardNum];
  84. }
  85. //兑换时间
  86. self.timeLabel.text = [NSString stringWithFormat:@"兑换时间:%@ - %@",[HJAppService time_timestampToString:[NSString stringWithFormat:@"%ld",(long)[HJAppService timeSwitchTimestamp:model.mpCompaignsRewardSettingAPI.exchangeStartDate]] withType:kTimeStampDateOnlyHorizonLine] ,[HJAppService time_timestampToString:[NSString stringWithFormat:@"%ld",(long)[HJAppService timeSwitchTimestamp:model.mpCompaignsRewardSettingAPI.exchangeEndDate]] withType:kTimeStampDateOnlyHorizonLine]];
  87. if ([self.timeLabel.text isEqualToString:@"兑换时间:1900-01-01 - 2100-01-01"])
  88. {
  89. self.timeLabel.text = @"兑换时间:不限";
  90. }
  91. }
  92. #pragma mark - setter and getter
  93. - (UIView *)bgView {
  94. if (_bgView == nil)
  95. {
  96. _bgView = [[UIView alloc]init];
  97. _bgView.backgroundColor = [UIColor whiteColor];
  98. }
  99. return _bgView;
  100. }
  101. - (UILabel *)titleLabel {
  102. if (_titleLabel == nil)
  103. {
  104. _titleLabel = [[UILabel alloc]init];
  105. _titleLabel.font = [UIFont boldSystemFontOfSize:18];
  106. _titleLabel.textColor = COLOR_BACK3;
  107. }
  108. return _titleLabel;
  109. }
  110. - (UILabel *)IntegralLabel {
  111. if (_IntegralLabel == nil)
  112. {
  113. _IntegralLabel = [[UILabel alloc]init];
  114. _IntegralLabel.font = [UIFont systemFontOfSize:14];
  115. _IntegralLabel.textColor = [UIColor colorFromHexString:@"FF7D0B"];
  116. }
  117. return _IntegralLabel;
  118. }
  119. - (UILabel *)conditionsLabel {
  120. if (_conditionsLabel == nil)
  121. {
  122. _conditionsLabel = [[UILabel alloc]init];
  123. _conditionsLabel.font = [UIFont systemFontOfSize:14];
  124. _conditionsLabel.textColor = COLOR_GRAY9;
  125. }
  126. return _conditionsLabel;
  127. }
  128. - (UIView *)lineView {
  129. if (_lineView == nil)
  130. {
  131. _lineView = [[UIView alloc]init];
  132. _lineView.backgroundColor = COLOR_BACKE;
  133. }
  134. return _lineView;
  135. }
  136. - (UILabel *)inventoryLabel {
  137. if (_inventoryLabel == nil)
  138. {
  139. _inventoryLabel = [[UILabel alloc]init];
  140. _inventoryLabel.font = [UIFont systemFontOfSize:12];
  141. _inventoryLabel.textColor = COLOR_BACK3;
  142. }
  143. return _inventoryLabel;
  144. }
  145. - (UILabel *)timeLabel {
  146. if (_timeLabel == nil)
  147. {
  148. _timeLabel = [[UILabel alloc]init];
  149. _timeLabel.font = [UIFont systemFontOfSize:12];
  150. _timeLabel.textColor = COLOR_BACK3;
  151. }
  152. return _timeLabel;
  153. }
  154. /*
  155. // Only override drawRect: if you perform custom drawing.
  156. // An empty implementation adversely affects performance during animation.
  157. - (void)drawRect:(CGRect)rect {
  158. // Drawing code
  159. }
  160. */
  161. @end