SaleDetailView.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // SaleDetailView.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/12/21.
  6. //
  7. import UIKit
  8. class SaleDetailView: UIView {
  9. @IBOutlet weak var contentHeight: NSLayoutConstraint!
  10. @IBOutlet weak var tableView: UITableView!
  11. @IBOutlet weak var blackView: UIView!
  12. /// 原价
  13. @IBOutlet weak var OldPrice: UILabel!
  14. /// 优惠金额
  15. @IBOutlet weak var saleMoney: UILabel!
  16. var model : ShopCarPriceDetailModel!
  17. var dataSource : [SaleDetailModel]?
  18. override func awakeFromNib() {
  19. super.awakeFromNib()
  20. self.tableView.register(withType: SaleDetailViewCellTableViewCell.self)
  21. }
  22. func configModel(model : ShopCarPriceDetailModel){
  23. self.dataSource = model.mealPriceMsgs
  24. self.OldPrice.text = "S$\(model.originalPrice ?? "")"
  25. self.saleMoney.text = "S$\(model.discountAmount ?? "")"
  26. if (self.dataSource?.count ?? 0) > 0{
  27. if (self.dataSource?.count ?? 0) > 4{
  28. self.contentHeight.constant = 220 - 60 + 44 * 5
  29. }else{
  30. self.contentHeight.constant = CGFloat(220 - 60 + 44 * (self.dataSource?.count ?? 0))
  31. }
  32. }else{
  33. self.contentHeight.constant = 300
  34. }
  35. self.tableView.reloadData()
  36. }
  37. public func showWith(model : ShopCarPriceDetailModel?){
  38. self.model = model
  39. self.configModel(model: self.model)
  40. kAppDelegateWindow.addSubview(self)
  41. self.blackView.alpha = 0
  42. self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  43. UIView.animate(withDuration: 0.5) {
  44. self.frame = CGRect.init(x: 0, y: 0, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  45. self.layoutIfNeeded()
  46. }
  47. DELAY(0.5) {
  48. self.blackView.alpha = 0.3
  49. }
  50. }
  51. /// 隐藏
  52. public func hidden(){
  53. self.blackView.alpha = 0
  54. UIView.animate(withDuration: 0.5) {
  55. self.frame = CGRect.init(x: 0, y: kSCREEN_HEIGHT, width: kSCREEN_WIDTH, height: kSCREEN_HEIGHT)
  56. self.layoutIfNeeded()
  57. }
  58. DELAY(0.5) {
  59. self.removeFromSuperview()
  60. }
  61. }
  62. @IBAction func closeAction(_ sender: UIButton) {
  63. self.hidden()
  64. }
  65. }
  66. extension SaleDetailView : UITableViewDelegate,UITableViewDataSource{
  67. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  68. return self.dataSource?.count ?? 0
  69. }
  70. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  71. let cell = tableView.dequeueReusableCell(withIdentifier: "SaleDetailViewCellTableViewCell") as! SaleDetailViewCellTableViewCell
  72. let model : SaleDetailModel = self.dataSource![indexPath.row]
  73. cell.configModel(model: model)
  74. return cell
  75. }
  76. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  77. return 0.01
  78. }
  79. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  80. // for item in self.dataSource! {
  81. // let model : PaySettleTypeModel = item
  82. // model.isSelect = false
  83. // }
  84. // let senderModel : PaySettleTypeModel = self.dataSource![indexPath.row]
  85. // senderModel.isSelect = true
  86. // self.paySetModel = senderModel
  87. // self.tableView.reloadData()
  88. }
  89. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  90. return 0.01
  91. }
  92. }