QuoteViewController.swift 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //
  2. // QuoteViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by Handy_Cao on 2020/10/23.
  6. // Copyright © 2020 Muchinfo. All rights reserved.
  7. //
  8. import UIKit
  9. import SwiftyAttributes
  10. import JXSegmentedView
  11. import WHToast
  12. /// 商品行情视图容器控制类
  13. class QuoteViewController: BaseViewController {
  14. // MARK: - 属性列表
  15. /// 分段控制器
  16. @IBOutlet weak var segmentedView: JXSegmentedView! {
  17. didSet {
  18. segmentedView.delegate = self
  19. segmentedView.dataSource = dataSource
  20. segmentedView.indicators = [self.indicator]
  21. }
  22. }
  23. /// 内容装载视图
  24. @IBOutlet weak var contentStackView: UIStackView!
  25. /// 海南网警
  26. @IBOutlet weak var police: UIButton!
  27. /// 检索按钮
  28. @IBOutlet weak var search: UIButton!
  29. /// 类目按钮
  30. @IBOutlet weak var category: UIButton!
  31. /// segmentedDataSource
  32. let dataSource: JXSegmentedTitleDataSource = {
  33. $0.titleNormalColor = UIColorFromHex(rgbValue: 0x333333)
  34. $0.titleNormalFont = .font_16
  35. $0.titleSelectedColor = UIColorFromHex(rgbValue: 0x60a1e3)
  36. $0.titleSelectedFont = .font_18
  37. $0.isTitleColorGradientEnabled = true
  38. return $0
  39. } (JXSegmentedTitleDataSource())
  40. /// 市场信息
  41. var markets: [(name: String, marketid: Int)] {
  42. get {
  43. return MTP2BusinessCore.shared.goodsManager?.getGoodsGroupInfos(.TRADEMODE_TRADEMODE_HSBY_SHOP) ?? []
  44. }
  45. }
  46. // /// 热卖商品视图
  47. // lazy var hotQuoteController: HotQuoteViewController = {
  48. // $0.view.frame = contentStackView.bounds
  49. // return $0
  50. // } (UIStoryboard(name: "Quote", bundle: nil).instantiateViewController(withIdentifier: "HotQuote") as! HotQuoteViewController)
  51. // /// 新品上市视图
  52. // lazy var newQuoteController: NewQuoteViewController = {
  53. // $0.view.frame = contentStackView.bounds
  54. // return $0
  55. // } (UIStoryboard(name: "Quote", bundle: nil).instantiateViewController(withIdentifier: "NewQuote") as! NewQuoteViewController)
  56. /// 特卖商城
  57. lazy var specialSaleController: SpecialSaleViewController = {
  58. $0.view.frame = contentStackView.bounds
  59. return $0
  60. } (UIStoryboard(name: "Quote", bundle: nil).instantiateViewController(withIdentifier: "SpecialSale") as! SpecialSaleViewController)
  61. // MARK: - 生命周期相关
  62. required init?(coder aDecoder: NSCoder) {
  63. super.init(coder: aDecoder)
  64. /// 设置TabBar图片
  65. self.tabBarItem.image = UIImage(named: "quote_normal")?.withRenderingMode(.alwaysOriginal)
  66. self.tabBarItem.selectedImage = UIImage(named: "quote_selected")?.withRenderingMode(.alwaysOriginal)
  67. }
  68. override func viewDidLoad() {
  69. super.viewDidLoad()
  70. // Do any additional setup after loading the view.
  71. /// 不需要返回按钮
  72. addBackBarButtonItem(true)
  73. /// UI界面显示
  74. buildView()
  75. }
  76. override func viewWillAppear(_ animated: Bool) {
  77. super.viewWillAppear(animated)
  78. /// 刷新数据
  79. dataSource.titles = markets.map({ (obj) -> String in
  80. return obj.name
  81. })
  82. segmentedView.reloadData()
  83. /// 隐藏导航栏
  84. self.navigationController?.setNavigationBarHidden(true, animated: true)
  85. if markets.count != 0 {
  86. /// 特卖商城
  87. specialSaleController.marketid = "\(markets[0].marketid)"
  88. self.addChild(specialSaleController)
  89. specialSaleController.didMove(toParent: self)
  90. contentStackView.addArrangedSubview(specialSaleController.view)
  91. /// 请求数据
  92. specialSaleController.initData()
  93. }
  94. }
  95. // MARK: - 初始化
  96. /// UI界面显示
  97. fileprivate func buildView() {
  98. // showController(selectedIndex: 0)
  99. // /// 市场ID
  100. // specialSaleController.marketid = markets[0].marketid
  101. }
  102. // MARK: - 交互相关
  103. @IBAction func onButtonPressed(_ sender: UIButton) {
  104. switch sender {
  105. case police: /// 海南网警
  106. push(storyboardName: "Feedback", storyboardId: "Feedback")
  107. case category: /// 类目
  108. let category = viewController(name: "Category", identifier: "CategoryID")
  109. self.navigationController?.pushViewController(category, animated: true)
  110. default: break
  111. }
  112. }
  113. // MARK: - UI显示
  114. /// Tab也切换时显示的容器
  115. /// - Parameter index: index
  116. fileprivate func showController(selectedIndex index: Int) {
  117. // switch index {
  118. // case 0: /// 热卖商品
  119. //// /// 移出新品上市视图
  120. //// removeChildren(hotQuoteController)
  121. //// /// 移出新品上市视图
  122. //// removeChildren(newQuoteController)
  123. // /// 添加特卖商城视图
  124. //// addChildren(specialSaleController)
  125. //// case 1:
  126. //// /// 移出新品上市视图
  127. //// removeChildren(hotQuoteController)
  128. //// /// 移出新品上市视图
  129. //// removeChildren(specialSaleController)
  130. //// /// 添加特卖商城视图
  131. //// addChildren(newQuoteController)
  132. // default: /// 竞价商品
  133. //// /// 移出新品上市视图
  134. //// removeChildren(newQuoteController)
  135. // /// 移出新品上市视图
  136. // removeChildren(specialSaleController)
  137. //// /// 添加特卖商城视图
  138. //// addChildren(hotQuoteController)
  139. // }
  140. }
  141. /// addChildren
  142. /// - Parameter child: child
  143. fileprivate func addChildren(_ child: UIViewController) {
  144. if !contentStackView.arrangedSubviews.contains(child.view) {
  145. self.addChild(child)
  146. child.didMove(toParent: self)
  147. contentStackView.addArrangedSubview(child.view)
  148. }
  149. }
  150. /// removeChildren
  151. /// - Parameter child: child
  152. fileprivate func removeChildren(_ child: UIViewController) {
  153. if contentStackView.arrangedSubviews.contains(child.view) {
  154. child.removeFromParent()
  155. contentStackView.removeArrangedSubview(child.view)
  156. child.view.removeFromSuperview()
  157. }
  158. }
  159. // MARK: - Navigation
  160. // In a storyboard-based application, you will often want to do a little preparation before navigation
  161. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  162. // Get the new view controller using segue.destination.
  163. // Pass the selected object to the new view controller.
  164. }
  165. }
  166. extension QuoteViewController: JXSegmentedViewDelegate {
  167. func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
  168. // /// 显示相应的视图
  169. // self.showController(selectedIndex: index)
  170. /// 市场ID
  171. specialSaleController.marketid = "\(markets[index].marketid)"
  172. /// 请求数据
  173. specialSaleController.initData()
  174. // /// 隐藏分类按钮
  175. // self.category.isHidden = !(index == 0)
  176. }
  177. }