ShoppingMallViewController.swift 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // ShoppingMallViewController.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/3/7.
  6. // Copyright © 2019 南鑫林. All rights reserved.
  7. //
  8. import UIKit
  9. class ShoppingMallViewController: BaseViewController {
  10. deinit {
  11. if observe != nil {
  12. NotificationCenter.default.removeObserver(observe!)
  13. }
  14. }
  15. weak var observe : NSObjectProtocol?
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18. setupViews()
  19. setupLayouts()
  20. setupData()
  21. NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "ChooseSelfAddressNoti"), object: nil, queue: operationQueue) {
  22. [weak self] (notification) in
  23. }
  24. }
  25. override func setupViews() {
  26. super.setupViews()
  27. navigationBar.addSubview(navigationBarView)
  28. view.addSubview(shoppingMallView)
  29. }
  30. override func setupLayouts() {
  31. navigationBarView.snp.makeConstraints { (make) in
  32. make.top.equalToSuperview().offset(kSafeStatusBarHeight)
  33. make.left.right.bottom.equalToSuperview()
  34. }
  35. shoppingMallView.snp.makeConstraints { (make) in
  36. make.bottom.left.right.equalToSuperview()
  37. make.top.equalTo(kNavBarTotalHeight)
  38. }
  39. }
  40. override func setupData() {
  41. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("ProductDetailVC"), object: nil, queue: OperationQueue.main) {[weak self] (notification) in
  42. let productModel = notification.object as! ProductModel
  43. let vc = ProductDetailViewController()
  44. vc.productId = productModel.id
  45. vc.shopId = productModel.shopId
  46. self?.navigationController?.pushViewController(vc, animated: true)
  47. }
  48. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("ShoppingMallBanner"), object: nil, queue: OperationQueue.main) {[weak self] (notification) in
  49. let cmsRuleModel = notification.object as? CMSRuleModel
  50. self?.pushVCCMSRule(cmsRuleModel: cmsRuleModel, areaType: "banner")
  51. }
  52. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("ShoppingMallCategory"), object: nil, queue: OperationQueue.main) {[weak self] (notification) in
  53. let cmsRuleModel = notification.object as? CMSRuleModel
  54. self?.pushVCCMSRule(cmsRuleModel: cmsRuleModel, areaType: "category")
  55. }
  56. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("ShoppingMallSpecial"), object: nil, queue: OperationQueue.main) {[weak self] (notification) in
  57. let cmsRuleModel = notification.object as? CMSRuleModel
  58. self?.pushVCCMSRule(cmsRuleModel: cmsRuleModel, areaType: "special")
  59. }
  60. observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("ShoppingMallFloor"), object: nil, queue: OperationQueue.main) {[weak self] (notification) in
  61. let cmsRuleModel = notification.object as? CMSRuleModel
  62. self?.pushVCCMSRule(cmsRuleModel: cmsRuleModel, areaType: "floor")
  63. }
  64. //搜索
  65. navigationBarView.searchBlock = {
  66. [weak self] in
  67. let vc = SearchViewController()
  68. let nav = BaseNavigationViewController.init(rootViewController: vc)
  69. self?.present(nav, animated: true, completion: {
  70. })
  71. }
  72. //分类
  73. navigationBarView.categoryButton.rx.tap.subscribe(onNext: {
  74. [weak self] in
  75. let vc = CategoryViewController()
  76. vc.navigationBar.title = "团购分类"
  77. self?.navigationController?.pushViewController(vc, animated: true)
  78. }).disposed(by: disposeBag)
  79. }
  80. func pushVCCMSRule(cmsRuleModel:CMSRuleModel?,areaType:String) {
  81. switch cmsRuleModel?.linkType {
  82. case 1:
  83. let vc = SpecialViewController()
  84. vc.navigationBar.title = cmsRuleModel?.title
  85. vc.cmsRuleModel = cmsRuleModel
  86. vc.area_type = areaType
  87. self.navigationController?.pushViewController(vc, animated: true)
  88. break
  89. case 2:
  90. let vc = BaseWebViewController()
  91. vc.URLString = cmsRuleModel?.linkUrl
  92. self.navigationController?.pushViewController(vc, animated: true)
  93. break
  94. default:
  95. break
  96. }
  97. }
  98. private lazy var navigationBarView: ShoppingMallNavigationBarView = {
  99. let navigationBarView = ShoppingMallNavigationBarView()
  100. navigationBarView.selfAddrTipClosure = {
  101. [weak self] in
  102. let model = DeliveryMethodTypeModel.shared().getModel()
  103. if model?.deliveryMethodType == "1" { //自提
  104. }
  105. }
  106. return navigationBarView
  107. }()
  108. private lazy var shoppingMallView: ShoppingMallView = {
  109. let shoppingMallView = ShoppingMallView()
  110. return shoppingMallView
  111. }()
  112. }