PayMentSelectView.swift 3.5 KB

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