CNLiveShopTransViewController.swift 4.87 KB
//
//  CNLiveShopTransViewController.swift
//  metaCode
//
//  Created by open on 2023/11/15.
//

import Foundation
import JXSegmentedView
import JXPagingView

class CNLiveShopTransViewController: CNLiveBaseViewController {
    
    lazy var viewControllers: NSMutableArray = {
        let viewControllers = NSMutableArray.init()
        viewControllers.add(CNLiveShopTransListViewController.init())
        viewControllers.add(CNLiveShopTransListViewController.init())
        return viewControllers
    }()
    
    lazy var dataSource: JXSegmentedNumberDataSource = {
        let dataSource = JXSegmentedNumberDataSource()
        dataSource.titles = ["达人","电商"]
        dataSource.numbers = [0,0,0,0]
        dataSource.isTitleColorGradientEnabled = true
        dataSource.itemWidth = JXSegmentedViewAutomaticDimension
        dataSource.itemSpacing = 0
        dataSource.titleNormalFont = Font_15_Fit
        dataSource.titleSelectedFont = Font_15_Fit
        dataSource.titleNormalColor = HexColor("#999999")!
        dataSource.titleSelectedColor = HexColor("#28C1C6")!
        return dataSource
    }()
    
    lazy var categoryView: JXSegmentedView = {
        let categoryView = JXSegmentedView.init(frame: CGRectMake(0, KNavigationHeight, KSreenWidth, CGFloat(kCNLiveShopOrderListSectionTitleHeight)))
        categoryView.dataSource = dataSource
        categoryView.delegate = self
        categoryView.collectionView.backgroundColor = HexColor("fafbfd")
        categoryView.backgroundColor = .white
        
        let lineView = JXSegmentedIndicatorBackgroundView.init()
        lineView.indicatorColor = HexColor("#28C1C6")!
        lineView.indicatorHeight = 2
        lineView.indicatorPosition = .bottom
        lineView.indicatorWidthIncrement = 0
        lineView.indicatorCornerRadius = 0
        categoryView.indicators = [lineView]
        
        return categoryView
    }()
    
    lazy var screenButton: UIButton = {
        let screenButton = UIButton.init(type: .custom)
        screenButton.frame = CGRect(x: KSreenWidth - adapt_length(length: 40), y: (get_system_nav_height() - (get_system_statusBar_height() + adapt_length(length: 30)))/2 + get_system_statusBar_height(), width: adapt_length(length: 30), height: adapt_length(length: 30))
        screenButton.setImage(UIImage(named: "DS_order_search"), for: .normal)
        screenButton.backgroundColor = .clear
        screenButton.layer.masksToBounds  = true
        screenButton.layer.cornerRadius = 5
        screenButton.addTarget(self, action: #selector(screenButtonClick), for: .touchUpInside)
        return screenButton
    }()
    
    lazy var listContainerView: JXSegmentedListContainerView! = {
        return JXSegmentedListContainerView(dataSource: self)
    }()
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.interactivePopGestureRecognizer?.isEnabled = (categoryView.selectedIndex == 0)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.navigationController?.interactivePopGestureRecognizer?.isEnabled = true
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        navigationBarHidden = false
        titleName = "交易记录"
        
        view.addSubview(categoryView)

        categoryView.listContainer = listContainerView
        view.addSubview(listContainerView)
        
        topNavView.addSubview(screenButton)
        
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()

        categoryView.frame = CGRect(x: 0, y: KNavigationHeight, width: view.bounds.size.width, height: CGFloat(kCNLiveShopOrderListSectionTitleHeight))
        listContainerView.frame = CGRect(x: 0, y: KNavigationHeight+CGFloat(kCNLiveShopOrderListSectionTitleHeight), width: view.bounds.size.width, height: view.bounds.size.height - CGFloat(kCNLiveShopOrderListSectionTitleHeight) - KNavigationHeight)
    }
    
    @objc func screenButtonClick() {

    }
    
    
}
extension CNLiveShopTransViewController: JXSegmentedViewDelegate {
    func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
        navigationController?.interactivePopGestureRecognizer?.isEnabled = (segmentedView.selectedIndex == 0)
    }
}

extension CNLiveShopTransViewController: JXSegmentedListContainerViewDataSource {
    func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
        if let titleDataSource = categoryView.dataSource as? JXSegmentedBaseDataSource {
            return titleDataSource.dataSource.count
        }
        return 0
    }

    func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
        return viewControllers[index] as! JXSegmentedListContainerViewListDelegate
    }
}