Commit 16a50699 authored by 刘俊宏's avatar 刘俊宏

完善时间选择器

parent 2e7f7c5b
...@@ -241,7 +241,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate,loginDelegate, UITabBarCon ...@@ -241,7 +241,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate,loginDelegate, UITabBarCon
tabBarC = tabBarController tabBarC = tabBarController
let v1 = OrderListViewController() let v1 = OrderListViewController()
let v2 = CRKListVC() let v2 = GoodsManageListVC()
let v3 = WorkCViewController() let v3 = WorkCViewController()
let v4 = WarehoseMangementListVC() let v4 = WarehoseMangementListVC()
let v5 = PersonCenterViewController() let v5 = PersonCenterViewController()
......
...@@ -109,11 +109,18 @@ class ShowTimeSelectView: UIView ,TimeSelectViewDelgate{ ...@@ -109,11 +109,18 @@ class ShowTimeSelectView: UIView ,TimeSelectViewDelgate{
var beginDateByWork: Date? = nil { var beginDateByWork: Date? = nil {
didSet { didSet {
calendarV.beginDateByWork = beginDateByWork calendarV.beginDateByWork = beginDateByWork
if BeginDate != nil && EndDate != nil {
calendarV.setOldDate(beginD: BeginDate, endD: EndDate)
let timeInterval:TimeInterval = BeginDate.timeIntervalSince1970
let timeIntervalEnd:TimeInterval = EndDate.timeIntervalSince1970
timeLbl.text = dayByDouble(sender: timeInterval) + "-" + dayByDouble(sender: timeIntervalEnd)
}
} }
} }
var BeginDate: Date! = nil var BeginDate: Date! = nil
var EndDate: Date! = nil var EndDate: Date! = nil
func selectMoreDate(beginDate: Date, endginDate: Date) { func selectMoreDate(beginDate: Date, endginDate: Date) {
print("选择日期·····") print("选择日期·····")
let timeInterval:TimeInterval = beginDate.timeIntervalSince1970 let timeInterval:TimeInterval = beginDate.timeIntervalSince1970
......
...@@ -21,7 +21,7 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate { ...@@ -21,7 +21,7 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate {
var moreSelection:Bool = false { var moreSelection:Bool = false {
didSet{ didSet{
calendarC.allowsMultipleSelection = moreSelection; calendarC.allowsMultipleSelection = moreSelection;
} }
} }
...@@ -51,11 +51,11 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate { ...@@ -51,11 +51,11 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate {
//切换年 //切换年
@objc func changeYear(sender:UIButton) { @objc func changeYear(sender:UIButton) {
print("切换年\(calendarC.currentPage)") print("切换年\(calendarC.currentPage)")
if sender.tag == 1 { if sender.tag == 1 {
let dateA = calendarC.currentPage.addingTimeInterval(TimeInterval(365*60*60*24)) let dateA = calendarC.currentPage.addingTimeInterval(TimeInterval(365*60*60*24))
let nextDate = self.gregorian.date(byAdding: .day, value: 1, to: dateA)! let nextDate = self.gregorian.date(byAdding: .day, value: 1, to: dateA)!
calendarC.setCurrentPage(nextDate, animated: false) calendarC.setCurrentPage(nextDate, animated: false)
}else if sender.tag == 0{ }else if sender.tag == 0{
let dateA = calendarC.currentPage.addingTimeInterval(TimeInterval(-365*60*60*24)) let dateA = calendarC.currentPage.addingTimeInterval(TimeInterval(-365*60*60*24))
...@@ -63,14 +63,14 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate { ...@@ -63,14 +63,14 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate {
calendarC.setCurrentPage(nextDate, animated: false) calendarC.setCurrentPage(nextDate, animated: false)
} }
} }
@objc func changeMoth(sender:UIButton) { @objc func changeMoth(sender:UIButton) {
print("切换月\(calendarC.currentPage)") print("切换月\(calendarC.currentPage)")
if sender.tag == 1 { if sender.tag == 1 {
let dateA = calendarC.currentPage.addingTimeInterval(TimeInterval(30*60*60*24)) let dateA = calendarC.currentPage.addingTimeInterval(TimeInterval(30*60*60*24))
let nextDate = self.gregorian.date(byAdding: .day, value: 1, to: dateA)! let nextDate = self.gregorian.date(byAdding: .day, value: 1, to: dateA)!
calendarC.setCurrentPage(nextDate, animated: true) calendarC.setCurrentPage(nextDate, animated: true)
}else if sender.tag == 0{ }else if sender.tag == 0{
let dateA = calendarC.currentPage.addingTimeInterval(TimeInterval(-30*60*60*24)) let dateA = calendarC.currentPage.addingTimeInterval(TimeInterval(-30*60*60*24))
...@@ -91,30 +91,30 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate { ...@@ -91,30 +91,30 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate {
//MARKl:--新增限定时间 ,如果不为nil就是有限定的时间 //MARKl:--新增限定时间 ,如果不为nil就是有限定的时间
var beginDateByWork: Date? = nil var beginDateByWork: Date? = nil
func setOldDate (beginD: Date , endD:Date) { func setOldDate (beginD: Date , endD:Date) {
let selectArr = calendarC.selectedDates let selectArr = calendarC.selectedDates
for select in selectArr{ for select in selectArr{
calendarC.deselect(select) calendarC.deselect(select)
} }
calendarC.select(beginD) calendarC.select(beginD)
BeginDate = beginD BeginDate = beginD
let number = numberOfDaysWithFromDate(fromDate: BeginDate, toDate: endD)! let number = numberOfDaysWithFromDate(fromDate: BeginDate, toDate: endD)!
EndDate = endD EndDate = endD
for i in 0 ..< number { for i in 0 ..< number {
let dateA = endD.addingTimeInterval(TimeInterval(-i*60*60*24)) let dateA = endD.addingTimeInterval(TimeInterval(-i*60*60*24))
calendarC.select(dateA) calendarC.select(dateA)
} }
self.configureVisibleCells() self.configureVisibleCells()
} }
// let date1 = "2018-12-14 08:30:00".toDate()! // let date1 = "2018-12-14 08:30:00".toDate()!
// print("指定日期当天的开始时间:", date1.dateAtStartOf(.day).date) // print("指定日期当天的开始时间:", date1.dateAtStartOf(.day).date)
// print("指定日期当天的结束时间:", date1.dateAtEndOf(.day).date) // print("指定日期当天的结束时间:", date1.dateAtEndOf(.day).date)
func clearTheSelect(){ func clearTheSelect(){
let selectArr = calendarC.selectedDates let selectArr = calendarC.selectedDates
for select in selectArr { for select in selectArr {
...@@ -141,12 +141,15 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate { ...@@ -141,12 +141,15 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate {
let beginDateByWorkT:TimeInterval = beginDateByWork!.timeIntervalSince1970 let beginDateByWorkT:TimeInterval = beginDateByWork!.timeIntervalSince1970
HUD.flash(.label("所选日期不得小于" + dayByDouble(sender: beginDateByWorkT)), delay: 1.2) HUD.flash(.label("所选日期不得小于" + dayByDouble(sender: beginDateByWorkT)), delay: 1.2)
SelectAction = false SelectAction = false
}else{ }else{
calendarC.select(date) calendarC.select(date)
BeginDate = date BeginDate = date
SelectAction = true SelectAction = true
EndDate = nil EndDate = nil
let dateEnd = BeginDate.addingTimeInterval(TimeInterval(60*60*24 - 1))
self.delegate?.selectMoreDate(beginDate: BeginDate, endginDate: dateEnd)
} }
}else{ }else{
...@@ -154,10 +157,12 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate { ...@@ -154,10 +157,12 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate {
BeginDate = date BeginDate = date
SelectAction = true SelectAction = true
EndDate = nil EndDate = nil
let dateEnd = BeginDate.addingTimeInterval(TimeInterval(60*60*24 - 1))
self.delegate?.selectMoreDate(beginDate: BeginDate, endginDate: dateEnd)
} }
}else{ }else{
//MARK:--日期小于方法 //MARK:--日期小于方法
let number = numberOfDaysWithFromDate(fromDate: BeginDate, toDate: date)! let number = numberOfDaysWithFromDate(fromDate: BeginDate, toDate: date)!
...@@ -168,25 +173,29 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate { ...@@ -168,25 +173,29 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate {
calendar.deselect(select) calendar.deselect(select)
} }
if beginDateByWork != nil { if beginDateByWork != nil {
let number = numberOfDaysWithFromDate(fromDate: beginDateByWork!, toDate: date)! let number = numberOfDaysWithFromDate(fromDate: beginDateByWork!, toDate: date)!
if number < 0 { if number < 0 {
let beginDateByWorkT:TimeInterval = beginDateByWork!.timeIntervalSince1970 let beginDateByWorkT:TimeInterval = beginDateByWork!.timeIntervalSince1970
HUD.flash(.label("所选日期不得小于" + dayByDouble(sender: beginDateByWorkT)), delay: 1.2) HUD.flash(.label("所选日期不得小于" + dayByDouble(sender: beginDateByWorkT)), delay: 1.2)
SelectAction = false SelectAction = false
}else{ }else{
calendarC.select(date) calendarC.select(date)
BeginDate = date BeginDate = date
SelectAction = true SelectAction = true
EndDate = nil EndDate = nil
} let dateEnd = BeginDate.addingTimeInterval(TimeInterval(60*60*24 - 1))
self.delegate?.selectMoreDate(beginDate: BeginDate, endginDate: dateEnd)
}else{ }
calendarC.select(date)
BeginDate = date }else{
SelectAction = true calendarC.select(date)
EndDate = nil BeginDate = date
} SelectAction = true
EndDate = nil
let dateEnd = BeginDate.addingTimeInterval(TimeInterval(60*60*24 - 1))
self.delegate?.selectMoreDate(beginDate: BeginDate, endginDate: dateEnd)
}
}else{ }else{
SelectAction = false SelectAction = false
...@@ -196,13 +205,14 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate { ...@@ -196,13 +205,14 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate {
calendarC.select(dateA) calendarC.select(dateA)
} }
self.delegate?.selectMoreDate(beginDate: BeginDate, endginDate: EndDate) let dateEnd = EndDate.addingTimeInterval(TimeInterval(60*60*24 - 1))
self.delegate?.selectMoreDate(beginDate: BeginDate, endginDate: dateEnd)
} }
} }
} }
self.configureVisibleCells() self.configureVisibleCells()
} }
func calendar(_ calendar: FSCalendar, didDeselect date: Date, at monthPosition: FSCalendarMonthPosition) { func calendar(_ calendar: FSCalendar, didDeselect date: Date, at monthPosition: FSCalendarMonthPosition) {
...@@ -217,20 +227,22 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate { ...@@ -217,20 +227,22 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate {
SelectAction = true SelectAction = true
BeginDate = date BeginDate = date
EndDate = nil EndDate = nil
let dateEnd = BeginDate.addingTimeInterval(TimeInterval(60*60*24 - 1))
self.delegate?.selectMoreDate(beginDate: BeginDate, endginDate: dateEnd)
} }
self.configureVisibleCells() self.configureVisibleCells()
} }
//MARK:--最大天数为今日 //MARK:--最大天数为今日
// func maximumDate(for calendar: FSCalendar) -> Date { // func maximumDate(for calendar: FSCalendar) -> Date {
// return Date() // return Date()
// } // }
// func calendar(_ calendar: FSCalendar, shouldSelect date: Date, at monthPosition: FSCalendarMonthPosition) -> Bool { // func calendar(_ calendar: FSCalendar, shouldSelect date: Date, at monthPosition: FSCalendarMonthPosition) -> Bool {
// return monthPosition == .current // return monthPosition == .current
// } // }
// //
// func calendar(_ calendar: FSCalendar, shouldDeselect date: Date, at monthPosition: FSCalendarMonthPosition) -> Bool { // func calendar(_ calendar: FSCalendar, shouldDeselect date: Date, at monthPosition: FSCalendarMonthPosition) -> Bool {
// return monthPosition == .current // return monthPosition == .current
// } // }
//MARK:--计算日期差 //MARK:--计算日期差
...@@ -260,52 +272,52 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate { ...@@ -260,52 +272,52 @@ class TimeSelectView: UIView, FSCalendarDataSource, FSCalendarDelegate {
} }
private func configure(cell: FSCalendarCell, for date: Date, at position: FSCalendarMonthPosition) { private func configure(cell: FSCalendarCell, for date: Date, at position: FSCalendarMonthPosition) {
let diyCell = (cell as! DIYCalendarCell) let diyCell = (cell as! DIYCalendarCell)
// if position == .current { // if position == .current {
var selectionType = SelectionType.none var selectionType = SelectionType.none
if calendarC.selectedDates.contains(date) {
let previousDate = self.gregorian.date(byAdding: .day, value: -1, to: date)!
let nextDate = self.gregorian.date(byAdding: .day, value: 1, to: date)!
if calendarC.selectedDates.contains(date) { if calendarC.selectedDates.contains(date) {
let previousDate = self.gregorian.date(byAdding: .day, value: -1, to: date)! if calendarC.selectedDates.contains(previousDate) && calendarC.selectedDates.contains(nextDate) {
let nextDate = self.gregorian.date(byAdding: .day, value: 1, to: date)! selectionType = .middle
if calendarC.selectedDates.contains(date) {
if calendarC.selectedDates.contains(previousDate) && calendarC.selectedDates.contains(nextDate) {
selectionType = .middle
}
else if calendarC.selectedDates.contains(previousDate) && calendarC.selectedDates.contains(date) {
selectionType = .rightBorder
}
else if calendarC.selectedDates.contains(nextDate) {
selectionType = .leftBorder
}
else {
selectionType = .single
}
diyCell.selectionLayer.isHidden = false
} }
} else if calendarC.selectedDates.contains(previousDate) && calendarC.selectedDates.contains(date) {
else { selectionType = .rightBorder
selectionType = .none }
diyCell.selectionType = selectionType else if calendarC.selectedDates.contains(nextDate) {
diyCell.selectionLayer.isHidden = true selectionType = .leftBorder
}
else {
selectionType = .single
}
diyCell.selectionLayer.isHidden = false
} }
}
else {
selectionType = .none
diyCell.selectionType = selectionType
diyCell.selectionLayer.isHidden = true
if selectionType == .none { }
diyCell.selectionLayer.isHidden = true
diyCell.selectionType = selectionType if selectionType == .none {
diyCell.selectionLayer.isHidden = true
return
}
diyCell.selectionLayer.isHidden = false
diyCell.selectionType = selectionType diyCell.selectionType = selectionType
// } return
// else { }
// diyCell.selectionType = .none diyCell.selectionLayer.isHidden = false
// diyCell.selectionLayer.isHidden = true diyCell.selectionType = selectionType
// }
// }
// else {
// diyCell.selectionType = .none
// diyCell.selectionLayer.isHidden = true
// }
} }
......
...@@ -1054,6 +1054,12 @@ class EPViewController: BaseViewController,UITableViewDelegate,UITableViewDataSo ...@@ -1054,6 +1054,12 @@ class EPViewController: BaseViewController,UITableViewDelegate,UITableViewDataSo
if cell.nameLbl.text == "预设预付定金时间段" { if cell.nameLbl.text == "预设预付定金时间段" {
print("定金时间段") print("定金时间段")
let timeSelectV = ShowTimeSelectView(frame: self.view.window!.bounds) let timeSelectV = ShowTimeSelectView(frame: self.view.window!.bounds)
if dj_time_start != 0 && dj_time_end != 0{
var time = TimeInterval(exactly: dj_time_start!)
timeSelectV.BeginDate = Date(timeIntervalSince1970: time!)
time = TimeInterval(exactly: dj_time_end!)
timeSelectV.EndDate = Date(timeIntervalSince1970: time!)
}
timeSelectV.beginDateByWork = Date() timeSelectV.beginDateByWork = Date()
timeSelectV.titleLbl.text = "预设预付定金时间段" timeSelectV.titleLbl.text = "预设预付定金时间段"
timeSelectV.delegate = self timeSelectV.delegate = self
...@@ -1070,6 +1076,12 @@ class EPViewController: BaseViewController,UITableViewDelegate,UITableViewDataSo ...@@ -1070,6 +1076,12 @@ class EPViewController: BaseViewController,UITableViewDelegate,UITableViewDataSo
let timeSelectV = ShowTimeSelectView(frame: self.view.window!.bounds) let timeSelectV = ShowTimeSelectView(frame: self.view.window!.bounds)
timeSelectV.titleLbl.text = "预设预付尾款时间段" timeSelectV.titleLbl.text = "预设预付尾款时间段"
timeSelectV.delegate = self timeSelectV.delegate = self
if wk_time_start != 0 && wk_time_end != 0{
var time = TimeInterval(exactly: wk_time_start!)
timeSelectV.BeginDate = Date(timeIntervalSince1970: time!)
time = TimeInterval(exactly: wk_time_end!)
timeSelectV.EndDate = Date(timeIntervalSince1970: time!)
}
let dijitime:TimeInterval = TimeInterval(exactly: (dj_time_start! + (24 * 60 * 60)))! let dijitime:TimeInterval = TimeInterval(exactly: (dj_time_start! + (24 * 60 * 60)))!
let beginDate = Date(timeIntervalSince1970: dijitime) let beginDate = Date(timeIntervalSince1970: dijitime)
timeSelectV.beginDateByWork = beginDate timeSelectV.beginDateByWork = beginDate
......
...@@ -632,6 +632,12 @@ class ProductDetailViewController: BaseViewController,UITableViewDelegate,UITabl ...@@ -632,6 +632,12 @@ class ProductDetailViewController: BaseViewController,UITableViewDelegate,UITabl
if cell.nameLbl.text == "预设预付定金时间段" { if cell.nameLbl.text == "预设预付定金时间段" {
print("定金时间段") print("定金时间段")
let timeSelectV = ShowTimeSelectView(frame: self.view.window!.bounds) let timeSelectV = ShowTimeSelectView(frame: self.view.window!.bounds)
if dj_time_start != 0 && dj_time_end != 0{
var time = TimeInterval(exactly: dj_time_start!)
timeSelectV.BeginDate = Date(timeIntervalSince1970: time!)
time = TimeInterval(exactly: dj_time_end!)
timeSelectV.EndDate = Date(timeIntervalSince1970: time!)
}
timeSelectV.beginDateByWork = Date() timeSelectV.beginDateByWork = Date()
timeSelectV.titleLbl.text = "预设预付定金时间段" timeSelectV.titleLbl.text = "预设预付定金时间段"
timeSelectV.delegate = self timeSelectV.delegate = self
...@@ -648,6 +654,12 @@ class ProductDetailViewController: BaseViewController,UITableViewDelegate,UITabl ...@@ -648,6 +654,12 @@ class ProductDetailViewController: BaseViewController,UITableViewDelegate,UITabl
let timeSelectV = ShowTimeSelectView(frame: self.view.window!.bounds) let timeSelectV = ShowTimeSelectView(frame: self.view.window!.bounds)
timeSelectV.titleLbl.text = "预设预付尾款时间段" timeSelectV.titleLbl.text = "预设预付尾款时间段"
timeSelectV.delegate = self timeSelectV.delegate = self
if wk_time_start != 0 && wk_time_end != 0{
var time = TimeInterval(exactly: wk_time_start!)
timeSelectV.BeginDate = Date(timeIntervalSince1970: time!)
time = TimeInterval(exactly: wk_time_end!)
timeSelectV.EndDate = Date(timeIntervalSince1970: time!)
}
let dijitime:TimeInterval = TimeInterval(exactly: (dj_time_start! + (24 * 60 * 60)))! let dijitime:TimeInterval = TimeInterval(exactly: (dj_time_start! + (24 * 60 * 60)))!
let beginDate = Date(timeIntervalSince1970: dijitime) let beginDate = Date(timeIntervalSince1970: dijitime)
timeSelectV.beginDateByWork = beginDate timeSelectV.beginDateByWork = beginDate
......
...@@ -46,7 +46,8 @@ class WorkCViewController: BaseViewController, UITableViewDelegate, UITableViewD ...@@ -46,7 +46,8 @@ class WorkCViewController: BaseViewController, UITableViewDelegate, UITableViewD
//MARK:--二维码方法 //MARK:--二维码方法
@IBAction func codeAction(_ sender: UIButton) { @IBAction func codeAction(_ sender: UIButton) {
print("二维码方法")//加一个透明的显示弹窗 print("二维码方法")//加一个透明的显示弹窗
print("指定日期当天的开始时间:", Date().dateAtStartOf(.day).date)
print("指定日期当天的结束时间:", Date().dateAtEndOf(.day).date)
} }
//MARK:--头部按钮方法 //MARK:--头部按钮方法
let selectV = WorkSelectTimeView() let selectV = WorkSelectTimeView()
......
...@@ -160,8 +160,8 @@ class OrderListViewController: BaseViewController ,UISearchBarDelegate, SearchBa ...@@ -160,8 +160,8 @@ class OrderListViewController: BaseViewController ,UISearchBarDelegate, SearchBa
vc.endTime = 0 vc.endTime = 0
}else{ }else{
let timeInterval:TimeInterval = BeginDate!.timeIntervalSince1970 let timeInterval:TimeInterval = BeginDate!.timeIntervalSince1970
let timeIntervalEnd:TimeInterval = EndDate!.timeIntervalSince1970 let timeIntervalEnd:TimeInterval = EndDate!.timeIntervalSince1970
vc.startTime = Int(timeInterval) vc.startTime = Int(timeInterval)
vc.endTime = Int(timeIntervalEnd) vc.endTime = Int(timeIntervalEnd)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment