无故事王国
2023-09-18 b395e5ea758b24803743535f86bf443765237551
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
//  PaymentCourseView.swift
//  WanPai
//
//  Created by 无故事王国 on 2023/9/15.
//
 
import UIKit
import JQTools
import RxDataSources
import RxSwift
class PaymentCourseView: UIView,JQNibView{
    @IBOutlet weak var view_container: UIView!
    @IBOutlet weak var cons_bottom: NSLayoutConstraint!
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var label_num: UILabel!
    private var disposeBag:DisposeBag!
    private var models = [CourseListSubModel]()
    private var selectIndex:Int?
    private var clouse:((Int)->Void)!
 
    private var id:Int!
    override func awakeFromNib() {
        super.awakeFromNib()
        tableView.delegate = self
        tableView.dataSource = self
        tableView.separatorStyle = .none
        tableView.register(UINib(nibName: "PaymentCourseTCell", bundle: nil), forCellReuseIdentifier: "_PaymentCourseTCell")
        cons_bottom.constant =  -(225 + UIDevice.jq_safeEdges.bottom)
        alpha = 0
        disposeBag = DisposeBag()
        layoutIfNeeded()
    }
 
 
    static func show(id:Int,number:Int,clouse:@escaping (Int)->Void){
         let paymentCourseView = PaymentCourseView.jq_loadNibView()
        paymentCourseView.id = id
        paymentCourseView.label_num.text = "所需课时数:\(number)"
        paymentCourseView.clouse = clouse
        paymentCourseView.frame = sceneDelegate?.window?.frame ?? .zero
        sceneDelegate?.window?.addSubview(paymentCourseView)
        paymentCourseView.cons_bottom.constant = 0
        UIView.animate(withDuration: 0.4) {
            paymentCourseView.alpha = 1
            paymentCourseView.layoutIfNeeded()
        }
        paymentCourseView.queryData()
    }
 
 
    private func queryData(){
        Services.querypaymentCompetitionCourseList(id: id).subscribe(onNext: { data in
            if let models = data.data{
                self.models = models
                self.tableView.reloadData()
            }
        }) { error in
 
        }.disposed(by: disposeBag)
    }
 
 
 
    private func hidden(){
        cons_bottom.constant =  -(225 + UIDevice.jq_safeEdges.bottom)
        UIView.animate(withDuration: 0.5) {
            self.alpha = 0
            self.layoutIfNeeded()
        } completion: { _ in
            self.removeFromSuperview()
        }
    }
 
    override func layoutSubviews() {
        super.layoutSubviews()
        view_container.jq_addCorners(corner: [.topLeft,.topRight], radius: 20, width: JQ_ScreenW, height: JQ_ScreenH)
    }
 
 
    @IBAction func paymentAction(_ sender: UIButton) {
        guard selectIndex != nil else {
            alert(msg: "请选择课时");return
        }
        let model = models[selectIndex!]
        clouse(model.id)
        hidden()
    }
 
    @IBAction func hiddenAction(_ sender: UIButton) {
        hidden()
    }
}
 
extension PaymentCourseView:UITableViewDelegate{
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        selectIndex = indexPath.row
        tableView.reloadData()
    }
 
}
 
extension PaymentCourseView:UITableViewDataSource{
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let model = models[indexPath.row]
        let cell = tableView.dequeueReusableCell(withIdentifier: "_PaymentCourseTCell") as! PaymentCourseTCell
        cell.courseListSubModel = model
        cell.isselect(indexPath.row == selectIndex)
        return cell
    }
 
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return models.count
    }
 
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
}