QSLMessageHeaderView.swift 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //
  2. // QSLMessageHeaderView.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2024/12/5.
  6. //
  7. import UIKit
  8. protocol QSLMessageHeaderViewDelegate: NSObjectProtocol {
  9. func refuseBtnAction(model: QSLRequestModel)
  10. func accpetBtnAction(model: QSLRequestModel)
  11. func jumpToRequest()
  12. }
  13. class QSLMessageHeaderView: UIView {
  14. weak var delegate: QSLMessageHeaderViewDelegate?
  15. var model: QSLRequestModel?
  16. lazy var contentView: UIView = {
  17. let view = UIView()
  18. view.backgroundColor = .white
  19. return view
  20. }()
  21. lazy var avatarImageView: UIImageView = {
  22. let imageView = UIImageView()
  23. imageView.image = UIImage(named: "friends_cell_other_avatar")
  24. return imageView
  25. }()
  26. lazy var titleLabel: UILabel = {
  27. let label = UILabel()
  28. label.text("用户1388888888向您发出了好友申请")
  29. label.mediumFont(15)
  30. label.textColor = .hexStringColor(hexString: "#404040")
  31. label.setSpecificTextColor("1388888888", color: .hexStringColor(hexString: "#15CBA1"))
  32. return label
  33. }()
  34. lazy var timeLabel: UILabel = {
  35. let label = UILabel()
  36. label.text("2023-10-20 09:43")
  37. label.font(13)
  38. label.textColor = .hexStringColor(hexString: "#A7A7A7")
  39. return label
  40. }()
  41. lazy var refuseBtn: UIButton = {
  42. let btn = UIButton()
  43. btn.backgroundColor = QSLColor.backGroundColor
  44. btn.title("拒绝")
  45. btn.textColor(.hexStringColor(hexString: "#A7A7A7"))
  46. btn.addRadius(radius: 16.rpx)
  47. btn.addBorder(borderWidth: 1.rpx, borderColor: .hexStringColor(hexString: "#E2E2E2"))
  48. btn.addTarget(self, action: #selector(refuseBtnAction), for: .touchUpInside)
  49. return btn
  50. }()
  51. lazy var agreeBtn: UIButton = {
  52. let btn = UIButton()
  53. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#15CBA1"), width: 120.rpx, height: 32.rpx, direction: .horizontal)
  54. btn.title("同意")
  55. btn.addRadius(radius: 16.rpx)
  56. btn.addBorder(borderWidth: 1.rpx, borderColor: .hexStringColor(hexString: "#E2E2E2"))
  57. btn.addTarget(self, action: #selector(agreeBtnAction), for: .touchUpInside)
  58. return btn
  59. }()
  60. lazy var checkBtn: UIButton = {
  61. let btn = UIButton()
  62. btn.title("查看全部申请")
  63. btn.image(UIImage(named: "public_arrow_right_A7"))
  64. btn.textColor(.hexStringColor(hexString: "#A7A7A7"))
  65. btn.font(13)
  66. btn.setImageTitleLayout(.imgRight, spacing: 0)
  67. btn.addTarget(self, action: #selector(checkBtnAction), for: .touchUpInside)
  68. return btn
  69. }()
  70. override init(frame: CGRect) {
  71. super.init(frame: frame)
  72. initView()
  73. }
  74. required init?(coder: NSCoder) {
  75. fatalError("init(coder:) has not been implemented")
  76. }
  77. @objc func refuseBtnAction() {
  78. ///拒绝好友申请埋点
  79. gravityInstance?.track(QSLGravityConst.friend_reject_request, properties: ["id": 04006])
  80. if let model = self.model {
  81. delegate?.refuseBtnAction(model: model)
  82. }
  83. }
  84. @objc func agreeBtnAction() {
  85. ///拒绝好友申请埋点
  86. gravityInstance?.track(QSLGravityConst.friend_agree_request, properties: ["id": 04005])
  87. if let model = self.model {
  88. delegate?.accpetBtnAction(model: model)
  89. }
  90. }
  91. @objc func checkBtnAction() {
  92. delegate?.jumpToRequest()
  93. }
  94. func config(model: QSLRequestModel) {
  95. self.model = model
  96. self.titleLabel.text = "用户\(model.userPhone)向您发出了好友申请"
  97. self.titleLabel.setSpecificTextColor(model.userPhone, color: .hexStringColor(hexString: "#15CBA1"))
  98. self.timeLabel.text = Date.timestampToFormatterTimeString(timestamp: model.createTime)
  99. switch QSLRequestType(rawValue: model.status) {
  100. case .wait:
  101. break
  102. case .refused:
  103. self.agreeBtn.isHidden = true
  104. self.refuseBtn.title("已拒绝")
  105. break
  106. case .agreed:
  107. self.agreeBtn.isHidden = true
  108. self.refuseBtn.backgroundColor = .white
  109. self.refuseBtn.layer.borderColor = QSLColor.themeMainColor.cgColor
  110. self.refuseBtn.title("已同意")
  111. self.refuseBtn.textColor(QSLColor.themeMainColor)
  112. break
  113. default:
  114. break
  115. }
  116. }
  117. }
  118. extension QSLMessageHeaderView {
  119. func initView() {
  120. self.backgroundColor = QSLColor.backGroundColor
  121. self.addSubview(contentView)
  122. contentView.snp.makeConstraints { make in
  123. make.top.right.left.equalTo(0)
  124. make.bottom.equalTo(-8.rpx)
  125. }
  126. contentView.addSubview(avatarImageView)
  127. avatarImageView.snp.makeConstraints { make in
  128. make.size.equalTo(CGSize(width: 48.rpx, height: 48.rpx))
  129. make.left.equalTo(12.rpx)
  130. make.top.equalTo(20.rpx)
  131. }
  132. contentView.addSubview(titleLabel)
  133. titleLabel.snp.makeConstraints { make in
  134. make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
  135. make.right.equalTo(-12.rpx)
  136. make.bottom.equalTo(avatarImageView.snp.centerY)
  137. }
  138. contentView.addSubview(timeLabel)
  139. timeLabel.snp.makeConstraints { make in
  140. make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
  141. make.right.equalTo(-12.rpx)
  142. make.top.equalTo(titleLabel.snp.bottom).offset(3.rpx)
  143. }
  144. contentView.addSubview(refuseBtn)
  145. refuseBtn.snp.makeConstraints { make in
  146. make.size.equalTo(CGSize(width: 120.rpx, height: 32.rpx))
  147. make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
  148. make.top.equalTo(timeLabel.snp.bottom).offset(16.rpx)
  149. }
  150. contentView.addSubview(agreeBtn)
  151. agreeBtn.snp.makeConstraints { make in
  152. make.size.equalTo(CGSize(width: 120.rpx, height: 32.rpx))
  153. make.left.equalTo(refuseBtn.snp.right).offset(12.rpx)
  154. make.top.equalTo(timeLabel.snp.bottom).offset(16.rpx)
  155. }
  156. contentView.addSubview(checkBtn)
  157. checkBtn.snp.makeConstraints { make in
  158. make.size.equalTo(CGSize(width: 100.rpx, height: 20.rpx))
  159. make.centerX.equalToSuperview()
  160. make.bottom.equalTo(-8.rpx)
  161. }
  162. }
  163. }