Robert
4 天以前 bfe324e547c704b79b98ce5785686bd83def1daf
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
//
//  CommonYearsPickerView.swift
//  WanPai
//
//  Created by 无故事王国 on 2024/3/5.
//
 
import UIKit
import JQTools
import QMUIKit
import RxSwift
import RxCocoa
 
class CommonYearsPickerView: UIView,JQNibView{
 
                @IBOutlet weak var view_container: UIView!
                @IBOutlet weak var cons_bottom: NSLayoutConstraint!
                @IBOutlet weak var pickerView: UIPickerView!
                
                @IBOutlet weak var pickviewTwo: UIPickerView!
    private var clickClouse:(((Int,String))->Void)!
                private var disposeBag = DisposeBag()
                private var years = [Int]()
    var dataSoure : [String :[Any]] = [:]
    var selectIndex : Int = 0
 
    var titleArr = ["年度排名","季度排名","全部"]
//    var selectData : (Int,String)?
                override func awakeFromNib() {
                                super.awakeFromNib()
                                years = (Date().jq_nowYear()-5...Date().jq_nowYear()).map{$0}.sorted(by: {$0 > $1})
//                                years.insert(0, at: 0)
                                cons_bottom.constant = -(JQ_ScreenW * 1.1)
                                pickerView.delegate = self
                                pickerView.dataSource = self
                                alpha = 0
                                layoutIfNeeded()
                                setRx()
                    
                  
                    
                    for item in titleArr {
                        var array = Array<[String:String]>()
                        if item == "季度排名" {
                            for intem1 in years {
                                if intem1 != 0 {
                                    for i in 0..<4 {
                                        if i == 0 {
                                            array.append(["\(intem1)第1季度":"\(intem1)-01-01-\(intem1)-03-30"])
                                        }else if i == 1 {
                                            array.append(["\(intem1)第2季度":"\(intem1)-04-01-\(intem1)-06-30"])
                                        }else if i == 2 {
                                            array.append(["\(intem1)第3季度":"\(intem1)-07-01-\(intem1)-09-30"])
                                        }else if i == 3 {
                                            array.append(["\(intem1)第4季度":"\(intem1)-10-01-\(intem1)-12-30"])
                                        }
                                       
                                    }
                                }
                            }
                            dataSoure[item] =  array
                        }else if item == "年度排名" {
                            dataSoure[item] = years
                        }else if item == "全部" {
                            dataSoure[item] = ["全部"]
                        }
                       
                    }
                    print(dataSoure);
                }
 
                static func show(clickClouse:@escaping ((Int,String))->Void){
                                let studentChooseView = CommonYearsPickerView.jq_loadNibView()
                                studentChooseView.frame = sceneDelegate?.window?.frame ?? .zero
                                studentChooseView.clickClouse = clickClouse
                                sceneDelegate?.window?.addSubview(studentChooseView)
                                studentChooseView.cons_bottom.constant = 0
 
                                UIView.animate(withDuration: 0.4) {
                                                studentChooseView.alpha = 1
                                                studentChooseView.layoutIfNeeded()
                                }
                }
 
                private func setRx(){
 
                }
 
                @IBAction func closeAction(_ sender: UIButton) {
                                closeAction()
                }
 
                override func layoutSubviews() {
                                super.layoutSubviews()
                                DispatchQueue.main.asyncAfter(wallDeadline: .now()+0.1) {
                                                self.view_container.jq_addCorners(corner: [.topLeft,.topRight], radius: 20)
                                }
                }
 
                private func closeAction(){
                                self.cons_bottom.constant = -(JQ_ScreenW * 1.1)
                                UIView.animate(withDuration: 0.4) {
                                                self.alpha = 0
                                                self.layoutIfNeeded()
                                } completion: { _ in
                                                self.removeFromSuperview()
                                }
                }
 
                @IBAction func completeAction(_ sender: UIButton) {
                    let index = pickerView.selectedRow(inComponent: 1)
                    var str = ""
                    if selectIndex == 1 {
                        if let dict  = dataSoure[titleArr[selectIndex]]?[index] as? Dictionary<String, String>   {
                            str = "\(dict.values.first ?? "")"
                        }
                       
                    }else{
                        str =   "\(dataSoure[titleArr[selectIndex]]?[index] ?? "")"
                    }
                   
                    clickClouse((selectIndex,str))
                    closeAction()
                }
}
 
extension CommonYearsPickerView:UIPickerViewDelegate{
 
                func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
                    if component == 0 {
                        let label = UILabel()
                        label.text = "\(titleArr[row])"
                        label.textColor = UIColor(hexString: "3C3C3C")
                        label.textAlignment = .center
                        label.font = UIFont.systemFont(ofSize: 18, weight: .semibold)
                        label.bounds = CGRect(origin: .zero, size: CGSize(width: 100, height: 45))
                        return label
                    }else{
                        let label = UILabel()
 
                        if selectIndex == 1 {
                            if let dict  = dataSoure[titleArr[selectIndex]]?[row] as? Dictionary<String, String>   {
                                label.text = "\(dict.keys.first ?? "")"
                            }
                           
                        }else{
                            label.text =   "\(dataSoure[titleArr[selectIndex]]?[row] ?? "")"
                        }
                     
                       
                        label.textColor = UIColor(hexString: "3C3C3C")
                        label.textAlignment = .center
                        label.font = UIFont.systemFont(ofSize: 18, weight: .semibold)
                        label.bounds = CGRect(origin: .zero, size: CGSize(width: 120, height: 45))
                        return label
                    }
                            
                }
 
                func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
                                return 50
                }
     func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int){
         if component == 0 {
             selectIndex = row
             pickerView.reloadComponent(1)
         }
        
    }
}
 
extension CommonYearsPickerView:UIPickerViewDataSource{
                func numberOfComponents(in pickerView: UIPickerView) -> Int {
                                return 2
                }
                
                func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
                    
                    if dataSoure.keys.count == 0 {
                        return 0
                    }
                    
                    if component == 0 {
                        return dataSoure.count
                    }else{
                        return dataSoure[titleArr[selectIndex]]!.count
                    }
                }
}