Просмотр исходного кода

商品详情 -- 头条评论图片展示

Chris лет назад: 5
Родитель
Сommit
c5448ba515

+ 1 - 2
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductAllComment/View/ProductAllCommentView.swift

@@ -128,8 +128,7 @@ extension ProductAllCommentView : UITableViewDelegate, UITableViewDataSource {
         return productAllCommentArray?.isEmpty ?? true ? 0 : productAllCommentArray?.count ?? 0
     }
     
-    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-        
+    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {        
         let cell = ProductDetailEvaluationListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
         cell.productCommentModel = productAllCommentArray?[indexPath.row]
         cell.frame = tableView.bounds

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

@@ -68,13 +68,11 @@ 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(collectionView.snp.bottom).offset(15)
             make.left.equalTo(avatarImagView)

+ 58 - 28
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/Cell/ProductDetailEvaluation/ProductDetailEvaluationTableViewCell.swift

@@ -10,6 +10,8 @@ import UIKit
 
 class ProductDetailEvaluationTableViewCell: UITableViewCell {
     
+    var commentImages: Array<String> = []
+    
     class func cellWith(tableView:UITableView,indexPath:IndexPath) -> ProductDetailEvaluationTableViewCell {
         let ID = "ProductDetailEvaluationTableViewCell"
         tableView.register(ProductDetailEvaluationTableViewCell.self, forCellReuseIdentifier: ID)
@@ -39,6 +41,7 @@ class ProductDetailEvaluationTableViewCell: UITableViewCell {
         addSubview(avatarImageView)
         addSubview(nickNameLabel)
         addSubview(evaluationLabel)
+        addSubview(collectionView)
     }
     
     private func setupLayouts() {
@@ -54,7 +57,13 @@ class ProductDetailEvaluationTableViewCell: UITableViewCell {
         evaluationLabel.snp.makeConstraints { (make) in
             make.top.equalTo(avatarImageView.snp.bottom).offset(5)
             make.left.equalTo(avatarImageView)
-            make.right.bottom.equalTo(-14)
+            make.right.equalTo(-14)
+        }
+        collectionView.snp.makeConstraints { (make) in
+            make.top.equalTo(evaluationLabel.snp_bottom)
+            make.left.right.equalToSuperview()
+            make.height.equalTo(200)
+            make.bottom.equalToSuperview()
         }
     }
     
@@ -82,65 +91,86 @@ class ProductDetailEvaluationTableViewCell: UITableViewCell {
         return evaluationLabel
     }()
     
-    var productCommentModel : ProductCommentModel? {
-        didSet {
-            avatarImageView.kf.setImage(with: kURLImage(name: productCommentModel?.avatar ?? "pic_preload"), placeholder: kImage(name: "pic_preload"))
-            nickNameLabel.text = productCommentModel?.username
-            let attributeString = NSMutableAttributedString(string:productCommentModel?.content ?? "")
-            attributeString.changeAllLineSpacing(2)
-            evaluationLabel.attributedText = attributeString
-        }
-    }
-    
     private lazy var collectionView: UICollectionView = {
         let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
-        collectionView.backgroundColor = UIColor.white
+        collectionView.backgroundColor = kffffffColor
         collectionView.delegate = self;
         collectionView.dataSource = self;
         collectionView.showsVerticalScrollIndicator = false
         collectionView.showsHorizontalScrollIndicator = false
-        collectionView.cornerRadius = 4
-        collectionView.masksToBounds = true
         return collectionView
     }()
     
     private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
         let collectionViewLayout = UICollectionViewFlowLayout.init()
-        collectionViewLayout.minimumLineSpacing = 7
+        collectionViewLayout.minimumLineSpacing = 10
         collectionViewLayout.minimumInteritemSpacing = 0
-        collectionViewLayout.scrollDirection = .horizontal
         return collectionViewLayout
     }()
+    
+    var productCommentModel : ProductCommentModel? {
+        didSet {
+            avatarImageView.kf.setImage(with: kURLImage(name: productCommentModel?.avatar ?? "pic_preload"), placeholder: kImage(name: "pic_preload"))
+            nickNameLabel.text = productCommentModel?.username
+            let attributeString = NSMutableAttributedString(string:productCommentModel?.content ?? "")
+            attributeString.changeAllLineSpacing(2)
+            evaluationLabel.attributedText = attributeString
+            
+            commentImages = productCommentModel?.imgs ?? []
+            if commentImages.count == 0 {
+                collectionView.snp.remakeConstraints { (make) in
+                    make.top.equalTo(evaluationLabel.snp_bottom)
+                    make.left.right.equalToSuperview()
+                    make.height.equalTo(0)
+                    make.bottom.equalToSuperview()
+                }
+            } else {
+                collectionView.reloadData()
+            }
+        }
+    }
+    
+    //加载数据
+    func reloadData() {
+        //collectionView重新加载数据
+        self.collectionView.reloadData()
+        //更新collectionView的高度约束
+        let contentSize = self.collectionView.collectionViewLayout.collectionViewContentSize
+        collectionView.snp.remakeConstraints { (make) in
+            make.top.equalTo(evaluationLabel.snp_bottom)
+            make.left.right.equalToSuperview()
+            make.height.equalTo(contentSize.height)
+            make.bottom.equalToSuperview().offset(-14)
+        }
+        self.collectionView.collectionViewLayout.invalidateLayout()
+    }
 }
 
 extension ProductDetailEvaluationTableViewCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
     func numberOfSections(in collectionView: UICollectionView) -> Int {
-        return 0
+        return 1
     }
     
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        return 0
+        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, didSelectItemAt indexPath: IndexPath) {
-//        let productSearchModel = productSearchListModel?.data?[indexPath.row]
-//        if let jumpToDetailClosure = self.jumpToDetailClosure {
-//            jumpToDetailClosure(productSearchModel?.id ?? 0, productSearchModel?.shopId ?? 0)
-//        }
-    }
-    
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
-        return CGSize(width:(kScreenWidth-30-(14*3))/4, height: (kScreenWidth-30-(14*3))/4)
+        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: 14, bottom: 10, right: 14)
+        return UIEdgeInsets(top: 10, left: 15, bottom: 0, right: 15)
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
+        
     }
     
 }

+ 3 - 2
RainbowPlanet/RainbowPlanet/Modules/ShoppingMallModule/ProductDetail/View/ProductDetailView.swift

@@ -351,8 +351,6 @@ extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
     }
     
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-        
-        
         switch indexPath.section {
         case 0:
             let cell = ProductDetailProductInfoTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
@@ -396,6 +394,9 @@ extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
         case 2:
             let cell = ProductDetailEvaluationTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
             cell.productCommentModel = productCommentListModel?.data?[indexPath.row]
+            cell.frame = tableView.bounds
+            cell.layoutIfNeeded()
+            cell.reloadData()
             return cell
         case 3:
             let cell = ProductDetailShopTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)