// // PromotionSheetView.swift // ADHTuanCan // // Created by 敖德亨 on 2023/11/8. // import UIKit class PromotionSheetView: UIView { @IBOutlet weak var blackView: UIView! @IBOutlet weak var contentHeight: NSLayoutConstraint! @IBOutlet weak var tableView: UITableView! var dataSource : [PromotionListItemModel]? override func awakeFromNib() { super.awakeFromNib() self.tableView.register(withType: BrokerageCell.self) self.tableView.ly_emptyView = LYEmptyView.emptyActionView(with: UIImage.init(named: "暂无数据"), titleStr: "暂无数据", detailStr: "", btnTitleStr: "", btnClick: {[weak self] in }) } func configModel(dataSource : [PromotionListItemModel]?){ self.dataSource = dataSource if (self.dataSource?.count ?? 0) > 0{ if (self.dataSource?.count ?? 0) > 4{ self.contentHeight.constant = 204 - 60 + 80 * 5 }else{ self.contentHeight.constant = CGFloat(204 - 60 + 80 * (self.dataSource?.count ?? 0)) } }else{ self.contentHeight.constant = 300 } self.tableView.reloadData() } @IBAction func backAction(_ sender: UIButton) { self.hidden() } @IBAction func cancelAction(_ sender: UIButton) { self.hidden() } 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() } } } extension PromotionSheetView : 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: "BrokerageCell") as! BrokerageCell cell.configPromotionModel(model: self.dataSource![indexPath.row]) return cell } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 0.01 } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { } func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { return 0.01 } }