ASOrderDetailsItemsCell.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // ASOrderDetailsItemsCell.m
  3. // Asteria
  4. //
  5. // Created by xingyu on 2024/5/16.
  6. //
  7. #import "ASOrderDetailsItemsCell.h"
  8. @interface ASOrderDetailsItemsCell()
  9. @property (nonatomic, strong) UIImageView *goodsImage;
  10. @property (nonatomic, strong) UILabel *nameLab;
  11. @property (nonatomic, strong) UILabel *countLab;
  12. @property (nonatomic, strong) UILabel *realPriceLab;
  13. @property (nonatomic, strong) UILabel *priceLab;
  14. @property (nonatomic, strong) UILabel *optLab;
  15. @property (nonatomic, strong) UILabel *giftLab;
  16. @end
  17. @implementation ASOrderDetailsItemsCell
  18. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  19. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  20. self.selectionStyle = UITableViewCellSelectionStyleNone;
  21. self.contentView.backgroundColor = _F8F8F8;
  22. UIView *backView = [[UIView alloc] init];
  23. backView.backgroundColor = Col_FFF;
  24. TT_ViewRadius(backView, 3);
  25. [self.contentView addSubview:backView];
  26. [backView mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.left.mas_equalTo(10);
  28. make.top.mas_equalTo(5);
  29. make.right.mas_equalTo(-10);
  30. make.bottom.mas_equalTo(0);
  31. }];
  32. _goodsImage = [[UIImageView alloc] init];
  33. _goodsImage.contentMode = UIViewContentModeScaleAspectFill;
  34. TT_ViewRadius(_goodsImage, 4);
  35. [backView addSubview:_goodsImage];
  36. [_goodsImage mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.mas_equalTo(10);
  38. make.top.mas_equalTo(20);
  39. make.width.height.mas_equalTo(86);
  40. }];
  41. _nameLab = [UILabel labelCreateWithText:@"sdafhasjkfah" font:[UIFont fontWithName:Rob_Regular size:12] textColor:Col_000];
  42. _nameLab.numberOfLines = 2;
  43. [backView addSubview:_nameLab];
  44. [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.top.mas_equalTo(20);
  46. make.right.mas_equalTo(-10);
  47. make.left.equalTo(_goodsImage.mas_right).offset(10);
  48. }];
  49. _countLab = [UILabel labelCreateWithText:@"x1" font:[UIFont fontWithName:Rob_Bold size:14] textColor:Col_000];
  50. [backView addSubview:_countLab];
  51. [_countLab mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.bottom.mas_equalTo(_goodsImage.mas_bottom).offset(0);
  53. make.left.equalTo(_goodsImage.mas_right).offset(10);
  54. }];
  55. _priceLab = [UILabel labelCreateWithText:@"123" font:[UIFont fontWithName:Rob_Regular size:12] textColor:[UIColor colorWithHexString:@"#8c8c8c"]];
  56. [backView addSubview:_priceLab];
  57. [_priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.centerY.mas_equalTo(_countLab);
  59. make.right.mas_equalTo(-10);
  60. }];
  61. _realPriceLab = [UILabel labelCreateWithText:@"" font:[UIFont fontWithName:Rob_Bold size:14] textColor:_0B0B0B];
  62. [backView addSubview:_realPriceLab];
  63. [_realPriceLab mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.centerY.mas_equalTo(_countLab);
  65. make.right.mas_equalTo(_priceLab.mas_left).offset(-6);
  66. }];
  67. _optLab = [UILabel labelCreateWithText:@"" font:[UIFont fontWithName:Rob_Regular size:12] textColor:_0B0B0B];
  68. _optLab.numberOfLines = 0;
  69. [backView addSubview:_optLab];
  70. [_optLab mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.top.mas_equalTo(_goodsImage.mas_bottom).offset(18);
  72. make.bottom.mas_equalTo(-20);
  73. make.right.mas_equalTo(-10);
  74. make.left.mas_equalTo(10);
  75. }];
  76. _giftLab = [UILabel labelCreateWithText:@"Gift" font:[UIFont fontWithName:Rob_Regular size:12] textColor:Col_000];
  77. _giftLab.textAlignment = NSTextAlignmentCenter;
  78. _giftLab.backgroundColor = _F0FFF9;
  79. [backView addSubview:_giftLab];
  80. [_giftLab mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.left.equalTo(self.nameLab);
  82. make.bottom.equalTo(self.goodsImage);
  83. make.width.equalTo(@64);
  84. make.height.equalTo(@23);
  85. }];
  86. }
  87. return self;
  88. }
  89. - (void)setItemModel:(ASOrderDetailsItemModel *)itemModel {
  90. _itemModel = itemModel;
  91. NSString *imageAllStr = [NSString stringWithFormat:@"https:%@%@%@",HostPath,ProductImgPath,AS_String_NotNull(_itemModel.image)];
  92. [self.goodsImage sd_setImageWithURL:[NSURL URLWithString:imageAllStr] placeholderImage:UIImageDefaultImg_SD];
  93. NSString *nameStr = AS_String_NotNull(_itemModel.name);
  94. if([nameStr hasPrefix:@"FREE"]){
  95. _giftLab.hidden = NO;
  96. _countLab.hidden = YES;
  97. _realPriceLab.hidden = YES;
  98. _priceLab.hidden = YES;
  99. }else{
  100. _giftLab.hidden = YES;
  101. _countLab.hidden = NO;
  102. _realPriceLab.hidden = NO;
  103. _priceLab.hidden = NO;
  104. }
  105. _nameLab.text = AS_String_NotNull(_itemModel.name);
  106. _countLab.text = [NSString stringWithFormat:@"X%@", AS_String_NotNull(_itemModel.qty_ordered)];
  107. _realPriceLab.text = [NSString stringWithFormat:@"%@%.2f", AS_String_NotNull(_itemModel.currency_symbol), [AS_String_NotNull(_itemModel.price) floatValue]];
  108. NSMutableAttributedString *priceAtr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%.2f",AS_String_NotNull(_itemModel.currency_symbol), [AS_String_NotNull(_itemModel.original_price) floatValue]]];
  109. [priceAtr addAttribute:NSStrikethroughStyleAttributeName
  110. value:[NSNumber numberWithInteger:NSUnderlineStyleSingle]
  111. range:NSMakeRange(0, priceAtr.length)];
  112. _priceLab.attributedText = priceAtr;
  113. NSArray *array = [Current_normalTool arrFromjsonStr:_itemModel.sku];
  114. NSString *optionStr = @"";
  115. for (int i = 0; i < array.count; i++) {
  116. NSDictionary *dic = [array objectAtIndex:i];
  117. optionStr = [NSString stringWithFormat:@"%@%@:%@", optionStr, dic[@"label"], dic[@"value"]];
  118. if (i < array.count - 1) {
  119. optionStr = [NSString stringWithFormat:@"%@ ", optionStr];
  120. }
  121. }
  122. self.optLab.text = optionStr;
  123. }
  124. @end