// // SaleDetailView.swift // ADHTuanCan // // Created by 敖德亨 on 2023/12/21. // import UIKit class SaleDetailView: UIView { @IBOutlet weak var contentHeight: NSLayoutConstraint! @IBOutlet weak var tableView: UITableView! @IBOutlet weak var blackView: UIView! /// 原价 @IBOutlet weak var OldPrice: UILabel! /// 优惠金额 @IBOutlet weak var saleMoney: UILabel! var model : ShopCarPriceDetailModel! var dataSource : [SaleDetailModel]? override func awakeFromNib() { super.awakeFromNib() self.tableView.register(withType: SaleDetailViewCellTableViewCell.self) } func configModel(model : ShopCarPriceDetailModel){ self.dataSource = model.mealPriceMsgs self.OldPrice.text = "S$\(model.originalPrice ?? "")" self.saleMoney.text = "S$\(model.discountAmount ?? "")" if (self.dataSource?.count ?? 0) > 0{ if (self.dataSource?.count ?? 0) > 4{ self.contentHeight.constant = 220 - 60 + 44 * 5 }else{ self.contentHeight.constant = CGFloat(220 - 60 + 44 * (self.dataSource?.count ?? 0)) } }else{ self.contentHeight.constant = 300 } self.tableView.reloadData() } public func showWith(model : ShopCarPriceDetailModel?){ self.model = model self.configModel(model: self.model) 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 closeAction(_ sender: UIButton) { self.hidden() } } extension SaleDetailView : 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: "SaleDetailViewCellTableViewCell") as! SaleDetailViewCellTableViewCell let model : SaleDetailModel = self.dataSource![indexPath.row] cell.configModel(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 : PaySettleTypeModel = item // model.isSelect = false // } // let senderModel : PaySettleTypeModel = self.dataSource![indexPath.row] // senderModel.isSelect = true // self.paySetModel = senderModel // self.tableView.reloadData() } func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { return 0.01 } }