宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-04-11 4356615a9252a987a62469331b1fcf91c102e24c
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
//
//  JobDetailHeaderVC.swift
//  OKProject
//
//  Created by 无故事王国 on 2022/5/17.
//  Copyright © 2022 yangwang. All rights reserved.
//
 
import UIKit
 
class JobDetailHeaderVC: YYViewController {
 
    private var jobListModel:JobListModel?
    @IBOutlet weak var titleL: UILabel!
    @IBOutlet weak var priceL: UILabel!
    @IBOutlet weak var infoL: UILabel!
    @IBOutlet weak var publishTimeL: UILabel!
    @IBOutlet weak var itemCollectionView: UICollectionView!
    @IBOutlet weak var collectionHeiCons: NSLayoutConstraint!
 
    override func viewDidLoad() {
        super.viewDidLoad()
 
        itemCollectionView.delegate = self
        itemCollectionView.dataSource = self
        itemCollectionView.register(UINib(nibName: "Common_SingleText_CCell", bundle: nil), forCellWithReuseIdentifier: "_Common_SingleText_CCell")
    }
 
 
    func setJobListModel(_ model:JobListModel?){
        if let m = model{
            jobListModel = m
            titleL.text = m.title
 
            if m.startSalary == 0 && m.endSalary == 0{
                priceL.text = "薪资面议"
            }else{
                priceL.text = String(format: "%.2lf-%.2lf元/月", m.startSalary,m.endSalary)
            }
 
            let createTime = DateClass.timeStringToDate(m.createTime)
            let diffday = DateClass.dateDifference(Date(), from: createTime)
 
            if diffday > 1.0{
                publishTimeL.text = String(format: "%@发布", DateClass.dateToDateString(createTime, dateFormat: "yyyy-MM-dd"))
            }else{
                let time = DateClass.timeStringToDate(m.createTime).timeIntervalSince1970 * 1000
                publishTimeL.text = String(format: "%@发布", DateClass.compareCurrentTime(str: "\(time)"))
            }
 
            var array = Array<String>()
            array.append(String(format: "招%ld人", m.recruitsNumber))
 
            if m.experienceRequirements.isEmpty{
                array.append("经验不限")
            }else{
                array.append(m.experienceRequirements)
            }
 
            if m.educationalRequirements.isEmpty{
                array.append("学历不限")
            }else{
                array.append(m.educationalRequirements)
            }
            infoL.text = array.joined(separator: " | ")
            itemCollectionView.reloadData()
        }
    }
 
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        collectionHeiCons.constant = itemCollectionView.contentSize.height + 10
    }
}
 
extension JobDetailHeaderVC:UICollectionViewDelegate{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
 
    }
}
 
extension JobDetailHeaderVC:UICollectionViewDataSource{
 
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return jobListModel?.welfare.components(separatedBy: ",").filter({!$0.isEmpty}).count ?? 0
    }
 
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let text = jobListModel!.welfare.components(separatedBy: ",").filter({!$0.isEmpty})[indexPath.row]
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_Common_SingleText_CCell", for: indexPath) as! Common_SingleText_CCell
        cell.titleL.text = text
        cell.titleL.font = UIFont.systemFont(ofSize: 12)
        cell.titleL.cornerRadius = 2
        cell.titleL.borderWidth = 0.6
        cell.titleL.maskToBounds = true
        cell.titleL.borderColor = UIColor.color(hexString: "#00BF30")
        cell.titleL.backgroundColor = .white
        cell.titleL.textColor = UIColor.color(hexString: "#00BF30")
        return cell
    }
}
 
extension JobDetailHeaderVC: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 5
    }
 
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let title = jobListModel!.welfare.components(separatedBy: ",").filter({!$0.isEmpty})[indexPath.row]
        let calCellW = title.width(UIFont.systemFont(ofSize: 15), height: 15)
        return CGSize(width: calCellW+6, height: 18)
    }
}