ShareGoodView.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // ShareGoodView.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2021/6/8.
  6. // Copyright © 2021 cat. All rights reserved.
  7. //
  8. #import "ShareGoodView.h"
  9. #import "CommodityDetailVC.h"
  10. @implementation ShareGoodView
  11. {
  12. UIImageView *thumbImg;
  13. UILabel *priceLb;
  14. UILabel *countLb;
  15. UILabel *titleLb;
  16. }
  17. -(instancetype)initWithFrame:(CGRect)frame andGoodsData:(CommodityDetailModel *)models{
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. _goodsModel = models;
  21. UITapGestureRecognizer *taps = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goGoodsDetail)];
  22. [self addGestureRecognizer:taps];
  23. UIView *backView = [[UIView alloc]init];
  24. backView.frame = CGRectMake(10, 5, self.height *0.7, self.height-10);
  25. backView.backgroundColor = UIColor.whiteColor;
  26. backView.layer.cornerRadius = 10;
  27. backView.layer.masksToBounds = YES;
  28. backView.layer.borderColor = Line_Cor.CGColor;
  29. backView.layer.borderWidth = 1;
  30. [self addSubview:backView];
  31. thumbImg = [[UIImageView alloc]init];
  32. thumbImg.frame = CGRectMake(0, 0, backView.width, backView.height *0.6);
  33. NSArray *first = models.thumbs_format;
  34. if (first.count > 0) {
  35. [thumbImg sd_setImageWithURL:[NSURL URLWithString:minstr(first[0])]];
  36. }
  37. // [thumbImg sd_setImageWithURL:[NSURL URLWithString:minstr([first valueForKey:@"thumb"])]];
  38. thumbImg.contentMode = UIViewContentModeScaleAspectFill;
  39. thumbImg.clipsToBounds = YES;
  40. [backView addSubview:thumbImg];
  41. priceLb = [[UILabel alloc]init];
  42. priceLb.font = [UIFont systemFontOfSize:16];
  43. priceLb.textColor = Pink_Cor;
  44. if ([models.type isEqual:@"1"]) {
  45. priceLb.text = [NSString stringWithFormat:@"%@%@",YZMsg(@"¥"), models.present_price];
  46. }else{
  47. priceLb.text = [NSString stringWithFormat:@"%@%@",YZMsg(@"¥"), models.price] ;
  48. }
  49. [backView addSubview:priceLb];
  50. [priceLb mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.left.equalTo(backView).offset(10);
  52. make.top.equalTo(thumbImg.mas_bottom).offset(5);
  53. }];
  54. _getMoneyLb = [[UILabel alloc]init];
  55. _getMoneyLb.font = [UIFont systemFontOfSize:11];
  56. _getMoneyLb.backgroundColor = RGBA(255, 88, 120, 0.2);
  57. _getMoneyLb.textColor =Normal_Color;
  58. _getMoneyLb.layer.cornerRadius = 3;
  59. _getMoneyLb.layer.borderColor = Normal_Color.CGColor;
  60. _getMoneyLb.layer.borderWidth = 1;
  61. _getMoneyLb.layer.masksToBounds = YES;
  62. _getMoneyLb.text = [NSString stringWithFormat:@" 被跟买得%@元 ",@"1.02"];
  63. _getMoneyLb.hidden = YES;
  64. [backView addSubview:_getMoneyLb];
  65. [_getMoneyLb mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.left.equalTo(priceLb.mas_right).offset(5);
  67. make.centerY.equalTo(priceLb.mas_centerY);
  68. make.height.mas_equalTo(15);
  69. }];
  70. if ([models.shop_uid isEqual:[Config getOwnID]]) {
  71. _getMoneyLb.hidden = NO;
  72. _getMoneyLb.text = [NSString stringWithFormat:YZMsg(@" 被跟买得%@元 "),models.commission];
  73. }else{
  74. _getMoneyLb.hidden = YES;
  75. }
  76. titleLb = [[UILabel alloc]init];
  77. titleLb.font = [UIFont systemFontOfSize:14];
  78. titleLb.textColor = UIColor.blackColor;
  79. titleLb.text = models.name;
  80. titleLb.numberOfLines = 0;
  81. titleLb.lineBreakMode = NSLineBreakByWordWrapping;
  82. [backView addSubview:titleLb];
  83. [titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.left.equalTo(priceLb.mas_left);
  85. make.top.equalTo(priceLb.mas_bottom).offset(5);
  86. make.right.equalTo(backView.mas_right).offset(-10);
  87. }];
  88. countLb = [[UILabel alloc]init];
  89. countLb.font = [UIFont systemFontOfSize:14];
  90. countLb.textColor = UIColor.grayColor;
  91. countLb.text =[NSString stringWithFormat:YZMsg(@"已售%@件"),models.sale_nums];
  92. countLb.numberOfLines = 0;
  93. countLb.lineBreakMode = NSLineBreakByWordWrapping;
  94. [backView addSubview:countLb];
  95. [countLb mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.left.equalTo(titleLb);
  97. make.top.equalTo(titleLb.mas_bottom).offset(5);
  98. }];
  99. }
  100. return self;
  101. }
  102. -(void)setGoodsModel:(CommodityDetailModel *)goodsModel
  103. {
  104. _goodsModel = goodsModel;
  105. NSArray *first = goodsModel.thumbs_format;
  106. if (first.count > 0) {
  107. [thumbImg sd_setImageWithURL:[NSURL URLWithString:minstr(first[0])]];
  108. }
  109. // priceLb.text = [NSString stringWithFormat:@"%@%@",YZMsg(@"¥"), goodsModel.price] ;
  110. if ([goodsModel.type isEqual:@"1"]) {
  111. priceLb.text = [NSString stringWithFormat:@"%@%@",YZMsg(@"¥"), goodsModel.present_price];
  112. }else{
  113. priceLb.text = [NSString stringWithFormat:@"%@%@",YZMsg(@"¥"), goodsModel.price] ;
  114. }
  115. countLb.text =[NSString stringWithFormat:YZMsg(@"已售%@件"),goodsModel.sale_nums];
  116. titleLb.text = goodsModel.name;
  117. // _getMoneyLb.text = [NSString stringWithFormat:@" 被跟买得%@元 ",@"1.02"];
  118. _getMoneyLb.hidden = YES;
  119. }
  120. -(void)goGoodsDetail{
  121. // [PublicObj checkGoodsExistenceWithID:_goodsModel.goodsid Existence:^(NSString *code, NSString *msg) {
  122. // if ([code isEqual:@"0"]) {
  123. CommodityDetailVC *detail = [[CommodityDetailVC alloc]init];
  124. detail.goodsID = _goodsModel.goodsid;
  125. detail.liveUid =_goodsModel.shop_uid;
  126. // detail.shareuid = self.shareUserid;
  127. [[YBBaseAppDelegate sharedAppDelegate] pushViewController:detail animated:YES];
  128. // }else{
  129. // [MBProgressHUD showError:msg];
  130. //
  131. // }
  132. // }];
  133. }
  134. @end