无故事王国
2023-09-20 2834569133090d46dd3f28a30100fa74661ef1e1
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
    //
    //  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
        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.tf_search.rx.text.orEmpty.bind(to: viewModel.search).disposed(by: disposeBag)
            headView.integral = model.userIntegral
        }
    }
 
    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
    }
}