LNOrderRefundInfoView.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // LNOrderRefundInfoView.swift
  3. // Lanu
  4. //
  5. // Created by OneeChan on 2025/12/23.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. class LNOrderRefundInfoView: UIView {
  11. private let reasonLabel = UILabel()
  12. private let photosView = LNMultiLineStackView()
  13. override init(frame: CGRect) {
  14. super.init(frame: frame)
  15. setupViews()
  16. }
  17. func update(_ detail: LNOrderDetailResponse) {
  18. isHidden = detail.reason.isEmpty
  19. reasonLabel.text = detail.reason
  20. var photos: [UIImageView] = []
  21. for (index, attachment) in detail.attachments.enumerated() {
  22. let imageView = UIImageView()
  23. imageView.sd_setImage(with: URL(string: attachment.attachmentUrl))
  24. photos.append(imageView)
  25. imageView.snp.makeConstraints { make in
  26. make.width.height.equalTo(100)
  27. }
  28. imageView.onTap { [weak self] in
  29. guard let self else { return }
  30. presentImagePreview(detail.attachments.map({ $0.attachmentUrl }), index)
  31. }
  32. }
  33. photosView.update(photos)
  34. }
  35. required init?(coder: NSCoder) {
  36. fatalError("init(coder:) has not been implemented")
  37. }
  38. }
  39. extension LNOrderRefundInfoView {
  40. private func setupViews() {
  41. backgroundColor = .fill
  42. layer.cornerRadius = 12
  43. let titleLabel = UILabel()
  44. titleLabel.text = .init(key: "A00146")
  45. titleLabel.font = .heading_h4
  46. titleLabel.textColor = .text_5
  47. addSubview(titleLabel)
  48. titleLabel.snp.makeConstraints { make in
  49. make.leading.equalToSuperview().offset(16)
  50. make.top.equalToSuperview().offset(16)
  51. }
  52. let holder = UIView()
  53. holder.backgroundColor = .fill_1
  54. holder.layer.cornerRadius = 12
  55. addSubview(holder)
  56. holder.snp.makeConstraints { make in
  57. make.horizontalEdges.equalToSuperview().inset(16)
  58. make.top.equalTo(titleLabel.snp.bottom).offset(8)
  59. }
  60. reasonLabel.font = .body_m
  61. reasonLabel.textColor = .text_5
  62. reasonLabel.numberOfLines = 0
  63. holder.addSubview(reasonLabel)
  64. reasonLabel.snp.makeConstraints { make in
  65. make.horizontalEdges.equalToSuperview().inset(12)
  66. make.verticalEdges.equalToSuperview().inset(10)
  67. }
  68. let photoLabel = UILabel()
  69. photoLabel.text = .init(key: "A00147")
  70. photoLabel.font = .heading_h4
  71. photoLabel.textColor = .text_5
  72. addSubview(photoLabel)
  73. photoLabel.snp.makeConstraints { make in
  74. make.leading.equalToSuperview().offset(16)
  75. make.top.equalTo(holder.snp.bottom).offset(16)
  76. }
  77. photosView.columns = 3
  78. photosView.itemDistribution = .equalSpacing
  79. addSubview(photosView)
  80. photosView.snp.makeConstraints { make in
  81. make.horizontalEdges.equalToSuperview().inset(16)
  82. make.bottom.equalToSuperview().offset(-16)
  83. make.top.equalTo(photoLabel.snp.bottom).offset(8)
  84. }
  85. }
  86. }