宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
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
//
//  MineCouponsVC.swift
//  OKProject
//
//  Created by alvin_y on 2020/6/15.
//  Copyright © 2020 yangwang. All rights reserved.
//
 
import UIKit
import VTMagic
 
 
/// 优惠券
class MineCouponsVC: YYViewController {
 
    var selectIndex:Int = 0
 
    
    /// 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.needPreloading = true
        vc.magicView.isScrollEnabled = false
        return vc
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
 
        // Do any additional setup after loading the view.
 
        vtmagic.magicView.switch(toPage: UInt(exactly: selectIndex)!, animated: true)
 
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "赠送", style: .plain, target: self, action: #selector(give))
        navigationItem.rightBarButtonItem?.tintColor = UIColor(hexString: "#666666")
        navigationItem.rightBarButtonItem?.setTitleTextAttributes([NSAttributedString.Key.font:UIFont.systemFont(ofSize: 14)], for: .normal)
    }
    
 
    //MARK: - UI
    override func setupViews() {
        super.setupViews()
        navigationItem.title = "我的优惠券"
        self.addChild(vtmagic)
        view.addSubview(vtmagic.magicView)
        view.backgroundColor = UIColor(hexString: "#F3F4F5")
    }
    
    //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()
    }
 
        /// 赠送
        @objc func give()  {
            let vc = MineGiveCouponsListVC()
            self.yy_push(vc: vc)
        }
 
}
// MARK: - VTMagicViewDataSource
extension MineCouponsVC: 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 = MineCouponsListVC(state: .unused)
            return vc
        case 1:
                let vc = MineMerchantCouponListVC(state: .used)
            return vc
        default:
            return UIViewController()
        }
    }
}
 
// MARK: - VTMagicViewDelegate
extension MineCouponsVC: VTMagicViewDelegate{
    func magicView(_ magicView: VTMagicView, didSelectItemAt itemIndex: UInt) {
    }
    func magicView(_ magicView: VTMagicView, viewDidAppear viewController: UIViewController, atPage pageIndex: UInt) {
    }
}