//
|
// CarMoreListView.swift
|
// OKProject
|
//
|
// Created by 无故事王国 on 2022/5/10.
|
// Copyright © 2022 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
import HandyJSON
|
|
class CarMoreListView: UIView,LDNibView{
|
|
@IBOutlet weak var itemCollectionView: UICollectionView!
|
@IBOutlet weak var itemCollectionHeiCons: NSLayoutConstraint!
|
|
private var fromType:Int? //来源
|
private var startDisplacement:Double? //开始排量
|
private var endDisplacement:Double? //结束排量
|
private var startMileage:Int? //开始里程
|
private var endMileage:Int? //结束里程
|
private var transmissionCase:String? //变速箱
|
private var startRenctPrice:Double? //租车价格
|
private var endRenctPrice:Double? //租车价格
|
private var startCarYear:Int? //开始年龄
|
private var endCarYear:Int? //结束年龄
|
private var takeCar:String?
|
private var welfare:String?
|
private var mutableSelect:Bool = false
|
|
|
private var items = [CellItemModel]()
|
private var type = 0{
|
didSet{
|
if type == 0{
|
items.append(CellItemModel(title: "来源", items: ["不限","个人","平台"]))
|
items.append(CellItemModel(title: "车龄", items: ["不限","一年以内","1-3年","3-5年","5-10年","10年以上"]))
|
items.append(CellItemModel(title: "里程", items: ["不限","一万公里以下","1-3万公里","3-5万公里","5-8万公里","8-12万公里","12万公里以上"]))
|
items.append(CellItemModel(title: "排量", items: ["不限","1.0L以下","1.0-1.6L","1.6-2.0L","2.0-2.5L","2.5-3.0L","3.0-4.0L","4.0L以上"]))
|
items.append(CellItemModel(title: "变速箱", items: ["不限","手动","自动"]))
|
itemCollectionHeiCons.constant = ScreenHeight * 0.47
|
selectSecionIndex = Array(repeating: [], count: items.count)
|
}else if type == 1{
|
items.append(CellItemModel(title: "价格", items: ["¥100以下","¥100-200","¥200-300","¥300-400","¥400以上"]))
|
items.append(CellItemModel(title: "取车证件", items: ["身份证","驾驶证","驾驶员资格证"]))
|
itemCollectionHeiCons.constant = ScreenHeight * 0.27
|
selectSecionIndex = Array(repeating: [], count: items.count)
|
}else{
|
items.append(CellItemModel(title: "福利待遇", items: ["不限","五险一金","包吃","包住","年底双薪","周末双休","交通补助","加班补助","饭补","话补","房补"]))
|
itemCollectionHeiCons.constant = ScreenHeight * 0.23
|
selectSecionIndex = Array(repeating: [0], count: items.count)
|
}
|
|
itemCollectionView.reloadData()
|
}
|
|
}
|
private var hiddenClouse:(()->Void)?
|
private var completeClouse:((Int?,Int?,Int?,Int?,Int?,Double?,Double?,String?)->Void)?
|
private var complete2Clouse:((Double?,Double?,String?)->Void)?
|
private var complete3Clouse:((String?)->Void)?
|
private var selectIndexClouse:((Array<[Int]>)->Void)?
|
public var selectSecionIndex = Array<[Int]>()
|
|
|
override func awakeFromNib() {
|
super.awakeFromNib()
|
alpha = 0
|
itemCollectionView.delegate = self
|
itemCollectionView.dataSource = self
|
itemCollectionView.register(HeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header")
|
itemCollectionView.contentInset = UIEdgeInsets(top: 0, left: 14, bottom: 0, right: 14)
|
itemCollectionView.register(UINib(nibName: "Common_SingleText_CCell", bundle: nil), forCellWithReuseIdentifier: "_Common_SingleText_CCell")
|
layoutIfNeeded()
|
|
setNeedsLayout()
|
layoutSubviews()
|
itemCollectionView.reloadData()
|
}
|
|
@discardableResult
|
static func show(_ vc:YYViewController,offsetTop:CGFloat = 0,type:Int = 0,selectIndex:Array<[Int]>?,selectClouse:@escaping (Int?,Int?,Int?,Int?,Int?,Double?,Double?,String?)->Void,hiddenClouse:@escaping ()->Void,selectIndexClouse:@escaping (Array<[Int]>)->Void)->CarMoreListView{
|
let carBrandListView = CarMoreListView.ld_loadNibView()
|
carBrandListView.type = type
|
carBrandListView.hiddenClouse = hiddenClouse
|
carBrandListView.completeClouse = selectClouse
|
carBrandListView.selectIndexClouse = selectIndexClouse
|
if selectIndex != nil{
|
carBrandListView.selectSecionIndex = selectIndex!
|
carBrandListView.itemCollectionView.reloadData()
|
}
|
vc.view.addSubview(carBrandListView)
|
carBrandListView.snp.makeConstraints { make in
|
make.edges.equalToSuperview().inset(UIEdgeInsets(top: offsetTop, left: 0, bottom: 0, right: 0))
|
}
|
|
UIView.animate(withDuration: 0.4) {
|
carBrandListView.alpha = 1
|
carBrandListView.layoutIfNeeded()
|
}
|
|
return carBrandListView
|
}
|
|
@discardableResult
|
static func showRent(_ vc:YYViewController,offsetTop:CGFloat = 0,type:Int = 0,selectIndex:Array<[Int]>?,selectClouse:@escaping (Double?,Double?,String?)->Void,hiddenClouse:@escaping ()->Void,selectIndexClouse:@escaping (Array<[Int]>)->Void)->CarMoreListView{
|
let carBrandListView = CarMoreListView.ld_loadNibView()
|
carBrandListView.type = type
|
carBrandListView.hiddenClouse = hiddenClouse
|
carBrandListView.complete2Clouse = selectClouse
|
carBrandListView.selectIndexClouse = selectIndexClouse
|
if selectIndex != nil{
|
carBrandListView.selectSecionIndex = selectIndex!
|
carBrandListView.itemCollectionView.reloadData()
|
}
|
vc.view.addSubview(carBrandListView)
|
carBrandListView.snp.makeConstraints { make in
|
make.edges.equalToSuperview().inset(UIEdgeInsets(top: offsetTop, left: 0, bottom: 0, right: 0))
|
}
|
|
UIView.animate(withDuration: 0.4) {
|
carBrandListView.alpha = 1
|
carBrandListView.layoutIfNeeded()
|
}
|
|
return carBrandListView
|
}
|
|
@discardableResult
|
static func showJob(_ vc:YYViewController,offsetTop:CGFloat = 0,type:Int = 0,selectIndex:Array<[Int]>?,selectClouse:@escaping (String?)->Void,hiddenClouse:@escaping ()->Void,selectIndexClouse:@escaping (Array<[Int]>)->Void)->CarMoreListView{
|
let carBrandListView = CarMoreListView.ld_loadNibView()
|
carBrandListView.type = type
|
carBrandListView.hiddenClouse = hiddenClouse
|
carBrandListView.mutableSelect = true
|
carBrandListView.complete3Clouse = selectClouse
|
carBrandListView.selectIndexClouse = selectIndexClouse
|
if selectIndex != nil{
|
carBrandListView.selectSecionIndex = selectIndex!
|
carBrandListView.itemCollectionView.reloadData()
|
}
|
vc.view.addSubview(carBrandListView)
|
carBrandListView.snp.makeConstraints { make in
|
make.edges.equalToSuperview().inset(UIEdgeInsets(top: offsetTop, left: 0, bottom: 0, right: 0))
|
}
|
|
UIView.animate(withDuration: 0.4) {
|
carBrandListView.alpha = 1
|
carBrandListView.layoutIfNeeded()
|
}
|
|
return carBrandListView
|
}
|
|
override func layoutSubviews() {
|
super.layoutSubviews()
|
|
}
|
|
@IBAction func hiddenAction(_ sender: UIButton) {
|
hidden()
|
}
|
|
@IBAction func resetAction(_ sender: UIButton) {
|
if type > 1{
|
selectSecionIndex = Array(repeating: [0], count: items.count)
|
}else{
|
selectSecionIndex = Array(repeating: [], count: items.count)
|
}
|
itemCollectionView.reloadData()
|
}
|
|
@IBAction func completeAction(_ sender: UIButton) {
|
|
if type == 0{
|
for (index,value) in selectSecionIndex.enumerated() {
|
switch index{
|
case 0:
|
if let value = value.first{
|
switch value{
|
case 1:fromType = 1
|
case 2:fromType = 2
|
default:fromType = nil
|
}
|
}else{
|
fromType = nil
|
}
|
case 1:
|
if let value = value.first{
|
switch value {
|
case 1:
|
startCarYear = nil
|
endCarYear = 1
|
case 2:
|
startCarYear = 1
|
endCarYear = 3
|
case 3:
|
startCarYear = 3
|
endCarYear = 5
|
case 4:
|
startCarYear = 5
|
endCarYear = 10
|
case 5:
|
startCarYear = 10
|
endCarYear = nil
|
default:
|
startCarYear = nil
|
endCarYear = nil
|
}
|
}else{
|
startCarYear = nil
|
endCarYear = nil
|
}
|
case 2:
|
|
if let value = value.first{
|
switch value{
|
case 1:
|
startMileage = nil
|
endMileage = 1
|
case 2:
|
startMileage = 1
|
endMileage = 3
|
case 3:
|
startMileage = 3
|
endMileage = 5
|
case 4:
|
startMileage = 5
|
endMileage = 8
|
case 5:
|
startMileage = 8
|
endMileage = 12
|
case 6:
|
startMileage = 12
|
endMileage = nil
|
default:
|
startMileage = nil
|
endMileage = nil
|
}
|
}else{
|
startMileage = nil
|
endMileage = nil
|
}
|
|
case 3:
|
|
if let value = value.first{
|
switch value{
|
case 1:
|
startDisplacement = nil
|
endDisplacement = 1.0
|
case 2:
|
startDisplacement = 1.0
|
endDisplacement = 1.6
|
case 3:
|
startDisplacement = 1.6
|
endDisplacement = 2.0
|
case 4:
|
startDisplacement = 2.0
|
endDisplacement = 2.5
|
case 5:
|
startDisplacement = 2.5
|
endDisplacement = 3.0
|
case 6:
|
startDisplacement = 3.0
|
endDisplacement = 4.0
|
case 7:
|
startDisplacement = 4.0
|
endDisplacement = nil
|
default:
|
startDisplacement = nil
|
endDisplacement = nil
|
}
|
}else{
|
startDisplacement = nil
|
endDisplacement = nil
|
}
|
|
case 4:
|
|
if let value = value.first{
|
switch value{
|
case 1:transmissionCase = "手动"
|
case 2:transmissionCase = "自动"
|
default:transmissionCase = nil
|
}
|
}else{
|
transmissionCase = nil
|
}
|
default:break
|
}
|
}
|
completeClouse?(fromType, startCarYear, endCarYear, startMileage, endMileage, startDisplacement, endDisplacement, transmissionCase)
|
}
|
|
if type == 1{
|
for (index,value) in selectSecionIndex.enumerated() {
|
switch index {
|
case 0:
|
if let v = value.first{
|
switch value.count{
|
case 0:
|
startRenctPrice = nil
|
endRenctPrice = 100
|
case 1:
|
startRenctPrice = 100
|
endRenctPrice = 200
|
case 2:
|
startRenctPrice = 200
|
endRenctPrice = 300
|
case 3:
|
startRenctPrice = 300
|
endRenctPrice = 400
|
case 4:
|
startRenctPrice = 400
|
endRenctPrice = nil
|
default:
|
startRenctPrice = nil
|
endRenctPrice = nil
|
}
|
}else{
|
startRenctPrice = nil
|
endRenctPrice = nil
|
}
|
case 1:
|
if let v = value.first{
|
switch v{
|
case 0:takeCar = "身份证"
|
case 1:takeCar = "驾驶证"
|
case 2:takeCar = "驾驶员资格证"
|
default:takeCar = nil
|
}
|
}else{
|
takeCar = nil
|
}
|
default:break
|
}
|
}
|
complete2Clouse?(startRenctPrice,endRenctPrice,takeCar)
|
}
|
|
if type == 2{
|
var temp = [String]()
|
for (_,value) in selectSecionIndex.enumerated() {
|
for (_,value1) in value.enumerated(){
|
switch value1{
|
case 0:temp.removeAll();break
|
case 1:temp.append("五险一金")
|
case 2:temp.append("包吃")
|
case 3:temp.append("包住")
|
case 4:temp.append("年底双薪")
|
case 5:temp.append("周末双休")
|
case 6:temp.append("交通补助")
|
case 7:temp.append("加班补助")
|
case 8:temp.append("饭补")
|
case 9:temp.append("话补")
|
case 10:temp.append("房补")
|
default:break
|
}
|
}
|
}
|
complete3Clouse?(temp.joined(separator: ","))
|
}
|
|
selectIndexClouse?(selectSecionIndex)
|
hidden()
|
}
|
|
func hidden(){
|
self.hiddenClouse?()
|
UIView.animate(withDuration: 0.4) {
|
self.alpha = 0
|
self.layoutIfNeeded()
|
} completion: { _ in
|
self.removeFromSuperview()
|
}
|
}
|
}
|
|
extension CarMoreListView:UICollectionViewDelegate{
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
if mutableSelect{
|
if indexPath.row == 0{
|
selectSecionIndex[indexPath.section] = [indexPath.row]
|
}else if selectSecionIndex[indexPath.section].contains(indexPath.row){
|
selectSecionIndex[indexPath.section].remove(at: 0)
|
if let index = selectSecionIndex[indexPath.section].firstIndex(of: indexPath.row){
|
selectSecionIndex[indexPath.section].remove(at: index)
|
}
|
}else{
|
if let index = selectSecionIndex[indexPath.section].firstIndex(of: 0){
|
selectSecionIndex[indexPath.section].remove(at: index)
|
}
|
selectSecionIndex[indexPath.section].append(indexPath.row)
|
}
|
}else{
|
selectSecionIndex[indexPath.section] = [indexPath.row]
|
}
|
|
collectionView.reloadData()
|
}
|
}
|
|
extension CarMoreListView:UICollectionViewDataSource{
|
|
func numberOfSections(in collectionView: UICollectionView) -> Int {
|
return items.count
|
}
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
return items[section].items.count
|
}
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_Common_SingleText_CCell", for: indexPath) as! Common_SingleText_CCell
|
cell.titleL.text = items[indexPath.section].items[indexPath.row]
|
cell.titleL.font = UIFont.systemFont(ofSize: 13)
|
cell.titleL.cornerRadius = 2
|
cell.titleL.maskToBounds = true
|
cell.borderColor = UIColor.color(hexString: "#EFEFEF")
|
|
if selectSecionIndex[indexPath.section].contains(indexPath.row){
|
cell.titleL.backgroundColor = UIColor.color(hexString: "#00BF30")
|
cell.titleL.textColor = .white
|
cell.borderWidth = 0
|
}else{
|
cell.titleL.backgroundColor = .white
|
cell.titleL.textColor = UIColor.color(hexString: "#727272")
|
cell.borderWidth = 0.5
|
}
|
return cell
|
}
|
}
|
|
extension CarMoreListView:UICollectionViewDelegateFlowLayout{
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
return 5
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
|
return 10
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
let title = items[indexPath.section].items[indexPath.row]
|
var calCellW = title.width(UIFont.systemFont(ofSize: 16, weight: .medium), height: 27)
|
|
if calCellW < 60{
|
calCellW = 60
|
}
|
return CGSize(width: calCellW, height: 27)
|
}
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
|
return CGSize(width: ScreenWidth, height: 48)
|
}
|
|
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
|
let cell = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header", for: indexPath) as! HeaderView
|
cell.setText(items[indexPath.section].title)
|
return cell
|
}
|
}
|
|
fileprivate struct CellItemModel:HandyJSON{
|
var title = ""
|
var items = Array<String>()
|
}
|
|
fileprivate class HeaderView:UICollectionReusableView{
|
|
private var titleL:UILabel!
|
|
override init(frame: CGRect) {
|
super.init(frame: frame)
|
setUI()
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
private func setUI(){
|
titleL = UILabel()
|
titleL.font = UIFont.systemFont(ofSize: 16, weight: .medium)
|
titleL.textColor = UIColor.color(hexString: "#333333")
|
addSubview(titleL)
|
titleL.snp.makeConstraints { make in
|
make.left.equalToSuperview()
|
make.centerY.equalToSuperview()
|
}
|
}
|
|
func setText(_ text:String){
|
titleL.text = text
|
}
|
}
|