XYVoiceMatchOrderDetailsInfoView.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //
  2. // XYVoiceMatchOrderDetailsInfoView.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/11/20.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYVoiceMatchOrderDetailsInfoView.h"
  9. #import "XYVoiceChatDetailsModel.h"
  10. @interface XYVoiceMatchOrderDetailsInfoView ()
  11. @property (nonatomic, strong) UIView *detailsInfoView;
  12. @property (nonatomic, strong) UIView *amountView;
  13. @property (nonatomic, strong) UIView *amountLine;
  14. @property (nonatomic, strong) UILabel *amountTitleLabel;
  15. @property (nonatomic, strong) UILabel *amountLabel;
  16. @end
  17. @implementation XYVoiceMatchOrderDetailsInfoView
  18. #pragma mark — Public
  19. - (void)setupViewDataWithModel:(XYVoiceChatDetailsModel *)model {
  20. [self buildDetailsInfoViewWithModel:model];
  21. self.amountLabel.text = StringIsEmpty(model.consumeAmount)?@"- -":[NSString stringWithFormat:@"%@%@", model.consumeAmount, App_CoinName(Wallet_Type_Star_Diamond)];
  22. }
  23. - (void)buildDetailsInfoViewWithModel:(XYVoiceChatDetailsModel *)model {
  24. NSArray *infos = @[kLocalizedString(@"订单编号:"), [NSString stringWithFormat:@"%@ %@", model.hisId, kLocalizedString(@"复制")], kLocalizedString(@"品类:"), model.skillName, kLocalizedString(@"单价:"), [NSString stringWithFormat:@"%@%@/%@", model.hisPrice, App_CoinName(Wallet_Type_Star_Diamond), model.unitText], kLocalizedString(@"数量:"), @"1"];
  25. for (UIView *view in self.detailsInfoView.subviews) {
  26. [view removeFromSuperview];
  27. }
  28. UILabel *tempLabel;
  29. for (NSInteger i = 0; i < infos.count; i++) {
  30. UILabel *label = [UILabel new];
  31. label.font = Font(14);
  32. label.text = infos[i];
  33. [self.detailsInfoView addSubview:label];
  34. if (i%2 == 0) {
  35. // 奇数
  36. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.equalTo(self.detailsInfoView).offset(20.0f);
  38. if (tempLabel) {
  39. make.top.equalTo(tempLabel.mas_bottom).offset(10.0f);
  40. }else {
  41. make.top.equalTo(self.detailsInfoView).offset(21.0f);
  42. }
  43. make.width.equalTo(@70.0f);
  44. make.height.equalTo(@(20.0f));
  45. }];
  46. }else {
  47. // 偶数
  48. label.textColor = Color_TextFont;
  49. label.textAlignment = NSTextAlignmentRight;
  50. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.left.equalTo(tempLabel.mas_right).offset(20.0f);
  52. make.right.equalTo(self.detailsInfoView).offset(-20.0f);
  53. make.top.equalTo(tempLabel);
  54. make.height.equalTo(@(20.0f));
  55. }];
  56. }
  57. if (i == 1) {
  58. // 修改颜色
  59. [HandleString changeLabelColor:label string:kLocalizedString(@"复制") textColor:Color_Blue];
  60. // 添加复制事件
  61. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(copyAction:)];
  62. label.userInteractionEnabled = YES;
  63. [label addGestureRecognizer:tap];
  64. [label sizeToFit];
  65. }
  66. tempLabel = label;
  67. }
  68. }
  69. - (void)copyAction:(UITapGestureRecognizer *)tap {
  70. UILabel *label = (UILabel *)tap.view;
  71. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  72. pasteboard.string = [NSString stringWithFormat:@"%@", [label.text substringToIndex:label.text.length - 2]];
  73. [SVProgressHUD showSuccessWithStatus:kLocalizedString(@"已复制至剪切板")];
  74. }
  75. - (instancetype)initWithFrame:(CGRect)frame
  76. {
  77. self = [super initWithFrame:frame];
  78. if (self) {
  79. [self setupUI];
  80. }
  81. return self;
  82. }
  83. - (void)setupUI {
  84. [self addSubview:self.detailsInfoView];
  85. [self addSubview:self.amountView];
  86. [self.amountView addSubview:self.amountLine];
  87. [self.amountView addSubview:self.amountTitleLabel];
  88. [self.amountView addSubview:self.amountLabel];
  89. [self.detailsInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.left.right.top.equalTo(self);
  91. make.height.equalTo(@152.0f);
  92. }];
  93. [self.amountView mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.left.right.bottom.equalTo(self);
  95. make.height.equalTo(@54.0f);
  96. }];
  97. [self.amountLine mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.left.top.right.equalTo(self.amountView);
  99. make.height.equalTo(@(LINE_HEIGHT));
  100. }];
  101. [self.amountTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.left.equalTo(self.amountView).offset(20.0f);
  103. make.centerY.equalTo(self.amountView);
  104. }];
  105. [self.amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.right.equalTo(self.amountView).offset(-20.0f);
  107. make.centerY.equalTo(self.amountView);
  108. }];
  109. }
  110. #pragma mark — Getter
  111. - (UIView *)detailsInfoView {
  112. if (!_detailsInfoView) {
  113. _detailsInfoView = [UIView new];
  114. _detailsInfoView.backgroundColor = Color_Clear;
  115. }
  116. return _detailsInfoView;
  117. }
  118. - (UIView *)amountView {
  119. if (!_amountView) {
  120. _amountView = [UIView new];
  121. }
  122. return _amountView;
  123. }
  124. - (UIView *)amountLine {
  125. if (!_amountLine) {
  126. _amountLine = [UIView new];
  127. _amountLine.backgroundColor = Color_line;
  128. }
  129. return _amountLine;
  130. }
  131. - (UILabel *)amountTitleLabel {
  132. if (!_amountTitleLabel) {
  133. _amountTitleLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font_S(15)];
  134. _amountTitleLabel.text = kLocalizedString(@"合计:");
  135. }
  136. return _amountTitleLabel;
  137. }
  138. - (UILabel *)amountLabel {
  139. if (!_amountLabel) {
  140. _amountLabel = [UILabel createLabelTextColor:Color_TextRed fount:Font_S(15)];
  141. _amountLabel.textAlignment = NSTextAlignmentRight;
  142. }
  143. return _amountLabel;
  144. }
  145. @end