//
|
// 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)
|
let shopId = BehaviorRelay<Int?>(value: nil)
|
|
override func api() -> (Observable<BaseResponse<[MarketMdoel]>>)? {
|
Services.mallList(page:page,goodsType: goodsType.value, rank: rank.value, search: search.value, shopId: shopId.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)
|
|
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.backgroundColor = .white
|
return collect
|
}()
|
|
private var headView:CoinStoreHeadView = {
|
let head = CoinStoreHeadView.jq_loadNibView()
|
return head
|
}()
|
|
|
var benefitHomeModel:BenefitHomeModel?
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
title = "积分商城"
|
|
headView.viewModel = viewModel
|
headView.innerView = self.view
|
viewModel.configure(collectionView)
|
collectionView.jq_setEmptyView()
|
viewModel.beginRefresh()
|
|
|
if let model = benefitHomeModel{
|
headView.label_coin.text = "\(model.userIntegral)积分"
|
headView.label_username.text = model.userName
|
headView.img_cover.sd_setImage(with: URL(string: model.userHeadImg))
|
headView.integral = model.userIntegral
|
}else{
|
Services.benefitHome().subscribe(onNext: {[weak self] data in
|
guard let weakSelf = self else { return }
|
if let model = data.data{
|
self?.headView.label_coin.text = "\(model.userIntegral)积分"
|
self?.headView.label_username.text = model.userName
|
self?.headView.img_cover.sd_setImage(with: URL(string: model.userHeadImg))
|
self?.headView.integral = model.userIntegral
|
}
|
}) { error in
|
|
}.disposed(by: disposeBag)
|
}
|
}
|
|
override func setRx() {
|
headView.tf_search.rx.text.orEmpty.bind(to: viewModel.search).disposed(by: disposeBag)
|
}
|
|
override func setUI() {
|
view.addSubview(headView)
|
headView.snp.makeConstraints { make in
|
make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top)
|
make.left.right.equalToSuperview()
|
make.height.equalTo(JQ_ScreenW * 0.5564)
|
}
|
view.addSubview(collectionView)
|
collectionView.snp.makeConstraints { make in
|
make.top.equalTo(headView.snp.bottom)
|
make.left.right.bottom.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
|
}
|
}
|