//
|
// PaymentOrderResultVC.swift
|
// XQMuse
|
//
|
// Created by 无故事王国 on 2024/8/15.
|
//
|
|
import UIKit
|
import JQTools
|
class PaymentOrderResultVC: BaseVC {
|
|
var collectionView:UICollectionView!
|
private let topView = PaymentOrderResultTopView.jq_loadNibView()
|
private var id:Int!
|
private var type:PaymentOrderVC.PaymentOrderType!
|
private var price:Double!
|
private var models = [Any]()
|
|
init(type:PaymentOrderVC.PaymentOrderType,id:Int,price:Double) {
|
super.init(nibName: nil, bundle: nil)
|
self.id = id
|
self.type = type
|
self.price = price
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
title = "支付结果"
|
|
// //如果从支付过来的,移除支付
|
// navigationController!.viewControllers.removeAll { vc in
|
// if vc is PaymentOrderResultVC || vc is PaymentOrderVC{
|
// return true
|
// }
|
// return false
|
// }
|
|
NotificationCenter.default.post(name: CourseRefresh_Noti, object: nil)
|
|
yy_popBlock = { [weak self] () in
|
var toVC:UIViewController?
|
for v in self?.navigationController?.viewControllers ?? []{
|
if v is CourseDetialVC{
|
toVC = v;break
|
}
|
}
|
if toVC != nil{
|
self?.navigationController?.popToViewController(toVC!, animated: true)
|
}else{
|
self?.navigationController?.popToRootViewController(animated: true)
|
}
|
}
|
|
topView.setPrice(type: type, id: id, price: price)
|
|
if type == .course{
|
Services.coursePaymentSuccess(courseId: id).subscribe(onNext: {data in
|
self.models = data.data ?? []
|
self.collectionView.reloadData()
|
}).disposed(by: disposeBag)
|
}
|
|
if type == .muse{
|
Services.musePaymentSuccess(meditationId: id).subscribe(onNext: {data in
|
self.models = data.data ?? []
|
self.collectionView.reloadData()
|
}).disposed(by: disposeBag)
|
}
|
}
|
|
override func setUI() {
|
super.setUI()
|
view.backgroundColor = .white
|
|
let layout = HoverHeaderFlowLayout()
|
let w = (JQ_ScreenW - 18 * 3) / 2
|
layout.itemSize = CGSize(width: w, height: w * 1.319)
|
layout.headerReferenceSize = CGSize(width: JQ_ScreenW, height: 59)
|
collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
|
collectionView.backgroundColor = .clear
|
collectionView.delegate = self
|
collectionView.delegate = self
|
collectionView.dataSource = self
|
collectionView.backgroundColor = .white
|
collectionView.contentInset = UIEdgeInsets(top: 298, left: 18, bottom: 0, right: 18)
|
collectionView.register(UINib(nibName: "HomeRelaxBanner_2_1_CCell", bundle: nil), forCellWithReuseIdentifier: "_HomeRelaxBanner_2_1_CCell")
|
collectionView.register(PaymentOrderResultHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header")
|
view.addSubview(collectionView)
|
collectionView.snp.makeConstraints { make in
|
make.edges.equalToSuperview()
|
}
|
|
|
view.addSubview(topView)
|
topView.backgroundColor = .clear
|
topView.snp.makeConstraints {[unowned self] make in
|
make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(0)
|
make.left.right.equalToSuperview()
|
make.height.equalTo(278)
|
}
|
|
// view.addSubview(shadowView)
|
// shadowView.backgroundColor = .white
|
// shadowView.snp.makeConstraints {[unowned self] make in
|
// make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(0)
|
// make.left.right.equalToSuperview()
|
// make.height.equalTo(30)
|
// }
|
|
}
|
|
override func viewDidLayoutSubviews() {
|
super.viewDidLayoutSubviews()
|
// shadowView.jq_gradientColor(colorArr: [UIColor(hexStr: "#F5F5F5").withAlphaComponent(0.15).cgColor,UIColor.clear.cgColor], cornerRadius: 0, startPoint: CGPoint(x: 0, y: 0), endPoint: CGPoint(x: 0, y: 1), bounds: CGRect(x: 0, y: 0, width: JQ_ScreenW, height: 30),locations: [0.1,0.9])
|
}
|
}
|
|
|
extension PaymentOrderResultVC:UIScrollViewDelegate{
|
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
let v = (scrollView.contentOffset.y) + 298
|
topView.y = -v
|
navigationController?.navigationBar.standardAppearance.backgroundColor = .white
|
}
|
}
|
|
extension PaymentOrderResultVC:UICollectionViewDelegate & UICollectionViewDataSource{
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
return models.count
|
}
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
switch type {
|
case .course:
|
let model = models[indexPath.row] as! CourseModel
|
if model.courseType == .online{
|
let vc = CourseDetialVC(courseId: model.id)
|
push(vc: vc)
|
}else{
|
let vc = CourseDetialOfflineVC(courseId: model.id)
|
push(vc: vc)
|
}
|
|
case .muse:
|
let model = models[indexPath.row] as! MeditationModel
|
let vc = HomeItemDetailVC(id: model.id)
|
push(vc: vc)
|
case .none:break
|
}
|
}
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_1_CCell", for: indexPath) as! HomeRelaxBanner_2_1_CCell
|
let model = models[indexPath.row]
|
|
if let m = model as? CourseModel{
|
cell.setCourseModel(m)
|
}
|
|
if let m = model as? MeditationModel{
|
cell.setMeditationModel(m)
|
}
|
return cell
|
}
|
|
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
|
if kind == UICollectionView.elementKindSectionHeader{
|
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "header", for: indexPath) as! PaymentOrderResultHeaderView
|
return headerView
|
}
|
|
return UICollectionReusableView()
|
}
|
}
|
|
class PaymentOrderResultHeaderView:UICollectionReusableView{
|
|
override init(frame: CGRect) {
|
super.init(frame: frame)
|
setUI()
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
private func setUI(){
|
backgroundColor = .white
|
|
let lineView = UIView()
|
lineView.backgroundColor = UIColor(hexString: "#979797")?.withAlphaComponent(0.26)
|
addSubview(lineView)
|
lineView.snp.makeConstraints { make in
|
make.left.equalTo(76)
|
make.right.equalTo(-76)
|
make.height.equalTo(1)
|
make.centerY.equalToSuperview()
|
}
|
|
let lineLabel = UILabel()
|
lineLabel.text = "猜你喜欢"
|
lineLabel.backgroundColor = .white
|
lineLabel.textAlignment = .center
|
lineLabel.font = .systemFont(ofSize: 14, weight: .medium)
|
lineLabel.textColor = UIColor(hexString: "#3F4343")?.withAlphaComponent(0.79)
|
addSubview(lineLabel)
|
lineLabel.snp.makeConstraints { make in
|
make.center.equalToSuperview()
|
make.width.equalTo(71)
|
make.height.equalTo(20)
|
}
|
}
|
}
|