//
|
// CommoentReplyTCell.swift
|
// OKProject
|
//
|
// Created by 无故事王国 on 2022/5/9.
|
// Copyright © 2022 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
import HandyJSON
|
import RxCocoa
|
|
class CommoentReplyTCell: UITableViewCell {
|
|
@IBOutlet weak var dateTimeL: UILabel!
|
@IBOutlet weak var contentL: UILabel!
|
|
@IBOutlet weak var stackView: UIStackView!
|
@IBOutlet weak var replayL: UILabel!
|
@IBOutlet weak var closeBtn: UIButton!
|
|
@IBOutlet weak var v1_containerView: UIView!
|
@IBOutlet weak var t1_titleL: UILabel!
|
@IBOutlet weak var t1_moneyL: UILabel!
|
@IBOutlet weak var t1_itemCollectionView: UICollectionView!
|
|
@IBOutlet weak var v2_containerView: UIView!
|
@IBOutlet weak var t2_titleL: UILabel!
|
@IBOutlet weak var t2_moneyL: UILabel!
|
@IBOutlet weak var t2_addressL: UILabel!
|
@IBOutlet weak var t2_image: UIImageView!
|
@IBOutlet weak var t2_hintL: UILabel!
|
|
@IBOutlet weak var v3_containerView: UIView!
|
@IBOutlet weak var t3_titleL: UILabel!
|
@IBOutlet weak var t3_moneyL: UILabel!
|
@IBOutlet weak var t3_infoL: UILabel!
|
@IBOutlet weak var t3_image: UIImageView!
|
@IBOutlet weak var t3_hintL: UILabel!
|
|
@IBOutlet weak var replayHeiCons: NSLayoutConstraint!
|
@IBOutlet weak var contentHeiCons: NSLayoutConstraint!
|
@IBOutlet weak var contentTopCons: NSLayoutConstraint!
|
|
var delDelegate = Delegate<Void,Void>()
|
private var jobListModel:JobListModel?
|
|
override func awakeFromNib() {
|
super.awakeFromNib()
|
selectionStyle = .none
|
}
|
|
override func layoutSubviews() {
|
super.layoutSubviews()
|
t2_hintL.addRoundedCorners(corners: .bottomRight, rect: CGRect(x: 0, y: 0, width: 55, height: 20), radius: CGSize(width: 8, height: 8))
|
t3_hintL.addRoundedCorners(corners: .bottomRight, rect: CGRect(x: 0, y: 0, width: 55, height: 20), radius: CGSize(width: 8, height: 8))
|
}
|
|
func style(_ s:CommonStyle,m:CommentModel){
|
switch s {
|
case .job:
|
v1_containerView.isHidden = false
|
v2_containerView.isHidden = true
|
v3_containerView.isHidden = true
|
t1_itemCollectionView.delegate = self
|
t1_itemCollectionView.dataSource = self
|
t1_itemCollectionView.isScrollEnabled = false
|
t1_itemCollectionView.register(UINib(nibName: "Common_SingleText_CCell", bundle: nil), forCellWithReuseIdentifier: "_Common_SingleText_CCell")
|
|
if let model = JobListModel.deserialize(from: m.orderInfo){
|
self.jobListModel = model
|
self.t1_titleL.text = model.title
|
self.t1_moneyL.text = String(format: "%.2ld-%.2ld元/月", model.startSalary,model.endSalary)
|
self.t1_itemCollectionView.reloadData()
|
}
|
|
|
case .sell:
|
v1_containerView.isHidden = true
|
v2_containerView.isHidden = true
|
v3_containerView.isHidden = false
|
|
if let model = SellCarReqModel.deserialize(from: m.orderInfo){
|
t3_titleL.text = model.title
|
t3_moneyL.text = String(format: "%.2lf万", (model.transferPrice ?? 0) / 10000)
|
|
var temp = Array<String>()
|
temp.append(String(format: "%.2lf万公里", (model.mileage ?? 0) / 10000))
|
temp.append(model.operationUpdateTime ?? "")
|
temp.append(model.cityName ?? "")
|
t3_infoL.text = temp.filter({!$0.isEmpty}).joined(separator: "/")
|
|
t3_image.load(url: model.imgUrl ?? "", placeHolder: UIImage(named: "logo")!)
|
|
if model.userType == .user{
|
t3_hintL.text = "个人车辆"
|
// t3_hintL.backgroundColor = UIColor(hexString: "#00BF30")!.withAlphaComponent(0.79)
|
}else if model.userType == .business{
|
t3_hintL.text = "企业车辆"
|
// t3_hintL.backgroundColor = UIColor(hexString: "#FF8A3D")!.withAlphaComponent(0.79)
|
}else{
|
t3_hintL.text = ""
|
t3_hintL.backgroundColor = .clear
|
}
|
}
|
case .rent:
|
v1_containerView.isHidden = true
|
v2_containerView.isHidden = false
|
v3_containerView.isHidden = true
|
|
if let model = RentalModel.deserialize(from: m.orderInfo){
|
t2_titleL.text = model.title
|
t2_moneyL.text = String(format: "%.2lf元/天", model.rentMoney)
|
t2_addressL.text = model.addres
|
if let imgUrl = model.imgUrl.components(separatedBy: ",").filter({!$0.isEmpty}).first{
|
t2_image.load(url:imgUrl)
|
}
|
|
if model.userType == .user{
|
t2_hintL.text = "个人车辆"
|
t2_hintL.backgroundColor = UIColor(hexString: "#FF8A3D")!.withAlphaComponent(0.79)
|
}else if model.userType == .business{
|
t2_hintL.text = "企业车辆"
|
t2_hintL.backgroundColor = UIColor(hexString: "#00BF30")!.withAlphaComponent(0.79)
|
}else{
|
t2_hintL.text = ""
|
t2_hintL.backgroundColor = .clear
|
}
|
}
|
}
|
}
|
|
func setComment(_ m:CommentModel){
|
|
let createTime = DateClass.timeStringToDate(m.createTime)
|
let diffday = DateClass.dateDifference(Date(), from: createTime)
|
if diffday > 1.0{
|
dateTimeL.text = String(format: "%@", DateClass.dateToDateString(createTime, dateFormat: "yyyy/MM/dd"))
|
}else{
|
let time = DateClass.timeStringToDate(m.createTime).timeIntervalSince1970 * 1000
|
dateTimeL.text = String(format: "%@", DateClass.compareCurrentTime(str: "\(time)"))
|
}
|
|
var attribute = AttributedStringbuilder.build()
|
var attribute1 = AttributedStringbuilder.build()
|
let name = m.replyUserName
|
|
if m.commentId != 0{
|
attribute1 = attribute1.add(string: "\(m.userName)", withFont: .systemFont(ofSize: 14), withColor: UIColor(hexString: "#00BF30")!, lineSpace: 3)
|
attribute1 = attribute1.add(string: "回复", withFont: .systemFont(ofSize: 14), withColor: UIColor.black.withAlphaComponent(0.8), lineSpace: 3)
|
attribute1 = attribute1.add(string: "\(name):", withFont: UIFont.systemFont(ofSize: 14), withColor: UIColor(hexString: "#00BF30")!, lineSpace: 3)
|
attribute1 = attribute1.add(string: m.content, withFont: .systemFont(ofSize: 14), withColor: UIColor.black.withAlphaComponent(0.8), lineSpace: 3)
|
|
attribute = attribute.add(string: "\(name):", withFont: UIFont.systemFont(ofSize: 14), withColor: UIColor(hexString: "#00BF30")!, lineSpace: 3)
|
attribute = attribute.add(string: m.replyUserContent, withFont: UIFont.systemFont(ofSize: 14), withColor: .black.withAlphaComponent(0.8), lineSpace: 3)
|
}else{
|
attribute = attribute.add(string: m.content, withFont: UIFont.systemFont(ofSize: 14), withColor: .black.withAlphaComponent(0.8), lineSpace: 3)
|
}
|
|
contentL.attributedText = attribute.mutableAttributedString
|
replayL.attributedText = attribute1.mutableAttributedString
|
|
// self.replayHeiCons.constant = attribute1.mutableAttributedString.heightOfAttributedString(ScreenWidth - 25)
|
// self.contentHeiCons.constant = attribute.mutableAttributedString.heightOfAttributedString(ScreenWidth - 25)
|
|
//73703 【我的评论】评论内容过长,也要省略显示
|
contentL.lineBreakMode = .byTruncatingTail
|
replayL.lineBreakMode = .byTruncatingTail
|
style(m.type,m: m)
|
}
|
|
func replyStyle(_ b:Bool){
|
closeBtn.isHidden = b
|
if b{
|
contentTopCons.constant = 8
|
}else{
|
replayL.text = ""
|
contentTopCons.constant = 0
|
}
|
}
|
|
@IBAction func delCommentAction(_ sender: UIButton) {
|
alert(popup: .double, title: "提示", text: "是否删除当前评论?", submitTitle: "确定", cancelTitle: "取消") { [weak self] () in
|
self?.delDelegate.call()
|
} cancelClick: {
|
|
}
|
}
|
}
|
|
extension CommoentReplyTCell:UICollectionViewDelegate{
|
|
}
|
|
extension CommoentReplyTCell:UICollectionViewDataSource{
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
return jobListModel?.welfare.components(separatedBy: ",").filter({!$0.isEmpty}).count ?? 0
|
}
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
let item = jobListModel!.welfare.components(separatedBy: ",").filter({!$0.isEmpty})[indexPath.row]
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_Common_SingleText_CCell", for: indexPath) as! Common_SingleText_CCell
|
cell.titleL.borderColor = UIColor(hexString: "#29C951")!
|
cell.titleL.borderWidth = 0.6
|
cell.titleL.textColor = UIColor(hexString: "#29C951")
|
cell.titleL.font = UIFont.systemFont(ofSize: 12)
|
cell.titleL.text = item
|
cell.titleL.backgroundColor = .white
|
cell.titleL.cornerRadius = 2
|
|
return cell
|
}
|
}
|
|
extension CommoentReplyTCell:UICollectionViewDelegateFlowLayout{
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
return 0
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
|
return 8
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
let title = jobListModel!.welfare.components(separatedBy: ",").filter({!$0.isEmpty})[indexPath.row]
|
let calCellW = title.width(UIFont.systemFont(ofSize: 15), height: 15)
|
return CGSize(width: calCellW+6, height: 18)
|
}
|
}
|