LNMineOrderRecordView.swift 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. //
  2. // LNMineOrderRecordView.swift
  3. // Gami
  4. //
  5. // Created by OneeChan on 2026/1/22.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. class LNMineOrderRecordView: UIView {
  11. private let incomeLabel = UILabel()
  12. private let exposureLabel = UILabel()
  13. private let visitorLabel = UILabel()
  14. private let statusButton = UIButton()
  15. private let statusLabel = UILabel()
  16. private let statusDescLabel = UILabel()
  17. override init(frame: CGRect) {
  18. super.init(frame: frame)
  19. setupViews()
  20. LNEventDeliver.addObserver(self)
  21. onGameMateManagerInfoChanged()
  22. }
  23. required init?(coder: NSCoder) {
  24. fatalError("init(coder:) has not been implemented")
  25. }
  26. }
  27. extension LNMineOrderRecordView: LNGameMateManagerNotify {
  28. func onGameMateManagerInfoChanged() {
  29. guard let myGameMateInfo else { return }
  30. incomeLabel.text = myGameMateInfo.weekBeanIncome.toDisplay
  31. exposureLabel.text = "\(myGameMateInfo.exposureCountDay)"
  32. visitorLabel.text = "\(myGameMateInfo.potentialUserCount)"
  33. if myGameMateInfo.playmateOpen {
  34. statusButton.setBackgroundImage(.primary_7, for: .normal)
  35. statusLabel.text = .init(key: "B00087")
  36. statusDescLabel.text = .init(key: "B00088")
  37. } else {
  38. statusButton.setBackgroundImage(.primary_8, for: .normal)
  39. statusLabel.text = .init(key: "B00089")
  40. statusDescLabel.text = .init(key: "B00090")
  41. }
  42. }
  43. }
  44. extension LNMineOrderRecordView {
  45. private func setupViews() {
  46. layer.cornerRadius = 12
  47. backgroundColor = .fill
  48. onTap { [weak self] in
  49. guard let self else { return }
  50. pushToMateCenter()
  51. }
  52. let header = buildHeaderView()
  53. addSubview(header)
  54. header.snp.makeConstraints { make in
  55. make.horizontalEdges.equalToSuperview()
  56. make.top.equalToSuperview()
  57. }
  58. let recordView = buildRecordInfo()
  59. addSubview(recordView)
  60. recordView.snp.makeConstraints { make in
  61. make.horizontalEdges.equalToSuperview().inset(24)
  62. make.top.equalTo(header.snp.bottom)
  63. }
  64. let openButton = buildOpenButton()
  65. addSubview(openButton)
  66. openButton.snp.makeConstraints { make in
  67. make.horizontalEdges.equalToSuperview().inset(12)
  68. make.top.equalTo(recordView.snp.bottom).offset(12)
  69. make.bottom.equalToSuperview().offset(-12)
  70. }
  71. }
  72. private func buildHeaderView() -> UIView {
  73. let container = UIView()
  74. container.isUserInteractionEnabled = false
  75. container.snp.makeConstraints { make in
  76. make.height.equalTo(40)
  77. }
  78. let titleLabel = UILabel()
  79. titleLabel.text = .init(key: "B00071")
  80. titleLabel.font = .heading_h3
  81. titleLabel.textColor = .text_5
  82. container.addSubview(titleLabel)
  83. titleLabel.snp.makeConstraints { make in
  84. make.centerY.equalToSuperview()
  85. make.leading.equalToSuperview().offset(16)
  86. }
  87. let arrow = UIImageView.arrowImageView(size: 16)
  88. arrow.tintColor = .text_4
  89. container.addSubview(arrow)
  90. arrow.snp.makeConstraints { make in
  91. make.centerY.equalToSuperview()
  92. make.trailing.equalToSuperview().offset(-16)
  93. }
  94. return container
  95. }
  96. private func buildRecordInfo() -> UIView {
  97. let stackView = UIStackView()
  98. stackView.axis = .horizontal
  99. stackView.distribution = .equalSpacing
  100. stackView.spacing = 28
  101. stackView.alignment = .center
  102. stackView.isUserInteractionEnabled = false
  103. stackView.snp.makeConstraints { make in
  104. make.height.equalTo(56)
  105. }
  106. stackView.addArrangedSubview(buildInCome())
  107. stackView.addArrangedSubview(buildLine())
  108. stackView.addArrangedSubview(buildDataItemView(.init(key: "B00073"), contentLabel: exposureLabel))
  109. stackView.addArrangedSubview(buildDataItemView(.init(key: "B00116"), contentLabel: visitorLabel))
  110. return stackView
  111. }
  112. private func buildInCome() -> UIView {
  113. let container = UIView()
  114. container.snp.makeConstraints { make in
  115. make.width.greaterThanOrEqualTo(120)
  116. }
  117. let beanView = UIView()
  118. container.addSubview(beanView)
  119. beanView.snp.makeConstraints { make in
  120. make.centerX.equalToSuperview()
  121. make.top.equalToSuperview()
  122. }
  123. let beanIc = UIImageView.beanImageView()
  124. beanView.addSubview(beanIc)
  125. beanIc.snp.makeConstraints { make in
  126. make.centerY.equalToSuperview()
  127. make.leading.equalToSuperview()
  128. make.width.height.equalTo(20)
  129. }
  130. incomeLabel.text = "0"
  131. incomeLabel.font = .heading_h1
  132. incomeLabel.textColor = .text_5
  133. beanView.addSubview(incomeLabel)
  134. incomeLabel.snp.makeConstraints { make in
  135. make.verticalEdges.equalToSuperview()
  136. make.trailing.equalToSuperview()
  137. make.leading.equalTo(beanIc.snp.trailing)
  138. }
  139. let desclabel = UILabel()
  140. desclabel.text = .init(key: "B00072")
  141. desclabel.font = .body_s
  142. desclabel.textColor = .text_5
  143. desclabel.textAlignment = .center
  144. desclabel.numberOfLines = 2
  145. container.addSubview(desclabel)
  146. desclabel.snp.makeConstraints { make in
  147. make.horizontalEdges.equalToSuperview()
  148. make.bottom.equalToSuperview()
  149. make.top.equalTo(beanView.snp.bottom).offset(6)
  150. }
  151. return container
  152. }
  153. private func buildDataItemView(_ title: String, contentLabel: UILabel) -> UIView {
  154. let container = UIView()
  155. container.snp.makeConstraints { make in
  156. make.width.lessThanOrEqualTo(60)
  157. }
  158. contentLabel.text = "0"
  159. contentLabel.font = .heading_h2
  160. contentLabel.textColor = .text_5
  161. container.addSubview(contentLabel)
  162. contentLabel.snp.makeConstraints { make in
  163. make.top.equalToSuperview()
  164. make.centerX.equalToSuperview()
  165. }
  166. let descLabel = UILabel()
  167. descLabel.text = title
  168. descLabel.font = .body_s
  169. descLabel.textColor = .text_4
  170. descLabel.numberOfLines = 2
  171. descLabel.textAlignment = .center
  172. container.addSubview(descLabel)
  173. descLabel.snp.makeConstraints { make in
  174. make.horizontalEdges.equalToSuperview()
  175. make.bottom.equalToSuperview()
  176. make.top.equalTo(contentLabel.snp.bottom).offset(2)
  177. }
  178. return container
  179. }
  180. private func buildOpenButton() -> UIView {
  181. statusButton.layer.cornerRadius = 26
  182. statusButton.clipsToBounds = true
  183. statusButton.setBackgroundImage(.primary_8, for: .normal)
  184. statusButton.addAction(UIAction(handler: { _ in
  185. showLoading()
  186. let isOpen = myGameMateInfo?.playmateOpen == true
  187. LNGameMateManager.shared.enableGameMate(open: !isOpen) { success in
  188. dismissLoading()
  189. }
  190. }), for: .touchUpInside)
  191. statusButton.snp.makeConstraints { make in
  192. make.height.equalTo(56)
  193. }
  194. let container = UIView()
  195. container.isUserInteractionEnabled = false
  196. statusButton.addSubview(container)
  197. container.snp.makeConstraints { make in
  198. make.center.equalToSuperview()
  199. make.leading.greaterThanOrEqualToSuperview().offset(16)
  200. }
  201. statusLabel.font = .heading_h3
  202. statusLabel.textColor = .text_1
  203. statusLabel.textAlignment = .center
  204. container.addSubview(statusLabel)
  205. statusLabel.snp.makeConstraints { make in
  206. make.horizontalEdges.equalToSuperview()
  207. make.top.equalToSuperview()
  208. }
  209. statusDescLabel.font = .body_xs
  210. statusDescLabel.textColor = .primary_1
  211. container.addSubview(statusDescLabel)
  212. statusDescLabel.snp.makeConstraints { make in
  213. make.horizontalEdges.equalToSuperview()
  214. make.bottom.equalToSuperview()
  215. make.top.equalTo(statusLabel.snp.bottom)
  216. }
  217. return statusButton
  218. }
  219. private func buildLine() -> UIView {
  220. let line = UIView()
  221. line.backgroundColor = .init(hex: "#D9D9D9")
  222. line.snp.makeConstraints { make in
  223. make.width.equalTo(1)
  224. make.height.equalTo(37)
  225. }
  226. return line
  227. }
  228. }