ASOrderDetailsItemsCell.m 5.2 KB

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