//
|
// MineCommoentReplyListVC.swift
|
// OKProject
|
//
|
// Created by 无故事王国 on 2022/5/9.
|
// Copyright © 2022 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
|
class MineCommoentReplyListVC: YYTableViewController {
|
let viewModel = CommentViewModel()
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
viewModel.configure(tableView: tableView)
|
tableView.mj_header?.beginRefreshing()
|
}
|
|
//MARK: - UI
|
override func setupViews() {
|
super.setupViews()
|
tableView.separatorStyle = .none
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.backgroundColor = .clear
|
tableView.register(cellName: "CommoentReplyTCell", identifier: "_CommoentReplyTCell")
|
}
|
|
//MARK: - Layouts
|
override func defineLayouts() {
|
super.defineLayouts()
|
tableView.snp.makeConstraints { (make) in
|
if #available(iOS 11.0, *) {
|
make.edges.equalTo(view.safeAreaLayoutGuide)
|
} else {
|
make.edges.equalToSuperview()
|
}
|
}
|
}
|
}
|
|
|
// MARK: - UITableViewDelegate
|
extension MineCommoentReplyListVC:UITableViewDelegate{
|
// func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
// return UITableView.automaticDimension
|
// }
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
let model = viewModel.dataSource.value[indexPath.row]
|
if model.type == .sell{
|
let vc = CarDetailVC(type: .sell)
|
vc.id = model.orderId
|
yy_push(vc: vc)
|
}else if model.type == .rent{
|
let vc = CarDetailVC(type: .rent)
|
vc.id = model.orderId
|
yy_push(vc: vc)
|
}else if model.type == .job{
|
let vc = JobDetailVC()
|
vc.id = model.orderId
|
yy_push(vc: vc)
|
}
|
}
|
}
|
|
// MARK: - UITableViewDelegate
|
extension MineCommoentReplyListVC:UITableViewDataSource{
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return viewModel.dataSource.value.count
|
}
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let m = viewModel.dataSource.value[indexPath.row]
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_CommoentReplyTCell", for: indexPath) as! CommoentReplyTCell
|
cell.replyStyle(false)
|
cell.backgroundColor = .clear
|
cell.contentL.numberOfLines = 3
|
cell.setComment(m)
|
|
cell.delDelegate.delegate(on: self) {[weak self] _, _ in
|
guard let weakSelf = self else { return }
|
weakSelf.show()
|
APIManager.shared.provider.rx.request(.deleteComment(id: m.id)).map(YYModel<Nothing>.self).validate().subscribe(onSuccess: { data in
|
weakSelf.hide()
|
alert(text: "删除成功")
|
tableView.beginUpdates()
|
var temp = weakSelf.viewModel.dataSource.value
|
temp.remove(at: indexPath.row)
|
weakSelf.viewModel.dataSource.accept(temp)
|
tableView.deleteRows(at: [indexPath], with: .fade)
|
tableView.endUpdates()
|
}) {error in
|
weakSelf.hide()
|
}.disposed(by: weakSelf.disposeBag)
|
}
|
return cell
|
}
|
}
|