//
|
// Home_Style_4_TCell.swift
|
// XQMuse
|
//
|
// Created by 无故事王国 on 2024/8/13.
|
//
|
|
import UIKit
|
import JQTools
|
|
enum Home_Style_4_Style{
|
case style1
|
case style2
|
}
|
|
class Home_Style_4_TCell: UITableViewCell {
|
|
var style:Home_Style_4_Style!
|
private var showType: DisplayType!
|
var meditationModels = [MeditationModel]()
|
|
@IBOutlet weak var collectionView: UICollectionView!
|
|
override func awakeFromNib() {
|
super.awakeFromNib()
|
collectionView.delegate = self
|
collectionView.dataSource = self
|
collectionView.isPagingEnabled = true
|
collectionView.register(UINib(nibName: "Home_Style_4_Inner_1_CCell", bundle: nil), forCellWithReuseIdentifier: "_Home_Style_4_Inner_1_CCell")
|
collectionView.register(UINib(nibName: "Home_Style_4_Inner_CCell", bundle: nil), forCellWithReuseIdentifier: "_Home_Style_4_Inner_CCell")
|
collectionView.showsHorizontalScrollIndicator = false
|
}
|
|
func setModels(_ items:[MeditationModel],showType: DisplayType){
|
self.showType = showType
|
self.meditationModels = items
|
collectionView.reloadData()
|
}
|
}
|
|
extension Home_Style_4_TCell:UICollectionViewDelegate & UICollectionViewDataSource{
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
let m = meditationModels[indexPath.row]
|
guard m.id != 0 else{
|
alert(msg: "平台暂未设置私人定制");return
|
}
|
|
let isVip = UserViewModel.getAvatarInfo().isVip
|
|
if m.chargeType == .free || (m.chargeType == .vipFree && isVip == .yes) || (m.chargeType == .payment && m.isBuy == .yes){
|
let detailVC = HomeItemDetailVC(id: meditationModels[indexPath.row].id)
|
JQ_currentViewController().jq_push(vc: detailVC)
|
}else{
|
if m.chargeType == .vipFree{
|
let vc = VIPCenterVC()
|
JQ_currentViewController().jq_push(vc: vc)
|
}else{
|
let vc = PaymentOrderVC(museItemModel: m,type: .muse)
|
JQ_currentViewController().jq_push(vc:vc)
|
}
|
}
|
}
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
return meditationModels.count
|
}
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
if style == .style1{
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_Home_Style_4_Inner_1_CCell", for: indexPath) as! Home_Style_4_Inner_1_CCell
|
cell.setMeditationModel(meditationModels[indexPath.row],showType: showType)
|
return cell
|
}
|
|
if style == .style2{
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_Home_Style_4_Inner_CCell", for: indexPath) as! Home_Style_4_Inner_CCell
|
cell.setMeditationModel(meditationModels[indexPath.row],showType: showType)
|
return cell
|
}
|
|
return UICollectionViewCell()
|
}
|
}
|
|
extension Home_Style_4_TCell: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 {
|
if style == .style2{
|
return CGSize(width: JQ_ScreenW, height: JQ_ScreenW * 0.734)
|
}
|
|
if style == .style1{
|
return CGSize(width: JQ_ScreenW, height: JQ_ScreenW * 0.551)
|
}
|
|
return .zero
|
}
|
}
|