QSLFriendTableViewCell.swift 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. //
  2. // QSLFriendTableViewCell.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2024/11/26.
  6. //
  7. import UIKit
  8. protocol QSLFriendTableViewCellDelegate: NSObjectProtocol {
  9. func moreBtnAction(model: QSLUserModel, btn: UIButton)
  10. func roadBtnClickAction(model: QSLUserModel)
  11. }
  12. class QSLFriendTableViewCell: UITableViewCell {
  13. weak var delegate: QSLFriendTableViewCellDelegate?
  14. var userModel: QSLUserModel?
  15. lazy var bgView: UIView = {
  16. let view = UIView()
  17. view.addRadius(radius: 8.rpx)
  18. view.backgroundColor = .white
  19. return view
  20. }()
  21. lazy var avatarImageView: UIImageView = {
  22. let imageView = UIImageView()
  23. imageView.image = UIImage(named: "friends_cell_avatar")
  24. return imageView
  25. }()
  26. lazy var nameLabel: UILabel = {
  27. let label = UILabel()
  28. label.text("用户")
  29. label.mediumFont(16)
  30. label.textColor = QSLColor.Color_202020
  31. return label
  32. }()
  33. lazy var moreBtn: UIButton = {
  34. let btn = UIButton()
  35. btn.image(UIImage(named: "friends_cell_more_btn"))
  36. btn.addTarget(self, action: #selector(moreBtnAction), for: .touchUpInside)
  37. return btn
  38. }()
  39. lazy var locateIcon: UIImageView = {
  40. let imageView = UIImageView()
  41. imageView.image = UIImage(named: "friends_cell_location")
  42. return imageView
  43. }()
  44. lazy var addrLabel: UILabel = {
  45. let label = UILabel()
  46. label.numberOfLines = 0
  47. label.font(13)
  48. label.textColor = .hexStringColor(hexString: "#404040")
  49. label.text = "未知"
  50. label.changeLineSpace(space: 4)
  51. return label
  52. }()
  53. lazy var lineView: UIView = {
  54. let view = UIView()
  55. view.backgroundColor = .hexStringColor(hexString: "#F0F0F0", alpha: 0.2)
  56. return view
  57. }()
  58. lazy var timeLabel: UILabel = {
  59. let label = UILabel()
  60. label.text("未知")
  61. label.font(13)
  62. label.textColor = .hexStringColor(hexString: "#A7A7A7")
  63. return label
  64. }()
  65. lazy var checkBtn: UIButton = {
  66. let btn = UIButton()
  67. btn.addRadius(radius: 16.rpx)
  68. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 92.rpx, height: 32.rpx, direction: .horizontal)
  69. btn.title("查看轨迹")
  70. btn.textColor(.white)
  71. btn.mediumFont(15)
  72. btn.addTarget(self, action: #selector(checkBtnAction), for: .touchUpInside)
  73. return btn
  74. }()
  75. lazy var blurView: UIView = {
  76. let effect = UIBlurEffect(style: .light)
  77. let blur = UIVisualEffectView(effect: effect)
  78. blur.isHidden = true
  79. return blur
  80. }()
  81. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  82. super.init(style: style, reuseIdentifier: reuseIdentifier)
  83. initUI()
  84. }
  85. required init?(coder: NSCoder) {
  86. fatalError("init(coder:) has not been implemented")
  87. }
  88. func config(model: QSLUserModel) {
  89. self.userModel = model
  90. if model.isMine {
  91. self.timeLabel.text = Date().formateCurrentDate
  92. self.moreBtn.isHidden = true
  93. } else {
  94. self.moreBtn.isHidden = false
  95. if model.location.timestamp > 0 {
  96. self.timeLabel.text = Date.timestampToFormatterTimeString(timestamp: "\(model.location.timestamp)")
  97. } else {
  98. self.timeLabel.text = "未知"
  99. }
  100. }
  101. if model.remark.count > 0 {
  102. self.nameLabel.text = model.remark
  103. } else {
  104. self.nameLabel.text = model.phone
  105. }
  106. if model.location.addr.count > 0 {
  107. self.addrLabel.text = model.location.addr
  108. } else {
  109. self.addrLabel.text = "未知"
  110. }
  111. if !QSLBaseManager.shared.isVip() && !model.isMine {
  112. self.blurView.isHidden = false
  113. } else {
  114. if model.blockedMe {
  115. self.blurView.isHidden = false
  116. } else {
  117. self.blurView.isHidden = true
  118. }
  119. }
  120. }
  121. }
  122. extension QSLFriendTableViewCell {
  123. @objc func moreBtnAction() {
  124. if let model = self.userModel {
  125. delegate?.moreBtnAction(model: model, btn: self.moreBtn)
  126. }
  127. }
  128. @objc func checkBtnAction() {
  129. if QSLBaseManager.shared.isVip() {
  130. //点击搜索埋点
  131. gravityInstance?.track(QSLGravityConst.vip_location_click_queryTrack, properties: ["id": 03008])
  132. } else {
  133. //点击搜索埋点
  134. gravityInstance?.track(QSLGravityConst.location_click_queryTrack, properties: ["id": 03009])
  135. }
  136. if let model = self.userModel {
  137. delegate?.roadBtnClickAction(model: model)
  138. }
  139. }
  140. }
  141. extension QSLFriendTableViewCell {
  142. func initUI() {
  143. self.backgroundColor = .clear
  144. self.contentView.addSubview(bgView)
  145. bgView.snp.makeConstraints { make in
  146. make.edges.equalToSuperview()
  147. }
  148. bgView.addSubview(avatarImageView)
  149. avatarImageView.snp.makeConstraints { make in
  150. make.size.equalTo(CGSize(width: 48.rpx, height: 48.rpx))
  151. make.left.equalTo(16.rpx)
  152. make.top.equalTo(22.rpx)
  153. }
  154. bgView.addSubview(nameLabel)
  155. nameLabel.snp.makeConstraints { make in
  156. make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
  157. make.top.equalTo(avatarImageView.snp.top).offset(5.rpx)
  158. }
  159. bgView.addSubview(moreBtn)
  160. moreBtn.snp.makeConstraints { make in
  161. make.size.equalTo(CGSize(width: 24.rpx, height: 24.rpx))
  162. make.right.equalTo(-16.rpx)
  163. make.top.equalTo(20.rpx)
  164. }
  165. bgView.addSubview(locateIcon)
  166. locateIcon.snp.makeConstraints { make in
  167. make.size.equalTo(CGSize(width: 16.rpx, height: 16.rpx))
  168. make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
  169. make.top.equalTo(nameLabel.snp.bottom).offset(8.rpx)
  170. }
  171. bgView.addSubview(addrLabel)
  172. addrLabel.snp.makeConstraints { make in
  173. make.left.equalTo(locateIcon.snp.right)
  174. make.right.equalTo(-16.rpx)
  175. make.top.equalTo(locateIcon.snp.top)
  176. }
  177. bgView.addSubview(blurView)
  178. blurView.snp.makeConstraints { make in
  179. make.edges.equalTo(addrLabel.snp.edges)
  180. }
  181. bgView.addSubview(lineView)
  182. lineView.snp.makeConstraints { make in
  183. make.left.equalTo(16.rpx)
  184. make.right.equalTo(-16.rpx)
  185. make.height.equalTo(1.rpx)
  186. make.bottom.equalTo(-47.rpx)
  187. }
  188. bgView.addSubview(timeLabel)
  189. timeLabel.snp.makeConstraints { make in
  190. make.left.equalTo(16.rpx)
  191. make.bottom.equalTo(-14.rpx)
  192. }
  193. bgView.addSubview(checkBtn)
  194. checkBtn.snp.makeConstraints { make in
  195. make.size.equalTo(CGSize(width: 92.rpx, height: 32.rpx))
  196. make.right.equalTo(-16.rpx)
  197. make.centerY.equalTo(timeLabel.snp.centerY)
  198. }
  199. }
  200. }