宽窄优行-由【嘉易行】项目成品而来
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
//
//  HomeItemMoreView.swift
//  OKProject
//
//  Created by 无故事王国 on 2022/5/9.
//  Copyright © 2022 yangwang. All rights reserved.
//
 
import UIKit
import QMUIKit
import RxSwift
 
class HomeItemMoreView: UIView,LDNibView{
 
    @IBOutlet weak var containerView: UIView!
    @IBOutlet weak var collectionView: UICollectionView!
    @IBOutlet weak var containerTopCons: NSLayoutConstraint!
 
    private var handlerVC:YYViewController?
    private var itemsArray = Array<ShowModularModel>()
    private var clouse:((Int)->Void)?
    let mineRealNameViewModel = MineRealNameViewModel()
    private var homeDisposeBag = DisposeBag()
    private var mineRealNameModel:MineRealNameModel?
    var authdelegate = Delegate<Void,Void>()
 
    override func awakeFromNib() {
        super.awakeFromNib()
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.register(UINib(nibName: "Common_SingleImg_CCell", bundle: nil), forCellWithReuseIdentifier: "_Common_SingleImg_CCell")
        collectionView.contentInset = UIEdgeInsets(top: 0, left: 31, bottom: 0, right: 31)
        containerTopCons.constant = -ScreenWidth
        alpha = 0
        layoutIfNeeded()
 
        mineRealNameViewModel.queryRealNameSubject.subscribe(onNext: { data in
            switch data {
                case .success(let model):
                    if let model: MineRealNameModel = model as? MineRealNameModel{
                        self.mineRealNameModel = model
                    }
                default:break
            }
        }).disposed(by: homeDisposeBag)
    }
 
    @discardableResult
    static func show(_ vc:YYViewController,items:[ShowModularModel],clouse:@escaping (Int)->Void)->HomeItemMoreView{
 
        let homeItemMoreView = HomeItemMoreView.ld_loadNibView()
        homeItemMoreView.clouse = clouse
        homeItemMoreView.handlerVC = vc
        homeItemMoreView.itemsArray = items.filter({$0.type != 6 && $0.type != 7 && $0.userShow == 1})
        vc.view.addSubview(homeItemMoreView)
        homeItemMoreView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        homeItemMoreView.collectionView.reloadData()
 
        UIView.animate(withDuration: 0.3) {
            homeItemMoreView.containerTopCons.constant = 0
            homeItemMoreView.alpha = 1
            homeItemMoreView.layoutIfNeeded()
        } completion: { _ in
            homeItemMoreView.mineRealNameViewModel.queryRealName()
        }
 
        return homeItemMoreView
    }
 
    @IBAction func closeAction(_ sender: UIButton) {
        hidden()
    }
 
    private func hidden(){
        UIView.animate(withDuration: 0.3) {
            self.containerTopCons.constant = -ScreenWidth
            self.alpha = 0
            self.layoutIfNeeded()
        } completion: { _ in
            self.removeFromSuperview()
        }
    }
}
 
extension HomeItemMoreView:UICollectionViewDelegate{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let item = itemsArray[indexPath.row]
 
        guard mineRealNameModel != nil else {
            mineRealNameViewModel.queryRealName()
            alert(text: "正在加载数据,请重试");return
        }
 
        if (item.type == 5 || item.type == 4) && mineRealNameViewModel.idcode.value.isEmpty{
            alert(popup: .single, title: "您未实名认证!", text: "", submitTitle: "确定", cancelTitle: nil) {
                self.hidden()
                self.authdelegate.call()
            } cancelClick: {
 
            }
            return
        }
 
        clouse?(item.type)
        hidden()
    }
}
 
extension HomeItemMoreView:UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
       let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_Common_SingleImg_CCell", for: indexPath) as! Common_SingleImg_CCell
       let item = itemsArray[indexPath.row]
        cell.titleL.textColor = UIColor(hexString: "#3E3E3E")
        cell.titleL.font = UIFont.systemFont(ofSize: 14)
        cell.imgTopCons.constant = 0
        switch item.type {
            case 1:
                cell.img.image = UIImage(named: "home_item_job")
                cell.titleL.text = "招贤纳士"
            case 2:
                cell.img.image = UIImage(named: "home_item_hire")
                cell.titleL.text = "我要租车"
            case 3:
                cell.img.image = UIImage(named: "home_item_buy")
                cell.titleL.text = "我要买车"
            case 4:
                cell.img.image = UIImage(named: "home_item_resent")
                cell.titleL.text = "出租我的车辆"
            case 5:
                cell.img.image = UIImage(named: "home_item_sell")
                cell.titleL.text = "我要卖车"
            default:break
        }
        return cell
    }
 
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return itemsArray.count
    }
}
 
extension HomeItemMoreView:UICollectionViewDelegateFlowLayout{
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 25
    }
 
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 18
    }
 
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: 84, height: 82)
    }
}