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