宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//
//  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)
    }
}