LNOrderRoomApplySeatListPanel.swift 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // LNOrderRoomApplySeatListPanel.swift
  3. // Gami
  4. //
  5. // Created by OneeChan on 2026/3/18.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. import MJRefresh
  11. class LNOrderRoomApplySeatListPanel: LNPopupView {
  12. private let emptyView = LNNoMoreDataView()
  13. private let countLabel = UILabel()
  14. private let countDescLabel = UILabel()
  15. private let tableView = UITableView(frame: .zero, style: .plain)
  16. private weak var roomSession: LNOrderRoomViewModel?
  17. private var nextTag: String? = nil
  18. private var items: [LNRoomMicApplyPageVO] = []
  19. override init(frame: CGRect) {
  20. super.init(frame: frame)
  21. containerHeight = .percent(0.62)
  22. setupViews()
  23. }
  24. func update(_ room: LNOrderRoomViewModel?) {
  25. roomSession = room
  26. loadList()
  27. }
  28. required init?(coder: NSCoder) {
  29. fatalError("init(coder:) has not been implemented")
  30. }
  31. }
  32. private extension LNOrderRoomApplySeatListPanel {
  33. func loadList() {
  34. guard let roomSession else { return }
  35. roomSession.getApplyList(type: .all, next: nextTag, filter: nil) { [weak self] res in
  36. guard let self else { return }
  37. if let list = res?.list {
  38. if nextTag == nil {
  39. items.removeAll()
  40. }
  41. items.append(contentsOf: list)
  42. nextTag = res?.next
  43. tableView.reloadData()
  44. if items.isEmpty {
  45. emptyView.showNoData(tips: .init(key: "A00005"))
  46. } else {
  47. emptyView.hide()
  48. }
  49. } else {
  50. if items.isEmpty {
  51. emptyView.showNetworkError()
  52. }
  53. }
  54. tableView.mj_header?.endRefreshing()
  55. if nextTag?.isEmpty != false {
  56. tableView.mj_footer?.endRefreshingWithNoMoreData()
  57. } else {
  58. tableView.mj_footer?.endRefreshing()
  59. }
  60. updateCountView()
  61. }
  62. }
  63. }
  64. extension LNOrderRoomApplySeatListPanel: UITableViewDataSource {
  65. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  66. items.count
  67. }
  68. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  69. let cell = tableView.dequeueReusableCell(
  70. withIdentifier: LNOrderRoomApplySeatCell.className,
  71. for: indexPath
  72. ) as! LNOrderRoomApplySeatCell
  73. cell.update(item: items[indexPath.row], index: indexPath.row + 1)
  74. return cell
  75. }
  76. }
  77. private extension LNOrderRoomApplySeatListPanel {
  78. private func updateCountView() {
  79. let text = String(key: "A00333", items.count)
  80. let range = (text as NSString).range(of: .init(key: "A00334", items.count))
  81. let attrString = NSMutableAttributedString(string: text)
  82. attrString.addAttributes([
  83. .foregroundColor: UIColor.text_6
  84. ], range: range)
  85. countLabel.attributedText = attrString
  86. }
  87. func setupViews() {
  88. container.backgroundColor = .fill_7
  89. let countView = buildCountView()
  90. container.addSubview(countView)
  91. countView.snp.makeConstraints { make in
  92. make.top.equalToSuperview().offset(16)
  93. make.horizontalEdges.equalToSuperview().inset(16)
  94. make.height.equalTo(20)
  95. }
  96. let clearButton = UIButton()
  97. clearButton.layer.cornerRadius = 23.5
  98. clearButton.layer.borderColor = UIColor.fill.withAlphaComponent(0.2).cgColor
  99. clearButton.layer.borderWidth = 1
  100. clearButton.setTitle(.init(key: "A00372"), for: .normal)
  101. clearButton.setTitleColor(.text_2, for: .normal)
  102. clearButton.titleLabel?.font = .heading_h3
  103. clearButton.addAction(UIAction(handler: { [weak self] _ in
  104. guard let self else { return }
  105. roomSession?.cancelSeatApply { [weak self] success in
  106. guard let self else { return }
  107. guard success else { return }
  108. dismiss()
  109. }
  110. }), for: .touchUpInside)
  111. container.addSubview(clearButton)
  112. clearButton.snp.makeConstraints { make in
  113. make.horizontalEdges.equalToSuperview().inset(16)
  114. make.bottom.equalToSuperview().offset(commonBottomInset)
  115. make.height.equalTo(47)
  116. }
  117. let header = MJRefreshNormalHeader { [weak self] in
  118. guard let self else { return }
  119. self.nextTag = nil
  120. self.loadList()
  121. }
  122. header.lastUpdatedTimeLabel?.isHidden = true
  123. header.stateLabel?.isHidden = true
  124. tableView.mj_header = header
  125. let footer = MJRefreshAutoNormalFooter { [weak self] in
  126. guard let self else { return }
  127. self.loadList()
  128. }
  129. footer.setTitle("", for: .noMoreData)
  130. footer.setTitle(.init(key: "A00046"), for: .idle)
  131. tableView.mj_footer = footer
  132. tableView.backgroundColor = .clear
  133. tableView.separatorStyle = .none
  134. tableView.showsVerticalScrollIndicator = false
  135. tableView.showsHorizontalScrollIndicator = false
  136. tableView.allowsSelection = false
  137. tableView.dataSource = self
  138. tableView.register(LNOrderRoomApplySeatCell.self, forCellReuseIdentifier: LNOrderRoomApplySeatCell.className)
  139. container.addSubview(tableView)
  140. tableView.snp.makeConstraints { make in
  141. make.top.equalTo(countView.snp.bottom).offset(12)
  142. make.horizontalEdges.equalToSuperview()
  143. make.bottom.equalTo(clearButton.snp.top)
  144. }
  145. tableView.addSubview(emptyView)
  146. emptyView.snp.makeConstraints { make in
  147. make.centerX.equalToSuperview()
  148. make.centerY.equalToSuperview().multipliedBy(0.6)
  149. }
  150. }
  151. func buildCountView() -> UIView {
  152. let container = UIView()
  153. countLabel.font = .body_m
  154. countLabel.textColor = .text_1
  155. container.addSubview(countLabel)
  156. countLabel.snp.makeConstraints { make in
  157. make.leading.centerY.equalToSuperview()
  158. }
  159. return container
  160. }
  161. }