| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- //
- // QSLMessageHeaderView.swift
- // QuickSearchLocation
- //
- // Created by Destiny on 2024/12/5.
- //
- import UIKit
- protocol QSLMessageHeaderViewDelegate: NSObjectProtocol {
-
- func refuseBtnAction(model: QSLRequestModel)
-
- func accpetBtnAction(model: QSLRequestModel)
-
- func jumpToRequest()
- }
- class QSLMessageHeaderView: UIView {
-
- weak var delegate: QSLMessageHeaderViewDelegate?
-
- var model: QSLRequestModel?
-
- lazy var contentView: UIView = {
-
- let view = UIView()
- view.backgroundColor = .white
- return view
- }()
-
- lazy var avatarImageView: UIImageView = {
-
- let imageView = UIImageView()
- imageView.image = UIImage(named: "friends_cell_other_avatar")
- return imageView
- }()
-
- lazy var titleLabel: UILabel = {
-
- let label = UILabel()
- label.text("用户1388888888向您发出了好友申请")
- label.mediumFont(15)
- label.textColor = .hexStringColor(hexString: "#404040")
- label.setSpecificTextColor("1388888888", color: .hexStringColor(hexString: "#15CBA1"))
- return label
- }()
-
- lazy var timeLabel: UILabel = {
-
- let label = UILabel()
- label.text("2023-10-20 09:43")
- label.font(13)
- label.textColor = .hexStringColor(hexString: "#A7A7A7")
- return label
- }()
-
- lazy var refuseBtn: UIButton = {
-
- let btn = UIButton()
- btn.backgroundColor = QSLColor.backGroundColor
- btn.title("拒绝")
- btn.textColor(.hexStringColor(hexString: "#A7A7A7"))
- btn.addRadius(radius: 16.rpx)
- btn.addBorder(borderWidth: 1.rpx, borderColor: .hexStringColor(hexString: "#E2E2E2"))
- btn.addTarget(self, action: #selector(refuseBtnAction), for: .touchUpInside)
- return btn
- }()
-
- lazy var agreeBtn: UIButton = {
-
- let btn = UIButton()
- btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#15CBA1"), width: 120.rpx, height: 32.rpx, direction: .horizontal)
- btn.title("同意")
- btn.addRadius(radius: 16.rpx)
- btn.addBorder(borderWidth: 1.rpx, borderColor: .hexStringColor(hexString: "#E2E2E2"))
- btn.addTarget(self, action: #selector(agreeBtnAction), for: .touchUpInside)
- return btn
- }()
-
- lazy var checkBtn: UIButton = {
-
- let btn = UIButton()
- btn.title("查看全部申请")
- btn.image(UIImage(named: "public_arrow_right_A7"))
- btn.textColor(.hexStringColor(hexString: "#A7A7A7"))
- btn.font(13)
- btn.setImageTitleLayout(.imgRight, spacing: 0)
- btn.addTarget(self, action: #selector(checkBtnAction), for: .touchUpInside)
- return btn
- }()
-
- override init(frame: CGRect) {
- super.init(frame: frame)
- initView()
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- @objc func refuseBtnAction() {
-
- ///拒绝好友申请埋点
- gravityInstance?.track(QSLGravityConst.friend_reject_request, properties: ["id": 04006])
-
- if let model = self.model {
- delegate?.refuseBtnAction(model: model)
- }
- }
-
- @objc func agreeBtnAction() {
-
- ///拒绝好友申请埋点
- gravityInstance?.track(QSLGravityConst.friend_agree_request, properties: ["id": 04005])
-
- if let model = self.model {
- delegate?.accpetBtnAction(model: model)
- }
- }
-
- @objc func checkBtnAction() {
-
- delegate?.jumpToRequest()
- }
-
- func config(model: QSLRequestModel) {
- self.model = model
- self.titleLabel.text = "用户\(model.userPhone)向您发出了好友申请"
- self.titleLabel.setSpecificTextColor(model.userPhone, color: .hexStringColor(hexString: "#15CBA1"))
- self.timeLabel.text = Date.timestampToFormatterTimeString(timestamp: model.createTime)
-
- switch QSLRequestType(rawValue: model.status) {
- case .wait:
- break
- case .refused:
- self.agreeBtn.isHidden = true
- self.refuseBtn.title("已拒绝")
- break
- case .agreed:
- self.agreeBtn.isHidden = true
- self.refuseBtn.backgroundColor = .white
- self.refuseBtn.layer.borderColor = QSLColor.themeMainColor.cgColor
- self.refuseBtn.title("已同意")
- self.refuseBtn.textColor(QSLColor.themeMainColor)
- break
- default:
- break
- }
- }
- }
- extension QSLMessageHeaderView {
-
- func initView() {
-
- self.backgroundColor = QSLColor.backGroundColor
-
- self.addSubview(contentView)
- contentView.snp.makeConstraints { make in
- make.top.right.left.equalTo(0)
- make.bottom.equalTo(-8.rpx)
- }
-
- contentView.addSubview(avatarImageView)
- avatarImageView.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 48.rpx, height: 48.rpx))
- make.left.equalTo(12.rpx)
- make.top.equalTo(20.rpx)
- }
-
- contentView.addSubview(titleLabel)
- titleLabel.snp.makeConstraints { make in
- make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
- make.right.equalTo(-12.rpx)
- make.bottom.equalTo(avatarImageView.snp.centerY)
- }
-
- contentView.addSubview(timeLabel)
- timeLabel.snp.makeConstraints { make in
- make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
- make.right.equalTo(-12.rpx)
- make.top.equalTo(titleLabel.snp.bottom).offset(3.rpx)
- }
-
- contentView.addSubview(refuseBtn)
- refuseBtn.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 120.rpx, height: 32.rpx))
- make.left.equalTo(avatarImageView.snp.right).offset(8.rpx)
- make.top.equalTo(timeLabel.snp.bottom).offset(16.rpx)
- }
-
- contentView.addSubview(agreeBtn)
- agreeBtn.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 120.rpx, height: 32.rpx))
- make.left.equalTo(refuseBtn.snp.right).offset(12.rpx)
- make.top.equalTo(timeLabel.snp.bottom).offset(16.rpx)
- }
-
- contentView.addSubview(checkBtn)
- checkBtn.snp.makeConstraints { make in
- make.size.equalTo(CGSize(width: 100.rpx, height: 20.rpx))
- make.centerX.equalToSuperview()
- make.bottom.equalTo(-8.rpx)
- }
- }
- }
|