// // OrderListCell.swift // ADHTuanCan // // Created by 敖德亨 on 2023/10/8. // import UIKit import SwiftyUserDefaults class OrderListCell: UITableViewCell { /// 头像 @IBOutlet weak var headImh: UIImageView! /// 内容 @IBOutlet weak var contentLab: UILabel! /// 状态 @IBOutlet weak var typeLab: UILabel! /// 计数lab @IBOutlet weak var numCountLab: UILabel! /// 价格 @IBOutlet weak var priceLab: UILabel! @IBOutlet weak var foodView1: UIView! @IBOutlet weak var foodView2: UIView! @IBOutlet weak var foodView3: UIView! @IBOutlet weak var foodView4: UIView! @IBOutlet weak var foodName1: UILabel! @IBOutlet weak var foodImg1: UIImageView! @IBOutlet weak var foodLabOne: UILabel! @IBOutlet weak var foodLab2: UILabel! @IBOutlet weak var foodImg2: UIImageView! @IBOutlet weak var foodName3: UILabel! @IBOutlet weak var foodImg3: UIImageView! @IBOutlet weak var foodName4: UILabel! @IBOutlet weak var foodImg4: UIImageView! var dataModel : OrderListModel? ///待付款 @IBOutlet weak var willPayView: UIView! ///完成未评论 @IBOutlet weak var commentView: UIView! ///已完成 @IBOutlet weak var finishView: UIView! ///待配送 配送中 @IBOutlet weak var deliveryView: UIView! /// 列表按钮点击 1去支付 ,2取消订单 var callBackBlock : ((_ type : Int)->Void)? override func awakeFromNib() { super.awakeFromNib() // Initialization code } func showBtnViewWithType(type : String){ //待付款 if type === 1{ self.willPayView.isHidden = false self.deliveryView.isHidden = true self.commentView.isHidden = true self.finishView.isHidden = true } //待接单 if type === 2{ self.willPayView.isHidden = true self.deliveryView.isHidden = true self.commentView.isHidden = true self.finishView.isHidden = true } //待配送 if type === 3{ self.willPayView.isHidden = true self.deliveryView.isHidden = false self.commentView.isHidden = true self.finishView.isHidden = true } //已完成 if type === 4 || type === 5 || type === 6 || type === 7{ self.willPayView.isHidden = true self.deliveryView.isHidden = true self.commentView.isHidden = true self.finishView.isHidden = false } //待评论 if type === 8{ self.willPayView.isHidden = true self.deliveryView.isHidden = true self.commentView.isHidden = false self.finishView.isHidden = true } } func configModel(model : OrderListModel){ self.dataModel = model self.foodView4.isHidden = true if model.link == nil{ self.headImh.sd_setImage(url: URL.init(string: Defaults[\.Avatar] ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage")) }else{ self.headImh.sd_setImage(url: URL.init(string: model.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage")) } self.contentLab.text = "\(model.orderName ?? "")" self.priceLab.text = "s$\(model.orderPrice ?? "")" self.numCountLab.text = LanguagesUtil.createTextBy(Ctext: "共\(model.orderMeals?.count ?? 0)件", Etext: "total \(model.orderMeals?.count ?? 0)") self.showBtnViewWithType(type: model.status ?? "4") if model.status === 1{ self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "待付款", Etext: "Wait for payment") self.typeLab.textColor = UIColor.orange } if model.status === 2{ self.typeLab.text = "待接单" self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "待接单", Etext: "Waiting fo accept the order") self.typeLab.textColor = kThemeOfTextDarkColor } if model.status === 3{ self.typeLab.text = "待配送" self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "待配送", Etext: "Waiting for delivery") self.typeLab.textColor = kThemeColor } if model.status === 4{ self.typeLab.text = "已完成" self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "已完成", Etext: "Finished") self.typeLab.textColor = kThemeOfTextDarkColor } if model.status === 5{ self.typeLab.text = "已取消" self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "已取消", Etext: "Canceled") self.typeLab.textColor = kThemeOfTextDarkColor } if model.status === 6{ self.typeLab.text = "退款中" self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "退款中", Etext: "Being refunded") self.typeLab.textColor = kThemeOfTextDarkColor } if model.status === 7{ self.typeLab.text = "已退款" self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "已退款", Etext: "Refunded") self.typeLab.textColor = kThemeOfTextDarkColor } if model.status === 8{ //已评价 self.typeLab.text = "已完成" self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "已完成", Etext: "Finished") self.typeLab.textColor = kThemeOfTextDarkColor } if model.orderMeals?.count ?? 0 > 2{ self.foodLabOne.isHidden = true self.foodName1.isHidden = false self.foodView2.isHidden = false self.foodView3.isHidden = false for i in 0..<3{ let item : OrderListModelItem = model.orderMeals![i] if i == 0{ self.foodLabOne.text = "\(item.name ?? "")" self.foodName1.text = "\(item.name ?? "")" self.foodImg1.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage")) } if i == 1{ self.foodLab2.text = "\(item.name ?? "")" self.foodImg2.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage")) } if i == 2{ self.foodName3.text = "\(item.name ?? "")" self.foodImg3.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage")) } } if model.orderMeals?.count ?? 0 > 3{ self.foodView4.isHidden = false let item : OrderListModelItem = model.orderMeals![3] self.foodName4.text = "\(item.name ?? "")" self.foodImg4.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage")) } }else{ if model.orderMeals?.count == 1{ self.foodLabOne.isHidden = false self.foodName1.isHidden = true let item : OrderListModelItem = model.orderMeals![0] self.foodLabOne.text = "\(item.name ?? "")" self.foodName1.text = "\(item.name ?? "")" self.foodImg1.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage")) self.foodView2.isHidden = true self.foodView3.isHidden = true } if model.orderMeals?.count == 2{ self.foodLabOne.isHidden = true self.foodName1.isHidden = false self.foodView2.isHidden = false self.foodView3.isHidden = true for i in 0..<2{ let item : OrderListModelItem = model.orderMeals![i] if i == 0{ self.foodLabOne.text = "\(item.name ?? "")" self.foodName1.text = "\(item.name ?? "")" self.foodImg1.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage")) } if i == 1{ self.foodLab2.text = "\(item.name ?? "")" self.foodImg2.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage")) } } } if model.orderMeals?.count == 3{ self.foodLabOne.isHidden = true self.foodName1.isHidden = false self.foodView2.isHidden = false self.foodView3.isHidden = false for i in 0..<3{ let item : OrderListModelItem = model.orderMeals![i] if i == 0{ self.foodLabOne.text = "\(item.name ?? "")" self.foodName1.text = "\(item.name ?? "")" self.foodImg1.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage")) } if i == 1{ self.foodLab2.text = "\(item.name ?? "")" self.foodImg2.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage")) } if i == 2{ self.foodName3.text = "\(item.name ?? "")" self.foodImg3.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage")) } } } } } func setFoodViewDetail(){ } /// 去支付 /// - Parameter sender: <#sender description#> @IBAction func gotoPayAction(_ sender: UIButton) { if self.callBackBlock != nil{ self.callBackBlock!(1) } } /// 取消订单 /// - Parameter sender: <#sender description#> @IBAction func cancelAction(_ sender: UIButton) { if self.callBackBlock != nil{ self.callBackBlock!(2) } } }