QSLRequestController.swift 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // QSLRequestController.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2024/12/5.
  6. //
  7. import UIKit
  8. import CRRefresh
  9. class QSLRequestController: QSLBaseController {
  10. lazy var requestTableView: UITableView = {
  11. let tableView = UITableView(frame: .zero, style: .grouped)
  12. tableView.backgroundColor = .clear
  13. tableView.separatorStyle = .none
  14. tableView.showsVerticalScrollIndicator = false
  15. tableView.delegate = self
  16. tableView.dataSource = self
  17. tableView.tableViewNeverAdjustContentInset()
  18. tableView.bounces = true
  19. tableView.isUserInteractionEnabled = true
  20. tableView.isScrollEnabled = false
  21. tableView.contentInsetAdjustmentBehavior = .never
  22. tableView.register(cellClass: QSLRequestCell.self)
  23. tableView.cr.addHeadRefresh(animator: NormalHeaderAnimator()) { [weak self] in
  24. self?.requestRequestList()
  25. }
  26. return tableView
  27. }()
  28. var requestList: [QSLRequestModel] = [QSLRequestModel]()
  29. override func viewDidLoad() {
  30. super.viewDidLoad()
  31. initializeView()
  32. requestTableView.cr.beginHeaderRefresh()
  33. NotificationCenter.default.addObserver(self, selector: #selector(requestRequestList), name: QSLNotification.QSLRefreshRequest, object: nil)
  34. gravityInstance?.track(QSLGravityConst.message_request_show)
  35. }
  36. override func viewWillAppear(_ animated:Bool) {
  37. super.viewWillAppear(animated)
  38. self.navigationController?.setNavigationBarHidden(false, animated: animated)
  39. }
  40. override func viewDidDisappear(_ animated: Bool) {
  41. super.viewDidDisappear(animated)
  42. self.navigationController?.setNavigationBarHidden(true, animated: animated)
  43. }
  44. }
  45. extension QSLRequestController {
  46. // 请求好友请求列表
  47. @objc func requestRequestList() {
  48. self.requestList.removeAll()
  49. QSLNetwork().request(.requestList(dict: [:])) { response in
  50. self.requestTableView.cr.endHeaderRefresh()
  51. let requestList = response.mapArray(QSLRequestModel.self, modelKey: "data>list")
  52. self.requestList = requestList
  53. self.requestTableView.reloadData()
  54. } fail: { code, error in
  55. self.requestTableView.cr.endHeaderRefresh()
  56. self.requestTableView.reloadData()
  57. }
  58. }
  59. }
  60. extension QSLRequestController: QSLRequestCellDelegate {
  61. // 拒绝点击
  62. func refuseBtnAction(model: QSLRequestModel) {
  63. gravityInstance?.track(QSLGravityConst.message_request_disagree)
  64. QSLNetwork().request(.requestRefuse(dict: ["id": model.requestId])) { response in
  65. // 发送通知
  66. NotificationCenter.default.post(name: QSLNotification.QSLRefreshRequest, object: nil)
  67. } fail: { code, error in
  68. self.view.toast(text: error)
  69. }
  70. }
  71. // 同意点击
  72. func accpetBtnAction(model: QSLRequestModel) {
  73. gravityInstance?.track(QSLGravityConst.message_request_agree)
  74. gravityInstance?.track(QSLGravityConst.message_request_agree_show)
  75. QSLAlertView.alert(view: self.view, title: "添加好友", content: "1.您同意添加该用户为好友,则视为您同意本应用合法收集储存和使用信息;\n2.并同意将您的位置、轨迹等信息分享给该好友。", isOneBtn: true, oneBtnText: "确认添加", oneBtnClosure: {
  76. gravityInstance?.track(QSLGravityConst.message_request_agree_show_confirm)
  77. QSLNetwork().request(.requestAccept(dict: ["id": model.requestId])) { response in
  78. // 发送通知
  79. NotificationCenter.default.post(name: QSLNotification.QSLRefreshRequest, object: nil)
  80. } fail: { code, error in
  81. self.view.toast(text: error)
  82. }
  83. }, closeBtnClosure: {
  84. gravityInstance?.track(QSLGravityConst.message_request_agree_show_cancel)
  85. })
  86. }
  87. }
  88. // MARK: - 设置Tableview
  89. extension QSLRequestController: UITableViewDelegate, UITableViewDataSource {
  90. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  91. return self.requestList.count
  92. }
  93. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  94. let cell = tableView.dequeueReusableCell(cellType: QSLRequestCell.self, cellForRowAt: indexPath)
  95. cell.selectionStyle = .none
  96. let model = self.requestList[indexPath.row]
  97. cell.config(model: model)
  98. cell.delegate = self
  99. return cell
  100. }
  101. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  102. return 117.rpx
  103. }
  104. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  105. return 1.rpx
  106. }
  107. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  108. return 0.0001
  109. }
  110. }
  111. extension QSLRequestController {
  112. func initializeView() {
  113. self.view.addSubview(requestTableView)
  114. requestTableView.snp.makeConstraints { make in
  115. make.left.right.bottom.equalTo(0)
  116. make.top.equalTo(0)
  117. }
  118. }
  119. }