口袋优选

KBGoodDetailView.m 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. //
  2. // KBGoodDetailView.m
  3. // YouHuiProject
  4. //
  5. // Created by xiaoxi on 2018/1/25.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBGoodDetailView.h"
  9. #import "KBGoodDetailModel.h"
  10. #import "KBGotoDetailView.h"
  11. #import "UIView+SDAutoLayout.h"
  12. #import "CCCopyLabel.h"
  13. @interface KBGoodDetailView ()
  14. @property (nonatomic, strong) CCCopyLabel *goodTitleLabel;
  15. @property (nonatomic, strong) UILabel *priceLabel;
  16. @property (nonatomic, strong) UIImageView *discountImageView;
  17. @property (nonatomic, strong) UILabel *discountPriceLabel;
  18. @property (nonatomic, strong) UILabel *freePostLabel;
  19. @property (nonatomic, strong) UILabel *volumeLabel;
  20. @property (nonatomic, strong) UILabel *quanType;
  21. @property (nonatomic, strong) UILabel *quanNum;
  22. @property (nonatomic, strong) UILabel *commissionPrice;
  23. @end
  24. @implementation KBGoodDetailView
  25. - (instancetype)initWithFrame:(CGRect)frame {
  26. self = [super initWithFrame:frame];
  27. if (self) {
  28. self.backgroundColor = [UIColor whiteColor];
  29. [self initSubviews];
  30. }
  31. return self;
  32. }
  33. - (void)setGoodModel:(KBGoodDetailModel *)goodModel {
  34. _goodModel = goodModel;
  35. NSString *quanType = [goodModel.is_coupon boolValue]?@"券":@"折";
  36. self.quanType.text = quanType;
  37. NSString *quanNum = [goodModel.is_coupon boolValue]?[NSString stringWithFormat:@"%@元",goodModel.coupon_price]:[NSString stringWithFormat:@"%@折",goodModel.coupon_price];
  38. self.quanNum.text = quanNum;
  39. //标题
  40. NSTextAttachment *textAttach = [[NSTextAttachment alloc]init];
  41. UIImage *img;
  42. if ([goodModel.shop_type isEqualToString:@"1"]) {
  43. img= [UIImage imageNamed:@"tm_shop"];
  44. }else if([goodModel.shop_type isEqualToString:@"0"]){
  45. // img= [UIImage imageNamed:@"share_title_tb"];
  46. }
  47. if (img) {
  48. textAttach.image = img;
  49. textAttach.bounds = CGRectMake(0, -4, img.size.width, img.size.height);
  50. }
  51. NSMutableAttributedString *attri;
  52. if ([goodModel.shop_type isEqualToString:@"1"]) {
  53. attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",goodModel.title]];
  54. }else {
  55. attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",goodModel.title]];
  56. }
  57. NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:textAttach];
  58. [attri insertAttributedString:string atIndex:0];
  59. NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  60. [paragraphStyle setLineSpacing:8];
  61. [attri addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [string length])];
  62. self.goodTitleLabel.textStr = goodModel.title;
  63. self.goodTitleLabel.attributedText = attri;
  64. NSString *priceText = [NSString stringWithFormat:@"原价 ¥%.2f", [goodModel.price floatValue]];
  65. // NSMutableAttributedString *attritu = [[NSMutableAttributedString alloc]initWithString:priceText];
  66. // [attritu addAttributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleThick),
  67. // NSForegroundColorAttributeName:[UIColor lightGrayColor],
  68. // NSBaselineOffsetAttributeName:@(0),
  69. // } range:[priceText rangeOfString:priceText]];
  70. self.priceLabel.text = priceText;
  71. NSString *dis_price = [goodModel.is_coupon boolValue] ? [NSString stringWithFormat:@"券后 ¥%.2f", [goodModel.discount_price floatValue]]:[NSString stringWithFormat:@"折后 ¥%.2f", [goodModel.discount_price floatValue]];
  72. NSMutableAttributedString *dispriceAttr = [[NSMutableAttributedString alloc]initWithString:dis_price];
  73. [dispriceAttr addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:13]} range:NSMakeRange(0, 3)];
  74. self.discountPriceLabel.attributedText = dispriceAttr;
  75. self.volumeLabel.text = [NSString stringWithFormat:@"月销 %@", goodModel.volume];
  76. self.freePostLabel.text = [goodModel.freeShipping isEqual:@1] ? @"包邮" : [NSString stringWithFormat:@"邮费 %@", goodModel.postage];
  77. self.discountImageView.hidden = ![goodModel.is_coupon boolValue];
  78. }
  79. - (void)initSubviews {
  80. [self addSubview:self.goodTitleLabel];
  81. [self addSubview:self.priceLabel];
  82. [self addSubview:self.discountImageView];
  83. [self addSubview:self.discountPriceLabel];
  84. [self addSubview:self.volumeLabel];
  85. [self addSubview:self.commissionPrice];
  86. [self.discountImageView addSubview:self.quanType];
  87. [self.discountImageView addSubview:self.quanNum];
  88. [self makeSubviewsConstraints];
  89. }
  90. - (void)makeSubviewsConstraints {
  91. [self.discountPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.left.mas_equalTo(FITSIZE(10));
  93. make.top.mas_equalTo(Fitsize(15));
  94. make.width.mas_lessThanOrEqualTo(Fitsize(200));
  95. make.height.mas_lessThanOrEqualTo(Fitsize(20));
  96. }];
  97. [self.discountImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.left.mas_equalTo(self.discountPriceLabel.mas_right).mas_offset(10);
  99. make.centerY.mas_equalTo(self.discountPriceLabel.mas_centerY);
  100. make.width.mas_equalTo(64);
  101. make.height.mas_equalTo(14);
  102. }];
  103. [self.quanType mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.top.left.bottom.mas_equalTo(0);
  105. make.width.mas_equalTo(20);
  106. }];
  107. [self.quanNum mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.left.mas_equalTo(20);
  109. make.top.bottom.right.mas_equalTo(0);
  110. }];
  111. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.left.equalTo(self.discountPriceLabel);
  113. make.top.equalTo(self.discountPriceLabel.mas_bottom).offset(FITSIZE(15));
  114. }];
  115. [self.goodTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  116. make.top.mas_equalTo(self.priceLabel.mas_bottom).offset(FITSIZE(10));
  117. make.left.equalTo(self.discountPriceLabel);
  118. make.right.equalTo(self).offset(-FITSIZE(10));
  119. }];
  120. [self.volumeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.right.equalTo(self).offset(-FITSIZE(20));
  122. make.centerY.mas_equalTo(self.priceLabel.mas_centerY);
  123. }];
  124. [self.commissionPrice mas_makeConstraints:^(MASConstraintMaker *make) {
  125. make.right.mas_equalTo(self.volumeLabel.mas_right);
  126. make.bottom.mas_equalTo(self.discountPriceLabel.mas_bottom);
  127. }];
  128. }
  129. - (void)couponTapAction:(UIGestureRecognizer *)sender {
  130. if ([self.delegate respondsToSelector:@selector(yh_GoodDetailViewTapCoupon)]) {
  131. [self.delegate yh_GoodDetailViewTapCoupon];
  132. }
  133. }
  134. - (void)shopTapAction:(UIGestureRecognizer *)sender {
  135. if ([self.delegate respondsToSelector:@selector(yh_GoodDetailViewTapShop)]) {
  136. [self.delegate yh_GoodDetailViewTapShop];
  137. }
  138. }
  139. #pragma mark - lazy
  140. - (CCCopyLabel *)goodTitleLabel {
  141. if (!_goodTitleLabel) {
  142. _goodTitleLabel = [[CCCopyLabel alloc] init];
  143. _goodTitleLabel.backgroundColor = [UIColor clearColor];
  144. _goodTitleLabel.textColor = [UIColor YHColorWithHex:0x222222];
  145. _goodTitleLabel.font = [UIFont systemFontOfSize:FITSIZE(14)];
  146. _goodTitleLabel.numberOfLines = 2;
  147. // _goodTitleLabel.hidden=YES;
  148. }
  149. return _goodTitleLabel;
  150. }
  151. - (UILabel *)priceLabel {
  152. if (!_priceLabel) {
  153. _priceLabel = [[UILabel alloc] init];
  154. _priceLabel.backgroundColor = [UIColor clearColor];
  155. _priceLabel.textColor = [UIColor YHColorWithHex:0x999999];
  156. _priceLabel.font = [UIFont systemFontOfSize:FITSIZE(13)];
  157. }
  158. return _priceLabel;
  159. }
  160. - (UIImageView *)discountImageView {
  161. if (!_discountImageView) {
  162. _discountImageView = [[UIImageView alloc] init];
  163. _discountImageView.backgroundColor = [UIColor clearColor];
  164. _discountImageView.image = [UIImage imageNamed:@"quan_bg"];
  165. _discountImageView.hidden = YES;
  166. }
  167. return _discountImageView;
  168. }
  169. - (UILabel *)discountPriceLabel {
  170. if (!_discountPriceLabel) {
  171. _discountPriceLabel = [[UILabel alloc] init];
  172. _discountPriceLabel.backgroundColor = [UIColor clearColor];
  173. _discountPriceLabel.textColor = [UIColor YHColorWithHex:0xff2420];
  174. _discountPriceLabel.font = [UIFont systemFontOfSize:FITSIZE(22)];
  175. }
  176. return _discountPriceLabel;
  177. }
  178. - (UILabel *)freePostLabel {
  179. if (!_freePostLabel) {
  180. _freePostLabel = [[UILabel alloc] init];
  181. _freePostLabel.backgroundColor = [UIColor clearColor];
  182. _freePostLabel.textColor = [UIColor YHColorWithHex:0x999999];
  183. _freePostLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
  184. }
  185. return _freePostLabel;
  186. }
  187. - (UILabel *)volumeLabel {
  188. if (!_volumeLabel) {
  189. _volumeLabel = [[UILabel alloc] init];
  190. _volumeLabel.backgroundColor = [UIColor clearColor];
  191. _volumeLabel.textColor = [UIColor YHColorWithHex:0x999999];
  192. _volumeLabel.font = [UIFont systemFontOfSize:FITSIZE(11)];
  193. }
  194. return _volumeLabel;
  195. }
  196. - (UILabel *)quanType {
  197. if (!_quanType) {
  198. _quanType = [[UILabel alloc] init];
  199. _quanType.textColor = [UIColor whiteColor];
  200. _quanType.font = [UIFont boldSystemFontOfSize:10];
  201. _quanType.textAlignment = NSTextAlignmentCenter;
  202. }
  203. return _quanType;
  204. }
  205. - (UILabel *)quanNum {
  206. if (!_quanNum) {
  207. _quanNum = [[UILabel alloc] init];
  208. _quanNum.textColor = [UIColor whiteColor];
  209. _quanNum.font = [UIFont boldSystemFontOfSize:10];
  210. _quanNum.textAlignment = NSTextAlignmentCenter;
  211. }
  212. return _quanNum;
  213. }
  214. - (UILabel *)commissionPrice {
  215. if (!_commissionPrice) {
  216. _commissionPrice = [[UILabel alloc] init];
  217. _commissionPrice.textColor = [UIColor homeRedColor];
  218. _commissionPrice.font = [UIFont systemFontOfSize:Fitsize(14)];
  219. _commissionPrice.textAlignment = NSTextAlignmentRight;
  220. _commissionPrice.hidden = YES;
  221. }
  222. return _commissionPrice;
  223. }
  224. @end