宽窄优行-由【嘉易行】项目成品而来
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
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
//
//  MerchantVC.swift
//  OKProject
//
//  Created by 无故事王国 on 2022/2/14.
//  Copyright © 2022 yangwang. All rights reserved.
//
 
import UIKit
import VTMagic
 
let MerchantListRefresh_Noti = Notification.Name.init(rawValue: "MerchantListRefresh_Noti")
 
class MerchantVC: YYViewController {
 
    var merchantInfoModel:MerchantInfoModel?
 
    /// VTMagicController
    private lazy var vtmagic: VTMagicController = {
        let vc = VTMagicController()
        vc.magicView.navigationColor = UIColor.color(light: UIColor.color(hexString: "#FFFFFF"), dark: UIColor.color(hexString: "#191919"))
        vc.magicView.layoutStyle = .divide
        vc.magicView.navigationHeight = 40
        vc.magicView.separatorColor = UIColor.clear
        vc.magicView.sliderColor = UIColor.clear
        vc.magicView.dataSource = self
        vc.magicView.delegate = self
        vc.magicView.isScrollEnabled = false
        return vc
    }()
 
    override func viewDidLoad() {
        super.viewDidLoad()
 
        guard merchantInfoModel != nil else {return}
        createNavTitleView()
    }
 
    private func createNavTitleView(){
        let headView = UIView()
        headView.frame = CGRect(x: 0, y: 0, width: ScreenWidth/2, height: 30)
 
        let imgV = UIImageView()
        imgV.cornerRadius = 15
        imgV.contentMode = .scaleToFill
        imgV.backgroundColor = .black
        imgV.load(url: merchantInfoModel!.headImg)
        imgV.maskToBounds = true
        headView.addSubview(imgV)
        imgV.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
 
        let titleL = UILabel()
        titleL.text = merchantInfoModel!.name
        titleL.font = UIFont.systemFont(ofSize: 18, weight: .medium)
        titleL.textColor = .black
        headView.addSubview(titleL)
        titleL.frame = CGRect(x: imgV.maxX + 11, y: 0, width: 120, height: 30)
        navigationItem.titleView = headView
    }
 
    //MARK: - UI
    override func setupViews() {
        super.setupViews()
        navigationItem.title = ""
        self.addChild(vtmagic)
        view.addSubview(vtmagic.magicView)
        navigationItem.rightBarButtonItem = UIBarButtonItem.yy_creat(image: UIImage(named: "btn_scan")!, target: self, alignment: .center, action: #selector(scanAction)).item
    }
 
    //MARK: - Layouts
    override func defineLayouts() {
        super.defineLayouts()
        vtmagic.magicView.snp.makeConstraints{make in
            if #available(iOS 11.0, *) {
                make.edges.equalTo(self.view.safeAreaLayoutGuide)
            } else {
                make.edges.equalToSuperview()
            }
        }
        vtmagic.magicView.reloadData()
    }
 
    //MARK: - Rx
    override func bindRx() {
        super.bindRx()
        NotificationCenter.default.rx.notification(MerchantListRefresh_Noti, object: nil).takeUntil(self.rx.deallocated).subscribe(onNext: {noti in
            if let value = noti.object as? Int{
                self.vtmagic.switch(toPage: UInt(value), animated: true)
            }
        }).disposed(by: disposeBag)
    }
 
    @objc func scanAction()  {
        let vc = ScanVC()
        yy_push(vc: vc)
    }
}
// MARK: - VTMagicViewDataSource
extension MerchantVC: VTMagicViewDataSource {
 
    func menuTitles(for magicView: VTMagicView) -> [String] {
        return ["进行中","已结束"]
    }
 
    func magicView(_ magicView: VTMagicView, menuItemAt itemIndex: UInt) -> UIButton {
        let bt = magicView.dequeueReusableItem(withIdentifier: "item")
        if let button = bt{
            return button
        }else{
            let bt = UIButton()
            bt.titleLabel?.font = UIFont.init(name: Medium, size: 13)!
            bt.setTitleColor(UIColor.color(light: ThemeColor, dark: UIColor.color(hexString: "#FFFFFF")), for: .selected)
            bt.setTitleColor(UIColor.color(light: UIColor.color(hexString: "#8C9097"), dark: UIColor.color(hexString: "#8C9097")), for: .normal)
            return bt
        }
    }
 
    func magicView(_ magicView: VTMagicView, viewControllerAtPage pageIndex: UInt) -> UIViewController {
        switch pageIndex {
        case 0:
            let vc = MerchantListVC()
                vc.type = .ongoing
            return vc
        case 1:
            let vc = MerchantListVC()
                vc.type = .end
            return vc
        default:
            return UIViewController()
        }
    }
}
 
// MARK: - VTMagicViewDelegate
extension MerchantVC: VTMagicViewDelegate{
    func magicView(_ magicView: VTMagicView, didSelectItemAt itemIndex: UInt) {
    }
    func magicView(_ magicView: VTMagicView, viewDidAppear viewController: UIViewController, atPage pageIndex: UInt) {
    }
}