123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- //
- // 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..<model!.mealFoodMsgs!.count{
- let model : MealFoodMsgModel = model!.mealFoodMsgs![i]
- let foodLab = self.foodLabList[i]
- foodLab.isHidden = false
-
- foodLab.text = "\(model.name ?? "")(\(model.comment ?? ""))"
-
- if model.comment.isEmptyStr{
- foodLab.text = "\(model.name ?? "")"
- }
-
-
- }
- }
-
- peopleNumBtn.setTitle("\(model?.numPeople ?? "0")", for: .normal)
- priceLab.text = "s$\(model?.price ?? "")"
- let star = "\(model?.deliveryStart ?? "")".prefix(5)
- let end = "\(model?.deliveryEnd ?? "")".prefix(5)
- timeBtn.text = "\(star)~\(end)"
- }
- }
|