CommunityReportViewController.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // CommunityReportViewController.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/8/31.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. class CommunityReportViewController: BaseViewController {
  10. var reportCategorys : [ReportCategory]?
  11. var postId : Int?
  12. var uId : Int?
  13. override func viewDidLoad() {
  14. super.viewDidLoad()
  15. setupViews()
  16. setupLayouts()
  17. setupData()
  18. }
  19. override func setupViews() {
  20. navigationBar.title = "举报"
  21. view.addSubview(tableView)
  22. }
  23. override func setupLayouts() {
  24. tableView.snp.makeConstraints { (make) in
  25. make.top.equalTo(kNavBarTotalHeight)
  26. make.left.right.bottom.equalToSuperview()
  27. }
  28. }
  29. override func setupData() {
  30. reportCategorys = ConfigModel.shared.object()?.reportCategory
  31. if reportCategorys?.isEmpty ?? true {
  32. DIYEmptyView.emptyNoDataTableView(tableView: tableView,imageStr:.one,detailStr:.one)
  33. }
  34. tableView.tableHeaderView = communityReportHeaderView
  35. tableView.reloadData()
  36. }
  37. private lazy var tableView: UITableView = {
  38. let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
  39. tableView.separatorStyle = .none
  40. tableView.backgroundColor = kf7f8faColor
  41. tableView.rowHeight = 48
  42. tableView.dataSource = self
  43. tableView.delegate = self
  44. return tableView
  45. }()
  46. private lazy var communityReportHeaderView: CommunityReportHeaderView = {
  47. let communityReportHeaderView = CommunityReportHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 44))
  48. return communityReportHeaderView
  49. }()
  50. func userMemberReportApi(reportCategoryId:Int?) {
  51. SwiftMoyaNetWorkServiceUser.shared().userMemberReportApi(reportType: 1, postId: postId ?? 0, reportCategory: reportCategoryId ?? 0) {[weak self](data) -> (Void) in
  52. self?.navigationController?.popViewController(animated: true)
  53. }
  54. }
  55. func userMemberReportUserApi(reportCategoryId:Int?) {
  56. SwiftMoyaNetWorkServiceUser.shared().userMemberReportApi(reportType: 0, objectUid: uId ?? 0, reportCategory: reportCategoryId ?? 0) {[weak self](data) -> (Void) in
  57. self?.navigationController?.popViewController(animated: true)
  58. }
  59. }
  60. }
  61. extension CommunityReportViewController : UITableViewDelegate,UITableViewDataSource {
  62. func numberOfSections(in tableView: UITableView) -> Int {
  63. return 1
  64. }
  65. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  66. return reportCategorys?.count ?? 0
  67. }
  68. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  69. let cell = CommunityReportTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  70. cell.reportCategory = reportCategorys?[indexPath.row]
  71. return cell
  72. }
  73. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  74. let reportCategory = reportCategorys?[indexPath.row]
  75. if uId != nil && uId != 0 {
  76. userMemberReportUserApi(reportCategoryId: reportCategory?.id)
  77. }else {
  78. userMemberReportApi(reportCategoryId: reportCategory?.id)
  79. }
  80. }
  81. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  82. return 0.000001
  83. }
  84. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  85. return 0.000001
  86. }
  87. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  88. return nil
  89. }
  90. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  91. return nil
  92. }
  93. }