r
2025-09-19 8c309ff419690cc77c9b178096878e18d4849fc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
//  YardBookingTimeView.swift
//  WanPai
//
//  Created by 无故事王国 on 2023/6/19.
//
 
import UIKit
import JQTools
 
class YardBookingTimeView: UIView,JQNibView{
 
    @IBOutlet weak var cons_viewTop: NSLayoutConstraint!
    @IBOutlet weak var tf_startTime: UITextField!
    @IBOutlet weak var tf_endTime: UITextField!
    private var defaultStarTime:String?
    private var defaultEndTime:String?
 
    private var closeClouse:((String,String)->Void)?
 
    override func awakeFromNib() {
        super.awakeFromNib()
        alpha = 0
        cons_viewTop.constant = -133
        layoutIfNeeded()
    }
 
    @discardableResult
    static func show(inView:UIView,afterView:UIView,defaultStarTime:String? = nil,defaultEndTime:String? = nil,closeClouse:@escaping (String,String)->Void)->YardBookingTimeView{
        let yardBookingTimeView = YardBookingTimeView.jq_loadNibView()
        inView.addSubview(yardBookingTimeView)
        yardBookingTimeView.closeClouse = closeClouse
        yardBookingTimeView.defaultStarTime = defaultStarTime
        yardBookingTimeView.defaultEndTime = defaultEndTime
        yardBookingTimeView.tf_startTime.text = defaultStarTime
        yardBookingTimeView.tf_endTime.text = defaultEndTime
        yardBookingTimeView.snp.makeConstraints { make in
            make.top.equalTo(afterView.snp.bottom)
            make.left.right.bottom.equalTo(inView)
        }
 
        yardBookingTimeView.cons_viewTop.constant = 0
        UIView.animate(withDuration: 0.4) {
            yardBookingTimeView.alpha = 1
            yardBookingTimeView.layoutIfNeeded()
        }
        return yardBookingTimeView
    }
 
 
    @IBAction func startTimeAction(_ sender: Any) {
        tf_endTime.text = ""
        CommonDatePickerView.show(type: .HHmm) {[weak self] _, _, _,hour,minute in
            self?.tf_startTime.text = String(format: "%02ld:%02ld", hour!,minute!)
        }
    }
 
    @IBAction func endTimeAction(_ sender: Any) {
        if tf_startTime.text == ""{
            alert(msg: "请先选择开始时间");return
        }
        CommonDatePickerView.show(type: .HHmm) { [weak self] _, _, _,hour,minute in
            if hour ?? 0 < self?.tf_startTime.text!.components(separatedBy: ":").first?.int ?? 0{
                alert(msg: "结束时间不能小于开始时间");return
            }
            self?.tf_endTime.text = String(format: "%02ld:%02ld", hour!,minute!)
 
            self?.cons_viewTop.constant = -133
            UIView.animate(withDuration: 0.4) {
                self!.alpha = 0
                self!.layoutIfNeeded()
            } completion: { _ in
                let startDate = self!.tf_startTime.text!
                let endDate = self!.tf_endTime.text!
                self!.closeClouse?(startDate,endDate)
                self!.removeFromSuperview()
            }
        }
    }
 
 
    @IBAction func closeAction(_ sender: Any) {
        //以下,点击空白收回,可能废弃
        cons_viewTop.constant = -133
        UIView.animate(withDuration: 0.4) {
            self.alpha = 0
            self.layoutIfNeeded()
        } completion: { _ in
            let startDate = self.tf_startTime.text!
            let endDate = self.tf_endTime.text!
            self.closeClouse?(startDate,endDate)
            self.removeFromSuperview()
        }
    }
}