123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- //
- // 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
- }
- }
|