Robert
6 小时以前 c547797c9267e2f3e3c24c7acb31502517f3b6e6
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
    //
    //  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?
    private var selectStore:NormalSimpleModel?
 
    
    init(selectStore:NormalSimpleModel? = nil,type:ExchangeType? = nil) {
        super.init(nibName: nil, bundle: nil)
        self.selectStore = selectStore
        self.viewModel.goodsType.accept(type)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "积分商城"
 
        if let store = selectStore{
            viewModel.shopId.accept(store.id)
            headView.btn_store.setTitle(store.name, for: .normal)
        }
 
        headView.viewModel = viewModel
        headView.innerView = self.view
        viewModel.configure(collectionView)
//        collectionView.jq_setEmptyView()
        viewModel.beginRefresh()
 
        headView.btn_type.setTitle(viewModel.goodsType.value?.strTitle ?? "商品类型", for: .normal)
 
 
//        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{
//
//        }
 
        getBenefitData()
    }
 
 
    private func getBenefitData(){
        Services.benefitHome().subscribe(onNext: {[weak self] data in
            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)
        NotificationCenter.default.rx.notification(UpdateWelfare_Noti, object: nil).take(until: self.rx.deallocated).subscribe(onNext: {[weak self] noti in
            self?.getBenefitData()
        }) { error in
 
        }.disposed(by: disposeBag)
    }
 
    override func setUI() {
        view.addSubview(headView)
        headView.frame = CGRect(x: 0, y:UIDevice.jq_safeEdges.top + (navigationController?.navigationBar.height)! , width: view.size.width, height: view.size.width * 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)
    }
}
 
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
    }
}