//
|
// 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()
|
|
}
|
}
|