QSLMineVipView.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // QSLMineVipView.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2024/4/15.
  6. //
  7. import UIKit
  8. protocol QSLMineVipViewDelegate: NSObjectProtocol {
  9. func unlockBtnAction()
  10. }
  11. class QSLMineVipView: UIView {
  12. struct UX {
  13. static let buttonWidth = (QSLConst.qsl_kScreenW - 24.0) / 3
  14. static let buttonHeight = 32.0
  15. }
  16. weak var delegate: QSLMineVipViewDelegate?
  17. lazy var vipBgImageView: UIImageView = {
  18. let imageView = UIImageView()
  19. imageView.image = UIImage(named: "mine_vip_bg")
  20. return imageView
  21. }()
  22. lazy var vipTitleIcon: UIImageView = {
  23. let imageView = UIImageView()
  24. imageView.image = UIImage(named: "mine_vip_title")
  25. return imageView
  26. }()
  27. lazy var vipContentLabel: UILabel = {
  28. let label = UILabel()
  29. label.text("升级VIP会员,解锁全部功能")
  30. label.font(13)
  31. label.textColor = .hexStringColor(hexString: "#FFFFFF", alpha: 0.8)
  32. let tap = UITapGestureRecognizer(target: self, action: #selector(contentLabelAction))
  33. label.isUserInteractionEnabled = true
  34. label.addGestureRecognizer(tap)
  35. return label
  36. }()
  37. lazy var vipUnlockButton: UIButton = {
  38. let btn = UIButton()
  39. btn.addRadius(radius: 4.rpx)
  40. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#FFE1CD"), color2: .hexStringColor(hexString: "#FEB484"), width: 80.rpx, height: 32.rpx, direction: .horizontal)
  41. btn.title("立即开通")
  42. btn.textColor(.hexStringColor(hexString: "#9B3800"))
  43. btn.boldFont(14)
  44. btn.addTarget(self, action: #selector(unlockBtnAction), for: .touchUpInside)
  45. return btn
  46. }()
  47. override init(frame: CGRect) {
  48. super.init(frame: frame)
  49. setUpUI()
  50. }
  51. required init?(coder: NSCoder) {
  52. fatalError("init(coder:) has not been implemented")
  53. }
  54. }
  55. extension QSLMineVipView {
  56. @objc func unlockBtnAction() {
  57. delegate?.unlockBtnAction()
  58. }
  59. @objc func contentLabelAction() {
  60. let model = QSLBaseManager.shared.userModel.memberModel
  61. if model.permanent {
  62. delegate?.unlockBtnAction()
  63. }
  64. }
  65. }
  66. // MARK: - UI相关
  67. extension QSLMineVipView {
  68. func updateUI() {
  69. if QSLBaseManager.shared.isLogin() && QSLBaseManager.shared.isVip() {
  70. let model = QSLBaseManager.shared.userModel.memberModel
  71. if model.permanent {
  72. self.vipUnlockButton.isHidden = true
  73. self.vipContentLabel.text("您已是尊贵的永久会员 >")
  74. } else {
  75. self.vipUnlockButton.isHidden = false
  76. let level = model.memberLevelString()
  77. let endTime = model.endTimestampString()
  78. self.vipUnlockButton.title("立即续费")
  79. self.vipContentLabel.text("\(level):\(endTime)到期")
  80. }
  81. } else {
  82. self.vipUnlockButton.isHidden = false
  83. self.vipUnlockButton.title("立即开通")
  84. self.vipContentLabel.text("升级VIP会员,解锁全部功能")
  85. }
  86. }
  87. func setUpUI() {
  88. addSubview(vipBgImageView)
  89. addSubview(vipContentLabel)
  90. addSubview(vipTitleIcon)
  91. addSubview(vipUnlockButton)
  92. vipBgImageView.snp.makeConstraints { make in
  93. make.edges.equalTo(0)
  94. }
  95. vipTitleIcon.snp.makeConstraints { make in
  96. make.left.equalTo(17.rpx)
  97. make.bottom.equalTo(self.snp.centerY)
  98. make.size.equalTo(CGSize(width: 65.5.rpx, height: 17.rpx))
  99. }
  100. vipContentLabel.snp.makeConstraints { make in
  101. make.left.equalTo(17.rpx)
  102. make.top.equalTo(vipTitleIcon.snp.bottom).offset(5.rpx)
  103. }
  104. vipUnlockButton.snp.makeConstraints { make in
  105. make.size.equalTo(CGSize(width: 80.rpx, height: 32.rpx))
  106. make.centerY.equalToSuperview()
  107. make.right.equalTo(-20.rpx)
  108. }
  109. }
  110. }