UserPayMentSheet.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // UserPayMentSheet.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/11/4.
  6. //
  7. import UIKit
  8. import SwiftyUserDefaults
  9. class UserPayMentSheet: UIView {
  10. @IBOutlet weak var blackView: UIView!
  11. @IBOutlet weak var tableView: UITableView!
  12. @IBOutlet weak var contentHeight: NSLayoutConstraint!
  13. @IBOutlet weak var priceLab: UILabel!
  14. /// hud 提示
  15. lazy var hud : MCHud! = {
  16. return MCHud()
  17. }()
  18. var dataSource : [PayMentTypeModel]?
  19. /// 支付方式Model
  20. var payMentModel : PayMentTypeModel?
  21. var payTypeBlock : ((_ model : PayMentTypeModel)->Void)?
  22. var payTypeSelectBlock : ((_ model : PayMentTypeModel)->Void)?
  23. override func awakeFromNib() {
  24. super.awakeFromNib()
  25. self.tableView.register(withType: payMentItemCell.self)
  26. }
  27. func configDataSource(dataSource : [PayMentTypeModel]?){
  28. self.dataSource = dataSource
  29. self.tableView.reloadData()
  30. self.contentHeight.constant = 334 - 100 + 50 * CGFloat(self.dataSource?.count ?? 0)
  31. }
  32. func getPayConfiguration(){
  33. if self.payTypeSelectBlock != nil{
  34. self.payTypeSelectBlock!(self.payMentModel!)
  35. }
  36. }
  37. public func show(){
  38. kAppDelegateWindow.addSubview(self)
  39. self.blackView.alpha = 0
  40. self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  41. UIView.animate(withDuration: 0.5) {
  42. self.frame = CGRect.init(x: 0, y: 0, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  43. self.layoutIfNeeded()
  44. }
  45. DELAY(0.5) {
  46. self.blackView.alpha = 0.3
  47. }
  48. }
  49. /// 隐藏
  50. public func hidden(){
  51. self.blackView.alpha = 0
  52. UIView.animate(withDuration: 0.5) {
  53. self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  54. self.layoutIfNeeded()
  55. }
  56. DELAY(0.5) {
  57. self.removeFromSuperview()
  58. }
  59. }
  60. @IBAction func hiddenAction(_ sender: UIButton) {
  61. self.hidden()
  62. }
  63. @IBAction func saveAction(_ sender: UIButton) {
  64. if self.payMentModel != nil{
  65. if self.payTypeBlock != nil{
  66. self.payTypeBlock!(self.payMentModel!)
  67. }
  68. self.hidden()
  69. }else{
  70. self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请选择支付方式", Etext: "Please select a payment method"))
  71. return
  72. }
  73. }
  74. }
  75. extension UserPayMentSheet : UITableViewDelegate,UITableViewDataSource{
  76. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  77. return self.dataSource?.count ?? 0
  78. }
  79. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  80. let cell = tableView.dequeueReusableCell(withIdentifier: "payMentItemCell") as! payMentItemCell
  81. let model : PayMentTypeModel = self.dataSource![indexPath.row]
  82. cell.configPayMentModel(model: model)
  83. return cell
  84. }
  85. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  86. return 0.01
  87. }
  88. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  89. for item in self.dataSource! {
  90. let model : PayMentTypeModel = item
  91. model.isSelect = false
  92. }
  93. let senderModel : PayMentTypeModel = self.dataSource![indexPath.row]
  94. senderModel.isSelect = true
  95. self.payMentModel = senderModel
  96. self.tableView.reloadData()
  97. }
  98. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  99. return 0.01
  100. }
  101. }