宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
//
//  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
    }
}