123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- //
- // AddEvaluateCell.swift
- // ADHTuanCan
- //
- // Created by 敖德亨 on 2023/11/10.
- //
- import UIKit
- class AddEvaluateCell: UITableViewCell {
- @IBOutlet weak var foodImg: UIImageView!
-
- @IBOutlet weak var foodName: UILabel!
-
- @IBOutlet weak var addBtnView: UIView!
- @IBOutlet weak var contentTV: UITextView!
- /// 星星按钮数组
- @IBOutlet var starBtnList: [UIButton]!
-
- @IBOutlet var deleteBtnList: [UIButton]!
- /// 添加图片Viewlist
- @IBOutlet var addImgViewList: [UIView]!
-
- @IBOutlet var foodImgIList: [UIImageView]!
-
- var dataModel : NeedEvaluateListModel?
-
- var reloadBlock : (()->Void)?
- var addImgBlock : (()->Void)?
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- self.contentTV.inputText(maxLength: 300) {
- self.dataModel?.comment = self.contentTV.text
- }
- for i in 0..<starBtnList.count{
-
- let starBtn : UIButton = starBtnList[i]
- starBtn.tag = i + 1000
- starBtn.addTarget(self, action: #selector(scoreAction(sender: )), for: .touchUpInside)
-
- }
-
-
- for i in 0..<deleteBtnList.count{
- let deleBtn : UIButton = deleteBtnList[i]
- deleBtn.tag = i + 100
- deleBtn.addTarget(self, action: #selector(deleteImgAction(sender: )), for: .touchUpInside)
- }
- }
- func configModel(model : NeedEvaluateListModel){
- self.dataModel = model
-
- //默认评分为0
- for item in starBtnList {
- let btn = item
- btn.isSelected = false
- }
-
- //默认隐藏图片
- for item in addImgViewList {
- let vview : UIView = item
- vview.isHidden = true
- }
-
-
- self.foodImg.sd_setImage(url: URL.init(string: model.link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
- self.foodName.text = "\(model.name ?? "")"
- self.contentTV.text = "\(model.comment ?? "")"
-
- //评分显示
- //设置评分5个
- var score = Int(model.score ?? "0")!
- if score > 5{
- score = 5
- }
- for i in 0..<score{
- let startBtn = starBtnList[i]
- startBtn.isSelected = true
- }
-
- //图片显示
- if let _ = model.links{
-
- if model.links!.count > 3{
- self.addBtnView.isHidden = true
- }else{
- self.addBtnView.isHidden = false
- }
-
- //设置数组不超过4个
- var ListCount = model.links!.count
- if ListCount > 3{
- ListCount = 3
- }
- for i in 0..<ListCount{
- let vview = addImgViewList[i]
- vview.isHidden = false
- let imgV = foodImgIList[i]
- let link = model.links![i]
- imgV.sd_setImage(url: URL.init(string: link ?? "") ,placeHolderImage: UIImage.init(named: "placeHolderImage"))
- }
-
- }else{
- self.addBtnView.isHidden = false
- }
-
-
- }
-
-
- /// 添加图片
- /// - Parameter sender: <#sender description#>
- @IBAction func addImgAction(_ sender: UIButton) {
- if self.addImgBlock != nil{
- self.addImgBlock!()
- }
- }
-
-
- @objc func deleteImgAction(sender : UIButton) {
-
- self.dataModel?.links?.remove(at: sender.tag - 100)
- if self.reloadBlock != nil{
- self.reloadBlock!()
- }
-
- }
-
- @objc func scoreAction(sender : UIButton){
-
- self.dataModel?.score = "\(sender.tag - 1000 + 1)"
- if self.reloadBlock != nil{
- self.reloadBlock!()
- }
- }
- }
|