| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- //
- // SpotsPageViewController.swift
- // MTP2_iOS
- //
- // Created by Muchinfo on 2021/9/16.
- // Copyright © 2021 Muchinfo. All rights reserved.
- //
- import UIKit
- import JXSegmentedView
- /// 现货主视图容器控制类
- class SpotsPageViewController: BaseViewController {
-
- // MARK: - 属性列表
- /// title
- @IBOutlet weak var segmentedView: JXSegmentedView! {
- didSet {
- segmentedView.dataSource = dataSource
- segmentedView.indicators = [indicator]
- segmentedView.delegate = self
- }
- }
- /// 内容承载视图
- @IBOutlet weak var contentView: UIView!
- /// 新增现货合同/购销计划
- @IBOutlet weak var new: UIBarButtonItem!
-
- /// 权限功能
- var roleTitles: [String] {
- get {
- var titles: [String] = []
- /// 权限控制
- guard let commonManager = MTP2BusinessCore.shared.commonManager else {
- return titles
- }
- if commonManager.containMenu(key: "client_spots_purchase") {
- titles.append("采购合同")
- }
- if commonManager.containMenu(key: "client_spots_sales") {
- titles.append("销售合同")
- }
- if commonManager.containMenu(key: "client_spots_hedgeplan") {
- titles.append("购销计划")
- }
- if commonManager.containMenu(key: "client_spots_link") {
- titles.append("期现关联")
- }
- return titles
- }
- }
-
- /// 采购视图容器控制类
- lazy var purchase: PurchaseViewController = {
- $0.econtractType = .Buy
- return $0
- }(viewController("Spots", "Purchase") as! PurchaseViewController)
-
- /// 销售视图容器控制类
- lazy var sales: PurchaseViewController = {
- $0.econtractType = .Sale
- return $0
- }(viewController("Spots", "Purchase") as! PurchaseViewController)
-
- /// 购销计划视图容器控制类
- lazy var hedgePlan: HedgePlanViewController = {
- /// 不是审核模式
- $0.isAduit = false
- return $0
- }(viewController("Spots", "HedgePlan") as! HedgePlanViewController)
-
- /// 期现关联视图容器控制类
- lazy var link: SpotsLinkViewController = {
- return $0
- }(viewController("Spots", "SpotsLink") as! SpotsLinkViewController)
- // MARK: - 生命周期
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- /// 允许横屏
- let app = UIApplication.shared.delegate as? AppDelegate
- app?.isRotation = true
- /// 侦听横竖屏切换
- NotificationCenter.default.addObserver(self, selector: #selector(orientationDidChange(interfaceOrientation:)), name: UIDevice.orientationDidChangeNotification, object: nil)
- }
-
- override func viewDidDisappear(_ animated: Bool) {
- super.viewDidDisappear(animated)
- /// 允许横屏
- let app = UIApplication.shared.delegate as? AppDelegate
- app?.isRotation = true
- /// 移出侦听
- NotificationCenter.default.removeObserver(self)
- }
-
- @objc func orientationDidChange(interfaceOrientation: UIInterfaceOrientation) {
- /// 横竖屏切换时 重新计算
- segmentedView.width = self.view.width
- segmentedView.reloadData()
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- /// 隐藏返回按钮
- addBackBarButtonItem(true)
- /// titles
- dataSource.titles = roleTitles
- segmentedView.reloadData()
- /// 默认显示采购视图
- showChildController(purchase)
- }
-
- // MARK: - 视图切换
- /// 添加子视图
- /// - Parameter controller: controller
- fileprivate func showChildController(_ controller: BaseViewController) {
- /// 先移出所有的子视图
- let childs: [UIViewController] = self.children
- childs.forEach { child in
- child.removeFromParent()
- child.view.removeFromSuperview()
- }
- /// 添加视图
- if !contentView.subviews.contains(controller.view) {
- controller.view.frame = contentView.bounds
- contentView.addSubview(controller.view)
- self.addChild(controller)
- controller.didMove(toParent: self)
- }
- }
-
- // MARK: - 交互操作
- /// onBarButtonItemPressed
- /// - Parameter sender: sender
- @IBAction fileprivate func onBarButtonItemPressed(_ sender: UIBarButtonItem) {
- switch sender {
- case new: /// 新增
- /// 新增现货合同/购销计划
- performSegue(withIdentifier: roleTitles[segmentedView.selectedIndex] == "购销计划" ? "ShowNewHedgePlan" : "ShowNewSpotContract", sender: nil)
- default:
- break
- }
- }
-
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destination.
- // Pass the selected object to the new view controller.
- ///
- if segue.identifier == "ShowNewHedgePlan", let n = segue.destination as? NewHedgePlanViewController {
- /// 新增购销计划
- n.popBlock = { (_ takeInfo: Any?) in
- /// 刷新列表数据
- self.hedgePlan.mainScrollView.triggerRefreshing()
- }
- } else if segue.identifier == "ShowNewSpotContract", let n = segue.destination as? NewSpotContractViewController {
- /// 新增现货合同
- n.popBlock = { (_ takeInfo: Any?) in
- if self.roleTitles[self.segmentedView.selectedIndex] == "采购合同" {
- self.purchase.mainScrollView.triggerRefreshing()
- } else {
- self.sales.mainScrollView.triggerRefreshing()
- }
- }
- DispatchQueue.main.asyncAfter(deadline: .now()+0.3) {
- /// 合同类型
- n.econtractType = self.segmentedView.selectedIndex == 0 ? .Buy : .Sale
- }
- }
- }
- }
- // MARK: - JXSegmentedViewDelegate
- extension SpotsPageViewController: JXSegmentedViewDelegate {
- /// didSelectedItemAt
- /// - Parameters:
- /// - segmentedView: segmentedView
- /// - index: index
- func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
- switch roleTitles[index] {
- case "采购合同": /// 采购合同
- showChildController(purchase)
- case "销售合同": /// 销售合同
- showChildController(sales)
- case "期现关联": /// 期现关联
- showChildController(link)
- default: /// 购销计划
- showChildController(hedgePlan)
- }
- }
- }
|