LNOrderGenerateQRCodePanel.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // LNOrderGenerateQRCodePanel.swift
  3. // Lanu
  4. //
  5. // Created by OneeChan on 2025/11/26.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. class LNOrderGenerateQRCodePanel: LNPopupView {
  11. private let curSkillIc = UIImageView()
  12. private let curSkillNameLabel = UILabel()
  13. private let skillArrow = UIImageView.arrowImageView(size: 14)
  14. private let tabView = LNOrderQRTabView()
  15. private let showView = LNOrderQRCodeShowView()
  16. private let customView = LNOrderCustomView()
  17. private var curSkill: LNGameMateSkillVO? {
  18. didSet {
  19. if oldValue?.id != curSkill?.id {
  20. onSkillChanged()
  21. }
  22. }
  23. }
  24. override init(frame: CGRect) {
  25. super.init(frame: frame)
  26. setupViews()
  27. DispatchQueue.main.async { [weak self] in
  28. guard let self else { return }
  29. tabView.curType = .normal
  30. curSkill = myUserInfo.skills.first
  31. }
  32. }
  33. required init?(coder: NSCoder) {
  34. fatalError("init(coder:) has not been implemented")
  35. }
  36. }
  37. extension LNOrderGenerateQRCodePanel: LNOrderQRTabViewDelegate {
  38. func onOrderQRTabView(view: LNOrderQRTabView, didChangedType newType: LNOrderSource) {
  39. switch newType {
  40. case .normal:
  41. showView.isHidden = false
  42. customView.isHidden = true
  43. case .custom:
  44. showView.isHidden = true
  45. customView.isHidden = false
  46. }
  47. }
  48. }
  49. extension LNOrderGenerateQRCodePanel {
  50. private func onSkillChanged() {
  51. curSkillIc.sd_setImage(with: URL(string: curSkill?.icon ?? ""))
  52. curSkillNameLabel.text = curSkill?.name
  53. if let curSkill {
  54. showView.update(curSkill)
  55. customView.update(curSkill)
  56. }
  57. }
  58. }
  59. extension LNOrderGenerateQRCodePanel {
  60. private func setupViews() {
  61. container.backgroundColor = .primary_1
  62. let skill = buildSkillView()
  63. container.addSubview(skill)
  64. skill.snp.makeConstraints { make in
  65. make.horizontalEdges.equalToSuperview()
  66. make.top.equalToSuperview()
  67. }
  68. let tab = buildTabView()
  69. container.addSubview(tab)
  70. tab.snp.makeConstraints { make in
  71. make.horizontalEdges.equalToSuperview().inset(16)
  72. make.top.equalTo(skill.snp.bottom)
  73. }
  74. container.addSubview(showView)
  75. showView.snp.makeConstraints { make in
  76. make.horizontalEdges.equalToSuperview()
  77. make.top.equalTo(tab.snp.bottom)
  78. make.bottom.equalToSuperview().offset(-36)
  79. }
  80. container.addSubview(customView)
  81. customView.snp.makeConstraints { make in
  82. make.horizontalEdges.equalToSuperview()
  83. make.top.equalTo(tab.snp.bottom)
  84. make.bottom.equalToSuperview().offset(-36)
  85. }
  86. }
  87. private func buildSkillView() -> UIView {
  88. let container = UIView()
  89. container.snp.makeConstraints { make in
  90. make.height.equalTo(45)
  91. }
  92. curSkillIc.layer.cornerRadius = 10
  93. curSkillIc.clipsToBounds = true
  94. container.addSubview(curSkillIc)
  95. curSkillIc.snp.makeConstraints { make in
  96. make.centerY.equalToSuperview()
  97. make.leading.equalToSuperview().offset(16)
  98. make.width.height.equalTo(26)
  99. }
  100. curSkillNameLabel.font = .heading_h5
  101. curSkillNameLabel.textColor = .text_5
  102. container.addSubview(curSkillNameLabel)
  103. curSkillNameLabel.snp.makeConstraints { make in
  104. make.centerY.equalToSuperview()
  105. make.leading.equalTo(curSkillIc.snp.trailing).offset(4)
  106. }
  107. skillArrow.tintColor = .text_4
  108. container.addSubview(skillArrow)
  109. skillArrow.snp.makeConstraints { make in
  110. make.centerY.equalToSuperview()
  111. make.leading.equalTo(curSkillNameLabel.snp.trailing).offset(4)
  112. }
  113. container.onTap { [weak self] in
  114. guard let self else { return }
  115. let panel = LNOrderSkillListPanel(curSkillId: curSkill?.id) { [weak self] skill in
  116. guard let self else { return }
  117. self.curSkill = skill
  118. }
  119. panel.popup()
  120. }
  121. return container
  122. }
  123. private func buildTabView() -> UIView {
  124. tabView.delegate = self
  125. return tabView
  126. }
  127. }
  128. #if DEBUG
  129. import SwiftUI
  130. struct LNOrderQRPanelPreview: UIViewRepresentable {
  131. func makeUIView(context: Context) -> some UIView {
  132. let container = UIView()
  133. container.backgroundColor = .lightGray
  134. let view = LNOrderGenerateQRCodePanel()
  135. view.popup(container)
  136. return container
  137. }
  138. func updateUIView(_ uiView: UIViewType, context: Context) { }
  139. }
  140. #Preview(body: {
  141. LNOrderQRPanelPreview()
  142. })
  143. #endif