PromotionSheetView.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // PromotionSheetView.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/11/8.
  6. //
  7. import UIKit
  8. class PromotionSheetView: UIView {
  9. @IBOutlet weak var blackView: UIView!
  10. @IBOutlet weak var contentHeight: NSLayoutConstraint!
  11. @IBOutlet weak var tableView: UITableView!
  12. var dataSource : [PromotionListItemModel]?
  13. override func awakeFromNib() {
  14. super.awakeFromNib()
  15. self.tableView.register(withType: BrokerageCell.self)
  16. self.tableView.ly_emptyView = LYEmptyView.emptyActionView(with: UIImage.init(named: "暂无数据"), titleStr: "暂无数据", detailStr: "", btnTitleStr: "", btnClick: {[weak self] in
  17. })
  18. }
  19. func configModel(dataSource : [PromotionListItemModel]?){
  20. self.dataSource = dataSource
  21. if (self.dataSource?.count ?? 0) > 0{
  22. if (self.dataSource?.count ?? 0) > 4{
  23. self.contentHeight.constant = 204 - 60 + 80 * 5
  24. }else{
  25. self.contentHeight.constant = CGFloat(204 - 60 + 80 * (self.dataSource?.count ?? 0))
  26. }
  27. }else{
  28. self.contentHeight.constant = 300
  29. }
  30. self.tableView.reloadData()
  31. }
  32. @IBAction func backAction(_ sender: UIButton) {
  33. self.hidden()
  34. }
  35. @IBAction func cancelAction(_ sender: UIButton) {
  36. self.hidden()
  37. }
  38. public func show(){
  39. kAppDelegateWindow.addSubview(self)
  40. self.blackView.alpha = 0
  41. self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  42. UIView.animate(withDuration: 0.5) {
  43. self.frame = CGRect.init(x: 0, y: 0, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  44. self.layoutIfNeeded()
  45. }
  46. DELAY(0.5) {
  47. self.blackView.alpha = 0.3
  48. }
  49. }
  50. /// 隐藏
  51. public func hidden(){
  52. self.blackView.alpha = 0
  53. UIView.animate(withDuration: 0.5) {
  54. self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  55. self.layoutIfNeeded()
  56. }
  57. DELAY(0.5) {
  58. self.removeFromSuperview()
  59. }
  60. }
  61. }
  62. extension PromotionSheetView : UITableViewDelegate,UITableViewDataSource{
  63. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  64. return self.dataSource?.count ?? 0
  65. }
  66. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  67. let cell = tableView.dequeueReusableCell(withIdentifier: "BrokerageCell") as! BrokerageCell
  68. cell.configPromotionModel(model: self.dataSource![indexPath.row])
  69. return cell
  70. }
  71. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  72. return 0.01
  73. }
  74. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  75. }
  76. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  77. return 0.01
  78. }
  79. }