宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-04-06 a1ae6802080a22e6e6ce6d0935e95facb1daca5c
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
//
//  MerchantListVC.swift
//  OKProject
//
//  Created by 无故事王国 on 2022/2/14.
//  Copyright © 2022 yangwang. All rights reserved.
//
 
import UIKit
import RxSwift
 
 
class MerchantListVC: YYTableViewController {
 
    let viewModel = MerchantViewModel()
    let customerViewModel = MineContactCustomerServiceViewModel()
    var type:ActiveStatus = .ongoing
 
    override func viewDidLoad() {
        super.viewDidLoad()
 
        view.backgroundColor = UIColor(hexString: "#F3F4F5")
        viewModel.orderType.accept(type)
        customerViewModel.queryCustomerPhone()
    }
 
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        tableView.beginRefreshing()
    }
 
    //MARK: - UI
    override func setupViews() {
        super.setupViews()
        tableView.separatorStyle = .none
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(cellName: "MerchantCouponTCell", identifier: "_MerchantCouponTCell")
        viewModel.configure(tableView: tableView)
//        tableView.beginRefreshing()
        emptyImage = UIImage(named: "empty_data")
        emptyTitleColor = UIColor.black
        emptyTitle = "您还没有优惠券信息\n您可以和平台联系,建立合作哦~\n平台电话:"
    }
 
 
    //MARK: - Layouts
    override func defineLayouts() {
        super.defineLayouts()
        tableView.snp.remakeConstraints { (make) in
            make.edges.equalToSuperview()
        }
    }
 
    //MARK: - Rx
    override func bindRx() {
        super.bindRx()
 
        customerViewModel.requestSubject
            .subscribe(onNext: {[unowned self] (status) in
                switch status{
                case .loading:break
                case .success(_):
                        self.emptyTitle = "您还没有优惠券信息\n您可以和平台联系,建立合作哦~\n平台电话:\(customerViewModel.platform.value)"
                    self.tableView.reloadData()
                    break
                case .error(_):
                    break
                }
            }).disposed(by: rx.disposeBag)
    }
 
    @objc func recordAction(_ btn:UIButton){
        let m = viewModel.dataSource.value[btn.tag - 10]
        let vc = MerchantCouponRecordVC()
        vc.id = m.id
        vc.activityId = m.activityId
        yy_push(vc: vc)
    }
}
 
 
// MARK: - UITableViewDelegate
extension MerchantListVC:UITableViewDelegate{
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
    }
}
 
// MARK: - UITableViewDelegate
extension MerchantListVC:UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return viewModel.dataSource.value.count
    }
 
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let m = viewModel.dataSource.value[indexPath.row]
        let cell = tableView.dequeueReusableCell(withIdentifier: "_MerchantCouponTCell", for: indexPath) as! MerchantCouponTCell
        cell.selectionStyle = .none
        cell.contentView.backgroundColor = .clear
        cell.backgroundColor = .clear
        cell.type = type
        cell.merchantCouponModel = m
        cell.recordBtn.tag = 10 + indexPath.row
        cell.checkImg.isHidden = true
        cell.invaildImg.isHidden = true
        cell.recordBtn.addTarget(self, action: #selector(recordAction(_:)), for: .touchUpInside)
        return cell
    }
}