KWMineHomeOrderSubView.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. //
  2. // KWMineHomeOrderSubView.m
  3. // westkissMob
  4. //
  5. // Created by iOS on 2022/10/12.
  6. //
  7. #import "KWMineHomeOrderSubView.h"
  8. @interface KWMineHomeOrderSubView ()
  9. @property (nonatomic, strong) UILabel *titleLB;
  10. @property (nonatomic, strong) UILabel *priceLb;
  11. @property (nonatomic, strong) UILabel *xLB;
  12. @property (nonatomic, strong) UILabel *numLB;
  13. @property (nonatomic, strong) UIImageView *imgV;
  14. @property (nonatomic, strong) UILabel *giftTipV;
  15. @property (nonatomic, strong) UIButton *editBt;
  16. @property (nonatomic, strong) KWMineOrderProInfoModel *m;
  17. @end
  18. @implementation KWMineHomeOrderSubView
  19. - (void)setData:(KWMineOrderProInfoModel *)model canEdit:(BOOL)canEdit {
  20. self.m = model;
  21. self.titleLB.text = model.name;
  22. self.priceLb.text = [NSString stringWithFormat:@"%@%.2f", model.currency_symbol, [model.price floatValue]];
  23. self.numLB.text = model.qty_ordered;
  24. NSString *imageStr = [NSString stringWithFormat:@"https:%@%@%@",HostPath,ProductImgPath,model.image];
  25. [self.imgV sd_setImageWithURL:[NSURL URLWithString:imageStr.urlEncode] placeholderImage:[UIImage imageNamed:@"product_defualtImg"]];
  26. self.editBt.hidden = !canEdit;
  27. [self showGift:model.is_gift.intValue == 1];
  28. }
  29. - (void)showGift:(BOOL)isGift {
  30. self.giftTipV.hidden = !isGift;
  31. self.numLB.hidden = isGift;
  32. self.xLB.hidden = isGift;
  33. self.priceLb.hidden = isGift;
  34. if (isGift) {
  35. self.editBt.hidden = true;
  36. }
  37. }
  38. - (void)btAction:(UIButton *)bt {
  39. if (self.m && self.toAddCommentBlock) {
  40. self.toAddCommentBlock(self.m);
  41. }
  42. UIViewController *vc = [CTMediator.sharedInstance Goods_WriteReview:@{@"entity_id":self.m.product_id}];
  43. [Current_normalTool.currentNav pushViewController:vc animated:true];
  44. }
  45. -(instancetype)init {
  46. self = [super init];
  47. if (self) {
  48. [self loadSubV];
  49. }
  50. return self;
  51. }
  52. - (void)loadSubV {
  53. self.backgroundColor = UIColor.clearColor;
  54. [self addSubview:self.imgV];
  55. [self addSubview:self.titleLB];
  56. [self addSubview:self.priceLb];
  57. [self addSubview:self.xLB];
  58. [self addSubview:self.numLB];
  59. [self addSubview:self.editBt];
  60. [self addSubview:self.giftTipV];
  61. [_imgV mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.top.equalTo(self).offset(0);
  63. make.left.equalTo(self).offset(0);
  64. make.bottom.equalTo(self).offset(0);
  65. make.width.height.equalTo(@86);
  66. }];
  67. [_titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.top.equalTo(self.imgV);
  69. make.left.equalTo(self.imgV.mas_right).offset(10);
  70. make.right.equalTo(self).offset(0);
  71. make.height.equalTo(@35);
  72. }];
  73. [self.priceLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
  74. [self.priceLb mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.bottom.equalTo(self.imgV);
  76. make.left.equalTo(self.titleLB);
  77. make.height.equalTo(@17);
  78. }];
  79. [self.xLB mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.width.equalTo(@17);
  81. make.height.equalTo(@17);
  82. make.left.equalTo(self.priceLb.mas_right);
  83. make.centerY.equalTo(self.priceLb);
  84. }];
  85. [self.numLB mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.width.equalTo(@25);
  87. make.height.equalTo(@17);
  88. make.left.equalTo(self.xLB.mas_right);
  89. make.centerY.equalTo(self.priceLb);
  90. }];
  91. [self.editBt mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.bottom.centerY.equalTo(self.priceLb);
  93. make.width.height.equalTo(@24);
  94. make.right.equalTo(self);
  95. }];
  96. [self.giftTipV mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.leading.equalTo(self.titleLB);
  98. make.bottom.equalTo(self.imgV);
  99. make.width.equalTo(@86);
  100. make.height.equalTo(@23);
  101. }];
  102. }
  103. - (UIImageView *)imgV {
  104. if (!_imgV) {
  105. UIImageView *imgV = [[UIImageView alloc] init];
  106. _imgV = imgV;
  107. }
  108. return _imgV;
  109. }
  110. - (UILabel *)titleLB {
  111. if (!_titleLB) {
  112. UILabel *lb = [[UILabel alloc] init];
  113. lb.font = [UIFont fontWithName:Rob_Regular size:12];
  114. lb.textColor = [UIColor blackColor];
  115. lb.backgroundColor = [UIColor clearColor];
  116. lb.numberOfLines = 2;
  117. _titleLB = lb;
  118. }
  119. return _titleLB;
  120. }
  121. - (UILabel *)priceLb {
  122. if (!_priceLb) {
  123. UILabel *lb = [[UILabel alloc] init];
  124. lb.font = [UIFont fontWithName:Rob_Bold size:14];
  125. lb.textColor = _0B0B0B;
  126. lb.backgroundColor = [UIColor clearColor];
  127. _priceLb = lb;
  128. }
  129. return _priceLb;
  130. }
  131. - (UILabel *)xLB {
  132. if (!_xLB) {
  133. UILabel *lb = [[UILabel alloc] init];
  134. lb.font = [UIFont fontWithName:Rob_Regular size:14];
  135. lb.textColor = _0B0B0B;
  136. lb.backgroundColor = [UIColor clearColor];
  137. lb.textAlignment = NSTextAlignmentCenter;
  138. lb.text = @"x";
  139. _xLB = lb;
  140. }
  141. return _xLB;
  142. }
  143. - (UILabel *)numLB {
  144. if (!_numLB) {
  145. UILabel *lb = [[UILabel alloc] init];
  146. lb.font = [UIFont fontWithName:Rob_Regular size:14];
  147. lb.textColor = _0B0B0B;
  148. lb.backgroundColor = [UIColor clearColor];
  149. _numLB = lb;
  150. }
  151. return _numLB;
  152. }
  153. - (UIButton *)editBt {
  154. if (!_editBt) {
  155. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  156. [bt setImage:[UIImage imageNamed:@"mine_add_comment"] forState:UIControlStateNormal];
  157. [bt addTarget:self action:@selector(btAction:) forControlEvents:UIControlEventTouchUpInside];
  158. _editBt = bt;
  159. }
  160. return _editBt;
  161. }
  162. - (UILabel *)giftTipV {
  163. if (!_giftTipV) {
  164. UILabel *lb = [UILabel baseLb];
  165. lb.font = [UIFont fontWithName:Rob_Regular size:12];
  166. lb.textAlignment = NSTextAlignmentCenter;
  167. lb.textColor = Col_000;
  168. lb.text = @"Gift";
  169. lb.backgroundColor = _F0FFF9;
  170. lb.layer.cornerRadius = 3;
  171. lb.layer.masksToBounds = true;
  172. lb.hidden = true;
  173. _giftTipV = lb;
  174. }
  175. return _giftTipV;
  176. }
  177. @end