杨锴
2025-05-11 7453d2d0cef415b34323d1b91e6cfa4a6ba31178
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//
//  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!
    private var storeId: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()
    }
 
    static func show(storeId:Int,number:Int,clouse:@escaping (Int)->Void){
        let paymentCourseView = PaymentCourseView.jq_loadNibView()
        paymentCourseView.storeId = storeId
        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.queryStoreData()
    }
 
 
    private func queryData(){
        Services.querypaymentCompetitionCourseList(id: id).subscribe(onNext: { data in
            if let models = data.data{
                self.models = models
                self.tableView.reloadData()
            }
        }) {  error in
            if let er = error as? NetworkRequest.NetRequestError{
                switch er {
                    case .Other(let code,let string):
                        let vc = PaymentResultVC(result: .fail(string,code), objType: .yard,handleVC: nil)
                        JQ_currentViewController().jq_push(vc: vc)
                    default:
                        let vc = PaymentResultVC(result: .fail("支付失败",0), objType: .yard,handleVC: nil)
                        JQ_currentViewController().jq_push(vc: vc)
                }
            }
        }.disposed(by: disposeBag)
    }
 
    private func queryStoreData(){
        Services.getMyCourseList(storeId: storeId).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) {
        let model = models[indexPath.row]
        guard model.courseNum != 0 else {return}
        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)
        if model.courseNum == 0{
            cell.contentView.alpha = 0.3
        }else{
            cell.contentView.alpha = 1.0
        }
        return cell
    }
 
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return models.count
    }
 
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
}