Sin descripción

FKProBottomView.m 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. //
  2. // FKProBottomView.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/8/13.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKProBottomView.h"
  9. @interface FKProBottomView ()
  10. @property (nonatomic, strong) UIButton *goBuyBtn;
  11. @property (nonatomic, strong) UIButton *addBasketBtn;
  12. @property (nonatomic, strong) UIButton *collectBtn;
  13. @property (nonatomic, strong) UIButton *serveBtn;
  14. @property (nonatomic, copy) void(^actionBlock)(kProBottomAction actionType);
  15. @end
  16. @implementation FKProBottomView
  17. - (instancetype)initWithAction:(void(^)(kProBottomAction actionType))actionBlock{
  18. if (self = [super init]){
  19. [self addAllSubviews];
  20. self.actionBlock = actionBlock;
  21. }
  22. return self;
  23. }
  24. - (void)addAllSubviews{
  25. self.backgroundColor = [UIColor whiteColor];
  26. UIView *leftContainer = [[UIView alloc]init];
  27. UIView *topLine = [[UIView alloc]init];
  28. topLine.backgroundColor = UIColorFromRGB(0xcccccc);
  29. [self addSubview:leftContainer];
  30. [self addSubview:self.goBuyBtn];
  31. [self addSubview:self.addBasketBtn];
  32. [self addSubview:self.goToBasketBtn];
  33. [self addSubview:self.collectBtn];
  34. [self addSubview:self.serveBtn];
  35. [self addSubview:topLine];
  36. [self.goToBasketBtn addSubview:self.redPoint];
  37. CGFloat rightItemW = 100.0f;
  38. if (UISCREENWIDTH <= 320) {
  39. rightItemW = 80.0f;
  40. }
  41. CGFloat offsetY = 0;
  42. if (IS_IPHONE_X) {
  43. offsetY = -14;
  44. }
  45. [self.goBuyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.right.equalTo(self).offset(-10);
  47. make.centerY.equalTo(self).offset(offsetY);
  48. make.size.mas_equalTo(CGSizeMake(rightItemW, 40));
  49. }];
  50. [self.addBasketBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.right.equalTo(self.goBuyBtn.mas_left).offset(- 10);
  52. make.centerY.equalTo(self.goBuyBtn);
  53. make.size.mas_equalTo(CGSizeMake(rightItemW, 40));
  54. }];
  55. [leftContainer mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.left.top.bottom.equalTo(self);
  57. make.right.equalTo(self.addBasketBtn.mas_left);
  58. }];
  59. [self.collectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.centerY.equalTo(self.goBuyBtn);
  61. make.height.equalTo(self);
  62. make.centerX.equalTo(leftContainer);
  63. }];
  64. [self.goToBasketBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.equalTo(self.collectBtn.mas_right).offset(10);
  66. make.centerY.equalTo(self.goBuyBtn);
  67. make.height.equalTo(self);
  68. }];
  69. [self.serveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.right.equalTo(self.collectBtn.mas_left).offset(- 10);
  71. make.centerY.equalTo(self.goBuyBtn);
  72. make.height.equalTo(self);
  73. }];
  74. [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.left.right.top.equalTo(self);
  76. make.height.mas_equalTo(0.5);
  77. }];
  78. [self.redPoint mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.centerX.equalTo(self.goToBasketBtn).offset(8);
  80. make.centerY.equalTo(self.goToBasketBtn).offset(-10 + offsetY);
  81. make.width.height.mas_equalTo(5);
  82. }];
  83. }
  84. - (void)resetContentWithDataModel:(FKProductDetailItem *)dataModel specDataCenter:(FKProductSpecDataCenter *)dataCenter{
  85. if ([dataModel isKindOfClass:[FKProductDetailItem class]]) {
  86. self.collected = dataModel.currentUser.hasCollect;
  87. self.addBasketBtn.hidden = NO;
  88. self.goBuyBtn.hidden = NO;
  89. self.goBuyBtn.userInteractionEnabled = YES;
  90. [self.goBuyBtn setBackgroundColor:UIColorFromRGB(0xf85a5a)];
  91. [self.goBuyBtn setTitle:@"立即购买" forState:UIControlStateNormal];
  92. if (dataCenter && [dataCenter getTotalStock] <= 0){
  93. // 抢光
  94. self.goBuyBtn.userInteractionEnabled = NO;
  95. [self.goBuyBtn setBackgroundColor:UIColorFromRGB(0xcccccc)];
  96. [self.goBuyBtn setTitle:@"已抢光" forState:UIControlStateNormal];
  97. } else if (!dataModel.productInfo.productOnLine || ![dataModel.productInfo isProductValid]) {
  98. // 产品下线
  99. self.goBuyBtn.userInteractionEnabled = NO;
  100. [self.goBuyBtn setBackgroundColor:UIColorFromRGB(0xcccccc)];
  101. if ([dataModel.productInfo offLineStr]) {
  102. [self.goBuyBtn setTitle:[dataModel.productInfo offLineStr] forState:UIControlStateNormal];
  103. }
  104. } else if (dataModel.saleRule.isOnlyNew && dataModel.currentUser.hasEverBuy){
  105. // 新用户专享
  106. self.goBuyBtn.userInteractionEnabled = NO;
  107. [self.goBuyBtn setBackgroundColor:UIColorFromRGB(0xcccccc)];
  108. [self.goBuyBtn setTitle:@"新用户专享" forState:UIControlStateNormal];
  109. }
  110. }
  111. }
  112. - (void)setCollected:(BOOL)collected{
  113. _collected = collected;
  114. self.collectBtn.selected = collected;
  115. }
  116. - (void)clickActionBtn:(UIButton *)sender {
  117. if (sender.tag == kProBottomActionCollect) {
  118. self.collected = !self.collected;
  119. }
  120. if (self.actionBlock) {
  121. self.actionBlock(sender.tag);
  122. }
  123. }
  124. - (UIButton *)goBuyBtn{
  125. if (_goBuyBtn == nil) {
  126. UIFont *font = [UIFont systemFontOfSize:14];
  127. if (UISCREENWIDTH <= 320) {
  128. font = [UIFont systemFontOfSize:13];
  129. }
  130. _goBuyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  131. _goBuyBtn.titleLabel.font = font;
  132. _goBuyBtn.backgroundColor = UIColorFromRGB(0xff6362);
  133. _goBuyBtn.tag = kProBottomActionBuy;
  134. _goBuyBtn.hidden = YES;
  135. [_goBuyBtn setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
  136. [_goBuyBtn setTitle:@"立即购买" forState:UIControlStateNormal];
  137. [_goBuyBtn addTarget:self
  138. action:@selector(clickActionBtn:)
  139. forControlEvents:UIControlEventTouchUpInside];
  140. }
  141. return _goBuyBtn;
  142. }
  143. - (UIButton *)addBasketBtn{
  144. if (_addBasketBtn == nil) {
  145. UIFont *font = [UIFont systemFontOfSize:14];
  146. if (UISCREENWIDTH <= 320) {
  147. font = [UIFont systemFontOfSize:13];
  148. }
  149. _addBasketBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  150. _addBasketBtn.titleLabel.font = font;
  151. _addBasketBtn.layer.borderWidth = 1.0f;
  152. _addBasketBtn.layer.borderColor = UIColorFromRGB(0xff6362).CGColor;
  153. _addBasketBtn.tag = kProBottomActionAddBasket;
  154. _addBasketBtn.hidden = YES;
  155. [_addBasketBtn setTitleColor:UIColorFromRGB(0xff6362) forState:UIControlStateNormal];
  156. [_addBasketBtn setTitle:@"加入购物车" forState:UIControlStateNormal];
  157. [_addBasketBtn addTarget:self
  158. action:@selector(clickActionBtn:)
  159. forControlEvents:UIControlEventTouchUpInside];
  160. }
  161. return _addBasketBtn;
  162. }
  163. - (UIButton *)goToBasketBtn{
  164. if (_goToBasketBtn == nil) {
  165. _goToBasketBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  166. _goToBasketBtn.tag = kProBottomActionGoToBasket;
  167. [_goToBasketBtn setImage:[UIImage imageNamed:@"goToBasket"] forState:UIControlStateNormal];
  168. [_goToBasketBtn addTarget:self
  169. action:@selector(clickActionBtn:)
  170. forControlEvents:UIControlEventTouchUpInside];
  171. }
  172. return _goToBasketBtn;
  173. }
  174. - (UIButton *)collectBtn{
  175. if (_collectBtn == nil) {
  176. _collectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  177. _collectBtn.tag = kProBottomActionCollect;
  178. [_collectBtn setImage:[UIImage imageNamed:@"proCollect"] forState:UIControlStateNormal];
  179. [_collectBtn setImage:[UIImage imageNamed:@"proSelectedH"] forState:UIControlStateSelected];
  180. [_collectBtn addTarget:self
  181. action:@selector(clickActionBtn:)
  182. forControlEvents:UIControlEventTouchUpInside];
  183. }
  184. return _collectBtn;
  185. }
  186. - (UIButton *)serveBtn{
  187. if (_serveBtn == nil) {
  188. _serveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  189. _serveBtn.tag = kProBottomActionServer;
  190. [_serveBtn setImage:[UIImage imageNamed:@"goToServe"] forState:UIControlStateNormal];
  191. [_serveBtn addTarget:self
  192. action:@selector(clickActionBtn:)
  193. forControlEvents:UIControlEventTouchUpInside];
  194. }
  195. return _serveBtn;
  196. }
  197. - (UIView *)redPoint{
  198. if (_redPoint == nil) {
  199. _redPoint = [[UIView alloc]init];
  200. _redPoint.backgroundColor = UIColorFromRGB(0xff624a);
  201. _redPoint.layer.cornerRadius = 2.5f;
  202. _redPoint.hidden = YES;
  203. }
  204. return _redPoint;
  205. }
  206. @end