省钱达人

DRGoodDetailView.m 9.7KB

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