//
|
// CoinStoreCenterVC.swift
|
// WanPai
|
//
|
// Created by 无故事王国 on 2023/6/29.
|
//
|
|
import UIKit
|
import JQTools
|
import RxSwift
|
import RxRelay
|
|
class CoinStoreViewModel:RefreshModel<MarketMdoel>{
|
var goodsType = BehaviorRelay<ExchangeType?>(value: nil)
|
var rank = BehaviorRelay<Sort2Type?>(value: nil)
|
let search = BehaviorRelay<String?>(value: nil)
|
|
override func api() -> (Observable<BaseResponse<[MarketMdoel]>>)? {
|
Services.mallList(goodsType: goodsType.value, rank: rank.value, search: search.value)
|
}
|
}
|
|
class CoinStoreCenterVC: BaseVC {
|
|
private let viewModel = CoinStoreViewModel()
|
|
private lazy var collectionView:BaseCollectionView = {
|
|
let CellW:Double = (JQ_ScreenW) / 2.0
|
let CellH:Double = CellW * 1.3428
|
|
let flowLayout = UICollectionViewFlowLayout()
|
flowLayout.minimumLineSpacing = 0
|
flowLayout.minimumInteritemSpacing = 0
|
flowLayout.itemSize = CGSize(width: CellW, height: CellH)
|
flowLayout.headerReferenceSize = CGSize(width: JQ_ScreenW, height: JQ_ScreenW * 0.5564)
|
flowLayout.sectionHeadersPinToVisibleBounds = true
|
|
let collect = BaseCollectionView(frame: .zero, collectionViewLayout: flowLayout)
|
collect.delegate = self
|
collect.dataSource = self
|
collect.contentInset = UIEdgeInsets(top: 0, left:0, bottom: 14, right: 0)
|
collect.register(UINib(nibName: "CoinStoreCCell", bundle: nil), forCellWithReuseIdentifier: "_CoinStoreCCell")
|
collect.register(UINib(nibName: "CoinStoreHeadView", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "_CoinStoreHeadView")
|
return collect
|
}()
|
|
var benefitHomeModel:BenefitHomeModel?
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
title = "积分商城"
|
|
viewModel.configure(collectionView,needMore: false)
|
collectionView.jq_setEmptyView()
|
viewModel.beginRefresh()
|
}
|
|
override func setUI() {
|
view.addSubview(collectionView)
|
collectionView.snp.makeConstraints { make in
|
make.edges.equalToSuperview()
|
}
|
}
|
}
|
|
|
extension CoinStoreCenterVC:UICollectionViewDelegate{
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
let model = viewModel.dataSource.value[indexPath.row]
|
let vc = WelfareRedeemGoodsDetailVC(commodityId: model.goodId, goodsType: model.goodsType)
|
push(vc: vc)
|
}
|
|
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
|
let headView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "_CoinStoreHeadView", for: indexPath) as! CoinStoreHeadView
|
headView.innerView = self.view
|
headView.viewModel = viewModel
|
headView.label_coin.text = "\(benefitHomeModel?.userIntegral ?? 0)积分"
|
headView.label_username.text = benefitHomeModel?.userName ?? ""
|
headView.img_cover.sd_setImage(with: URL(string: benefitHomeModel?.userHeadImg))
|
headView.tf_search.rx.text.orEmpty.bind(to: viewModel.search).disposed(by: disposeBag)
|
headView.integral = benefitHomeModel?.userIntegral ?? 0
|
|
return headView
|
}
|
}
|
|
extension CoinStoreCenterVC:UICollectionViewDataSource{
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
let model = viewModel.dataSource.value[indexPath.row]
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_CoinStoreCCell", for: indexPath) as! CoinStoreCCell
|
cell.marketModel = model
|
return cell
|
}
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
return viewModel.dataSource.value.count
|
}
|
|
func numberOfSections(in collectionView: UICollectionView) -> Int {
|
return 1
|
}
|
}
|