123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- //
- // CommunityVideoSubCommentController.swift
- // RainbowPlanet
- //
- // Created by Christopher on 2019/7/11.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- // 视频--子评论Vc
- import UIKit
- import IQKeyboardManagerSwift
- class CommunityVideoSubCommentController: BaseViewController {
-
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- }
-
- var communityVideoItemModel : CommunityVideoItemModel?
- var communityPostCommentModel : CommunityPostCommentModel?
-
- var communityPostReplysModel : CommunityPostReplysModel?
- var communityPostReplyModels = Array<CommunityPostReplyModel>()
- var communityPostReplyModel : CommunityPostReplyModel?
-
-
- override func viewDidLoad() {
-
- super.viewDidLoad()
- setupViews()
- setupLayouts()
- setupData()
- }
-
- override func setupViews() {
- navigationBar.title = "3条评论"
- view.backgroundColor = kf7f8faColor
-
- view.addSubview(tableView)
- view.addSubview(commentInputView)
- }
-
- override func setupLayouts() {
- tableView.snp.makeConstraints { (make) in
- make.top.equalToSuperview().offset(kNavBarTotalHeight)
- make.left.right.equalTo(0)
- make.bottom.equalTo(commentInputView.snp.top)
- }
- commentInputView.snp.makeConstraints { (make) in
- make.bottom.left.right.equalToSuperview()
- make.height.equalTo(48 + kSafeTabBarHeight)
- }
- }
-
- 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
- return tableView
- }()
-
- lazy var commentInputView: CommentInputView = {
- let commentInputView = CommentInputView()
- return commentInputView
- }()
-
- override func setupData() {
- tableView.addHeader(withBeginRefresh: true, animation: false) { [weak self] (page) in
- self?.communityPostReplyApi(page: page)
- }
- tableView.addAutoNormalFooter(withAutomaticallyRefresh: true, loadMoreBlock: {
- [weak self] (page) in
- self?.communityPostReplyApi(page: page)
- })
- commentInputView.commentInputViewClosure = {
- [weak self] in
- self?.showKeyBoardCommentView(placeholder: "添加评论...")
- }
- }
-
- /// 显示键盘
- func showKeyBoardCommentView(placeholder:String) {
-
- KeyBoardInputView.show(placeholder: placeholder, inputViewResultClosure: {
- [weak self] text in
- self?.communityPostCommentApi(text: text, complete: {
- [weak self] in
- self?.communityPostReplyModel = nil
- })
- }) {
- [weak self] in
- self?.communityPostReplyModel = nil
- }
- }
- }
- extension CommunityVideoSubCommentController {
-
- /// 获取子评论
- ///
- /// - Parameter page: 分页
- func communityPostReplyApi(page:Int) {
- SwiftMoyaNetWorkServiceCommunity.shared().communityPostReplyApi(postId: communityPostCommentModel?.id ?? 0, page: page,completion: {
- [weak self] (communityPostReplysModel) -> (Void) in
- let communityPostReplysModel = communityPostReplysModel as? CommunityPostReplysModel
-
- if communityPostReplysModel?.pagination?.currentPage == 1{
- self?.communityPostReplyModels.removeAll()
- self?.tableView.resetNoMoreData()
- }
- self?.communityPostReplyModels = (self?.communityPostReplyModels)! + (communityPostReplysModel?.data!)!
- self?.navigationBar.title = "\(communityPostReplysModel?.pagination?.total ?? 0)条评论"
- self?.tableView.reloadData()
- MJRefreshManager.mjRefreshManagerPaginationNoHiddenFooter(tableView: self?.tableView, pagination: communityPostReplysModel?.pagination)
- }) {
- [weak self] loadingStatus in
- MJRefreshManager.mjRefreshManagerLoadingStatus(tableView: self?.tableView,loadingStatus: loadingStatus)
-
- }
- }
-
- func communityPostCommentApi(text:String,complete:@escaping () -> ()) {
- let communityCustomCommnetModel = CommunityCustomCommnetModel()
- communityCustomCommnetModel.postId = communityVideoItemModel?.id ?? 0
- communityCustomCommnetModel.content = text
- communityCustomCommnetModel.parentId = communityPostCommentModel?.id
- communityCustomCommnetModel.replyUid = communityPostReplyModel?.uid
- communityCustomCommnetModel.replyUsername = communityPostReplyModel?.username
- SwiftMoyaNetWorkServiceCommunity.shared().communityPostCommentApi(communityCustomCommnetModel: communityCustomCommnetModel) {
- [weak self] (communityPostCommentIdModel) -> (Void) in
-
- let communityPostCommentIdModel = communityPostCommentIdModel as? CommunityPostCommentIdModel
- let communityPostReplyModel = CommunityPostReplyModel()
- communityPostReplyModel.avatar = UserModel.shared().getModel()?.avatarurl
- communityPostReplyModel.content = text
- communityPostReplyModel.createdAt = "刚刚"
- communityPostReplyModel.id = communityPostCommentIdModel?.id
- communityPostReplyModel.username = UserModel.shared().getModel()?.username
- communityPostReplyModel.uid = UserModel.shared().getModel()?.uid
- if self?.communityPostReplyModel != nil {
- communityPostReplyModel.replyUsername = self?.communityPostReplyModel?.username
- }
- self?.communityPostReplyModels.insert(communityPostReplyModel, at: 0)
- self?.communityPostReplysModel?.pagination?.total = 1 + (self?.communityPostReplysModel?.pagination?.total ?? 0)
- self?.tableView.reloadSections([1], with: UITableView.RowAnimation.none)
- self?.navigationBar.title = "\(self?.communityPostReplysModel?.pagination?.total ?? 0)条评论"
-
- if self?.communityPostReplyModel != nil {
- VirusViewModel.shared.comment(communityVideoItemModel: (self?.communityVideoItemModel)!, id: communityPostCommentIdModel?.id ?? 0,content: text, communityPostCommentModel: (self?.communityPostCommentModel)!, communityPostReplyModel: (self?.communityPostReplyModel)!)
-
- }else {
- VirusViewModel.shared.comment(communityVideoItemModel: (self?.communityVideoItemModel)!, id: communityPostCommentIdModel?.id ?? 0,content: text, communityPostCommentModel: (self?.communityPostCommentModel)!)
-
- }
- complete()
-
- }
- }
- }
- // MARK: - tableView dataSource && delegate
- extension CommunityVideoSubCommentController: 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) {
- tableView.deselectRow(at: indexPath, animated: true)
-
- switch indexPath.section {
- case 0:
- break
- default:
- communityPostReplyModel = communityPostReplyModels[indexPath.row]
- if communityPostReplyModel?.isDelete != 1 {
- CommentReplyView.commentReplyView(id:communityPostReplyModel?.id,uid: communityPostReplyModel?.uid,userName: communityPostReplyModel?.username ?? "", content: communityPostReplyModel?.content ?? "", replyClosure: {
- [weak self] in
- self?.showKeyBoardCommentView(placeholder: "回复:@\(self?.communityPostReplyModel?.username ?? "")")
- }, deleteClosure: {
- [weak self] in
- self?.communityPostReplyModel?.isDelete = 1
- self?.communityPostReplyModel?.content = "该回复已被删除"
- tableView.reloadData()
- })
- }else {
- SwiftProgressHUD.shared().showText("该评论已删除,暂时不能评论")
- }
-
- break
- }
- }
-
- 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()
- }
-
- }
|