|
@@ -10,6 +10,8 @@ import UIKit
|
|
|
|
|
|
class ProductDetailEvaluationTableViewCell: UITableViewCell {
|
|
class ProductDetailEvaluationTableViewCell: UITableViewCell {
|
|
|
|
|
|
|
|
+ var commentImages: Array<String> = []
|
|
|
|
+
|
|
class func cellWith(tableView:UITableView,indexPath:IndexPath) -> ProductDetailEvaluationTableViewCell {
|
|
class func cellWith(tableView:UITableView,indexPath:IndexPath) -> ProductDetailEvaluationTableViewCell {
|
|
let ID = "ProductDetailEvaluationTableViewCell"
|
|
let ID = "ProductDetailEvaluationTableViewCell"
|
|
tableView.register(ProductDetailEvaluationTableViewCell.self, forCellReuseIdentifier: ID)
|
|
tableView.register(ProductDetailEvaluationTableViewCell.self, forCellReuseIdentifier: ID)
|
|
@@ -39,6 +41,7 @@ class ProductDetailEvaluationTableViewCell: UITableViewCell {
|
|
addSubview(avatarImageView)
|
|
addSubview(avatarImageView)
|
|
addSubview(nickNameLabel)
|
|
addSubview(nickNameLabel)
|
|
addSubview(evaluationLabel)
|
|
addSubview(evaluationLabel)
|
|
|
|
+ addSubview(collectionView)
|
|
}
|
|
}
|
|
|
|
|
|
private func setupLayouts() {
|
|
private func setupLayouts() {
|
|
@@ -54,7 +57,13 @@ class ProductDetailEvaluationTableViewCell: UITableViewCell {
|
|
evaluationLabel.snp.makeConstraints { (make) in
|
|
evaluationLabel.snp.makeConstraints { (make) in
|
|
make.top.equalTo(avatarImageView.snp.bottom).offset(5)
|
|
make.top.equalTo(avatarImageView.snp.bottom).offset(5)
|
|
make.left.equalTo(avatarImageView)
|
|
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
|
|
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 = {
|
|
private lazy var collectionView: UICollectionView = {
|
|
let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
|
|
let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
|
|
- collectionView.backgroundColor = UIColor.white
|
|
|
|
|
|
+ collectionView.backgroundColor = kffffffColor
|
|
collectionView.delegate = self;
|
|
collectionView.delegate = self;
|
|
collectionView.dataSource = self;
|
|
collectionView.dataSource = self;
|
|
collectionView.showsVerticalScrollIndicator = false
|
|
collectionView.showsVerticalScrollIndicator = false
|
|
collectionView.showsHorizontalScrollIndicator = false
|
|
collectionView.showsHorizontalScrollIndicator = false
|
|
- collectionView.cornerRadius = 4
|
|
|
|
- collectionView.masksToBounds = true
|
|
|
|
return collectionView
|
|
return collectionView
|
|
}()
|
|
}()
|
|
|
|
|
|
private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
|
|
private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
|
|
let collectionViewLayout = UICollectionViewFlowLayout.init()
|
|
let collectionViewLayout = UICollectionViewFlowLayout.init()
|
|
- collectionViewLayout.minimumLineSpacing = 7
|
|
|
|
|
|
+ collectionViewLayout.minimumLineSpacing = 10
|
|
collectionViewLayout.minimumInteritemSpacing = 0
|
|
collectionViewLayout.minimumInteritemSpacing = 0
|
|
- collectionViewLayout.scrollDirection = .horizontal
|
|
|
|
return collectionViewLayout
|
|
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 {
|
|
extension ProductDetailEvaluationTableViewCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
|
|
func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
- return 0
|
|
|
|
|
|
+ return 1
|
|
}
|
|
}
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
- return 0
|
|
|
|
|
|
+ return commentImages.count
|
|
}
|
|
}
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = ProductDetailEvaluationImageCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
|
|
let cell = ProductDetailEvaluationImageCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
|
|
-
|
|
|
|
|
|
+ cell.imageUrl = commentImages[indexPath.row]
|
|
return cell
|
|
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 {
|
|
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 {
|
|
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) {
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|