126 lines
4.0 KiB
Swift
126 lines
4.0 KiB
Swift
//
|
|
// VPMeUserInfoCell.swift
|
|
// Veloria
|
|
//
|
|
// Created by 湖南秦九 on 2025/5/26.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class VPMeUserInfoCell: VPTableViewCell {
|
|
|
|
|
|
var userInfo: VPUserInfo? {
|
|
didSet {
|
|
avatarImageView.vp_setImage(url: userInfo?.avator, placeholder: UIImage(named: "avatar_placeholder_icon_01"))
|
|
|
|
if let name = userInfo?.family_name, name.count > 0 {
|
|
nicknameLabel.text = name
|
|
} else {
|
|
nicknameLabel.text = "veloria_visitor".localized
|
|
}
|
|
|
|
idLabel.text = "ID \(userInfo?.customer_id ?? "")"
|
|
|
|
loginButton.isHidden = !(userInfo?.is_tourist ?? true)
|
|
|
|
}
|
|
}
|
|
|
|
private lazy var avatarImageView: VPImageView = {
|
|
let imageView = VPImageView()
|
|
imageView.layer.cornerRadius = 22
|
|
imageView.layer.masksToBounds = true
|
|
imageView.layer.borderWidth = 1
|
|
imageView.layer.borderColor = UIColor.colorFFFFFF().cgColor
|
|
return imageView
|
|
}()
|
|
|
|
private lazy var nicknameLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .fontBold(ofSize: 16)
|
|
label.textColor = .colorFFFFFF()
|
|
return label
|
|
}()
|
|
|
|
private lazy var idLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .fontRegular(ofSize: 12)
|
|
label.textColor = .colorB5B5B5()
|
|
return label
|
|
}()
|
|
|
|
private lazy var loginButton: VPGradientButton = {
|
|
let title = AttributedString.createAttributedString(string: "veloria_check_in".localized, color: .colorFFFFFF(), font: .fontRegular(ofSize: 12))
|
|
|
|
var config = UIButton.Configuration.plain()
|
|
config.imagePlacement = .leading
|
|
config.imagePadding = 6
|
|
config.image = UIImage(named: "login_icon_01")
|
|
config.attributedTitle = title
|
|
config.contentInsets = .init(top: 0, leading: 12, bottom: 0, trailing: 12)
|
|
|
|
let button = VPGradientButton(configuration: config)
|
|
button.colors = [UIColor.color05CEA0(alpha: 0.3).cgColor, UIColor.color7C174F(alpha: 0.3).cgColor]
|
|
button.locations = [0, 1]
|
|
button.startPoint = .init(x: 0, y: 0.3)
|
|
button.endPoint = .init(x: 1, y: 0.8)
|
|
button.layer.cornerRadius = 17
|
|
button.layer.masksToBounds = true
|
|
button.bt_setGradientBorder()
|
|
button.addTarget(self, action: #selector(handleLoginButton), for: .touchUpInside)
|
|
return button
|
|
}()
|
|
|
|
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
|
|
bc_setupUI()
|
|
}
|
|
|
|
@MainActor required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
@objc private func handleLoginButton() {
|
|
VPLoginManager.manager.openLogin()
|
|
}
|
|
|
|
}
|
|
|
|
extension VPMeUserInfoCell {
|
|
|
|
private func bc_setupUI() {
|
|
contentView.addSubview(avatarImageView)
|
|
contentView.addSubview(nicknameLabel)
|
|
contentView.addSubview(idLabel)
|
|
// contentView.addSubview(loginButton)
|
|
|
|
avatarImageView.snp.makeConstraints { make in
|
|
make.left.equalToSuperview()
|
|
make.bottom.equalToSuperview()
|
|
make.width.height.equalTo(44)
|
|
make.top.equalToSuperview().offset(36)
|
|
}
|
|
|
|
nicknameLabel.snp.makeConstraints { make in
|
|
make.top.equalTo(avatarImageView).offset(3)
|
|
make.left.equalTo(avatarImageView.snp.right).offset(10)
|
|
make.right.lessThanOrEqualToSuperview().offset(-170)
|
|
}
|
|
|
|
idLabel.snp.makeConstraints { make in
|
|
make.left.equalTo(nicknameLabel)
|
|
make.bottom.equalTo(avatarImageView).offset(-3)
|
|
}
|
|
|
|
// loginButton.snp.makeConstraints { make in
|
|
// make.centerY.equalTo(avatarImageView)
|
|
// make.right.equalToSuperview()
|
|
// make.height.equalTo(34)
|
|
// }
|
|
|
|
}
|
|
|
|
}
|