MenuTableViewCell.swift 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // MenuTableViewCell.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/10/4.
  6. //
  7. import UIKit
  8. class MenuTableViewCell: UITableViewCell {
  9. @IBOutlet weak var foodImg: UIImageView!
  10. @IBOutlet weak var timeBtn: UILabel!
  11. @IBOutlet weak var headHeight: NSLayoutConstraint!
  12. @IBOutlet weak var headTyoeLab: UILabel!
  13. @IBOutlet weak var mealNameLab: UILabel!
  14. @IBOutlet var foodLabList: [UILabel]!
  15. ///数据视图
  16. @IBOutlet weak var dataView: UIView!
  17. @IBOutlet weak var priceLab: UILabel!
  18. //右滑距离 100
  19. @IBOutlet weak var slideConstant: NSLayoutConstraint!
  20. @IBOutlet weak var leftSlideConstant: NSLayoutConstraint!
  21. @IBOutlet weak var topLayerHeight: NSLayoutConstraint!
  22. ///就餐人数BTN
  23. @IBOutlet weak var peopleNumBtn: UIButton!
  24. ///减
  25. @IBAction func subtractionAction(_ sender: UIButton) {
  26. if self.dataModel?.numPeople == "1"{
  27. return
  28. }else{
  29. let str = (self.dataModel?.numPeople ?? "") -- "1"
  30. let strN = Convert.toFloat(str)
  31. let string = NSString.init(format: "%.0f", strN ?? 0)
  32. self.dataModel?.numPeople = "\(string)"
  33. peopleNumBtn.setTitle("\(string)", for: .normal)
  34. }
  35. if (self.addOrSubtractionBlock != nil)
  36. {
  37. self.addOrSubtractionBlock!(false)
  38. }
  39. }
  40. ///加
  41. @IBAction func addAction(_ sender: UIButton) {
  42. let str = (self.dataModel?.numPeople ?? "") ++ "1"
  43. let strN = Convert.toFloat(str)
  44. let string = NSString.init(format: "%.0f", strN ?? 0)
  45. self.dataModel?.numPeople = "\(string)"
  46. peopleNumBtn.setTitle("\(string)", for: .normal)
  47. if (self.addOrSubtractionBlock != nil)
  48. {
  49. self.addOrSubtractionBlock!(true)
  50. }
  51. }
  52. var selectTimeActionBlock : (()->Void)?
  53. @IBAction func selectTimeAction(_ sender: UIButton) {
  54. if self.selectTimeActionBlock != nil{
  55. self.selectTimeActionBlock!()
  56. }
  57. }
  58. @IBAction func peopleNumAction(_ sender: UIButton) {
  59. if (self.inPutNumBlock != nil)
  60. {
  61. self.inPutNumBlock!()
  62. }
  63. }
  64. /// 减少或增多 true + , false -
  65. var addOrSubtractionBlock : ((Bool)->Void)?
  66. var inPutNumBlock : (()->Void)?
  67. var deleteBlock : (()->Void)?
  68. var dataModel : ShopMealMsgDetailModel?
  69. override func awakeFromNib() {
  70. super.awakeFromNib()
  71. // Initialization code
  72. // self.headTyoeLab.text = ""
  73. // self.topLayerHeight.constant = 0
  74. }
  75. @IBAction func deleteAction(_ sender: UIButton) {
  76. if self.deleteBlock != nil{
  77. self.deleteBlock!()
  78. }
  79. }
  80. func addLeftSlideAction(){
  81. let swipe = UISwipeGestureRecognizer(target:self, action:#selector(swipeAction(_:)))
  82. swipe.direction = .left//监听方向
  83. self.dataView.addGestureRecognizer(swipe)
  84. let swiper = UISwipeGestureRecognizer(target:self, action:#selector(swipeAction(_:)))
  85. swiper.direction = .right//监听方向
  86. self.dataView.addGestureRecognizer(swiper)
  87. }
  88. @objc func swipeAction(_ guest: UISwipeGestureRecognizer){
  89. let point = guest.location(in: self.dataView)
  90. if guest.direction == .left{
  91. UIView.animate(withDuration: 0.2) {
  92. self.slideConstant.constant = 100
  93. self.dataView.layoutIfNeeded()
  94. self.leftSlideConstant.constant = -100
  95. self.dataView.layoutIfNeeded()
  96. }
  97. }
  98. if guest.direction == .right{
  99. UIView.animate(withDuration: 0.2) {
  100. self.slideConstant.constant = 0
  101. self.dataView.layoutIfNeeded()
  102. self.leftSlideConstant.constant = 0
  103. self.dataView.layoutIfNeeded()
  104. }
  105. }
  106. }
  107. func configModel(model : ShopMealMsgDetailModel? , isfirstLine : Bool){
  108. self.dataModel = model
  109. self.headTyoeLab.text = "\(model?.supplyType ?? "")"
  110. self.mealNameLab.text = "\(model?.name ?? "")"
  111. self.foodImg.sd_setImage(url: URL.init(string: model?.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
  112. if isfirstLine{
  113. self.mealNameLab.isHidden = false
  114. headHeight.constant = 30
  115. }else{
  116. self.mealNameLab.isHidden = true
  117. headHeight.constant = 0
  118. }
  119. for item in self.foodLabList {
  120. item.text = ""
  121. item.isHidden = true
  122. }
  123. if let _ = model?.mealFoodMsgs{
  124. for i in 0..<model!.mealFoodMsgs!.count{
  125. let model : MealFoodMsgModel = model!.mealFoodMsgs![i]
  126. let foodLab = self.foodLabList[i]
  127. foodLab.isHidden = false
  128. foodLab.text = "\(model.name ?? "")(\(model.comment ?? ""))"
  129. if model.comment.isEmptyStr{
  130. foodLab.text = "\(model.name ?? "")"
  131. }
  132. }
  133. }
  134. peopleNumBtn.setTitle("\(model?.numPeople ?? "0")", for: .normal)
  135. priceLab.text = "s$\(model?.price ?? "")"
  136. let star = "\(model?.deliveryStart ?? "")".prefix(5)
  137. let end = "\(model?.deliveryEnd ?? "")".prefix(5)
  138. timeBtn.text = "\(star)~\(end)"
  139. }
  140. }