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