|
@@ -0,0 +1,176 @@
|
|
|
+//
|
|
|
+// CommunitySubCommentController.swift
|
|
|
+// RainbowPlanet
|
|
|
+//
|
|
|
+// Created by Christopher on 2019/6/12.
|
|
|
+// Copyright © 2019 RainbowPlanet. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+import UIKit
|
|
|
+
|
|
|
+class CommunitySubCommentController: BaseViewController {
|
|
|
+
|
|
|
+ var communityPostCommentModel : CommunityPostCommentModel?
|
|
|
+ var communityPostReplyModels = Array<CommunityPostReplyModel>()
|
|
|
+
|
|
|
+ override func viewDidLoad() {
|
|
|
+ super.viewDidLoad()
|
|
|
+ setupViews()
|
|
|
+ setupLayouts()
|
|
|
+ setupData()
|
|
|
+ }
|
|
|
+
|
|
|
+ override func viewWillAppear(_ animated: Bool) {
|
|
|
+ cmtKeyboard.isDisappear = false
|
|
|
+ }
|
|
|
+
|
|
|
+ override func viewWillDisappear(_ animated: Bool) {
|
|
|
+ cmtKeyboard.isDisappear = true
|
|
|
+ }
|
|
|
+
|
|
|
+ override func setupViews() {
|
|
|
+ navigationBar.title = "3条评论"
|
|
|
+ view.backgroundColor = kf7f8faColor
|
|
|
+
|
|
|
+ view.addSubview(tableView)
|
|
|
+ view.addSubview(cmtKeyboard)
|
|
|
+ }
|
|
|
+
|
|
|
+ override func setupLayouts() {
|
|
|
+ tableView.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalToSuperview().offset(kNavBarTotalHeight)
|
|
|
+ make.left.right.bottom.equalTo(0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ lazy var tableView: UITableView = {
|
|
|
+ let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
|
|
|
+ tableView.separatorStyle = .none
|
|
|
+ tableView.backgroundColor = kf7f8faColor
|
|
|
+ tableView.dataSource = self
|
|
|
+ tableView.delegate = self
|
|
|
+ tableView.estimatedRowHeight = 0
|
|
|
+ tableView.estimatedSectionFooterHeight = 0
|
|
|
+ tableView.estimatedSectionHeaderHeight = 0
|
|
|
+ return tableView
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var cmtKeyboard: LXKeyBoard = {
|
|
|
+ let cmtKeyboard = LXKeyBoard.init()
|
|
|
+ cmtKeyboard.backgroundColor = kffffffColor
|
|
|
+ cmtKeyboard.maxLine = 3
|
|
|
+ cmtKeyboard.font = kRegularFont14
|
|
|
+ cmtKeyboard.topOrBottomEdge = 10
|
|
|
+ cmtKeyboard.beginUpdateUI()
|
|
|
+ cmtKeyboard.sendBlock = {
|
|
|
+ [weak self] (text) in
|
|
|
+ print("----\(text)")
|
|
|
+ }
|
|
|
+
|
|
|
+ return cmtKeyboard
|
|
|
+ }()
|
|
|
+
|
|
|
+ override func setupData() {
|
|
|
+ tableView.addHeaderWithHeader(withBeginRefresh: true, animation: false) { [weak self] (page) in
|
|
|
+ self?.communityPostReplyApi(page: page)
|
|
|
+ }
|
|
|
+ tableView.addFooterWithWithHeader(withAutomaticallyRefresh: false) {
|
|
|
+ [weak self] (page) in
|
|
|
+ self?.communityPostReplyApi(page: page)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+extension CommunitySubCommentController {
|
|
|
+
|
|
|
+ /// 获取子评论
|
|
|
+ ///
|
|
|
+ /// - Parameter page: 分页
|
|
|
+ func communityPostReplyApi(page:Int) {
|
|
|
+ SwiftMoyaNetWorkServiceCommunity.shared().communityPostReplyApi(postId: communityPostCommentModel?.id ?? 0, page: page) { [weak self] (communityPostReplysModel) -> (Void) in
|
|
|
+ let communityPostReplysModel = communityPostReplysModel as? CommunityPostReplysModel
|
|
|
+ if communityPostReplysModel?.pagination?.currentPage ?? 1 <= communityPostReplysModel?.pagination?.totalPages ?? 1 {
|
|
|
+ if communityPostReplysModel?.pagination?.currentPage == 1{
|
|
|
+ self?.communityPostReplyModels.removeAll()
|
|
|
+ }
|
|
|
+ self?.communityPostReplyModels = (self?.communityPostReplyModels)! + (communityPostReplysModel?.data!)!
|
|
|
+ self?.tableView.reloadData()
|
|
|
+ if self?.communityPostReplyModels.count ?? 0 >= communityPostReplysModel?.pagination?.total ?? 0 {
|
|
|
+ self?.tableView.endFooterNoMoreData()
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ self?.tableView.endFooterNoMoreData()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - tableView dataSource && delegate
|
|
|
+extension CommunitySubCommentController: UITableViewDataSource, UITableViewDelegate {
|
|
|
+
|
|
|
+ func numberOfSections(in tableView: UITableView) -> Int {
|
|
|
+ return 2
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
+ switch section {
|
|
|
+ case 0:
|
|
|
+ if communityPostCommentModel != nil {
|
|
|
+ return 1
|
|
|
+ }else {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ return communityPostReplyModels.isEmpty ? 0 : communityPostReplyModels.count
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
+
|
|
|
+ switch indexPath.section {
|
|
|
+ case 0:
|
|
|
+ let cell = CommunityMajorCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
+ cell.communityPostCommentModel = communityPostCommentModel
|
|
|
+ return cell
|
|
|
+ default:
|
|
|
+ let cell = CommunityReplyCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
+ cell.communityPostReplyModel = communityPostReplyModels[indexPath.row]
|
|
|
+ return cell
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
|
+ switch indexPath.section {
|
|
|
+ case 0:
|
|
|
+ return communityPostCommentModel?.height ?? 0
|
|
|
+ default:
|
|
|
+ return communityPostReplyModels[indexPath.row].height ?? 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
|
+ return 10
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
|
|
+ return UIView()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
|
|
|
+ return 0.000001
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
|
|
|
+ return UIView()
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|