| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- //
- // LNOrderGenerateQRCodePanel.swift
- // Lanu
- //
- // Created by OneeChan on 2025/11/26.
- //
- import Foundation
- import UIKit
- import SnapKit
- class LNOrderGenerateQRCodePanel: LNPopupView {
- private let curSkillIc = UIImageView()
- private let curSkillNameLabel = UILabel()
- private let skillArrow = UIImageView.arrowImageView(size: 14)
-
- private let tabView = LNOrderQRTabView()
-
- private let showView = LNOrderQRCodeShowView()
- private let customView = LNOrderCustomView()
-
- private var curSkill: LNGameMateSkillVO? {
- didSet {
- if oldValue?.id != curSkill?.id {
- onSkillChanged()
- }
- }
- }
-
- override init(frame: CGRect) {
- super.init(frame: frame)
-
- setupViews()
-
- DispatchQueue.main.async { [weak self] in
- guard let self else { return }
- tabView.curType = .normal
- curSkill = myUserInfo.skills.first
- }
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
- extension LNOrderGenerateQRCodePanel: LNOrderQRTabViewDelegate {
- func onOrderQRTabView(view: LNOrderQRTabView, didChangedType newType: LNOrderSource) {
- switch newType {
- case .normal:
- showView.isHidden = false
- customView.isHidden = true
- case .custom:
- showView.isHidden = true
- customView.isHidden = false
- }
- }
- }
- extension LNOrderGenerateQRCodePanel {
- private func onSkillChanged() {
- curSkillIc.sd_setImage(with: URL(string: curSkill?.icon ?? ""))
- curSkillNameLabel.text = curSkill?.name
-
- if let curSkill {
- showView.update(curSkill)
- customView.update(curSkill)
- }
- }
- }
- extension LNOrderGenerateQRCodePanel {
- private func setupViews() {
- container.backgroundColor = .primary_1
-
- let skill = buildSkillView()
- container.addSubview(skill)
- skill.snp.makeConstraints { make in
- make.horizontalEdges.equalToSuperview()
- make.top.equalToSuperview()
- }
-
- let tab = buildTabView()
- container.addSubview(tab)
- tab.snp.makeConstraints { make in
- make.horizontalEdges.equalToSuperview().inset(16)
- make.top.equalTo(skill.snp.bottom)
- }
-
- container.addSubview(showView)
- showView.snp.makeConstraints { make in
- make.horizontalEdges.equalToSuperview()
- make.top.equalTo(tab.snp.bottom)
- make.bottom.equalToSuperview().offset(-36)
- }
-
- container.addSubview(customView)
- customView.snp.makeConstraints { make in
- make.horizontalEdges.equalToSuperview()
- make.top.equalTo(tab.snp.bottom)
- make.bottom.equalToSuperview().offset(-36)
- }
- }
-
- private func buildSkillView() -> UIView {
- let container = UIView()
- container.snp.makeConstraints { make in
- make.height.equalTo(45)
- }
-
- curSkillIc.layer.cornerRadius = 10
- curSkillIc.clipsToBounds = true
- container.addSubview(curSkillIc)
- curSkillIc.snp.makeConstraints { make in
- make.centerY.equalToSuperview()
- make.leading.equalToSuperview().offset(16)
- make.width.height.equalTo(26)
- }
-
- curSkillNameLabel.font = .heading_h5
- curSkillNameLabel.textColor = .text_5
- container.addSubview(curSkillNameLabel)
- curSkillNameLabel.snp.makeConstraints { make in
- make.centerY.equalToSuperview()
- make.leading.equalTo(curSkillIc.snp.trailing).offset(4)
- }
-
- skillArrow.tintColor = .text_4
- container.addSubview(skillArrow)
- skillArrow.snp.makeConstraints { make in
- make.centerY.equalToSuperview()
- make.leading.equalTo(curSkillNameLabel.snp.trailing).offset(4)
- }
-
- container.onTap { [weak self] in
- guard let self else { return }
- let panel = LNOrderSkillListPanel(curSkillId: curSkill?.id) { [weak self] skill in
- guard let self else { return }
- self.curSkill = skill
- }
- panel.popup()
- }
-
- return container
- }
-
- private func buildTabView() -> UIView {
- tabView.delegate = self
-
- return tabView
- }
- }
- #if DEBUG
- import SwiftUI
- struct LNOrderQRPanelPreview: UIViewRepresentable {
- func makeUIView(context: Context) -> some UIView {
- let container = UIView()
- container.backgroundColor = .lightGray
-
- let view = LNOrderGenerateQRCodePanel()
- view.popup(container)
-
- return container
- }
-
- func updateUIView(_ uiView: UIViewType, context: Context) { }
- }
- #Preview(body: {
- LNOrderQRPanelPreview()
- })
- #endif
|