猎豆优选

LDTodayHorizontalGoodCell.m 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. //
  2. // LDTodayHorizontalGoodCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/12/11.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDTodayHorizontalGoodCell.h"
  9. @interface LDTodayHorizontalGoodCell ()
  10. @property (nonatomic, strong) UIImageView *imgView; //大图
  11. @property (nonatomic, strong) YYLabel *titleLabel; //标题
  12. @property (nonatomic, strong) UILabel *priceLabel; //原价
  13. @property (nonatomic, strong) UILabel *disPriceL; // 优惠后价格
  14. @property (nonatomic, strong) UIImageView *ticketNumber; //
  15. @property (nonatomic, strong) UILabel *zheKou; // 几折,或者几元券
  16. @property (nonatomic, strong) UILabel *ticketType;
  17. @property (nonatomic, strong) YYLabel *shopInfo;
  18. @property (nonatomic, strong) UIView *commissionBg;
  19. @property (nonatomic, strong) UILabel *commissionLabel;
  20. @property (nonatomic, strong) UILabel *volum;
  21. @property (nonatomic, strong) UILabel *redpriceLabel;//红包
  22. @property (nonatomic, strong) UIImageView *redImgV;
  23. @end
  24. @implementation LDTodayHorizontalGoodCell
  25. - (instancetype)initWithFrame:(CGRect)frame {
  26. self = [super initWithFrame:frame];
  27. if (self) {
  28. self.contentView.backgroundColor = [UIColor whiteColor];
  29. [self initSubViews];
  30. }
  31. return self;
  32. }
  33. - (void)initSubViews {
  34. [self.contentView addSubview:self.imgView];
  35. [self.contentView addSubview:self.titleLabel];
  36. [self.contentView addSubview:self.priceLabel];
  37. [self.contentView addSubview:self.disPriceL];
  38. [self.contentView addSubview:self.ticketNumber];
  39. [self.ticketNumber addSubview:self.zheKou];
  40. [self.ticketNumber addSubview:self.ticketType];
  41. [self.contentView addSubview:self.shopInfo];
  42. [self.contentView addSubview:self.commissionBg];
  43. [self.commissionBg addSubview:self.commissionLabel];
  44. [self.contentView addSubview:self.volum];
  45. [self.contentView addSubview:self.redpriceLabel];
  46. [self.contentView addSubview:self.redImgV];
  47. [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.top.mas_equalTo(16);
  49. make.left.mas_equalTo(8);
  50. make.width.height.mas_equalTo(115);
  51. }];
  52. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.mas_equalTo(self.imgView.mas_right).mas_offset(12);
  54. make.top.mas_equalTo(self.imgView).mas_offset(3);
  55. make.right.mas_equalTo(-10);
  56. }];
  57. [self.shopInfo mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.mas_equalTo(self.titleLabel);
  59. make.centerY.mas_equalTo(self.imgView.mas_centerY);
  60. }];
  61. [self.disPriceL mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.left.mas_equalTo(self.shopInfo.mas_left);
  63. make.top.mas_equalTo(self.shopInfo.mas_bottom).mas_offset(6);
  64. }];
  65. [self.redImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.bottom.mas_equalTo(self.imgView.mas_bottom).mas_offset(-2);
  67. make.left.mas_equalTo(self.titleLabel.mas_left);
  68. make.width.mas_equalTo(13);
  69. make.height.mas_equalTo(15);
  70. }];
  71. [self.redpriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.bottom.mas_equalTo(self.imgView.mas_bottom).mas_offset(-2);
  73. make.left.mas_equalTo(self.redImgV.mas_right);
  74. make.height.mas_equalTo(15);
  75. }];
  76. [self.ticketNumber mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.bottom.mas_equalTo(self.imgView.mas_bottom).mas_offset(-2);
  78. make.left.mas_equalTo(self.redpriceLabel.mas_right);
  79. make.width.mas_equalTo(64);
  80. make.height.mas_equalTo(15);
  81. }];
  82. [self.ticketType mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.left.top.bottom.mas_equalTo(0);
  84. make.width.mas_equalTo(20);
  85. }];
  86. [self.zheKou mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.left.mas_equalTo(20);
  88. make.top.bottom.right.mas_equalTo(0);
  89. }];
  90. [self.commissionBg mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.left.mas_equalTo(self.redpriceLabel.mas_right).mas_offset(10);
  92. make.width.mas_equalTo(65);
  93. make.height.mas_equalTo(15);
  94. make.bottom.mas_equalTo(self.imgView.mas_bottom).mas_offset(-2);
  95. }];
  96. [self.commissionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
  98. }];
  99. [self.volum mas_makeConstraints:^(MASConstraintMaker *make) {
  100. make.left.mas_equalTo(self.disPriceL.mas_right).mas_offset(10);
  101. make.centerY.mas_equalTo(self.disPriceL.mas_centerY);
  102. }];
  103. }
  104. - (void)setModel:(LDChildGoodModel *)model {
  105. //标题
  106. //标题
  107. NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",model.title]];
  108. attri.yy_font = [UIFont boldSystemFontOfSize:14];
  109. attri.yy_color = [UIColor blackColor];
  110. attri.yy_lineSpacing = 6;
  111. self.titleLabel.attributedText = attri;
  112. if (model.red_active_status.integerValue == 1) {//判断是否有红包
  113. self.redpriceLabel.text=[NSString stringWithFormat:@" %@元红包 ",model.red_active_money];
  114. [self.redImgV mas_updateConstraints:^(MASConstraintMaker *make) {
  115. make.width.mas_equalTo(13);
  116. }];
  117. }else{
  118. [self.redImgV mas_updateConstraints:^(MASConstraintMaker *make) {
  119. make.width.mas_equalTo(0);
  120. }];
  121. }
  122. //店铺信息
  123. if (model.shop_title.length > 0) {
  124. UIImage *img;
  125. if ([model.shop_type isEqualToString:@"1"]) {
  126. img= [UIImage imageNamed:@"tm_shop"];
  127. }else {
  128. img= [UIImage imageNamed:@"taobao_shop"];
  129. }
  130. YYAnimatedImageView *imgeView = [[YYAnimatedImageView alloc] initWithImage:img];
  131. imgeView.frame = CGRectMake(0, 0, 15, 15);
  132. NSMutableAttributedString *shopAtti = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",model.shop_title]];
  133. NSMutableAttributedString *mua = [NSMutableAttributedString yy_attachmentStringWithContent:imgeView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imgeView.frame.size alignToFont:[UIFont systemFontOfSize:14] alignment:YYTextVerticalAlignmentCenter];
  134. [shopAtti insertAttributedString:mua atIndex:0];
  135. shopAtti.yy_font = [UIFont systemFontOfSize:12];
  136. shopAtti.yy_color = [UIColor YHColorWithHex:0x9B9B9B];
  137. self.shopInfo.attributedText = shopAtti;
  138. self.shopInfo.hidden = NO;
  139. }else {
  140. self.shopInfo.hidden = YES;
  141. }
  142. //
  143. //大图
  144. [self.imgView yy_setImageWithURL:[NSURL URLWithString:model.img] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];
  145. //折后价
  146. NSString *disStr;
  147. if ([model.is_coupon boolValue]) {
  148. disStr = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
  149. self.zheKou.text = [NSString stringWithFormat:@"%@元",model.coupon_price];
  150. self.ticketType.text = @"券";
  151. }else {
  152. disStr = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
  153. self.zheKou.text = [NSString stringWithFormat:@"%@折",model.coupon_price];
  154. self.ticketType.text = @"折";
  155. }
  156. NSMutableAttributedString *disAttr = [[NSMutableAttributedString alloc] initWithString:disStr];
  157. [disAttr addAttributes:@{NSForegroundColorAttributeName:[UIColor homeRedColor]} range:NSMakeRange(0, disAttr.length)];
  158. [disAttr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} range:NSMakeRange(0, 1)];
  159. self.disPriceL.attributedText = disAttr;
  160. self.volum.text = [NSString stringWithFormat:@"月销 %@",model.volume];
  161. //券相关
  162. self.ticketNumber.hidden = ![model.is_coupon boolValue];
  163. CGFloat width = [model.is_coupon boolValue] ? 64 : 0;
  164. //券的位置
  165. [self.ticketNumber mas_updateConstraints:^(MASConstraintMaker *make) {
  166. make.width.mas_equalTo(width);
  167. }];
  168. // 预估佣金视图
  169. if (model.commission_price.floatValue>0) {//判断是否有预估佣金,
  170. [self.ticketNumber mas_updateConstraints:^(MASConstraintMaker *make) {
  171. if (model.red_active_status.integerValue == 1) {
  172. make.left.mas_equalTo(self.redpriceLabel.mas_right).mas_offset(85);
  173. }else{
  174. make.left.mas_equalTo(self.redpriceLabel.mas_right).mas_offset(75);
  175. }
  176. }];
  177. [self.commissionBg mas_updateConstraints:^(MASConstraintMaker *make) {
  178. if (model.red_active_status.integerValue == 1) {
  179. make.left.mas_equalTo(self.redpriceLabel.mas_right).mas_offset(10);
  180. }else{
  181. make.left.mas_equalTo(self.redpriceLabel.mas_right).mas_offset(0);
  182. }
  183. }];
  184. }else {
  185. [self.ticketNumber mas_updateConstraints:^(MASConstraintMaker *make) {
  186. make.left.mas_equalTo(self.redpriceLabel.mas_right).mas_offset(5);
  187. }];
  188. }
  189. self.commissionLabel.text = [NSString stringWithFormat:@"返¥%.2f",[model.commission_price floatValue]];
  190. if (model.commission_price.floatValue > 0) {
  191. self.commissionBg.hidden = NO;
  192. }else {
  193. self.commissionBg.hidden = YES;
  194. }
  195. }
  196. - (UIImageView *)imgView {
  197. if (!_imgView) {
  198. _imgView = [[UIImageView alloc] init];
  199. _imgView.backgroundColor = [UIColor YHColorWithHex:0xf0f0f0];
  200. }
  201. return _imgView;
  202. }
  203. - (YYLabel *)titleLabel {
  204. if (!_titleLabel) {
  205. _titleLabel = [[YYLabel alloc] init];
  206. _titleLabel.font = [UIFont boldSystemFontOfSize:15];
  207. _titleLabel.textColor = [UIColor YHColorWithHex:0x000000];
  208. _titleLabel.numberOfLines = 2;
  209. _titleLabel.preferredMaxLayoutWidth = SCREEN_WIDTH-145;
  210. }
  211. return _titleLabel;
  212. }
  213. - (UILabel *)priceLabel {
  214. if (!_priceLabel) {
  215. _priceLabel = [[UILabel alloc] init];
  216. _priceLabel.font = [UIFont systemFontOfSize:11];
  217. _priceLabel.textColor = [UIColor YHColorWithHex:0x999999];
  218. }
  219. return _priceLabel;
  220. }
  221. - (UILabel *)disPriceL {
  222. if (!_disPriceL) {
  223. _disPriceL = [[UILabel alloc] init];
  224. _disPriceL.font = [UIFont systemFontOfSize:15];
  225. _disPriceL.textColor = [UIColor homeRedColor];
  226. }
  227. return _disPriceL;
  228. }
  229. - (UIImageView *)ticketNumber {
  230. if (!_ticketNumber) {
  231. _ticketNumber = [[UIImageView alloc] init];
  232. _ticketNumber.image = [UIImage imageNamed:@"quan_bg"];
  233. }
  234. return _ticketNumber;
  235. }
  236. - (UILabel *)zheKou {
  237. if (!_zheKou) {
  238. _zheKou = [[UILabel alloc] init];
  239. _zheKou.textColor = [UIColor homeRedColor];
  240. _zheKou.textAlignment = NSTextAlignmentCenter;
  241. _zheKou.font = [UIFont systemFontOfSize:10];
  242. }
  243. return _zheKou;
  244. }
  245. - (UILabel *)ticketType {
  246. if (!_ticketType) {
  247. _ticketType = [[UILabel alloc] init];
  248. _ticketType.font = [UIFont systemFontOfSize:10];
  249. _ticketType.textAlignment = NSTextAlignmentCenter;
  250. _ticketType.textColor = [UIColor homeRedColor];
  251. }
  252. return _ticketType;
  253. }
  254. - (YYLabel *)shopInfo {
  255. if (!_shopInfo) {
  256. _shopInfo = [[YYLabel alloc] init];
  257. _shopInfo.displaysAsynchronously = YES;
  258. _shopInfo.font = [UIFont systemFontOfSize:12];
  259. _shopInfo.textColor = [UIColor YHColorWithHex:0x9B9B9B];
  260. }
  261. return _shopInfo;
  262. }
  263. - (UIView *)commissionBg {
  264. if (!_commissionBg) {
  265. _commissionBg = [[UIView alloc] init];
  266. _commissionBg.backgroundColor = [UIColor YHColorWithHex:0xFFF4DF];
  267. }
  268. return _commissionBg;
  269. }
  270. - (UILabel *)commissionLabel {
  271. if (!_commissionLabel) {
  272. _commissionLabel = [[UILabel alloc] init];
  273. _commissionLabel.textColor = [UIColor YHColorWithHex:0x99520F];
  274. _commissionLabel.font = [UIFont systemFontOfSize:10];
  275. _commissionLabel.textAlignment = NSTextAlignmentCenter;
  276. }
  277. return _commissionLabel;
  278. }
  279. - (UILabel *)volum {
  280. if (!_volum) {
  281. _volum = [[UILabel alloc] init];
  282. _volum.textColor = [UIColor YHColorWithHex:0xBBB9BB];
  283. _volum.font = [UIFont systemFontOfSize:10];
  284. }
  285. return _volum;
  286. }
  287. -(UIImageView *)redImgV
  288. {
  289. if (!_redImgV) {
  290. _redImgV = [[UIImageView alloc] init];
  291. // _redImgV.backgroundColor=[UIColor redColor];
  292. _redImgV.image = [UIImage imageNamed:@"red_detail"];
  293. }
  294. return _redImgV;
  295. }
  296. -(UILabel *)redpriceLabel
  297. {
  298. if (!_redpriceLabel) {
  299. _redpriceLabel = [[UILabel alloc] init];
  300. _redpriceLabel.textColor = [UIColor YHColorWithHex:0x99520F];
  301. _redpriceLabel.backgroundColor=[UIColor YHColorWithHex:0xFFF4DF];
  302. _redpriceLabel.font = [UIFont systemFontOfSize:10];
  303. _redpriceLabel.textAlignment = NSTextAlignmentCenter;
  304. }
  305. return _redpriceLabel;
  306. }
  307. @end