//
|
// 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
|
}
|
}
|