Selaa lähdekoodia

商品评价列表,展示图片

Chris 5 vuotta sitten
vanhempi
commit
99360cceb6

+ 3 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductAllComment/View/ProductAllCommentView.swift

@@ -132,6 +132,9 @@ extension ProductAllCommentView : UITableViewDelegate, UITableViewDataSource {
         
         let cell = ProductDetailEvaluationListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
         cell.productCommentModel = productAllCommentArray?[indexPath.row]
+        cell.frame = tableView.bounds
+        cell.layoutIfNeeded()
+        cell.reloadData()
         return cell
     }
     

+ 7 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductAllComment/View/ProductDetailEvaluationImageCollectionViewCell.swift

@@ -9,6 +9,13 @@
 import UIKit
 
 class ProductDetailEvaluationImageCollectionViewCell: UICollectionViewCell {
+    
+    var imageUrl: String? {
+        didSet {
+            iconImageView.kf.setImage(with: kURLImage(name: imageUrl ?? "pic_preload"), placeholder: kImage(name: "pic_preload"))
+        }
+    }
+    
     class func cellWith(collectionView:UICollectionView,indexPath:IndexPath) -> ProductDetailEvaluationImageCollectionViewCell {
         let ID = "ProductDetailEvaluationImageCollectionViewCell"
         collectionView.register(ProductDetailEvaluationImageCollectionViewCell.self, forCellWithReuseIdentifier: ID)

+ 83 - 2
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductAllComment/View/ProductDetailEvaluationListTableViewCell.swift

@@ -10,6 +10,8 @@ import UIKit
 
 class ProductDetailEvaluationListTableViewCell: UITableViewCell {
     
+    var commentImages: Array<String> = []
+    
     class func cellWith(tableView:UITableView,indexPath:IndexPath) -> ProductDetailEvaluationListTableViewCell {
         let ID = "ProductDetailEvaluationListTableViewCell"
         tableView.register(ProductDetailEvaluationListTableViewCell.self, forCellReuseIdentifier: ID)
@@ -36,13 +38,14 @@ class ProductDetailEvaluationListTableViewCell: UITableViewCell {
     //MRAK: - 设置View
     private func setupViews() {
         self.selectionStyle = .none
+        
         addSubview(avatarImagView)
         addSubview(nameLabel)
         addSubview(timeLabel)
         addSubview(infoLabel)
+        addSubview(collectionView)
         addSubview(skuLabel)
         addSubview(lineLabel)
-        
     }
     
     private func setupLayouts() {
@@ -65,8 +68,15 @@ class ProductDetailEvaluationListTableViewCell: UITableViewCell {
             make.left.equalTo(avatarImagView)
             make.right.equalTo(timeLabel)
         }
+        
+        collectionView.snp.makeConstraints { (make) in
+            make.top.equalTo(infoLabel.snp_bottom)
+            make.left.right.equalToSuperview()
+            make.height.equalTo(200)
+        }
+        
         skuLabel.snp.makeConstraints { (make) in
-            make.top.equalTo(infoLabel.snp.bottom).offset(15)
+            make.top.equalTo(collectionView.snp.bottom).offset(15)
             make.left.equalTo(avatarImagView)
             make.right.equalTo(timeLabel)
         }
@@ -114,6 +124,23 @@ class ProductDetailEvaluationListTableViewCell: UITableViewCell {
         return infoLabel
     }()
     
+    private lazy var collectionView: UICollectionView = {
+        let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
+        collectionView.backgroundColor = kffffffColor
+        collectionView.delegate = self;
+        collectionView.dataSource = self;
+        collectionView.showsVerticalScrollIndicator = false
+        collectionView.showsHorizontalScrollIndicator = false
+        return collectionView
+    }()
+    
+    private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
+        let collectionViewLayout = UICollectionViewFlowLayout.init()
+        collectionViewLayout.minimumLineSpacing = 10
+        collectionViewLayout.minimumInteritemSpacing = 0
+        return collectionViewLayout
+    }()
+    
     private lazy var skuLabel: UILabel = {
         let skuLabel = UILabel()
         skuLabel.text = "规格:500g"
@@ -138,7 +165,61 @@ class ProductDetailEvaluationListTableViewCell: UITableViewCell {
             infoLabel.attributedText = attributeString
             skuLabel.text = "规格:\(productCommentModel?.skuName ?? "")"
             
+            commentImages = productCommentModel?.imgs ?? []
+            if commentImages.count == 0 {
+                collectionView.snp.remakeConstraints { (make) in
+                    make.top.equalTo(infoLabel.snp_bottom)
+                    make.left.right.equalToSuperview()
+                    make.height.equalTo(0)
+                }
+            } else {
+                collectionView.reloadData()
+            }
         }
     }
+    
+    //加载数据
+    func reloadData() {
+        //collectionView重新加载数据
+        self.collectionView.reloadData()
+        //更新collectionView的高度约束
+        let contentSize = self.collectionView.collectionViewLayout.collectionViewContentSize
+        collectionView.snp.remakeConstraints { (make) in
+            make.top.equalTo(infoLabel.snp_bottom)
+            make.left.right.equalToSuperview()
+            make.height.equalTo(contentSize.height)
+            make.bottom.equalTo(skuLabel.snp_top).offset(-15)
+        }
+        self.collectionView.collectionViewLayout.invalidateLayout()
+    }
+
+}
 
+extension ProductDetailEvaluationListTableViewCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UICollectionViewDelegate {
+    func numberOfSections(in collectionView: UICollectionView) -> Int {
+        return 1
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
+        return commentImages.count
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
+        let cell = ProductDetailEvaluationImageCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
+        cell.imageUrl = commentImages[indexPath.row]
+        return cell
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
+        return CGSize(width:(kScreenWidth-30-5*3)/4, height: (kScreenWidth-30-5*3)/4)
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
+        return UIEdgeInsets(top: 10, left: 15, bottom: 0, right: 15)
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
+        
+    }
+    
 }