// // BrokerageSheetView.swift // ADHTuanCan // // Created by 敖德亨 on 2023/11/8. // import UIKit class BrokerageSheetView: UIView { @IBOutlet weak var blackView: UIView! @IBOutlet weak var tableView: UITableView! @IBOutlet weak var viewHeight: NSLayoutConstraint! var dataSource : [BrokerageListItemModel]? 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 : [BrokerageListItemModel]?){ self.dataSource = dataSource if (self.dataSource?.count ?? 0) > 0{ if (self.dataSource?.count ?? 0) > 4{ self.viewHeight.constant = 204 - 60 + 80 * 5 }else{ self.viewHeight.constant = CGFloat(204 - 60 + 80 * (self.dataSource?.count ?? 0)) } }else{ self.viewHeight.constant = 330 } self.tableView.reloadData() } 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 backViewAction(_ sender: UIButton) { self.hidden() } @IBAction func cancelAction(_ sender: UIButton) { self.hidden() } } extension BrokerageSheetView : 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.configModel(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 } }