//
|
// PaymentResultVC.swift
|
// WanPai
|
//
|
// Created by 杨锴 on 2023/6/8.
|
//
|
|
import UIKit
|
import JQTools
|
|
class PaymentResultVC: BaseVC {
|
|
enum PaymentResult:Equatable{
|
case success
|
case fail(String)
|
}
|
enum PaymentObjType{
|
case member //会员
|
case courseApply //课程报名
|
case activityApply //活动报名
|
case yard //场地预约
|
case games //邮箱
|
}
|
|
|
@IBOutlet weak var label_title: UILabel!
|
@IBOutlet weak var img_paymentState: UIImageView!
|
@IBOutlet weak var label_content: UILabel!
|
@IBOutlet weak var collectionView: UICollectionView!
|
@IBOutlet weak var btn_backHome: UIButton!
|
@IBOutlet weak var btn_again: UIButton!
|
@IBOutlet weak var btn_back: UIButton!
|
|
private var result:PaymentResult!
|
private var objType:PaymentObjType!
|
private var courseConfigId:Int?
|
private var handleVC:UIViewController?
|
private var models = [CourseCouponModel]()
|
|
required init(result:PaymentResult,objType:PaymentObjType,handleVC:UIViewController? = nil,courseConfigId:Int? = nil) {
|
super.init(nibName: nil, bundle: nil)
|
self.result = result
|
self.objType = objType
|
self.handleVC = handleVC
|
self.courseConfigId = courseConfigId
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
title = "成为会员"
|
|
|
switch objType{
|
case .member:
|
btn_again.isHidden = result == .success
|
btn_back.isHidden = result == .success
|
btn_backHome.isHidden = result != .success
|
collectionView.isHidden = result != .success
|
switch result {
|
case .fail:
|
img_paymentState.image = UIImage(named: "icon_fail")
|
label_content.text = "支付失败,这是失败原因!"
|
case .success:
|
img_paymentState.image = UIImage(named: "icon_success")
|
label_content.text = "支付成功,恭喜您成为玩湃会员!并获得优惠券!"
|
case .none:break
|
}
|
case .courseApply:
|
//课时购买
|
btn_backHome.isHidden = true
|
if let id = courseConfigId{
|
Services.paymentCourseCouponList(id: id).subscribe(onNext: { data in
|
if let models = data.data{
|
self.models = models
|
self.collectionView.reloadData()
|
}
|
}) { error in
|
|
}.disposed(by: disposeBag)
|
}
|
switch result {
|
case .fail(let str):
|
label_title.text = "支付失败"
|
btn_again.setTitle("再次支付", for: .normal)
|
btn_back.setTitle("返回", for: .normal)
|
img_paymentState.image = UIImage(named: "icon_fail")
|
label_content.text = str
|
case .success:
|
label_title.text = "支付成功"
|
btn_again.setTitle("立即预约", for: .normal)
|
btn_back.setTitle("返回首页", for: .normal)
|
img_paymentState.image = UIImage(named: "icon_success")
|
label_content.text = "报名成功,请及时预约课程上课!"
|
case .none:break
|
}
|
|
case .activityApply:
|
btn_backHome.isHidden = true
|
collectionView.isHidden = true
|
switch result {
|
case .fail:
|
btn_again.setTitle("再次支付", for: .normal)
|
btn_back.setTitle("返回", for: .normal)
|
img_paymentState.image = UIImage(named: "icon_fail")
|
label_content.text = "报名失败,这是失败原因!"
|
case .success:
|
btn_again.setTitle("查看报名", for: .normal)
|
btn_back.setTitle("返回首页", for: .normal)
|
img_paymentState.image = UIImage(named: "icon_success")
|
label_content.text = "报名成功,请注意赛事开始时间!"
|
case .none:break
|
}
|
|
case .yard:
|
btn_backHome.isHidden = true
|
collectionView.isHidden = true
|
switch result {
|
case .fail(let str):
|
btn_again.setTitle("再次支付", for: .normal)
|
btn_back.setTitle("返回", for: .normal)
|
img_paymentState.image = UIImage(named: "icon_fail")
|
label_content.text = str
|
case .success:
|
btn_again.setTitle("查看预约", for: .normal)
|
btn_back.setTitle("返回首页", for: .normal)
|
img_paymentState.image = UIImage(named: "icon_success")
|
label_content.text = "报名成功,请注意预约开始时间!"
|
case .none:break
|
}
|
|
case .games:
|
btn_backHome.isHidden = true
|
collectionView.isHidden = true
|
switch result {
|
case .fail(let str):
|
label_title.text = "支付失败"
|
btn_again.setTitle("再次支付", for: .normal)
|
btn_back.setTitle("返回", for: .normal)
|
img_paymentState.image = UIImage(named: "icon_fail")
|
label_content.text = str
|
case .success:
|
label_title.text = "支付成功"
|
btn_again.isHidden = true
|
btn_back.setTitleColor(.white, for: .normal)
|
btn_back.backgroundColor = Def_ThemeColor
|
btn_back.setTitle("我的数据", for: .normal)
|
img_paymentState.image = UIImage(named: "icon_success")
|
label_content.text = "支付成功"
|
case .none:break
|
}
|
|
case .none:break
|
}
|
|
|
collectionView.delegate = self
|
collectionView.dataSource = self
|
collectionView.contentInset = UIEdgeInsets(top: 0, left: 14, bottom: 0, right: 14)
|
collectionView.register(UINib(nibName: "CouponCCell", bundle: nil), forCellWithReuseIdentifier: "_CouponCCell")
|
}
|
|
@IBAction func paymentAgainAction(_ sender: UIButton) {
|
let str = sender.titleLabel?.text ?? ""
|
|
switch str{
|
case "查看预约":
|
dismiss(animated:true){ [weak self] in
|
let vc = YardBookingListVC()
|
self?.handleVC?.navigationController?.pushViewController(vc)
|
}
|
case "立即预约":
|
handleVC?.navigationController?.tabBarController?.selectedIndex = 1
|
handleVC?.navigationController?.popToRootViewController(animated: true)
|
dismiss(animated:true)
|
|
case "查看报名":
|
dismiss(animated:true){ [weak self] in
|
let vc = ActivitySignupListVC()
|
self?.handleVC?.navigationController?.pushViewController(vc)
|
}
|
default:break
|
}
|
}
|
|
|
@IBAction func backAction(_ sender: UIButton) {
|
if let handleVC{
|
handleVC.navigationController?.popToRootViewController(animated: true)
|
}
|
dismiss(animated: true) {
|
JQ_currentViewController().jq_push(vc: GamesDataSourceVC())
|
}
|
}
|
}
|
|
extension PaymentResultVC:UICollectionViewDelegate{
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
dismiss(animated: true)
|
handleVC?.navigationController?.popToRootViewController(animated: false)
|
let vc = WelfareCouponsListVC()
|
vc.hidesBottomBarWhenPushed = true
|
JQ_currentViewController().jq_push(vc: vc)
|
}
|
}
|
|
extension PaymentResultVC:UICollectionViewDataSource{
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
return models.count
|
}
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_CouponCCell", for: indexPath) as! CouponCCell
|
let model = models[indexPath.row]
|
cell.courseCouponModel = model
|
cell.showDetailClouse = {[weak self] () in
|
self?.dismiss(animated:true){ [weak self] in
|
let vc = WelfareCouponsListVC()
|
self?.handleVC?.navigationController?.pushViewController(vc)
|
}
|
}
|
return cell
|
}
|
|
}
|
|
extension PaymentResultVC:UICollectionViewDelegateFlowLayout{
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
return 0
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
|
return 0
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
return CGSize(width: JQ_ScreenW, height: 120)
|
}
|
}
|