ASOrderDetailsInfoCell.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // ASOrderDetailsInfoCell.m
  3. // Asteria
  4. //
  5. // Created by xingyu on 2024/5/15.
  6. //
  7. #import "ASOrderDetailsInfoCell.h"
  8. @interface ASOrderDetailsInfoCell()
  9. @property (nonatomic, strong) UIView *backView;
  10. @property (nonatomic, strong) UIView *lineView;
  11. @end
  12. @implementation ASOrderDetailsInfoCell
  13. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  14. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  15. self.selectionStyle = UITableViewCellSelectionStyleNone;
  16. self.contentView.backgroundColor = _F8F8F8;
  17. _backView = [[UIView alloc] init];
  18. _backView.backgroundColor = Col_FFF;
  19. TT_ViewRadius(_backView, 3);
  20. [self.contentView addSubview:_backView];
  21. [_backView mas_makeConstraints:^(MASConstraintMaker *make) {
  22. make.left.top.mas_equalTo(10);
  23. make.bottom.right.mas_equalTo(-10);
  24. }];
  25. UILabel *infoLab = [UILabel labelCreateWithText:@"order information" font:[UIFont fontWithName:Rob_Regular size:12] textColor:_0B0B0B];
  26. [_backView addSubview:infoLab];
  27. [infoLab mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.left.mas_equalTo (10);
  29. make.top.mas_equalTo(28);
  30. }];
  31. _lineView = [[UIView alloc] init];
  32. _lineView.backgroundColor = _F4F4F4;
  33. [_backView addSubview:_lineView];
  34. [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.mas_equalTo(10);
  36. make.right.mas_equalTo(-10);
  37. make.height.mas_equalTo(1);
  38. make.top.equalTo(infoLab.mas_bottom).offset(22);
  39. }];
  40. }
  41. return self;
  42. }
  43. - (void)setOrderModel:(ASOrderDetailsModel *)orderModel {
  44. _orderModel = orderModel;
  45. if (_orderModel == nil) {
  46. return;
  47. }
  48. NSString *addressStr = @"";
  49. NSString *payMethodStr = @"";
  50. NSDictionary *extension_attributes = _orderModel.extension_attributes;
  51. if (AS_Dict_valid(extension_attributes)) {
  52. NSArray *addresArr = [extension_attributes objectForKey:@"shipping_assignments"];
  53. if (AS_Array_valid(addresArr)) {
  54. NSDictionary *shipping_assignments = addresArr[0];
  55. NSDictionary *addresDic = [shipping_assignments objectForKey:@"shipping"];
  56. NSDictionary *addresDic1 = [addresDic objectForKey:@"address"];
  57. ASAddressModel *addressModel = [ASAddressModel mj_objectWithKeyValues:addresDic1];
  58. addressStr = [NSString stringWithFormat:@"%@ %@ %@ %@,%@ tel:%@", AS_String_NotNull(addressModel.firstname), AS_String_NotNull(addressModel.lastname), [addressModel.street componentsJoinedByString:@" "], AS_String_NotNull(addressModel.city), AS_String_NotNull(addressModel.postcode), AS_String_NotNull(addressModel.telephone)];
  59. }
  60. //支付方式
  61. NSArray *payInfoArr = [extension_attributes objectForKey:@"payment_additional_info"];
  62. for (int i = 0; i < payInfoArr.count; i++) {
  63. NSDictionary *payDic = payInfoArr[i];
  64. if ([payDic[@"key"] isEqualToString:@"method_title"]) {
  65. payMethodStr = AS_String_NotNull(payDic[@"value"]);
  66. break;
  67. }
  68. }
  69. }
  70. NSArray *titleArray = @[@"ship to:", @"order number:", @"status:", @"order date:", @"shipping method:", @"Payment method:"];
  71. NSArray *valueArray = @[addressStr, AS_String_NotNull(_orderModel.increment_id), AS_String_NotNull(_orderModel.status), AS_String_NotNull(_orderModel.created_at), AS_String_NotNull(_orderModel.shipping_description), payMethodStr];
  72. UILabel *tempLab = nil;
  73. for (int i = 0; i < titleArray.count; i++) {
  74. UILabel *rightLab = [UILabel labelCreateWithText:valueArray[i] font:[UIFont fontWithName:Rob_Regular size:12] textColor:_0B0B0B];
  75. rightLab.numberOfLines = 0;
  76. [_backView addSubview:rightLab];
  77. if (i == 0) {
  78. [rightLab mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.right.mas_equalTo(-10);
  80. make.left.mas_equalTo(140);
  81. make.top.mas_equalTo(_lineView.mas_bottom).offset(20);
  82. }];
  83. } else {
  84. [rightLab mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.right.mas_equalTo(-10);
  86. make.left.mas_equalTo(140);
  87. make.top.mas_equalTo(tempLab.mas_bottom).offset(20);
  88. }];
  89. }
  90. tempLab = rightLab;
  91. UILabel *leftLab = [UILabel labelCreateWithText:titleArray[i] font:[UIFont fontWithName:Rob_Regular size:12] textColor:_0B0B0B];
  92. [_backView addSubview:leftLab];
  93. [leftLab mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.left.mas_equalTo(10);
  95. make.centerY.mas_equalTo(rightLab);
  96. }];
  97. }
  98. UIView *lineView1 = [[UIView alloc] init];
  99. lineView1.backgroundColor = _F4F4F4;
  100. [_backView addSubview:lineView1];
  101. [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.left.mas_equalTo(10);
  103. make.right.mas_equalTo(-10);
  104. make.height.mas_equalTo(1);
  105. make.top.equalTo(tempLab.mas_bottom).offset(20);
  106. make.bottom.mas_equalTo(-20);
  107. }];
  108. }
  109. @end