CNLiveShopOrderViewController.swift 5.26 KB
//
//  CNLiveShopOrderViewController.swift
//  metaCode
//
//  Created by open on 2023/10/31.
//

import Foundation
import JXSegmentedView
import JXPagingView

let kCNLiveShopOrderListSectionTitleHeight = 49//标题显示
class CNLiveShopOrderViewController: CNLiveBaseViewController {
    
    lazy var viewControllers: NSMutableArray = {
        let viewControllers = NSMutableArray.init()
        viewControllers.add(CNLiveShopOrderListViewController.init(show_type: .all))
        viewControllers.add(CNLiveShopOrderListViewController.init(show_type: .will))
        viewControllers.add(CNLiveShopOrderListViewController.init(show_type: .have))
        viewControllers.add(CNLiveShopOrderListViewController.init(show_type: .end))
        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 searchButton: UIButton = {
        let searchButton = UIButton.init(type: .custom)
        searchButton.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))
        searchButton.setImage(UIImage(named: "DS_order_search"), for: .normal)
        searchButton.backgroundColor = .clear
        searchButton.layer.masksToBounds  = true
        searchButton.layer.cornerRadius = 5
        searchButton.addTarget(self, action: #selector(searchBtnClick), for: .touchUpInside)
        return searchButton
    }()
    
    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(searchButton)
        
    }
    
    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 searchBtnClick() {
        self.navigationController?.pushViewController(CNLiveShopOrderSearchViewController.init(), animated: true)
    }
}

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

extension CNLiveShopOrderViewController: 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
    }
}