123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- //
- // StatisticsSelectDateView.swift
- // JiaPeiManage
- //
- // Created by Ning.ge on 2023/6/29.
- //
- final class StatisticsSelectDateView: UIView,NibLoadable {
-
- //开始时间
- @IBOutlet weak var startdate_button: UIButton!
- //结束时间
- @IBOutlet weak var enddate_button: UIButton!
- //本月
- @IBOutlet weak var month_button: UIButton!
- //上月
- @IBOutlet weak var lastmonth_button: UIButton!
- //3个月
- @IBOutlet weak var threemonth_button: UIButton!
- //本年
- @IBOutlet weak var year_button: UIButton!
- //重置
- @IBOutlet weak var reset_button: UIButton!
- //确定
- @IBOutlet weak var confirm_button: UIButton!
- //选中的 btn
- public var current_button: UIButton!
- var dateType:DateType = .day
- var startDate:String = ""
- var endDate:String = ""
- var selectIndex = 0
- var showCount = 0 //show的次数
- override func awakeFromNib() {
- super.awakeFromNib()
- //本月
- month_button.tag = 99+0
- //上月
- lastmonth_button.tag = 99+1
- //3个月
- threemonth_button.tag = 99+2
- //本年
- year_button.tag = 99+3
- current_button = month_button
- }
- //日月年
- func setDateType(type:DateType){
- dateType = type
- if showCount>=1 {return}
- switch dateType {
- case .day:
- month_button.setTitle("昨日", for: .normal)
- lastmonth_button.setTitle("今日", for: .normal)
- threemonth_button.setTitle("本月", for: .normal)
- year_button.setTitle("上月", for: .normal)
- current_button.backgroundColor = UIColor("#0B2B4D")!
- current_button = threemonth_button
- current_button.backgroundColor = UIColor("#597CA1")!
- case .month:
- month_button.setTitle("本月", for: .normal)
- lastmonth_button.setTitle("上月", for: .normal)
- threemonth_button.setTitle("近3月", for: .normal)
- year_button.setTitle("本年", for: .normal)
- current_button.backgroundColor = UIColor("#0B2B4D")!
- current_button = year_button
- current_button.backgroundColor = UIColor("#597CA1")!
- case .year:
- month_button.setTitle("本年", for: .normal)
- lastmonth_button.setTitle("去年", for: .normal)
- threemonth_button.setTitle("近3年", for: .normal)
- year_button.setTitle("近5年", for: .normal)
- current_button.backgroundColor = UIColor("#0B2B4D")!
- current_button = year_button
- current_button.backgroundColor = UIColor("#597CA1")!
- }
- showCount+=1
- }
- //选中 - func
- func selectItemIndex(index:Int){
- selectIndex = index
- let button = self.viewWithTag(99+index) as! UIButton
- // button.backgroundColor = UIColor("#06203A")!
- if current_button != button {
- current_button.backgroundColor = UIColor("#0B2B4D")!
- button.backgroundColor = UIColor("#597CA1")!
- current_button = button
- }
- datehandledo()
- }
- //计算 - 日期
- func datehandledo(){
- switch dateType {
- case .day:
- dayhandledo()
- case .month:
- monthhandledo()
- case .year:
- yearhandledo()
- }
- }
-
- func dayhandledo(){
- switch selectIndex {
- case 0:
- let date = NYDate.getLastDate() //昨日
- startdate_button.setTitle(date, for: .normal)
- enddate_button.setTitle(date, for: .normal)
- case 1:
- let date = NYDate.getThisDate() //今日
- startdate_button.setTitle(date, for: .normal)
- enddate_button.setTitle(date, for: .normal)
- case 2:
- let dates = NYDate.getDateMonth()//本月
- startdate_button.setTitle(dates[0], for: .normal)
- enddate_button.setTitle(dates[1], for: .normal)
- case 3:
- let dates = NYDate.getDateMonthLast()//上月
- startdate_button.setTitle(dates[0], for: .normal)
- enddate_button.setTitle(dates[1], for: .normal)
- default:
- let date = NYDate.getLastDate() //昨日
- startdate_button.setTitle(date, for: .normal)
- enddate_button.setTitle(date, for: .normal)
- }
- }
-
- func monthhandledo(){
- var dates = [""]
- switch selectIndex {
- case 0:
- dates = NYDate.getDateMonth()//本月
- case 1:
- dates = NYDate.getDateMonthLast()//上月
- case 2:
- dates = NYDate.getDateMonthSectionNum(num: -2)//近3月
- case 3:
- dates = NYDate.getDateYear() //本年
- default:
- let date = NYDate.getLastDate() //昨日
- startdate_button.setTitle(date, for: .normal)
- enddate_button.setTitle(date, for: .normal)
- }
- startdate_button.setTitle(String(dates[0].prefix(7)), for: .normal)
- enddate_button.setTitle(String(dates[1].prefix(7)), for: .normal)
- }
-
- func yearhandledo(){
- var dates = [""]
- switch selectIndex {
- case 0:
- dates = NYDate.getDateYear() //本年
- case 1:
- dates = NYDate.getDateYearSectionNum(num: 1)//去年
- startdate_button.setTitle(String(dates[0].prefix(4)), for: .normal)
- enddate_button.setTitle(String(dates[0].prefix(4)), for: .normal)
- return
- case 2:
- dates = NYDate.getDateYearSectionNum(num: 2)//近3年
- case 3:
- dates = NYDate.getDateYearSectionNum(num: 4)//近5年
- default:
- let date = NYDate.getLastDate() //昨日
- startdate_button.setTitle(date, for: .normal)
- enddate_button.setTitle(date, for: .normal)
- }
- startdate_button.setTitle(String(dates[0].prefix(4)), for: .normal)
- enddate_button.setTitle(String(dates[1].prefix(4)), for: .normal)
- }
-
- }
|