Skip to content

Commit c7a4441

Browse files
committed
增加多日期查询
1 parent ca0655d commit c7a4441

File tree

3 files changed

+105
-84
lines changed

3 files changed

+105
-84
lines changed

12306ForMac/TicketViewControllers/TicketQueryViewController.swift

+95-73
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,10 @@ class TicketQueryViewController: BaseViewController {
2525
self.stackContentView.addView(firstSearchView, in:.top)
2626
self.stackContentView.addView(secondSearchView, in: .top)
2727
self.stackContentView.addView(ticketTableView, in: .top)
28-
2928
self.stackContentView.orientation = .vertical
3029
self.stackContentView.alignment = .centerX
3130
self.stackContentView.spacing = 0
3231

33-
self.fromStationNameTxt.tableViewDelegate = self
34-
self.toStationNameTxt.tableViewDelegate = self
35-
36-
self.fromStationNameTxt.stringValue = QueryDefaultManager.sharedInstance.lastFromStation
37-
self.toStationNameTxt.stringValue = QueryDefaultManager.sharedInstance.lastToStation
38-
39-
passengerViewControllerList = [PassengerViewController]()
40-
4132
filterBtn.isEnabled = false
4233
filterCbx.isEnabled = false
4334
filterBtn.isHidden = true
@@ -46,14 +37,27 @@ class TicketQueryViewController: BaseViewController {
4637
autoQueryNumTxt.isHidden = true
4738

4839
self.registerAllNotification()
40+
self.initQueryParams()
41+
self.initSortParams()
42+
}
43+
44+
private func initQueryParams() {
45+
self.fromStationNameTxt.tableViewDelegate = self
46+
self.toStationNameTxt.tableViewDelegate = self
47+
48+
self.fromStationNameTxt.stringValue = QueryDefaultManager.sharedInstance.lastFromStation
49+
self.toStationNameTxt.stringValue = QueryDefaultManager.sharedInstance.lastToStation
4950

5051
if QueryDefaultManager.sharedInstance.lastQueryDate.compare(Date()) == .orderedAscending {
51-
self.setQueryDateValue(Date())
52+
self.allSelectedDates.append(Date())
5253
}
5354
else {
54-
self.setQueryDateValue(QueryDefaultManager.sharedInstance.lastQueryDate as Date)
55+
self.allSelectedDates.append(QueryDefaultManager.sharedInstance.lastQueryDate as Date)
5556
}
56-
57+
self.setQueryDateValue(allSelectedDates,index:self.queryDateIndex)
58+
}
59+
60+
private func initSortParams(){
5761
let descriptorStartTime = NSSortDescriptor(key: TicketOrder.StartTime.rawValue, ascending: true)
5862
let descriptorArriveTime = NSSortDescriptor(key: TicketOrder.ArriveTime.rawValue, ascending: true)
5963
let descriptorLishi = NSSortDescriptor(key: TicketOrder.Lishi.rawValue, ascending: true)
@@ -69,24 +73,38 @@ class TicketQueryViewController: BaseViewController {
6973
@IBOutlet weak var queryBtn: NSButton!
7074
@IBOutlet weak var converCityBtn: NSButton!
7175
@IBOutlet weak var autoQueryNumTxt: NSTextField!
76+
@IBOutlet weak var queryDataLabel: NSTextField!
7277

7378
var autoQueryNum = 0
7479
var calendarViewController:LunarCalendarView?
7580
var repeatTimer:Timer?
7681
var ticketType:TicketType = .Normal
82+
var allSelectedDates:[Date] = [Date]()
83+
var queryDateIndex = 0
7784

7885
fileprivate func getDateStr(_ date:Date) -> String{
7986
let dateDescription = date.description
8087
let dateRange = dateDescription.range(of: " ")
8188
return dateDescription[dateDescription.startIndex..<dateRange!.lowerBound]
8289
}
8390

84-
fileprivate func setQueryDateValue(_ date:Date) {
91+
fileprivate func setQueryDateValue(_ dates:[Date], index:Int) {
8592
var calender = Calendar.current
8693
calender.timeZone = TimeZone(abbreviation: "UTC")!
87-
let trunkNextDate = calender.startOfDay(for: date)
8894

89-
self.queryDate.dateValue = trunkNextDate
95+
if dates.count > 1 {
96+
self.queryDataLabel.stringValue = "出发日期 \(dates.count)-\(index + 1)"
97+
}
98+
else {
99+
self.queryDataLabel.stringValue = "出发日期"
100+
}
101+
102+
self.queryDate.dateValue = calender.startOfDay(for: dates[index])
103+
self.queryDateIndex = index + 1
104+
if self.queryDateIndex >= self.allSelectedDates.count {
105+
self.queryDateIndex = 0
106+
}
107+
90108
}
91109

92110
fileprivate func stopAutoQuery(){
@@ -214,21 +232,6 @@ class TicketQueryViewController: BaseViewController {
214232
return popover
215233
}()
216234

217-
218-
219-
func openSubmitSheet(isAutoSubmit:Bool,ifShowCode:Bool = true) {
220-
submitWindowController = SubmitWindowController()
221-
submitWindowController.isAutoSubmit = isAutoSubmit
222-
submitWindowController.ifShowCode = ifShowCode
223-
if let window = self.view.window {
224-
window.beginSheet(submitWindowController.window!, completionHandler: {response in
225-
if response == NSModalResponseOK{
226-
///
227-
}
228-
})
229-
}
230-
}
231-
232235
func ticketOrderedBy(_ tickets:[QueryLeftNewDTO], orderedBy:TicketOrder, ascending:Bool) -> [QueryLeftNewDTO] {
233236
let sortedTickets:[QueryLeftNewDTO] = tickets.sorted{
234237
var isOriginAscending = true
@@ -253,42 +256,6 @@ class TicketQueryViewController: BaseViewController {
253256
return sortedTickets
254257
}
255258

256-
func filterTrain(){
257-
trainFilterWindowController.trains = ticketQueryResult.filter({item in
258-
return !item.isTicketInvalid()
259-
})
260-
trainFilterWindowController.fromStationName = self.fromStationNameTxt.stringValue
261-
trainFilterWindowController.toStationName = self.toStationNameTxt.stringValue
262-
trainFilterWindowController.trainDate = self.date!
263-
264-
265-
if let window = self.view.window {
266-
window.beginSheet(trainFilterWindowController.window!, completionHandler: {response in
267-
if response == NSModalResponseOK{
268-
self.trainFilterKey = self.trainFilterWindowController.trainFilterKey
269-
self.seatFilterKey = self.trainFilterWindowController.seatFilterKey
270-
logger.info("trainFilterKey:\(self.trainFilterKey)")
271-
logger.info("seatFilterKey:\(self.seatFilterKey)")
272-
273-
self.filterQueryResult = self.ticketQueryResult.filter({item in return self.trainFilterKey.contains("|" + item.TrainCode! + "|")})
274-
275-
if let ticketOrderX = self.ticketOrder, let ticketAscendingX = self.ticketAscending {
276-
self.filterQueryResult = self.ticketOrderedBy(self.filterQueryResult, orderedBy: ticketOrderX, ascending: ticketAscendingX)
277-
}
278-
279-
self.leftTicketTable.reloadData()
280-
281-
if GeneralPreferenceManager.sharedInstance.isAutoQueryAfterFilter {
282-
self.autoQuery = true
283-
}
284-
}
285-
else {
286-
self.autoQuery = false;
287-
}
288-
})
289-
}
290-
}
291-
292259
func queryTicketAndSubmit() {
293260
let summitHandler = {
294261
self.addAutoQueryNumStatus()
@@ -326,6 +293,10 @@ class TicketQueryViewController: BaseViewController {
326293
func queryTicket(_ summitHandler:@escaping ()->() = {}) {
327294
let fromStation = self.fromStationNameTxt.stringValue
328295
let toStation = self.toStationNameTxt.stringValue
296+
297+
298+
self.setQueryDateValue(allSelectedDates,index:self.queryDateIndex)
299+
329300
let date = getDateStr(queryDate.dateValue)
330301

331302
logger.info("\(fromStation) -> \(toStation) \(date) \(self.autoQueryNum)")
@@ -485,11 +456,60 @@ class TicketQueryViewController: BaseViewController {
485456
}
486457
}
487458

488-
489459
deinit{
490460
let notificationCenter = NotificationCenter.default
491461
notificationCenter.removeObserver(self)
492462
}
463+
464+
// MARK: - open sheet
465+
func openfilterTrainSheet(){
466+
trainFilterWindowController.trains = ticketQueryResult.filter({item in
467+
return !item.isTicketInvalid()
468+
})
469+
trainFilterWindowController.fromStationName = self.fromStationNameTxt.stringValue
470+
trainFilterWindowController.toStationName = self.toStationNameTxt.stringValue
471+
trainFilterWindowController.trainDate = self.date!
472+
473+
474+
if let window = self.view.window {
475+
window.beginSheet(trainFilterWindowController.window!, completionHandler: {response in
476+
if response == NSModalResponseOK{
477+
self.trainFilterKey = self.trainFilterWindowController.trainFilterKey
478+
self.seatFilterKey = self.trainFilterWindowController.seatFilterKey
479+
logger.info("trainFilterKey:\(self.trainFilterKey)")
480+
logger.info("seatFilterKey:\(self.seatFilterKey)")
481+
482+
self.filterQueryResult = self.ticketQueryResult.filter({item in return self.trainFilterKey.contains("|" + item.TrainCode! + "|")})
483+
484+
if let ticketOrderX = self.ticketOrder, let ticketAscendingX = self.ticketAscending {
485+
self.filterQueryResult = self.ticketOrderedBy(self.filterQueryResult, orderedBy: ticketOrderX, ascending: ticketAscendingX)
486+
}
487+
488+
self.leftTicketTable.reloadData()
489+
490+
if GeneralPreferenceManager.sharedInstance.isAutoQueryAfterFilter {
491+
self.autoQuery = true
492+
}
493+
}
494+
else {
495+
self.autoQuery = false;
496+
}
497+
})
498+
}
499+
}
500+
501+
func openSubmitTicketSheet(isAutoSubmit:Bool,ifShowCode:Bool = true) {
502+
submitWindowController = SubmitWindowController()
503+
submitWindowController.isAutoSubmit = isAutoSubmit
504+
submitWindowController.ifShowCode = ifShowCode
505+
if let window = self.view.window {
506+
window.beginSheet(submitWindowController.window!, completionHandler: {response in
507+
if response == NSModalResponseOK{
508+
///
509+
}
510+
})
511+
}
512+
}
493513

494514
// MARK: - notification
495515
func registerAllNotification() {
@@ -563,15 +583,15 @@ class TicketQueryViewController: BaseViewController {
563583
}
564584

565585
func recvDidSubmitNotification(_ note: Notification){
566-
openSubmitSheet(isAutoSubmit: false)
586+
openSubmitTicketSheet(isAutoSubmit: false)
567587
}
568588

569589
func recvAutoSubmitNotification(_ note: Notification){
570-
openSubmitSheet(isAutoSubmit: true)
590+
openSubmitTicketSheet(isAutoSubmit: true)
571591
}
572592

573593
func recvAutoSubmitWithoutRandCodeNotification(_ note: Notification){
574-
openSubmitSheet(isAutoSubmit: true,ifShowCode: false)
594+
openSubmitTicketSheet(isAutoSubmit: true,ifShowCode: false)
575595
}
576596

577597
// MARK: - Click Action
@@ -623,7 +643,7 @@ class TicketQueryViewController: BaseViewController {
623643
@IBAction func clickAutoQueryCbx(_ sender: NSButton) {
624644
if sender.state == NSOnState {
625645
if self.seatFilterKey == "" {
626-
self.filterTrain()
646+
self.openfilterTrainSheet()
627647
}
628648
else {
629649
autoQuery = true
@@ -635,7 +655,7 @@ class TicketQueryViewController: BaseViewController {
635655
}
636656

637657
@IBAction func clickFilterTrain(_ sender: AnyObject) {
638-
self.filterTrain()
658+
self.openfilterTrainSheet()
639659
}
640660

641661
@IBAction func clickAddPassenger(_ sender: NSButton) {
@@ -750,6 +770,7 @@ extension TicketQueryViewController:NSPopoverDelegate {
750770
@IBAction func showCalendar(_ sender: AnyObject){
751771
let calendarPopover = NSPopover()
752772
let cp = LunarCalendarView(with:self.queryDate.dateValue)
773+
cp.allSelectedDates = self.allSelectedDates
753774
calendarPopover.contentViewController = cp
754775
calendarPopover.appearance = NSAppearance(named: "NSAppearanceNameAqua")
755776
calendarPopover.animates = true
@@ -762,7 +783,8 @@ extension TicketQueryViewController:NSPopoverDelegate {
762783
}
763784

764785
func popoverDidClose(_ notification: Notification) {
765-
self.setQueryDateValue(calendarViewController!.allSelectedDates[0])
786+
self.allSelectedDates = calendarViewController!.allSelectedDates
787+
self.queryDateIndex = 0
766788

767789
autoQuery = false
768790
self.clickQueryTicketBtn(nil)

12306ForMac/TicketViewControllers/TicketQueryViewController.xib

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11201" systemVersion="16B2555" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
33
<dependencies>
44
<deployment identifier="macosx"/>
55
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/>
@@ -19,6 +19,7 @@
1919
<outlet property="leftTicketTable" destination="vdR-Hc-SYr" id="JQG-gl-oM1"/>
2020
<outlet property="passengersView" destination="gWk-xJ-t7i" id="pX7-IP-o2z"/>
2121
<outlet property="queryBtn" destination="FSF-1Q-g2J" id="XwL-Q2-kSv"/>
22+
<outlet property="queryDataLabel" destination="9qi-Pb-rDH" id="2EQ-8F-Wok"/>
2223
<outlet property="queryDate" destination="Be8-M1-vtw" id="WeT-Ds-CdC"/>
2324
<outlet property="secondSearchView" destination="Dhy-j5-W4F" id="OyI-vg-5xp"/>
2425
<outlet property="stackContentView" destination="Q3P-1n-q0W" id="6aq-aD-dmW"/>
@@ -489,7 +490,7 @@
489490
<rect key="frame" x="0.0" y="0.0" width="910" height="40"/>
490491
<subviews>
491492
<datePicker verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Be8-M1-vtw" customClass="ClickableDatePicker" customModule="订票助手" customModuleProvider="target">
492-
<rect key="frame" x="566" y="2" width="90" height="23"/>
493+
<rect key="frame" x="593" y="1.5" width="90" height="23"/>
493494
<constraints>
494495
<constraint firstAttribute="height" constant="23" id="8Aa-Zv-hKL"/>
495496
<constraint firstAttribute="width" constant="90" id="Vo0-fD-7UT"/>
@@ -507,7 +508,7 @@
507508
</connections>
508509
</datePicker>
509510
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="4jY-s2-8Ni" customClass="AutoCompleteTextField" customModule="订票助手" customModuleProvider="target">
510-
<rect key="frame" x="80" y="2" width="100" height="23"/>
511+
<rect key="frame" x="80" y="1.5" width="100" height="23"/>
511512
<constraints>
512513
<constraint firstAttribute="height" constant="23" id="5RR-3h-LZM"/>
513514
<constraint firstAttribute="width" constant="100" id="t04-b6-cBp"/>
@@ -527,7 +528,7 @@
527528
</userDefinedRuntimeAttributes>
528529
</textField>
529530
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="l4y-Hd-FVf" customClass="AutoCompleteTextField" customModule="订票助手" customModuleProvider="target">
530-
<rect key="frame" x="323" y="2" width="100" height="23"/>
531+
<rect key="frame" x="323" y="1.5" width="100" height="23"/>
531532
<constraints>
532533
<constraint firstAttribute="height" constant="23" id="C6k-54-5Fp"/>
533534
<constraint firstAttribute="width" constant="100" id="fmb-qp-YPt"/>
@@ -571,10 +572,10 @@
571572
</textFieldCell>
572573
</textField>
573574
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9qi-Pb-rDH">
574-
<rect key="frame" x="496" y="2" width="64" height="20"/>
575+
<rect key="frame" x="506" y="2" width="84" height="20"/>
575576
<constraints>
576577
<constraint firstAttribute="height" constant="20" id="BZV-gj-Tnd"/>
577-
<constraint firstAttribute="width" constant="60" id="ps4-lC-VpX"/>
578+
<constraint firstAttribute="width" constant="80" id="ps4-lC-VpX"/>
578579
</constraints>
579580
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="出发日期" id="yeJ-db-y74">
580581
<font key="font" metaFont="systemThin" size="13"/>
@@ -596,7 +597,7 @@
596597
</connections>
597598
</button>
598599
<button verticalHuggingPriority="750" allowsExpansionToolTips="YES" translatesAutoresizingMaskIntoConstraints="NO" id="aQQ-8z-kIM">
599-
<rect key="frame" x="193" y="6" width="50" height="16"/>
600+
<rect key="frame" x="193" y="5.5" width="50" height="16"/>
600601
<constraints>
601602
<constraint firstAttribute="width" constant="50" id="IuX-gs-s4I"/>
602603
<constraint firstAttribute="height" constant="16" id="z5f-YW-eTw"/>
@@ -627,11 +628,11 @@
627628
<constraint firstItem="amu-Qj-Yha" firstAttribute="leading" secondItem="Pal-9i-ZzT" secondAttribute="leading" constant="12" id="40s-Lm-XYb"/>
628629
<constraint firstItem="9qi-Pb-rDH" firstAttribute="centerY" secondItem="amu-Qj-Yha" secondAttribute="centerY" id="4ba-wR-dfD"/>
629630
<constraint firstItem="4N3-fA-XcK" firstAttribute="leading" secondItem="4jY-s2-8Ni" secondAttribute="trailing" constant="75" id="KY1-vl-Xct"/>
630-
<constraint firstItem="Be8-M1-vtw" firstAttribute="leading" secondItem="9qi-Pb-rDH" secondAttribute="trailing" constant="8" symbolic="YES" id="W29-IO-jZp"/>
631+
<constraint firstItem="Be8-M1-vtw" firstAttribute="leading" secondItem="9qi-Pb-rDH" secondAttribute="trailing" constant="5" id="W29-IO-jZp"/>
631632
<constraint firstItem="aQQ-8z-kIM" firstAttribute="leading" secondItem="4jY-s2-8Ni" secondAttribute="trailing" constant="13" id="YRK-jK-KDy"/>
632633
<constraint firstItem="8dY-Wq-KeS" firstAttribute="centerY" secondItem="FSF-1Q-g2J" secondAttribute="centerY" id="bTI-cs-KDE"/>
633634
<constraint firstItem="l4y-Hd-FVf" firstAttribute="leading" secondItem="4N3-fA-XcK" secondAttribute="trailing" constant="8" symbolic="YES" id="g5Y-dJ-fb2"/>
634-
<constraint firstItem="9qi-Pb-rDH" firstAttribute="leading" secondItem="l4y-Hd-FVf" secondAttribute="trailing" constant="75" id="gn5-kx-tix"/>
635+
<constraint firstItem="9qi-Pb-rDH" firstAttribute="leading" secondItem="l4y-Hd-FVf" secondAttribute="trailing" constant="85" id="gn5-kx-tix"/>
635636
<constraint firstItem="FSF-1Q-g2J" firstAttribute="centerY" secondItem="amu-Qj-Yha" secondAttribute="centerY" constant="-1" id="hna-g5-nGb"/>
636637
<constraint firstItem="aQQ-8z-kIM" firstAttribute="centerY" secondItem="4jY-s2-8Ni" secondAttribute="centerY" id="jsi-Gf-Fmt"/>
637638
<constraint firstItem="4N3-fA-XcK" firstAttribute="centerY" secondItem="amu-Qj-Yha" secondAttribute="centerY" id="nOH-lk-YH1"/>

12306ForMac/UserControls/LunarCalendar/LunarCalendarView.swift

-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ class LunarCalendarView:NSViewController{
113113
self.dayMakerColor = NSColor.darkGray
114114

115115
currentMonth = self.toUTC(date)
116-
117-
allSelectedDates.append(currentMonth)
118116
}
119117

120118
override func viewDidLoad() {

0 commit comments

Comments
 (0)