//
|
// 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) {
|
}
|
}
|