OrderFinishPayController.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // ShoppingCartFinishPayController.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/5/9.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. // 购物车--支付完成Vc
  8. import UIKit
  9. import RxSwift
  10. /// OrderFinishPayVCType
  11. ///
  12. /// - cart: 购物车
  13. /// - productDetail: 订单详情
  14. /// - order: 订单
  15. /// - orderDetails: 订单详情
  16. enum OrderFinishPayVCType {
  17. case cart
  18. case productDetail
  19. case order
  20. case orderDetail
  21. }
  22. class OrderFinishPayController: BaseViewController {
  23. override func didReceiveMemoryWarning() {
  24. super.didReceiveMemoryWarning()
  25. }
  26. var payStatus: Bool? = true {
  27. didSet {
  28. if payStatus ?? true {
  29. navigationBar.title = "支付成功"
  30. } else {
  31. navigationBar.title = "支付失败"
  32. }
  33. }
  34. }
  35. var orderFinishPayVCType : OrderFinishPayVCType?
  36. typealias ReloadClosure = () -> Void
  37. var reloadClosure : ReloadClosure?
  38. var productSearchModelArray = Array<ProductSearchModel>()
  39. override func viewDidLoad() {
  40. super.viewDidLoad()
  41. setupViews()
  42. setupLayouts()
  43. setupData()
  44. }
  45. override func setupViews() {
  46. view.addSubview(finishPayView)
  47. }
  48. override func setupLayouts() {
  49. finishPayView.snp.makeConstraints { (make) in
  50. make.bottom.left.right.equalToSuperview()
  51. make.top.equalTo(kNavBarTotalHeight)
  52. }
  53. }
  54. override func setupData() {
  55. if !(payStatus ?? true) {
  56. self.finishPayView.configModel = ConfigModel.shared.object()
  57. }
  58. finishPayView.tableView.addHeader(withBeginRefresh: true, animation: false) { [weak self] (page) in
  59. self?.productHotSaleApi(page: page)
  60. }
  61. navigationBar.onClickLeftButton = {
  62. [weak self] in
  63. switch self?.orderFinishPayVCType {
  64. case .cart?:
  65. self?.navigationController?.popToRootViewController(animated: true)
  66. break
  67. case .productDetail?:
  68. self?.navigationController?.popToClass(type: ProductDetailViewController.self)
  69. break
  70. case .order?:
  71. if self?.payStatus ?? true {
  72. if let reloadClosure = self?.reloadClosure {
  73. reloadClosure()
  74. }
  75. }
  76. self?.navigationController?.popViewController(animated: true)
  77. break
  78. case .orderDetail?:
  79. if self?.payStatus ?? true {
  80. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "OrderFinishPayVCOrderDetail"), object: nil)
  81. self?.navigationController?.popToClass(type: OrderViewController.self)
  82. }else {
  83. self?.navigationController?.popViewController(animated: true)
  84. }
  85. break
  86. default:
  87. break
  88. }
  89. }
  90. }
  91. private lazy var finishPayView: OrderFinishPayView = {
  92. let finishPayView = OrderFinishPayView()
  93. finishPayView.payStatus = payStatus
  94. finishPayView.repayTransBlock = {
  95. [weak self] in
  96. let vc = OrderViewController()
  97. vc.orderVCType = .pendingPayment
  98. self?.navigationController?.pushViewController(vc, animated: true)
  99. }
  100. finishPayView.jumpTransBlock = {
  101. [weak self] (jType) in
  102. switch jType {
  103. case PayJumpDes.homePage:
  104. self?.tabBarController?.selectedIndex = 0
  105. self?.navigationController?.popToRootViewController(animated: false)
  106. case PayJumpDes.checkOrder:
  107. let vc = OrderViewController()
  108. vc.orderVCType = .toBeShipped
  109. self?.navigationController?.pushViewController(vc, animated: true)
  110. }
  111. }
  112. finishPayView.jumpToDetailTransClosure = {
  113. [weak self] (proId, shopId) in
  114. let vc = ProductDetailViewController()
  115. vc.productId = proId
  116. vc.shopId = shopId
  117. self?.navigationController?.pushViewController(vc, animated: true)
  118. }
  119. return finishPayView
  120. }()
  121. /// 商品热销
  122. func productHotSaleApi(page:Int = 1) {
  123. SwiftMoyaNetWorkServiceProduct.shared().productHotSaleApi(page: page) { [weak self] (productSearchListModel) -> (Void) in
  124. let productSearchListModel = productSearchListModel as? ProductSearchListModel
  125. if productSearchListModel?.pagination?.currentPage ?? 1 <= productSearchListModel?.pagination?.totalPages ?? 1 {
  126. if productSearchListModel?.pagination?.currentPage == 1{
  127. self?.productSearchModelArray.removeAll()
  128. }
  129. self?.productSearchModelArray = (self?.productSearchModelArray)! + (productSearchListModel?.data!)!
  130. self?.finishPayView.hotSaleModelArr = self?.productSearchModelArray
  131. } else {
  132. self?.finishPayView.hotSaleModelArr = self?.productSearchModelArray
  133. }
  134. }
  135. }
  136. }