QSLRequestCell.swift 6.2 KB

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