QSLHomeFriendTableViewCell.swift 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. //
  2. // QSLHomeFriendTableViewCell.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by mac on 2024/4/12.
  6. //
  7. import UIKit
  8. import MarqueeLabel
  9. protocol QSLHomeFriendTableViewCellDelegate: NSObjectProtocol {
  10. func routeBtnAction(model: QSLUserModel)
  11. func locateBtnAction(model: QSLUserModel)
  12. }
  13. class QSLHomeFriendTableViewCell: UITableViewCell {
  14. var model: QSLUserModel?
  15. weak var delegate: QSLHomeFriendTableViewCellDelegate?
  16. lazy var bgView: UIView = {
  17. let view = UIView()
  18. view.backgroundColor = .white
  19. view.addRadius(radius: 8.rpx)
  20. return view
  21. }()
  22. lazy var avatarImageView: UIImageView = {
  23. let imageView = UIImageView()
  24. imageView.image = UIImage(named: "friends_cell_avatar")
  25. return imageView
  26. }()
  27. lazy var tagImageView: UIImageView = {
  28. let imageView = UIImageView()
  29. imageView.isHidden = true
  30. imageView.image = UIImage(named: "friends_cell_tag")
  31. return imageView
  32. }()
  33. lazy var nameLabel: UILabel = {
  34. let label = UILabel()
  35. label.text = "用户123"
  36. label.font = UIFont.textM(16)
  37. label.textColor = QSLColor.Color_202020
  38. return label
  39. }()
  40. lazy var timeLabel: UILabel = {
  41. let label = UILabel()
  42. label.text = "1分钟前"
  43. label.font(12)
  44. label.textColor = .hexStringColor(hexString: "#A7A7A7")
  45. return label
  46. }()
  47. lazy var locateButton: UIButton = {
  48. let button = UIButton()
  49. button.setBackgroundImage(UIImage(named: "home_friends_locate_btn"), for: .normal)
  50. button.addTarget(self, action: #selector(locateBtnAction), for: .touchUpInside)
  51. return button
  52. }()
  53. lazy var locateIcon: UIImageView = {
  54. let imageView = UIImageView()
  55. imageView.image = UIImage(named: "friends_cell_location")
  56. return imageView
  57. }()
  58. lazy var addrLabel: MarqueeLabel = {
  59. let label = MarqueeLabel(frame: .zero, duration: 8.0, fadeLength: 10)
  60. label.font(13)
  61. label.textColor = .hexStringColor(hexString: "#A7A7A7")
  62. label.text = "广东奥林匹克广东奥林匹克广东奥林匹克 "
  63. return label
  64. }()
  65. lazy var checkButton: UIButton = {
  66. let button = UIButton(frame: CGRect(x: 0, y: 0, width: 72.rpx, height: 28.rpx))
  67. button.mediumFont(15)
  68. button.textColor(QSLColor.themeMainColor)
  69. button.title("轨迹")
  70. button.addCorner(conrners: .allCorners, radius: 22.rpx, borderWidth: 1.rpx, borderColor: QSLColor.themeMainColor)
  71. button.addTarget(self, action: #selector(checkButtonAction), for: .touchUpInside)
  72. return button
  73. }()
  74. lazy var blurView: UIView = {
  75. let effect = UIBlurEffect(style: .light)
  76. let blur = UIVisualEffectView(effect: effect)
  77. blur.isHidden = true
  78. return blur
  79. }()
  80. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  81. super.init(style: style, reuseIdentifier: reuseIdentifier)
  82. self.setCellUI()
  83. }
  84. required init?(coder: NSCoder) {
  85. fatalError("init(coder:) has not been implemented")
  86. }
  87. @objc func locateBtnAction() {
  88. if let model = self.model {
  89. delegate?.locateBtnAction(model: model)
  90. }
  91. }
  92. @objc func checkButtonAction() {
  93. if let model = self.model {
  94. delegate?.routeBtnAction(model: model)
  95. }
  96. }
  97. func config(model: QSLUserModel) {
  98. self.model = model
  99. if model.isMine {
  100. self.timeLabel.text = "10秒前"
  101. } else {
  102. if model.location.timestamp > 0 {
  103. let date = Date.timestampToFormatterDate(timestamp: "\(model.location.timestamp)")
  104. self.timeLabel.text = date.callTimeAfterNow()
  105. } else {
  106. self.timeLabel.text = "未知"
  107. }
  108. }
  109. if model.remark.count > 0 {
  110. self.nameLabel.text = model.remark
  111. } else {
  112. self.nameLabel.text = model.phone
  113. }
  114. if model.location.addr.count > 0 {
  115. self.addrLabel.text = model.location.addr + " "
  116. } else {
  117. self.addrLabel.text = "未知"
  118. }
  119. if !QSLBaseManager.shared.isVip() && !model.isMine {
  120. self.blurView.isHidden = false
  121. } else {
  122. if model.blockedMe {
  123. self.blurView.isHidden = false
  124. } else {
  125. self.blurView.isHidden = true
  126. }
  127. }
  128. }
  129. }
  130. extension QSLHomeFriendTableViewCell {
  131. func setCellUI() {
  132. self.backgroundColor = .clear
  133. self.contentView.backgroundColor = .clear
  134. contentView.addSubview(bgView)
  135. bgView.snp.makeConstraints { make in
  136. make.left.equalTo(12.rpx)
  137. make.right.equalTo(-12.rpx)
  138. make.top.equalTo(0)
  139. make.bottom.equalTo(-8.rpx)
  140. }
  141. bgView.addSubview(avatarImageView)
  142. avatarImageView.snp.makeConstraints { make in
  143. make.size.equalTo(CGSize(width: 48.rpx, height: 48.rpx))
  144. make.left.equalTo(16.rpx)
  145. make.top.equalTo(16.rpx)
  146. }
  147. // bgView.addSubview(tagImageView)
  148. // tagImageView.snp.makeConstraints { make in
  149. // make.centerX.equalTo(avatarImageView.snp.centerX)
  150. // make.centerY.equalTo(avatarImageView.snp.bottom)
  151. // }
  152. bgView.addSubview(nameLabel)
  153. nameLabel.snp.makeConstraints { make in
  154. make.top.equalTo(avatarImageView.snp.top).offset(4.rpx)
  155. make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
  156. }
  157. bgView.addSubview(timeLabel)
  158. timeLabel.snp.makeConstraints { make in
  159. make.centerY.equalTo(nameLabel.snp.centerY)
  160. make.left.equalTo(nameLabel.snp.right).offset(8.rpx)
  161. }
  162. bgView.addSubview(locateButton)
  163. locateButton.snp.makeConstraints { make in
  164. make.size.equalTo(CGSize(width: 24.rpx, height: 24.rpx))
  165. make.left.equalTo(timeLabel.snp.right).offset(6.rpx)
  166. make.centerY.equalTo(timeLabel.snp.centerY)
  167. }
  168. bgView.addSubview(checkButton)
  169. checkButton.snp.makeConstraints { make in
  170. make.size.equalTo(CGSize(width: 72.rpx, height: 28.rpx))
  171. make.right.equalTo(-12.rpx)
  172. make.centerY.equalTo(nameLabel.snp.centerY)
  173. }
  174. bgView.addSubview(locateIcon)
  175. locateIcon.snp.makeConstraints { make in
  176. make.size.equalTo(CGSize(width: 16.rpx, height: 16.rpx))
  177. make.bottom.equalTo(avatarImageView.snp.bottom).offset(5.rpx)
  178. make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
  179. }
  180. bgView.addSubview(addrLabel)
  181. addrLabel.snp.makeConstraints { make in
  182. make.centerY.equalTo(locateIcon.snp.centerY)
  183. make.left.equalTo(locateIcon.snp.right)
  184. make.height.equalTo(20.rpx)
  185. make.right.equalTo(-12.rpx)
  186. }
  187. bgView.addSubview(blurView)
  188. blurView.snp.makeConstraints { make in
  189. make.edges.equalTo(addrLabel.snp.edges)
  190. }
  191. }
  192. }