宽窄优行-由【嘉易行】项目成品而来
无故事王国
2023-05-25 dc1998fc1ac124f6b9a0e434ccf91103dd936409
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
230
231
232
233
234
235
236
237
238
//
//  CarDetailCarRentInfoVC.swift
//  OKProject
//
//  Created by 无故事王国 on 2022/5/11.
//  Copyright © 2022 yangwang. All rights reserved.
//
 
import UIKit
import Lantern
 
class CarDetailCarRentInfoVC: YYViewController {
 
    private var type:CommonStyle!
    var rentalModel:RentalModel?
 
    let cellW:Double = (SCREEN_WIDTH - 27)
    let cellH:Double = (SCREEN_WIDTH - 27) * 0.497
 
    private var videoImg:UIImage?
 
    @IBOutlet weak var titleL: UILabel!
    @IBOutlet weak var rentMoneyL: UILabel! //租金
    @IBOutlet weak var cashPledgeL: UILabel! //押金
    @IBOutlet weak var contentL: UILabel! //内容
    @IBOutlet weak var descL: UILabel! //描述
    @IBOutlet weak var imageCollectionView: UICollectionView!
    @IBOutlet weak var describeCollHeiCons: NSLayoutConstraint!
 
    required init(type:CommonStyle) {
        super.init(nibName: nil, bundle: nil)
        self.type = type
    }
 
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }
 
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
 
    override func viewDidLoad() {
        super.viewDidLoad()
 
        imageCollectionView.delegate = self
        imageCollectionView.dataSource = self
        imageCollectionView.register(UINib(nibName: "Common_FullImg_CCell", bundle: nil), forCellWithReuseIdentifier: "_Common_FullImg_CCell")
 
        if let model = rentalModel{
            titleL.text = model.title
 
            let font1 = UIFont.systemFont(ofSize: 12)
 
            //租金
            var rentMoneyAttr = AttributedStringbuilder.build()
            rentMoneyAttr = rentMoneyAttr.add(string: "租金:", withFont: UIFont.systemFont(ofSize: 12), withColor: .black.withAlphaComponent(0.8))
            rentMoneyAttr = rentMoneyAttr.add(string: String(format: "%.2lf元/天", model.rentMoney), withFont: font1, withColor: UIColor(hexString: "#FF3D3D")!)
            rentMoneyL.attributedText = rentMoneyAttr.mutableAttributedString
 
            //押金
            var cashPledgeAttr = AttributedStringbuilder.build()
            cashPledgeAttr = cashPledgeAttr.add(string: "押金:", withFont: UIFont.systemFont(ofSize: 12), withColor: .black.withAlphaComponent(0.8))
            cashPledgeAttr = cashPledgeAttr.add(string: String(format: "%.2lf元", model.deposit), withFont: font1, withColor: UIColor(hexString: "#FF3D3D")!)
            cashPledgeL.attributedText = cashPledgeAttr.mutableAttributedString
 
            // 内容
            let font2 = UIFont.systemFont(ofSize: 14,weight: .medium)
            let numline:Double = 8
 
            var contentAttr = AttributedStringbuilder.build()
            //车辆品牌
            contentAttr = contentAttr.add(string: "车辆品牌:", withFont: font2, withColor: UIColor(hexString: "#696969")!.withAlphaComponent(0.8),lineSpace: numline)
            contentAttr = contentAttr.add(string: model.brandName, withFont: font2, withColor: .black,lineSpace: numline)
            contentAttr = contentAttr.add(string: "\n", withFont: font2, withColor: .black,lineSpace: numline)
 
            //座位
            contentAttr = contentAttr.add(string: "座位:", withFont: font2, withColor: UIColor(hexString: "#696969")!.withAlphaComponent(0.8),lineSpace: numline)
            contentAttr = contentAttr.add(string: model.seat, withFont: font2, withColor: .black,lineSpace: numline)
            contentAttr = contentAttr.add(string: "\n", withFont: font2, withColor: .black,lineSpace: numline)
 
            //排量
            contentAttr = contentAttr.add(string: "排量:", withFont: font2, withColor: UIColor(hexString: "#696969")!.withAlphaComponent(0.8),lineSpace: numline)
            contentAttr = contentAttr.add(string: model.displacement, withFont: font2, withColor: .black,lineSpace: numline)
            contentAttr = contentAttr.add(string: "\n", withFont: font2, withColor: .black,lineSpace: numline)
 
            //档位
            contentAttr = contentAttr.add(string: "档位:", withFont: font2, withColor: UIColor(hexString: "#696969")!.withAlphaComponent(0.8),lineSpace: numline)
            contentAttr = contentAttr.add(string: model.gear, withFont: font2, withColor: .black,lineSpace: numline)
            contentAttr = contentAttr.add(string: "\n", withFont: font2, withColor: .black,lineSpace: numline)
 
            //档位
            contentAttr = contentAttr.add(string: "取车证件:", withFont: font2, withColor: UIColor(hexString: "#696969")!.withAlphaComponent(0.8),lineSpace: numline)
            contentAttr = contentAttr.add(string: model.pickUpCarCarCertificates, withFont: font2, withColor: .black,lineSpace: numline)
            contentAttr = contentAttr.add(string: "\n", withFont: font2, withColor: .black,lineSpace: numline)
 
            //档位
            contentAttr = contentAttr.add(string: "联系人:", withFont: font2, withColor: UIColor(hexString: "#696969")!.withAlphaComponent(0.8),lineSpace: numline)
            contentAttr = contentAttr.add(string: model.contactsName, withFont: font2, withColor: .black,lineSpace: numline)
            contentAttr = contentAttr.add(string: "\n", withFont: font2, withColor: .black,lineSpace: numline)
 
            //档位
            contentAttr = contentAttr.add(string: "联系地址:", withFont: font2, withColor: UIColor(hexString: "#696969")!.withAlphaComponent(0.8),lineSpace: numline)
            contentAttr = contentAttr.add(string: model.addres, withFont: font2, withColor: .black,lineSpace: numline)
 
            contentL.attributedText = contentAttr.mutableAttributedString
 
            var descAttr = AttributedStringbuilder.build()
            descAttr = descAttr.add(string: model.describe, withFont: UIFont.systemFont(ofSize: 14, weight: .medium), withColor: UIColor(hexString: "#696969")!.withAlphaComponent(0.8),lineSpace: 4)
            descL.attributedText = descAttr.mutableAttributedString
 
            imageCollectionView.reloadData()
            calHei()
        }
 
 
//        if type == .rentIndividual{
//            rentMoneyL.isHidden = true
//            cashPledgeL.isHidden = true
//        }
    }
 
    private func calHei(){
        var count = rentalModel?.describeImgUrl.components(separatedBy: ",").filter({!$0.isEmpty}).count ?? 0
 
        if videoImg != nil{count += 1}
        describeCollHeiCons.constant = Double(count) * cellH + 8 * Double(count)
        imageCollectionView.reloadData()
    }
 
    @IBAction func callAction(_ sender: UIButton) {
        if let m = rentalModel{
            UIApplication.shared.open(URL(string: "telprompt://\(m.contactsPhone)")!, options: [:], completionHandler: nil)
        }
    }
}
extension CarDetailCarRentInfoVC:UICollectionViewDelegate{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
 
