//
|
// CarDetailCarCommentVC.swift
|
// OKProject
|
//
|
// Created by 无故事王国 on 2022/5/10.
|
// Copyright © 2022 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
import DZNEmptyDataSet
|
|
class CarDetailCarCommentVC: YYViewController{
|
|
@IBOutlet weak var commentView: UIView!
|
@IBOutlet weak var tableView: UITableView!
|
@IBOutlet weak var profileImg: UIImageView!
|
@IBOutlet weak var commentBottomCons: NSLayoutConstraint!
|
var scrollView:UIScrollView?
|
|
let viewModel = CommentOrderViewModel()
|
|
var orderId:Int?
|
var type:CommonStyle = .sell //类型(1=租车,2=卖车,3=招聘)
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
guard orderId != nil else {return}
|
|
viewModel.orderId.accept(orderId!)
|
viewModel.type.accept(type.rawValue)
|
|
viewModel.configure(tableView: tableView)
|
tableView.beginRefreshing()
|
|
commentView.isUserInteractionEnabled = true
|
profileImg.load(url: readUser().avatar, placeHolder: UIImage(named: "logo")!)
|
|
scrollView?.delegate = self
|
|
let a = Double((scrollView?.contentSize.height ?? 0)) - Double(ScreenHeight) - Double((scrollView?.contentOffset.y ?? 0))
|
commentBottomCons.constant = a
|
print("--->1 \(a)")
|
|
assert(scrollView != nil, "需要传adapterVC.scrollView")
|
}
|
|
override func bindRx() {
|
let tap = UITapGestureRecognizer(target: self, action: #selector(openCommentAction))
|
commentView.addGestureRecognizer(tap)
|
}
|
|
@objc func openCommentAction(){
|
|
guard orderId != nil else { alert(text: "数据错误");return}
|
|
PublishCommentView.show({[weak self]text in
|
guard let weakSelf = self else { return }
|
|
let type = weakSelf.type.rawValue
|
let orderId = weakSelf.orderId!
|
|
APIManager.shared.provider.rx.request(.insertComment(commentId: nil, content: text, orderId: orderId, type: type, replyUserId: nil)).map(YYModel<Nothing>.self).validate().subscribe(onSuccess: {data in
|
weakSelf.tableView.beginRefreshing()
|
}) { error in
|
alert(text: "评论失败")
|
}.disposed(by: weakSelf.disposeBag)
|
})
|
}
|
|
override func setupViews() {
|
super.setupViews()
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.separatorStyle = .none
|
tableView.register(CommentContentView.self, forHeaderFooterViewReuseIdentifier: "_CommentContentView")
|
tableView.register(UINib(nibName: "CommentReplyTCell", bundle: nil), forCellReuseIdentifier: "_CommentReplyTCell")
|
}
|
|
override func viewDidLayoutSubviews() {
|
super.viewDidLayoutSubviews()
|
commentView.addShadow(ofColor: UIColor(hexString: "#E6E6E6")!.withAlphaComponent(0.50), radius: 4, offset: CGSize(width: 0, height: -2), opacity: 1)
|
}
|
}
|
|
extension CarDetailCarCommentVC:UIScrollViewDelegate{
|
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
if tableView == scrollView{return}
|
let a = scrollView.contentSize.height - ScreenHeight - scrollView.contentOffset.y
|
print("--->2 \(a)")
|
if a < 0{return}
|
commentBottomCons.constant = a
|
}
|
}
|
|
extension CarDetailCarCommentVC:UITableViewDelegate{
|
|
}
|
|
extension CarDetailCarCommentVC:UITableViewDataSource{
|
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
let m = viewModel.dataSource.value[section]
|
var headView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "_CommentContentView") as? CommentContentView
|
if headView == nil{
|
headView = CommentContentView(reuseIdentifier: "_CommentContentView")
|
}
|
headView?.section = section
|
headView?.setCommentModel(m)
|
headView?.showAllDelegate.delegate(on: self, block: {_,_ in
|
m.showAll = true
|
tableView.reloadData()
|
})
|
|
headView?.replyDelegate.delegate(on: self, block: {_,_ in
|
tableView.mj_header?.beginRefreshing()
|
})
|
|
headView?.replyDelegate.delegate(on: self, block: {_,_ in
|
tableView.mj_header?.beginRefreshing()
|
})
|
|
headView?.showMoreDelegate.delegate(on: self) { (self, arge) in
|
let indexSet = IndexSet.Element(bitPattern: UInt(bitPattern: arge))
|
tableView.reloadSections(IndexSet(integer: indexSet), with: .fade)
|
}
|
|
return headView!
|
}
|
|
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
var h:Double = 55
|
let m = viewModel.dataSource.value[section]
|
|
if m.replyCommentList.count > 10{
|
h += 32
|
}
|
if m.showAll{
|
h += m.contentHeight
|
}else{
|
h += 51
|
}
|
return h
|
}
|
|
|
func numberOfSections(in tableView: UITableView) -> Int {
|
return viewModel.dataSource.value.count
|
}
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
let m = viewModel.dataSource.value[section]
|
if m.showOther{
|
return m.replyCommentList.count
|
}
|
return 0
|
}
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let m = viewModel.dataSource.value[indexPath.section].replyCommentList[indexPath.row]
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_CommentReplyTCell") as! CommentReplyTCell
|
cell.setCommentModel(m)
|
cell.replyDelegate.delegate(on: self) {_,_ in
|
tableView.mj_header?.beginRefreshing()
|
}
|
return cell
|
}
|
}
|