123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- //
- // CommonPayView.swift
- // RainbowPlanet
- //
- // Created by Christopher on 2019/5/10.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- // 支付View
- import UIKit
- import FWPopupView
- import RxSwift
- import RxCocoa
- enum PayType {
- case wechatPay
- case aliPay
- }
- class CommonPayView: FWPopupView {
-
- let disposeBag = DisposeBag()
-
- typealias DismissTransBlock = () -> Void
- var disTransBlock : DismissTransBlock?
-
- typealias ConfirmPayBlock = (_ pType: PayType) -> Void
- var confirmPayBlock : ConfirmPayBlock?
-
- var curPayType : PayType = PayType.wechatPay
-
- override init(frame: CGRect) {
- super.init(frame: frame)
-
- self.backgroundColor = kf7f8faColor
- addSubview(confirmPayBtn)
- addSubview(tableView)
-
- setupLayouts()
- }
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- func setupLayouts() {
- confirmPayBtn.snp.makeConstraints { (make) in
- make.left.right.equalToSuperview()
- make.bottom.equalTo(-kSafeTabBarHeight)
- make.height.equalTo(50)
- }
- tableView.snp.makeConstraints { (make) in
- make.left.right.top.equalToSuperview()
- make.bottom.equalTo(confirmPayBtn.snp_top).offset(-20)
- }
- }
-
- lazy var tableView: UITableView = {
- let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
- tableView.separatorStyle = .none
- tableView.backgroundColor = kf7f8faColor
- tableView.dataSource = self
- tableView.delegate = self
- tableView.estimatedRowHeight = 0.000001
- tableView.estimatedSectionFooterHeight = 0.000001
- tableView.estimatedSectionHeaderHeight = 0.000001
- return tableView
- }()
-
- private lazy var confirmPayBtn: UIButton = {
- let confirmPayBtn = UIButton(type: UIButton.ButtonType.custom)
- confirmPayBtn.backgroundColor = kFFA42FColor
- confirmPayBtn.setTitle("确认支付", for: UIControl.State.normal)
- confirmPayBtn.setTitleColor(kffffffColor, for: UIControl.State.normal)
- confirmPayBtn.titleLabel?.font = kScaleRegularFont16
- confirmPayBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
- if let confirmPayBlock = self?.confirmPayBlock {
- confirmPayBlock(self!.curPayType)
- }
- }).disposed(by: disposeBag)
- return confirmPayBtn
- }()
-
- }
- extension CommonPayView : UITableViewDelegate, UITableViewDataSource {
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return 2
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- switch indexPath.row {
- case 0:
- let cell = CommonPayCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.titleLabel.text = "微信"
- cell.iconImageView.image = kImage(name: "common_pay_wechat")
-
- if (curPayType == PayType.wechatPay) {
- cell.statusImageView.image = kImage(name: "common_check_icon")
- } else {
- cell.statusImageView.image = kImage(name: "common_uncheck_icon")
- }
-
- return cell
- case 1:
- let cell = CommonPayCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.titleLabel.text = "支付宝"
- cell.iconImageView.image = kImage(name: "common_pay_alipay")
-
- if (curPayType == PayType.aliPay) {
- cell.statusImageView.image = kImage(name: "common_check_icon")
- } else {
- cell.statusImageView.image = kImage(name: "common_uncheck_icon")
- }
-
- return cell
-
- default:
- return UITableViewCell()
- }
- }
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- if indexPath.row == 0 {
- curPayType = PayType.wechatPay
- } else {
- curPayType = PayType.aliPay
- }
- tableView.reloadData()
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 48
- }
-
- func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
- return 50
- }
-
- func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
- let headerView = CommonPayHeader(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 50))
- headerView.payAmount = 155
- headerView.dismissBlock = {
- [weak self] in
- if let disTransBlock = self?.disTransBlock {
- disTransBlock()
- }
- }
- return headerView
- }
-
- func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
- return 0.000001
- }
- func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
- return nil
- }
-
- }
|