        if videoImg == nil{
            let count = rentalModel?.describeImgUrl.components(separatedBy: ",").filter({!$0.isEmpty}).count ?? 0
            let lantern = Lantern()
            lantern.numberOfItems = {return count}
 
            lantern.cellClassAtIndex = { _ in LanternImageCell.self}
 
            lantern.transitionAnimator = LanternZoomAnimator(previousView: { index -> UIView? in
                let cell = collectionView.cellForItem(at: IndexPath(item: index, section: indexPath.section)) as! Common_FullImg_CCell
                return cell.img
            })
 
            // UIPageIndicator样式的页码指示器
            lantern.pageIndicator = LanternDefaultPageIndicator()
 
            lantern.pageIndex = indexPath.item
 
            lantern.reloadCellAtIndex = { context in
                let lanternCell = context.cell as? LanternImageCell
                let cell = collectionView.cellForItem(at: IndexPath(item:context.index, section: indexPath.section)) as! Common_FullImg_CCell
                lanternCell?.imageView.image = cell.img.image
            }
            //不要使用push
            lantern.show()
        }else{
            if indexPath.row == 0{
                let player = AVKitPlayerController()
               player.playURL  = rentalModel?.videoUrl ?? ""
               present(player, animated: true)
            }else{
                let count = rentalModel?.describeImgUrl.components(separatedBy: ",").filter({!$0.isEmpty}).count ?? 0
                let lantern = Lantern()
                lantern.numberOfItems = {return count}
 
                lantern.cellClassAtIndex = { _ in LanternImageCell.self}
 
                lantern.transitionAnimator = LanternZoomAnimator(previousView: { index -> UIView? in
                    let cell = collectionView.cellForItem(at: IndexPath(item: index + 1, section: indexPath.section)) as! Common_FullImg_CCell
                    return cell.img
                })
 
                // UIPageIndicator样式的页码指示器
                lantern.pageIndicator = LanternDefaultPageIndicator()
 
                lantern.pageIndex = indexPath.item - 1
 
                lantern.reloadCellAtIndex = { context in
                    let lanternCell = context.cell as? LanternImageCell
                    let cell = collectionView.cellForItem(at: IndexPath(item:context.index + 1, section: indexPath.section)) as! Common_FullImg_CCell
                    lanternCell?.imageView.image = cell.img.image
                }
                //不要使用push
                lantern.show()
            }
        }
    }
}
 
extension CarDetailCarRentInfoVC:UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        let count = rentalModel?.describeImgUrl.components(separatedBy: ",").filter({!$0.isEmpty}).count ?? 0
 
        if videoImg != nil{
            return count + 1
        }
        return count
    }
 
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let imgUrl = rentalModel!.describeImgUrl.components(separatedBy: ",").filter({!$0.isEmpty})
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_Common_FullImg_CCell", for: indexPath) as! Common_FullImg_CCell
        cell.closeBtn.isHidden = true
 
        if videoImg != nil{
            if indexPath.row == 0{
                cell.img.image = videoImg
            }else{
                cell.img.load(url: imgUrl[indexPath.row - 1])
            }
        }else{
            cell.img.load(url: imgUrl[indexPath.row])
        }
        return cell
    }
}
 
extension CarDetailCarRentInfoVC :UICollectionViewDelegateFlowLayout{
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 8
    }
 
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 0
    }
 
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: cellW, height: cellH)
    }
}