CNLiveShopTransViewController.swift 4.18 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(show_type: .all))
        viewControllers.add(CNLiveShopTransListViewController.init(show_type: .income))
        viewControllers.add(CNLiveShopTransListViewController.init(show_type: .outcome))
        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 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)
    }
    
    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)
    }
}
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
    }
}