// // ASOrderDetailsInfoCell.m // Asteria // // Created by xingyu on 2024/5/15. // #import "ASOrderDetailsInfoCell.h" @interface ASOrderDetailsInfoCell() @property (nonatomic, strong) UIView *backView; @property (nonatomic, strong) UIView *lineView; @end @implementation ASOrderDetailsInfoCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.selectionStyle = UITableViewCellSelectionStyleNone; self.contentView.backgroundColor = _F8F8F8; _backView = [[UIView alloc] init]; _backView.backgroundColor = Col_FFF; TT_ViewRadius(_backView, 3); [self.contentView addSubview:_backView]; [_backView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.mas_equalTo(10); make.bottom.right.mas_equalTo(-10); }]; UILabel *infoLab = [UILabel labelCreateWithText:@"order information" font:[UIFont fontWithName:Rob_Regular size:12] textColor:_0B0B0B]; [_backView addSubview:infoLab]; [infoLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo (10); make.top.mas_equalTo(28); }]; _lineView = [[UIView alloc] init]; _lineView.backgroundColor = _F4F4F4; [_backView addSubview:_lineView]; [_lineView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.right.mas_equalTo(-10); make.height.mas_equalTo(1); make.top.equalTo(infoLab.mas_bottom).offset(22); }]; } return self; } - (void)setOrderModel:(ASOrderDetailsModel *)orderModel { _orderModel = orderModel; if (_orderModel == nil) { return; } NSString *addressStr = @""; NSString *payMethodStr = @""; NSDictionary *extension_attributes = _orderModel.extension_attributes; if (AS_Dict_valid(extension_attributes)) { NSArray *addresArr = [extension_attributes objectForKey:@"shipping_assignments"]; if (AS_Array_valid(addresArr)) { NSDictionary *shipping_assignments = addresArr[0]; NSDictionary *addresDic = [shipping_assignments objectForKey:@"shipping"]; NSDictionary *addresDic1 = [addresDic objectForKey:@"address"]; ASAddressModel *addressModel = [ASAddressModel mj_objectWithKeyValues:addresDic1]; 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)]; } //支付方式 NSArray *payInfoArr = [extension_attributes objectForKey:@"payment_additional_info"]; for (int i = 0; i < payInfoArr.count; i++) { NSDictionary *payDic = payInfoArr[i]; if ([payDic[@"key"] isEqualToString:@"method_title"]) { payMethodStr = AS_String_NotNull(payDic[@"value"]); break; } } } NSArray *titleArray = @[@"ship to:", @"order number:", @"status:", @"order date:", @"shipping method:", @"Payment method:"]; 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]; UILabel *tempLab = nil; for (int i = 0; i < titleArray.count; i++) { UILabel *rightLab = [UILabel labelCreateWithText:valueArray[i] font:[UIFont fontWithName:Rob_Regular size:12] textColor:_0B0B0B]; rightLab.numberOfLines = 0; [_backView addSubview:rightLab]; if (i == 0) { [rightLab mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-10); make.left.mas_equalTo(140); make.top.mas_equalTo(_lineView.mas_bottom).offset(20); }]; } else { [rightLab mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-10); make.left.mas_equalTo(140); make.top.mas_equalTo(tempLab.mas_bottom).offset(20); }]; } tempLab = rightLab; UILabel *leftLab = [UILabel labelCreateWithText:titleArray[i] font:[UIFont fontWithName:Rob_Regular size:12] textColor:_0B0B0B]; [_backView addSubview:leftLab]; [leftLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.centerY.mas_equalTo(rightLab); }]; } UIView *lineView1 = [[UIView alloc] init]; lineView1.backgroundColor = _F4F4F4; [_backView addSubview:lineView1]; [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.right.mas_equalTo(-10); make.height.mas_equalTo(1); make.top.equalTo(tempLab.mas_bottom).offset(20); make.bottom.mas_equalTo(-20); }]; } @end