OrderListCell.swift 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. //
  2. // OrderListCell.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/10/8.
  6. //
  7. import UIKit
  8. import SwiftyUserDefaults
  9. class OrderListCell: UITableViewCell {
  10. /// 头像
  11. @IBOutlet weak var headImh: UIImageView!
  12. /// 内容
  13. @IBOutlet weak var contentLab: UILabel!
  14. /// 状态
  15. @IBOutlet weak var typeLab: UILabel!
  16. /// 计数lab
  17. @IBOutlet weak var numCountLab: UILabel!
  18. /// 价格
  19. @IBOutlet weak var priceLab: UILabel!
  20. @IBOutlet weak var foodView1: UIView!
  21. @IBOutlet weak var foodView2: UIView!
  22. @IBOutlet weak var foodView3: UIView!
  23. @IBOutlet weak var foodView4: UIView!
  24. @IBOutlet weak var foodName1: UILabel!
  25. @IBOutlet weak var foodImg1: UIImageView!
  26. @IBOutlet weak var foodLabOne: UILabel!
  27. @IBOutlet weak var foodLab2: UILabel!
  28. @IBOutlet weak var foodImg2: UIImageView!
  29. @IBOutlet weak var foodName3: UILabel!
  30. @IBOutlet weak var foodImg3: UIImageView!
  31. @IBOutlet weak var foodName4: UILabel!
  32. @IBOutlet weak var foodImg4: UIImageView!
  33. var dataModel : OrderListModel?
  34. ///待付款
  35. @IBOutlet weak var willPayView: UIView!
  36. ///完成未评论
  37. @IBOutlet weak var commentView: UIView!
  38. ///已完成
  39. @IBOutlet weak var finishView: UIView!
  40. ///待配送 配送中
  41. @IBOutlet weak var deliveryView: UIView!
  42. /// 列表按钮点击 1去支付 ,2取消订单
  43. var callBackBlock : ((_ type : Int)->Void)?
  44. override func awakeFromNib() {
  45. super.awakeFromNib()
  46. // Initialization code
  47. }
  48. func showBtnViewWithType(type : String){
  49. //待付款
  50. if type === 1{
  51. self.willPayView.isHidden = false
  52. self.deliveryView.isHidden = true
  53. self.commentView.isHidden = true
  54. self.finishView.isHidden = true
  55. }
  56. //待接单
  57. if type === 2{
  58. self.willPayView.isHidden = true
  59. self.deliveryView.isHidden = true
  60. self.commentView.isHidden = true
  61. self.finishView.isHidden = true
  62. }
  63. //待配送
  64. if type === 3{
  65. self.willPayView.isHidden = true
  66. self.deliveryView.isHidden = false
  67. self.commentView.isHidden = true
  68. self.finishView.isHidden = true
  69. }
  70. //已完成
  71. if type === 4 || type === 5 || type === 6 || type === 7{
  72. self.willPayView.isHidden = true
  73. self.deliveryView.isHidden = true
  74. self.commentView.isHidden = true
  75. self.finishView.isHidden = false
  76. }
  77. //待评论
  78. if type === 8{
  79. self.willPayView.isHidden = true
  80. self.deliveryView.isHidden = true
  81. self.commentView.isHidden = false
  82. self.finishView.isHidden = true
  83. }
  84. }
  85. func configModel(model : OrderListModel){
  86. self.dataModel = model
  87. self.foodView4.isHidden = true
  88. if model.link == nil{
  89. self.headImh.sd_setImage(url: URL.init(string: Defaults[\.Avatar] ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
  90. }else{
  91. self.headImh.sd_setImage(url: URL.init(string: model.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
  92. }
  93. self.contentLab.text = "\(model.orderName ?? "")"
  94. self.priceLab.text = "s$\(model.orderPrice ?? "")"
  95. self.numCountLab.text = LanguagesUtil.createTextBy(Ctext: "共\(model.orderMeals?.count ?? 0)件", Etext: "total \(model.orderMeals?.count ?? 0)")
  96. self.showBtnViewWithType(type: model.status ?? "4")
  97. if model.status === 1{
  98. self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "待付款", Etext: "Wait for payment")
  99. self.typeLab.textColor = UIColor.orange
  100. }
  101. if model.status === 2{
  102. self.typeLab.text = "待接单"
  103. self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "待接单", Etext: "Waiting fo accept the order")
  104. self.typeLab.textColor = kThemeOfTextDarkColor
  105. }
  106. if model.status === 3{
  107. self.typeLab.text = "待配送"
  108. self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "待配送", Etext: "Waiting for delivery")
  109. self.typeLab.textColor = kThemeColor
  110. }
  111. if model.status === 4{
  112. self.typeLab.text = "已完成"
  113. self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "已完成", Etext: "Finished")
  114. self.typeLab.textColor = kThemeOfTextDarkColor
  115. }
  116. if model.status === 5{
  117. self.typeLab.text = "已取消"
  118. self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "已取消", Etext: "Canceled")
  119. self.typeLab.textColor = kThemeOfTextDarkColor
  120. }
  121. if model.status === 6{
  122. self.typeLab.text = "退款中"
  123. self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "退款中", Etext: "Being refunded")
  124. self.typeLab.textColor = kThemeOfTextDarkColor
  125. }
  126. if model.status === 7{
  127. self.typeLab.text = "已退款"
  128. self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "已退款", Etext: "Refunded")
  129. self.typeLab.textColor = kThemeOfTextDarkColor
  130. }
  131. if model.status === 8{
  132. //已评价
  133. self.typeLab.text = "已完成"
  134. self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "已完成", Etext: "Finished")
  135. self.typeLab.textColor = kThemeOfTextDarkColor
  136. }
  137. if model.orderMeals?.count ?? 0 > 2{
  138. self.foodLabOne.isHidden = true
  139. self.foodName1.isHidden = false
  140. self.foodView2.isHidden = false
  141. self.foodView3.isHidden = false
  142. for i in 0..<3{
  143. let item : OrderListModelItem = model.orderMeals![i]
  144. if i == 0{
  145. self.foodLabOne.text = "\(item.name ?? "")"
  146. self.foodName1.text = "\(item.name ?? "")"
  147. self.foodImg1.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
  148. }
  149. if i == 1{
  150. self.foodLab2.text = "\(item.name ?? "")"
  151. self.foodImg2.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
  152. }
  153. if i == 2{
  154. self.foodName3.text = "\(item.name ?? "")"
  155. self.foodImg3.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
  156. }
  157. }
  158. if model.orderMeals?.count ?? 0 > 3{
  159. self.foodView4.isHidden = false
  160. let item : OrderListModelItem = model.orderMeals![3]
  161. self.foodName4.text = "\(item.name ?? "")"
  162. self.foodImg4.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
  163. }
  164. }else{
  165. if model.orderMeals?.count == 1{
  166. self.foodLabOne.isHidden = false
  167. self.foodName1.isHidden = true
  168. let item : OrderListModelItem = model.orderMeals![0]
  169. self.foodLabOne.text = "\(item.name ?? "")"
  170. self.foodName1.text = "\(item.name ?? "")"
  171. self.foodImg1.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
  172. self.foodView2.isHidden = true
  173. self.foodView3.isHidden = true
  174. }
  175. if model.orderMeals?.count == 2{
  176. self.foodLabOne.isHidden = true
  177. self.foodName1.isHidden = false
  178. self.foodView2.isHidden = false
  179. self.foodView3.isHidden = true
  180. for i in 0..<2{
  181. let item : OrderListModelItem = model.orderMeals![i]
  182. if i == 0{
  183. self.foodLabOne.text = "\(item.name ?? "")"
  184. self.foodName1.text = "\(item.name ?? "")"
  185. self.foodImg1.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
  186. }
  187. if i == 1{
  188. self.foodLab2.text = "\(item.name ?? "")"
  189. self.foodImg2.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
  190. }
  191. }
  192. }
  193. if model.orderMeals?.count == 3{
  194. self.foodLabOne.isHidden = true
  195. self.foodName1.isHidden = false
  196. self.foodView2.isHidden = false
  197. self.foodView3.isHidden = false
  198. for i in 0..<3{
  199. let item : OrderListModelItem = model.orderMeals![i]
  200. if i == 0{
  201. self.foodLabOne.text = "\(item.name ?? "")"
  202. self.foodName1.text = "\(item.name ?? "")"
  203. self.foodImg1.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
  204. }
  205. if i == 1{
  206. self.foodLab2.text = "\(item.name ?? "")"
  207. self.foodImg2.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
  208. }
  209. if i == 2{
  210. self.foodName3.text = "\(item.name ?? "")"
  211. self.foodImg3.sd_setImage(url: URL.init(string: item.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
  212. }
  213. }
  214. }
  215. }
  216. }
  217. func setFoodViewDetail(){
  218. }
  219. /// 去支付
  220. /// - Parameter sender: <#sender description#>
  221. @IBAction func gotoPayAction(_ sender: UIButton) {
  222. if self.callBackBlock != nil{
  223. self.callBackBlock!(1)
  224. }
  225. }
  226. /// 取消订单
  227. /// - Parameter sender: <#sender description#>
  228. @IBAction func cancelAction(_ sender: UIButton) {
  229. if self.callBackBlock != nil{
  230. self.callBackBlock!(2)
  231. }
  232. }
  233. }