AddEvaluateCell.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // AddEvaluateCell.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/11/10.
  6. //
  7. import UIKit
  8. class AddEvaluateCell: UITableViewCell {
  9. @IBOutlet weak var foodImg: UIImageView!
  10. @IBOutlet weak var foodName: UILabel!
  11. @IBOutlet weak var addBtnView: UIView!
  12. @IBOutlet weak var contentTV: UITextView!
  13. /// 星星按钮数组
  14. @IBOutlet var starBtnList: [UIButton]!
  15. @IBOutlet var deleteBtnList: [UIButton]!
  16. /// 添加图片Viewlist
  17. @IBOutlet var addImgViewList: [UIView]!
  18. @IBOutlet var foodImgIList: [UIImageView]!
  19. var dataModel : NeedEvaluateListModel?
  20. var reloadBlock : (()->Void)?
  21. var addImgBlock : (()->Void)?
  22. override func awakeFromNib() {
  23. super.awakeFromNib()
  24. self.contentTV.inputText(maxLength: 300) {
  25. self.dataModel?.comment = self.contentTV.text
  26. }
  27. for i in 0..<starBtnList.count{
  28. let starBtn : UIButton = starBtnList[i]
  29. starBtn.tag = i + 1000
  30. starBtn.addTarget(self, action: #selector(scoreAction(sender: )), for: .touchUpInside)
  31. }
  32. for i in 0..<deleteBtnList.count{
  33. let deleBtn : UIButton = deleteBtnList[i]
  34. deleBtn.tag = i + 100
  35. deleBtn.addTarget(self, action: #selector(deleteImgAction(sender: )), for: .touchUpInside)
  36. }
  37. }
  38. func configModel(model : NeedEvaluateListModel){
  39. self.dataModel = model
  40. //默认评分为0
  41. for item in starBtnList {
  42. let btn = item
  43. btn.isSelected = false
  44. }
  45. //默认隐藏图片
  46. for item in addImgViewList {
  47. let vview : UIView = item
  48. vview.isHidden = true
  49. }
  50. self.foodImg.sd_setImage(url: URL.init(string: model.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
  51. self.foodName.text = "\(model.name ?? "")"
  52. self.contentTV.text = "\(model.comment ?? "")"
  53. //评分显示
  54. //设置评分5个
  55. var score = Int(model.score ?? "0")!
  56. if score > 5{
  57. score = 5
  58. }
  59. for i in 0..<score{
  60. let startBtn = starBtnList[i]
  61. startBtn.isSelected = true
  62. }
  63. //图片显示
  64. if let _ = model.links{
  65. if model.links!.count > 3{
  66. self.addBtnView.isHidden = true
  67. }else{
  68. self.addBtnView.isHidden = false
  69. }
  70. //设置数组不超过4个
  71. var ListCount = model.links!.count
  72. if ListCount > 3{
  73. ListCount = 3
  74. }
  75. for i in 0..<ListCount{
  76. let vview = addImgViewList[i]
  77. vview.isHidden = false
  78. let imgV = foodImgIList[i]
  79. let link = model.links![i]
  80. imgV.sd_setImage(url: URL.init(string: link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
  81. }
  82. }else{
  83. self.addBtnView.isHidden = false
  84. }
  85. }
  86. /// 添加图片
  87. /// - Parameter sender: <#sender description#>
  88. @IBAction func addImgAction(_ sender: UIButton) {
  89. if self.addImgBlock != nil{
  90. self.addImgBlock!()
  91. }
  92. }
  93. @objc func deleteImgAction(sender : UIButton) {
  94. self.dataModel?.links?.remove(at: sender.tag - 100)
  95. if self.reloadBlock != nil{
  96. self.reloadBlock!()
  97. }
  98. }
  99. @objc func scoreAction(sender : UIButton){
  100. self.dataModel?.score = "\(sender.tag - 1000 + 1)"
  101. if self.reloadBlock != nil{
  102. self.reloadBlock!()
  103. }
  104. }
  105. }