| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- //
- // LNRoomSeatApplyListPanel.swift
- // Gami
- //
- // Created by OneeChan on 2026/3/13.
- //
- import Foundation
- import UIKit
- import SnapKit
- enum LNRoomSeatApplyTabType: Int, CaseIterable {
- case guest
- case playmate
- }
- class LNRoomSeatApplyListPanel: LNPopupView {
- private let tabBackgroundView = UIView()
- private let guestTabButton = UIButton()
- private let playmateTabButton = UIButton()
- private let tabSelectionView = UIView()
-
- private let countLabel = UILabel()
- private let countDescLabel = UILabel()
- private let filterButton = UIButton()
-
- private let tableView = UITableView(frame: .zero, style: .plain)
-
- private var guestItems: [LNRoomSeatApplyItem] = []
- private var playmateItems: [LNRoomSeatApplyItem] = []
- private var playmateCategoryTitle: String = "所有品类"
-
- private weak var roomSession: LNRoomViewModel?
-
- private var curTab: LNRoomSeatApplyTabType = .guest {
- didSet {
- guard oldValue != curTab else { return }
- reloadData()
- }
- }
-
- override init(frame: CGRect) {
- super.init(frame: frame)
-
- containerHeight = .percent(0.62)
-
- setupViews()
- }
-
- func update(_ room: LNRoomViewModel?) {
- roomSession = room
-
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
- extension LNRoomSeatApplyListPanel: UITableViewDataSource, UITableViewDelegate {
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- currentItems.count
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(
- withIdentifier: LNRoomSeatApplyListCell.className,
- for: indexPath
- ) as! LNRoomSeatApplyListCell
- let item = currentItems[indexPath.row]
- cell.update(room: roomSession, item: item, index: indexPath.row + 1)
- return cell
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- 64
- }
- }
- extension LNRoomSeatApplyListPanel {
- private var currentItems: [LNRoomSeatApplyItem] {
- switch curTab {
- case .guest: guestItems
- case .playmate: playmateItems
- }
- }
-
- private func reloadData() {
- updateTabs()
- countLabel.text = .init(key: "A00334", currentItems.count)
- filterButton.isHidden = curTab != .playmate
- filterButton.setTitle(playmateCategoryTitle, for: .normal)
- tableView.reloadData()
- }
-
- private func updateTabs() {
- let normalColor = UIColor.text_2
- let selectedColor = UIColor.text_5
- let selectedButton = curTab == .guest ? guestTabButton : playmateTabButton
-
- guestTabButton.setTitleColor(curTab == .guest ? selectedColor : normalColor, for: .normal)
- playmateTabButton.setTitleColor(curTab == .playmate ? selectedColor : normalColor, for: .normal)
-
- tabSelectionView.snp.remakeConstraints { make in
- make.centerY.equalToSuperview()
- make.leading.equalTo(selectedButton.snp.leading).offset(3)
- make.trailing.equalTo(selectedButton.snp.trailing).offset(-3)
- make.height.equalTo(26)
- }
-
- UIView.animate(withDuration: 0.25) { [weak self] in
- self?.tabBackgroundView.layoutIfNeeded()
- }
- }
-
- private func setupViews() {
- container.backgroundColor = .fill_7
-
- let tabView = buildTabView()
- container.addSubview(tabView)
- tabView.snp.makeConstraints { make in
- make.top.equalToSuperview().offset(16)
- make.horizontalEdges.equalToSuperview().inset(33)
- make.height.equalTo(32)
- }
-
- let countView = buildCountView()
- container.addSubview(countView)
- countView.snp.makeConstraints { make in
- make.top.equalTo(tabView.snp.bottom).offset(16)
- make.horizontalEdges.equalToSuperview().inset(16)
- make.height.equalTo(30)
- }
-
- let clearButton = UIButton()
- clearButton.layer.cornerRadius = 23.5
- clearButton.layer.borderColor = .fill_7
- clearButton.layer.borderWidth = 1
- clearButton.setTitle(.init(key: "A00335"), for: .normal)
- clearButton.setTitleColor(.text_2, for: .normal)
- clearButton.titleLabel?.font = .heading_h3
- clearButton.addAction(UIAction(handler: { [weak self] _ in
- guard let self else { return }
-
- }), for: .touchUpInside)
- container.addSubview(clearButton)
- clearButton.snp.makeConstraints { make in
- make.horizontalEdges.equalToSuperview().inset(16)
- make.bottom.equalToSuperview().offset(commonBottomInset)
- make.height.equalTo(47)
- }
-
- tableView.backgroundColor = .clear
- tableView.separatorStyle = .none
- tableView.showsVerticalScrollIndicator = false
- tableView.showsHorizontalScrollIndicator = false
- tableView.rowHeight = 64
- tableView.dataSource = self
- tableView.delegate = self
- tableView.register(LNRoomSeatApplyListCell.self, forCellReuseIdentifier: LNRoomSeatApplyListCell.className)
- container.addSubview(tableView)
- tableView.snp.makeConstraints { make in
- make.top.equalTo(countView.snp.bottom).offset(8)
- make.horizontalEdges.equalToSuperview().inset(16)
- make.bottom.equalTo(clearButton.snp.top)
- }
- }
-
- private func buildTabView() -> UIView {
- tabBackgroundView.backgroundColor = .fill.withAlphaComponent(0.2)
- tabBackgroundView.layer.cornerRadius = 16
- tabBackgroundView.clipsToBounds = true
-
- tabSelectionView.backgroundColor = .primary_1
- tabSelectionView.layer.cornerRadius = 13
- tabSelectionView.isUserInteractionEnabled = false
- tabBackgroundView.addSubview(tabSelectionView)
-
- let stackView = UIStackView()
- stackView.axis = .horizontal
- stackView.distribution = .fillEqually
- tabBackgroundView.addSubview(stackView)
- stackView.snp.makeConstraints { make in
- make.edges.equalToSuperview()
- }
-
- guestTabButton.setTitle(.init(key: "A00331"), for: .normal)
- guestTabButton.titleLabel?.font = .heading_h4
- guestTabButton.addAction(UIAction(handler: { [weak self] _ in
- self?.curTab = .guest
- }), for: .touchUpInside)
- stackView.addArrangedSubview(guestTabButton)
-
- playmateTabButton.setTitle(.init(key: "A00332"), for: .normal)
- playmateTabButton.titleLabel?.font = .heading_h4
- playmateTabButton.addAction(UIAction(handler: { [weak self] _ in
- self?.curTab = .playmate
- }), for: .touchUpInside)
- stackView.addArrangedSubview(playmateTabButton)
-
- return tabBackgroundView
- }
-
- private func buildCountView() -> UIView {
- let container = UIView()
-
- let stackView = UIStackView()
- stackView.axis = .horizontal
- stackView.spacing = 5
- stackView.alignment = .center
- container.addSubview(stackView)
- stackView.snp.makeConstraints { make in
- make.leading.centerY.equalToSuperview()
- }
-
- countLabel.font = .body_m
- countLabel.textColor = .text_6
- stackView.addArrangedSubview(countLabel)
-
- countDescLabel.font = .body_m
- countDescLabel.textColor = .text_1
- countDescLabel.text = .init(key: "A00333")
- stackView.addArrangedSubview(countDescLabel)
-
- filterButton.backgroundColor = .fill.withAlphaComponent(0.15)
- filterButton.layer.cornerRadius = 15
- filterButton.clipsToBounds = true
- filterButton.titleLabel?.font = .body_s
- filterButton.setTitleColor(.text_1, for: .normal)
- filterButton.setImage(.init(systemName: "chevron.down"), for: .normal)
- filterButton.tintColor = .text_1
- filterButton.semanticContentAttribute = .forceRightToLeft
- filterButton.imageEdgeInsets = .init(top: 0, left: 4, bottom: 0, right: -4)
- filterButton.contentEdgeInsets = .init(top: 0, left: 12, bottom: 0, right: 12)
- filterButton.addAction(UIAction(handler: { [weak self] _ in
- guard let self else { return }
- }), for: .touchUpInside)
- container.addSubview(filterButton)
- filterButton.snp.makeConstraints { make in
- make.centerY.trailing.equalToSuperview()
- make.height.equalTo(30)
- }
-
- return container
- }
- }
|