CommonPayView.swift 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // CommonPayView.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/5/10.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. // 支付View
  8. import UIKit
  9. import FWPopupView
  10. import RxSwift
  11. import RxCocoa
  12. enum PayType {
  13. case wechatPay
  14. case aliPay
  15. }
  16. class CommonPayView: FWPopupView {
  17. let disposeBag = DisposeBag()
  18. typealias DismissTransBlock = () -> Void
  19. var disTransBlock : DismissTransBlock?
  20. typealias ConfirmPayBlock = (_ pType: PayType) -> Void
  21. var confirmPayBlock : ConfirmPayBlock?
  22. var curPayType : PayType = PayType.wechatPay
  23. override init(frame: CGRect) {
  24. super.init(frame: frame)
  25. self.backgroundColor = kf7f8faColor
  26. addSubview(confirmPayBtn)
  27. addSubview(tableView)
  28. setupLayouts()
  29. }
  30. required init?(coder aDecoder: NSCoder) {
  31. fatalError("init(coder:) has not been implemented")
  32. }
  33. func setupLayouts() {
  34. confirmPayBtn.snp.makeConstraints { (make) in
  35. make.left.right.equalToSuperview()
  36. make.bottom.equalTo(-kSafeTabBarHeight)
  37. make.height.equalTo(50)
  38. }
  39. tableView.snp.makeConstraints { (make) in
  40. make.left.right.top.equalToSuperview()
  41. make.bottom.equalTo(confirmPayBtn.snp_top).offset(-20)
  42. }
  43. }
  44. lazy var tableView: UITableView = {
  45. let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
  46. tableView.separatorStyle = .none
  47. tableView.backgroundColor = kf7f8faColor
  48. tableView.dataSource = self
  49. tableView.delegate = self
  50. tableView.estimatedRowHeight = 0.000001
  51. tableView.estimatedSectionFooterHeight = 0.000001
  52. tableView.estimatedSectionHeaderHeight = 0.000001
  53. return tableView
  54. }()
  55. private lazy var confirmPayBtn: UIButton = {
  56. let confirmPayBtn = UIButton(type: UIButton.ButtonType.custom)
  57. confirmPayBtn.backgroundColor = kFFA42FColor
  58. confirmPayBtn.setTitle("确认支付", for: UIControl.State.normal)
  59. confirmPayBtn.setTitleColor(kffffffColor, for: UIControl.State.normal)
  60. confirmPayBtn.titleLabel?.font = kScaleRegularFont16
  61. confirmPayBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
  62. if let confirmPayBlock = self?.confirmPayBlock {
  63. confirmPayBlock(self!.curPayType)
  64. }
  65. }).disposed(by: disposeBag)
  66. return confirmPayBtn
  67. }()
  68. }
  69. extension CommonPayView : UITableViewDelegate, UITableViewDataSource {
  70. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  71. return 2
  72. }
  73. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  74. switch indexPath.row {
  75. case 0:
  76. let cell = CommonPayCell.cellWith(tableView: tableView, indexPath: indexPath)
  77. cell.titleLabel.text = "微信"
  78. cell.iconImageView.image = kImage(name: "common_pay_wechat")
  79. if (curPayType == PayType.wechatPay) {
  80. cell.statusImageView.image = kImage(name: "common_check_icon")
  81. } else {
  82. cell.statusImageView.image = kImage(name: "common_uncheck_icon")
  83. }
  84. return cell
  85. case 1:
  86. let cell = CommonPayCell.cellWith(tableView: tableView, indexPath: indexPath)
  87. cell.titleLabel.text = "支付宝"
  88. cell.iconImageView.image = kImage(name: "common_pay_alipay")
  89. if (curPayType == PayType.aliPay) {
  90. cell.statusImageView.image = kImage(name: "common_check_icon")
  91. } else {
  92. cell.statusImageView.image = kImage(name: "common_uncheck_icon")
  93. }
  94. return cell
  95. default:
  96. return UITableViewCell()
  97. }
  98. }
  99. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  100. if indexPath.row == 0 {
  101. curPayType = PayType.wechatPay
  102. } else {
  103. curPayType = PayType.aliPay
  104. }
  105. tableView.reloadData()
  106. }
  107. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  108. return 48
  109. }
  110. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  111. return 50
  112. }
  113. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  114. let headerView = CommonPayHeader(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 50))
  115. headerView.payAmount = 155
  116. headerView.dismissBlock = {
  117. [weak self] in
  118. if let disTransBlock = self?.disTransBlock {
  119. disTransBlock()
  120. }
  121. }
  122. return headerView
  123. }
  124. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  125. return 0.000001
  126. }
  127. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  128. return nil
  129. }
  130. }