宽窄优行-由【嘉易行】项目成品而来
无故事王国
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
//
//  CarDetailCarInfoVC.swift
//  OKProject
//
//  Created by 无故事王国 on 2022/5/10.
//  Copyright © 2022 yangwang. All rights reserved.
//
 
import UIKit
import QMUIKit
import WebKit
import Lantern
 
class CarDetailCarInfoVC: YYViewController {
 
    @IBOutlet weak var scrollView: CustomScrollView!
    @IBOutlet weak var titleL: UILabel! //标题
    @IBOutlet weak var priceL: UILabel! //价格
    @IBOutlet weak var carTypeL: UILabel! //类型
    @IBOutlet weak var infoL: UILabel! //含税价格
    @IBOutlet weak var firmL: UILabel! //厂商
    @IBOutlet weak var brandNameL: UILabel! //所属厂商
    @IBOutlet weak var mileageL: UILabel! //表里程
    @IBOutlet weak var displacementL: UILabel! //排量
    @IBOutlet weak var transmissionCaseL: UILabel! //变速箱
    @IBOutlet weak var locationOfLicensePlateL: UILabel! //拍照地
    @IBOutlet weak var transferTimesL: UILabel! //过户次数
    @IBOutlet weak var levelL: UILabel! //级别
    @IBOutlet weak var licensingTimeL: UILabel! //上牌时间
    @IBOutlet weak var contactsNameL: UILabel! //联系人
    @IBOutlet weak var isAuthBtn: QMUIButton!
    @IBOutlet weak var addresL: UILabel!
    @IBOutlet weak var describeCollectionView: UICollectionView!
    @IBOutlet weak var describeCollHeiCons: NSLayoutConstraint!
    @IBOutlet weak var describeL: UILabel!
    @IBOutlet weak var moreBtn: QMUIButton!
    @IBOutlet weak var webView: WKWebView!
    @IBOutlet weak var webViewHeiCons: NSLayoutConstraint!
 
    var carSellModel:CarSellModel?
 
    private var videoImg:UIImage?
 
    private let agreementViewModel = AgreementViewModel()
 
    let cellW:Double = (SCREEN_WIDTH - 27)
    let cellH:Double = (SCREEN_WIDTH - 27) * 0.497
 
    override func viewDidLoad() {
        super.viewDidLoad()
        describeCollectionView.delegate = self
        describeCollectionView.dataSource = self
        describeCollectionView.register(UINib(nibName: "Common_FullImg_CCell", bundle: nil), forCellWithReuseIdentifier: "_Common_FullImg_CCell")
        moreBtn.spacingBetweenImageAndTitle = 7
        moreBtn.imagePosition = .right
        
 
        if let model = carSellModel{
            self.carSellModel = model
            self.isAuthBtn.isHidden = model.isAuth == 1
            self.titleL.text = model.title
            self.priceL.text = String(format: "%.2lf万", Double(model.transferPrice)/10000.0)
            self.carTypeL.text = model.category == "1" ? "非运营车辆":"运营车辆"
 
            let trans = model.includingTransferFee == 1 ? "不包含过户费":"包含过户费"
            self.infoL.text = String(format: "新车含税价格:%.2lf万/%@", Double(model.newCarPrice)/10000.0,trans)
 
            self.brandNameL.text = model.brandName
            //73645 【车辆详情】部分字段没有显示单位
            self.mileageL.text = String(format: "%.2lf万公里", model.mileage)
            self.displacementL.text = String(format: "%@L", model.displacement)
            self.transmissionCaseL.text = model.transmissionCase
            self.locationOfLicensePlateL.text = model.locationOfLicensePlate
            //73645 【车辆详情】部分字段没有显示单位
            self.transferTimesL.text = String(format: "%@次", model.transferTimes)
            self.levelL.text = model.level
            self.licensingTimeL.text = model.licensingTime
            self.contactsNameL.text = model.contactsName
            self.isAuthBtn.isHidden = model.userType != .business
            //73512 【买车】列表-进入详情:1.商家信息联系地址要展示完全,目前没有显示 省市。
            self.addresL.text = String(format: "%@%@%@", model.provinceName,model.cityName,model.addres)
 
            if !model.videoUrl.isEmpty{
                let asset = AVURLAsset(url: URL(string: model.videoUrl)!)
                let gen = AVAssetImageGenerator(asset: asset)
                gen.appliesPreferredTrackTransform = true
                let time = CMTimeMakeWithSeconds(0.0, preferredTimescale: 1)
                var actualTime : CMTime = CMTimeMakeWithSeconds(0, preferredTimescale: 0)
                do {
                    let image = try gen.copyCGImage(at: time, actualTime: &actualTime)
                    self.videoImg = UIImage(cgImage: image)
                } catch  {
                    print("错误")
                }
            }
 
            let attribute = AttributedStringbuilder.build()
            self.describeL.attributedText = attribute.add(string: model.describe, withFont: UIFont.systemFont(ofSize: 14, weight: .medium), withColor: .black.withAlphaComponent(0.8), lineSpace: 3).mutableAttributedString
            calHei()
        }
 
        agreementViewModel.type.accept(.question)
        agreementViewModel.agreement()
    }
 
    override func bindRx() {
 
        agreementViewModel.requestSubject.subscribe(onNext: {state in
            switch state {
                case .success(let model):
                    guard let data: SwitchCityModel = model as? SwitchCityModel else {return}
                    self.webView.loadHTMLString(data.content.ld_warpHtml, baseURL: nil)
                default:break
            }
 
        }).disposed(by: disposeBag)
 
        self.webView.scrollView.rx.observe(CGSize.self, "contentSize").map { (size) -> CGFloat? in
            if let size = size{
                return size.height
            }
            return nil
        }.subscribe(onNext: { [unowned self](height) in
            if let height = height{
                self.webViewHeiCons.constant = height
            }
        }).disposed(by: disposeBag)
    }
 
    @IBAction func moreAction(_ sender: UIButton) {
         let vc = MinePublishSaleDetailMoreVC()
        vc.carSellModel = carSellModel
        yy_push(vc: vc)
    }
 
    private func calHei(){
        var count = carSellModel?.describeImgUrl.components(separatedBy: ",").filter({!$0.isEmpty}).count ?? 0
 
        if videoImg != nil{count += 1}
        describeCollHeiCons.constant = Double(count) * cellH + 8 * Double(count)
        describeCollectionView.reloadData()
    }
 
 
    @IBAction func callAction(_ sender: UIButton) {
        if let phone = carSellModel?.contactsPhone{
            UIApplication.shared.open(URL(string: "telprompt://\(phone)")!, options: [:], completionHandler: nil)
        }
    }
}
 
extension CarDetailCarInfoVC:UICollectionViewDelegate{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
 
        if videoImg == nil{
            let count = carSellModel?.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  = carSellModel?.videoUrl ?? ""
               present(player, animated: true)
            }else{
                let count = carSellModel?.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 CarDetailCarInfoVC:UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        let count = carSellModel?.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 = carSellModel!.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 CarDetailCarInfoVC :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)
    }
}
 
 
class CustomScrollView:UIScrollView{
    override init(frame: CGRect) {
        super.init(frame: frame)
 
    }
 
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
 
    override func awakeFromNib() {
        super.awakeFromNib()
 
    }
}