| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- //
- // QSLFriendTableViewCell.swift
- // QuickSearchLocation
- //
- // Created by Destiny on 2024/11/26.
- //
- import UIKit
- protocol QSLFriendTableViewCellDelegate: NSObjectProtocol {
-
- func moreBtnAction(model: QSLUserModel, btn: UIButton)
-
- func roadBtnClickAction(model: QSLUserModel)
- }
- class QSLFriendTableViewCell: UITableViewCell {
-
- weak var delegate: QSLFriendTableViewCellDelegate?
-
- var userModel: QSLUserModel?
-
- lazy var bgView: UIView = {
-
- let view = UIView()
- view.addRadius(radius: 8.rpx)
- view.backgroundColor = .white
- return view
- }()
-
- lazy var avatarImageView: UIImageView = {
-
- let imageView = UIImageView()
- imageView.image = UIImage(named: "friends_cell_avatar")
- return imageView
- }()
-
- lazy var nameLabel: UILabel = {
-
- let label = UILabel()
- label.text("用户")
- label.mediumFont(16)
- label.textColor = QSLColor.Color_202020
- return label
- }()
-
- lazy var moreBtn: UIButton = {
-
- let btn = UIButton()
- btn.image(UIImage(named: "friends_cell_more_btn"))
- btn.addTarget(self, action: #selector(moreBtnAction), for: .touchUpInside)
- return btn
- }()
-
- lazy var locateIcon: UIImageView = {
-
- let imageView = UIImageView()
- imageView.image = UIImage(named: "friends_cell_location")
- return imageView
- }()
-
- lazy var addrLabel: UILabel = {
-
- let label = UILabel()
- label.numberOfLines = 0
- label.font(13)
- label.textColor = .hexStringColor(hexString: "#404040")
- label.text = "未知"
- label.changeLineSpace(space: 4)
- return label
- }()
-
- lazy var lineView: UIView = {
-
- let view = UIView()
- view.backgroundColor = .hexStringColor(hexString: "#F0F0F0", alpha: 0.2)
- return view
- }()
-
- lazy var timeLabel: UILabel = {
-
- let label = UILabel()
- label.text("未知")
- label.font(13)
- label.textColor = .hexStringColor(hexString: "#A7A7A7")
- return label
- }()
-
- lazy var checkBtn: UIButton = {
-
- let btn = UIButton()
- btn.addRadius(radius: 16.rpx)
- btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 92.rpx, height: 32.rpx, direction: .horizontal)
- btn.title("查看轨迹")
- btn.textColor(.white)
- btn.mediumFont(15)
- btn.addTarget(self, action: #selector(checkBtnAction), for: .touchUpInside)
- return btn
- }()
-
- lazy var blurView: UIView = {
-
- let effect = UIBlurEffect(style: .light)
- let blur = UIVisualEffectView(effect: effect)
- blur.isHidden = true
- return blur
- }()
-
- override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
-
- initUI()
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- func config(model: QSLUserModel) {
- self.userModel = model
-
- if model.isMine {
- self.timeLabel.text = Date().formateCurrentDate
- self.moreBtn.isHidden = true
- } else {
- self.moreBtn.isHidden = false
-
- if model.location.timestamp > 0 {
- self.timeLabel.text = Date.timestampToFormatterTimeString(timestamp: "\(model.location.timestamp)")
- } else {
- self.timeLabel.text = "未知"
- }
- }
-
- if model.remark.count > 0 {
- self.nameLabel.text = model.remark
- } else {
- self.nameLabel.text = model.phone
- }
-
- if model.location.addr.count > 0 {
- self.addrLabel.text = model.location.addr
- } else {
- self.addrLabel.text = "未知"
- }
-
- if !QSLBaseManager.shared.isVip() && !model.isMine {
- self.blurView.isHidden = false
- } else {
- if model.blockedMe {
- self.blurView.isHidden = false
- } else {
- self.blurView.isHidden = true
- }
- }
- }
- }
- extension QSLFriendTableViewCell {
-
- @objc func moreBtnAction() {
-
- if let model = self.userModel {
- delegate?.moreBtnAction(model: model, btn: self.moreBtn)
- }
- }
-
- @objc func checkBtnAction() {
-
- if let model = self.userModel {
- delegate?.roadBtnClickAction(model: model)
- }
- }
- }
- extension QSLFriendTableViewCell {
-
- func initUI() {
-
- self.backgroundColor = .clear
-
- self.contentView.addSubview(bgView)
- bgView.snp.makeConstraints { make in
- make.edges.equalToSuperview()
- }
-
- bgView.addSubview(avatarImageView)
- avatarImageView.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 48.rpx, height: 48.rpx))
- make.left.equalTo(16.rpx)
- make.top.equalTo(22.rpx)
- }
-
- bgView.addSubview(nameLabel)
- nameLabel.snp.makeConstraints { make in
- make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
- make.top.equalTo(avatarImageView.snp.top).offset(5.rpx)
- }
-
- bgView.addSubview(moreBtn)
- moreBtn.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 24.rpx, height: 24.rpx))
- make.right.equalTo(-16.rpx)
- make.top.equalTo(20.rpx)
- }
-
- bgView.addSubview(locateIcon)
- locateIcon.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 16.rpx, height: 16.rpx))
- make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
- make.top.equalTo(nameLabel.snp.bottom).offset(8.rpx)
- }
-
- bgView.addSubview(addrLabel)
- addrLabel.snp.makeConstraints { make in
- make.left.equalTo(locateIcon.snp.right)
- make.right.equalTo(-16.rpx)
- make.top.equalTo(locateIcon.snp.top)
- }
-
- bgView.addSubview(blurView)
- blurView.snp.makeConstraints { make in
- make.edges.equalTo(addrLabel.snp.edges)
- }
-
- bgView.addSubview(lineView)
- lineView.snp.makeConstraints { make in
- make.left.equalTo(16.rpx)
- make.right.equalTo(-16.rpx)
- make.height.equalTo(1.rpx)
- make.bottom.equalTo(-47.rpx)
- }
-
- bgView.addSubview(timeLabel)
- timeLabel.snp.makeConstraints { make in
- make.left.equalTo(16.rpx)
- make.bottom.equalTo(-14.rpx)
- }
-
- bgView.addSubview(checkBtn)
- checkBtn.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 92.rpx, height: 32.rpx))
- make.right.equalTo(-16.rpx)
- make.centerY.equalTo(timeLabel.snp.centerY)
- }
- }
- }
|