//
|
// 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
|
}
|
}
|
}
|