QSLRequestCell.swift 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. if let model = self.model {
  68. delegate?.refuseBtnAction(model: model)
  69. }
  70. }
  71. @objc func agreeBtnAction() {
  72. if let model = self.model {
  73. delegate?.accpetBtnAction(model: model)
  74. }
  75. }
  76. func config(model: QSLRequestModel) {
  77. self.model = model
  78. self.titleLabel.text = "用户\(model.userPhone)向您发出了好友申请"
  79. self.titleLabel.setSpecificTextColor(model.userPhone, color: .hexStringColor(hexString: "#15CBA1"))
  80. self.timeLabel.text = Date.timestampToFormatterTimeString(timestamp: model.createTime)
  81. switch QSLRequestType(rawValue: model.status) {
  82. case .wait:
  83. self.agreeBtn.isHidden = false
  84. self.refuseBtn.isEnabled = true
  85. self.refuseBtn.title("拒绝")
  86. self.refuseBtn.backgroundColor = QSLColor.backGroundColor
  87. self.refuseBtn.layer.borderColor = UIColor.hexStringColor(hexString: "#E2E2E2").cgColor
  88. self.refuseBtn.textColor(.hexStringColor(hexString: "#A7A7A7"))
  89. break
  90. case .agreed:
  91. self.agreeBtn.isHidden = true
  92. self.refuseBtn.isEnabled = false
  93. self.refuseBtn.backgroundColor = .white
  94. self.refuseBtn.layer.borderColor = QSLColor.themeMainColor.cgColor
  95. self.refuseBtn.title("已同意")
  96. self.refuseBtn.textColor(QSLColor.themeMainColor)
  97. break
  98. case .refused:
  99. self.agreeBtn.isHidden = true
  100. self.refuseBtn.isEnabled = false
  101. self.refuseBtn.title("已拒绝")
  102. self.refuseBtn.backgroundColor = QSLColor.backGroundColor
  103. self.refuseBtn.layer.borderColor = UIColor.hexStringColor(hexString: "#E2E2E2").cgColor
  104. self.refuseBtn.textColor(.hexStringColor(hexString: "#A7A7A7"))
  105. break
  106. default:
  107. break
  108. }
  109. }
  110. }
  111. extension QSLRequestCell {
  112. func initView() {
  113. contentView.addSubview(avatarImageView)
  114. avatarImageView.snp.makeConstraints { make in
  115. make.size.equalTo(CGSize(width: 48.rpx, height: 48.rpx))
  116. make.left.equalTo(12.rpx)
  117. make.top.equalTo(20.rpx)
  118. }
  119. contentView.addSubview(titleLabel)
  120. titleLabel.snp.makeConstraints { make in
  121. make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
  122. make.right.equalTo(-12.rpx)
  123. make.bottom.equalTo(avatarImageView.snp.centerY)
  124. }
  125. contentView.addSubview(timeLabel)
  126. timeLabel.snp.makeConstraints { make in
  127. make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
  128. make.right.equalTo(-12.rpx)
  129. make.top.equalTo(titleLabel.snp.bottom).offset(3.rpx)
  130. }
  131. contentView.addSubview(refuseBtn)
  132. refuseBtn.snp.makeConstraints { make in
  133. make.size.equalTo(CGSize(width: 120.rpx, height: 32.rpx))
  134. make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
  135. make.top.equalTo(timeLabel.snp.bottom).offset(16.rpx)
  136. }
  137. contentView.addSubview(agreeBtn)
  138. agreeBtn.snp.makeConstraints { make in
  139. make.size.equalTo(CGSize(width: 120.rpx, height: 32.rpx))
  140. make.left.equalTo(refuseBtn.snp.right).offset(12.rpx)
  141. make.top.equalTo(timeLabel.snp.bottom).offset(16.rpx)
  142. }
  143. }
  144. }