QSLFriendTableViewCell.swift 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 let model = self.userModel {
  130. delegate?.roadBtnClickAction(model: model)
  131. }
  132. }
  133. }
  134. extension QSLFriendTableViewCell {
  135. func initUI() {
  136. self.backgroundColor = .clear
  137. self.contentView.addSubview(bgView)
  138. bgView.snp.makeConstraints { make in
  139. make.edges.equalToSuperview()
  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(22.rpx)
  146. }
  147. bgView.addSubview(nameLabel)
  148. nameLabel.snp.makeConstraints { make in
  149. make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
  150. make.top.equalTo(avatarImageView.snp.top).offset(5.rpx)
  151. }
  152. bgView.addSubview(moreBtn)
  153. moreBtn.snp.makeConstraints { make in
  154. make.size.equalTo(CGSize(width: 24.rpx, height: 24.rpx))
  155. make.right.equalTo(-16.rpx)
  156. make.top.equalTo(20.rpx)
  157. }
  158. bgView.addSubview(locateIcon)
  159. locateIcon.snp.makeConstraints { make in
  160. make.size.equalTo(CGSize(width: 16.rpx, height: 16.rpx))
  161. make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
  162. make.top.equalTo(nameLabel.snp.bottom).offset(8.rpx)
  163. }
  164. bgView.addSubview(addrLabel)
  165. addrLabel.snp.makeConstraints { make in
  166. make.left.equalTo(locateIcon.snp.right)
  167. make.right.equalTo(-16.rpx)
  168. make.top.equalTo(locateIcon.snp.top)
  169. }
  170. bgView.addSubview(blurView)
  171. blurView.snp.makeConstraints { make in
  172. make.edges.equalTo(addrLabel.snp.edges)
  173. }
  174. bgView.addSubview(lineView)
  175. lineView.snp.makeConstraints { make in
  176. make.left.equalTo(16.rpx)
  177. make.right.equalTo(-16.rpx)
  178. make.height.equalTo(1.rpx)
  179. make.bottom.equalTo(-47.rpx)
  180. }
  181. bgView.addSubview(timeLabel)
  182. timeLabel.snp.makeConstraints { make in
  183. make.left.equalTo(16.rpx)
  184. make.bottom.equalTo(-14.rpx)
  185. }
  186. bgView.addSubview(checkBtn)
  187. checkBtn.snp.makeConstraints { make in
  188. make.size.equalTo(CGSize(width: 92.rpx, height: 32.rpx))
  189. make.right.equalTo(-16.rpx)
  190. make.centerY.equalTo(timeLabel.snp.centerY)
  191. }
  192. }
  193. }