// // MenuTableViewCell.swift // ADHTuanCan // // Created by 敖德亨 on 2023/10/4. // import UIKit class MenuTableViewCell: UITableViewCell { @IBOutlet weak var foodImg: UIImageView! @IBOutlet weak var timeBtn: UILabel! @IBOutlet weak var headHeight: NSLayoutConstraint! @IBOutlet weak var headTyoeLab: UILabel! @IBOutlet weak var mealNameLab: UILabel! @IBOutlet var foodLabList: [UILabel]! ///数据视图 @IBOutlet weak var dataView: UIView! @IBOutlet weak var priceLab: UILabel! //右滑距离 100 @IBOutlet weak var slideConstant: NSLayoutConstraint! @IBOutlet weak var leftSlideConstant: NSLayoutConstraint! @IBOutlet weak var topLayerHeight: NSLayoutConstraint! ///就餐人数BTN @IBOutlet weak var peopleNumBtn: UIButton! ///减 @IBAction func subtractionAction(_ sender: UIButton) { if self.dataModel?.numPeople == "1"{ return }else{ let str = (self.dataModel?.numPeople ?? "") -- "1" let strN = Convert.toFloat(str) let string = NSString.init(format: "%.0f", strN ?? 0) self.dataModel?.numPeople = "\(string)" peopleNumBtn.setTitle("\(string)", for: .normal) } if (self.addOrSubtractionBlock != nil) { self.addOrSubtractionBlock!(false) } } ///加 @IBAction func addAction(_ sender: UIButton) { let str = (self.dataModel?.numPeople ?? "") ++ "1" let strN = Convert.toFloat(str) let string = NSString.init(format: "%.0f", strN ?? 0) self.dataModel?.numPeople = "\(string)" peopleNumBtn.setTitle("\(string)", for: .normal) if (self.addOrSubtractionBlock != nil) { self.addOrSubtractionBlock!(true) } } var selectTimeActionBlock : (()->Void)? @IBAction func selectTimeAction(_ sender: UIButton) { if self.selectTimeActionBlock != nil{ self.selectTimeActionBlock!() } } @IBAction func peopleNumAction(_ sender: UIButton) { if (self.inPutNumBlock != nil) { self.inPutNumBlock!() } } /// 减少或增多 true + , false - var addOrSubtractionBlock : ((Bool)->Void)? var inPutNumBlock : (()->Void)? var deleteBlock : (()->Void)? var dataModel : ShopMealMsgDetailModel? override func awakeFromNib() { super.awakeFromNib() // Initialization code // self.headTyoeLab.text = "" // self.topLayerHeight.constant = 0 } @IBAction func deleteAction(_ sender: UIButton) { if self.deleteBlock != nil{ self.deleteBlock!() } } func addLeftSlideAction(){ let swipe = UISwipeGestureRecognizer(target:self, action:#selector(swipeAction(_:))) swipe.direction = .left//监听方向 self.dataView.addGestureRecognizer(swipe) let swiper = UISwipeGestureRecognizer(target:self, action:#selector(swipeAction(_:))) swiper.direction = .right//监听方向 self.dataView.addGestureRecognizer(swiper) } @objc func swipeAction(_ guest: UISwipeGestureRecognizer){ let point = guest.location(in: self.dataView) if guest.direction == .left{ UIView.animate(withDuration: 0.2) { self.slideConstant.constant = 100 self.dataView.layoutIfNeeded() self.leftSlideConstant.constant = -100 self.dataView.layoutIfNeeded() } } if guest.direction == .right{ UIView.animate(withDuration: 0.2) { self.slideConstant.constant = 0 self.dataView.layoutIfNeeded() self.leftSlideConstant.constant = 0 self.dataView.layoutIfNeeded() } } } func configModel(model : ShopMealMsgDetailModel? , isfirstLine : Bool){ self.dataModel = model self.headTyoeLab.text = "\(model?.supplyType ?? "")" self.mealNameLab.text = "\(model?.name ?? "")" self.foodImg.sd_setImage(url: URL.init(string: model?.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage")) if isfirstLine{ self.mealNameLab.isHidden = false headHeight.constant = 30 }else{ self.mealNameLab.isHidden = true headHeight.constant = 0 } for item in self.foodLabList { item.text = "" item.isHidden = true } if let _ = model?.mealFoodMsgs{ for i in 0..