// // UserPayMentSheet.swift // ADHTuanCan // // Created by 敖德亨 on 2023/11/4. // import UIKit import SwiftyUserDefaults class UserPayMentSheet: UIView { @IBOutlet weak var blackView: UIView! @IBOutlet weak var tableView: UITableView! @IBOutlet weak var contentHeight: NSLayoutConstraint! @IBOutlet weak var priceLab: UILabel! /// hud 提示 lazy var hud : MCHud! = { return MCHud() }() var dataSource : [PayMentTypeModel]? /// 支付方式Model var payMentModel : PayMentTypeModel? var payTypeBlock : ((_ model : PayMentTypeModel)->Void)? var payTypeSelectBlock : ((_ model : PayMentTypeModel)->Void)? override func awakeFromNib() { super.awakeFromNib() self.tableView.register(withType: payMentItemCell.self) } func configDataSource(dataSource : [PayMentTypeModel]?){ self.dataSource = dataSource self.tableView.reloadData() self.contentHeight.constant = 334 - 100 + 50 * CGFloat(self.dataSource?.count ?? 0) } func getPayConfiguration(){ if self.payTypeSelectBlock != nil{ self.payTypeSelectBlock!(self.payMentModel!) } } public func show(){ kAppDelegateWindow.addSubview(self) self.blackView.alpha = 0 self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT) UIView.animate(withDuration: 0.5) { self.frame = CGRect.init(x: 0, y: 0, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT) self.layoutIfNeeded() } DELAY(0.5) { self.blackView.alpha = 0.3 } } /// 隐藏 public func hidden(){ self.blackView.alpha = 0 UIView.animate(withDuration: 0.5) { self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT) self.layoutIfNeeded() } DELAY(0.5) { self.removeFromSuperview() } } @IBAction func hiddenAction(_ sender: UIButton) { self.hidden() } @IBAction func saveAction(_ sender: UIButton) { if self.payMentModel != nil{ if self.payTypeBlock != nil{ self.payTypeBlock!(self.payMentModel!) } self.hidden() }else{ self.hud.showFailure(LanguagesUtil.createTextBy(Ctext: "请选择支付方式", Etext: "Please select a payment method")) return } } } extension UserPayMentSheet : UITableViewDelegate,UITableViewDataSource{ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.dataSource?.count ?? 0 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "payMentItemCell") as! payMentItemCell let model : PayMentTypeModel = self.dataSource![indexPath.row] cell.configPayMentModel(model: model) return cell } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 0.01 } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { for item in self.dataSource! { let model : PayMentTypeModel = item model.isSelect = false } let senderModel : PayMentTypeModel = self.dataSource![indexPath.row] senderModel.isSelect = true self.payMentModel = senderModel self.tableView.reloadData() } func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { return 0.01 } }