younger_times
2023-07-26 a31b91712fd7d382ecc02397fd358d3f595e747c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
    //
    //  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
    }
}