|
@@ -7,16 +7,22 @@
|
|
|
//
|
|
|
|
|
|
import UIKit
|
|
|
+import SwiftyJSON
|
|
|
|
|
|
class ProductDetailProductSkuTableViewCell: UITableViewCell {
|
|
|
|
|
|
var productDetailModel : ProductDetailModel? {
|
|
|
didSet {
|
|
|
-
|
|
|
+ if productDetailModel?.report?.isEmpty ?? true {
|
|
|
+ iconImageView.isHidden = true
|
|
|
+ titleLabel.isHidden = true
|
|
|
+ }else {
|
|
|
+ iconImageView.isHidden = false
|
|
|
+ titleLabel.isHidden = false
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
class func cellWith(tableView:UITableView,indexPath:IndexPath) -> ProductDetailProductSkuTableViewCell {
|
|
|
let ID = "ProductDetailProductSkuTableViewCell"
|
|
|
tableView.register(ProductDetailProductSkuTableViewCell.self, forCellReuseIdentifier: ID)
|
|
@@ -43,34 +49,82 @@ class ProductDetailProductSkuTableViewCell: UITableViewCell {
|
|
|
//MRAK: - 设置View
|
|
|
private func setupViews() {
|
|
|
self.selectionStyle = .none
|
|
|
- addSubview(topBgView)
|
|
|
- topBgView.addSubview(selectedLabel)
|
|
|
- topBgView.addSubview(skuCollectionView)
|
|
|
+ addSubview(bgView)
|
|
|
+ bgView.addSubview(skuLabel)
|
|
|
+ bgView.addSubview(skuCollectionView)
|
|
|
+ bgView.addSubview(goImageView)
|
|
|
+ bgView.addSubview(selectedLabel)
|
|
|
+
|
|
|
addSubview(iconCollectionView)
|
|
|
+ addSubview(iconImageView)
|
|
|
+ addSubview(titleLabel)
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private func setupLayouts() {
|
|
|
- topBgView.snp.makeConstraints { (make) in
|
|
|
+ bgView.snp.makeConstraints { (make) in
|
|
|
make.top.left.right.equalToSuperview()
|
|
|
- make.bottom.equalTo(skuCollectionView)
|
|
|
+ make.bottom.equalTo(iconCollectionView.snp.top)
|
|
|
}
|
|
|
- skuCollectionView.snp.makeConstraints { (make) in
|
|
|
- make.top.right.equalToSuperview()
|
|
|
- make.width.equalTo(kScreenWidth - 54)
|
|
|
- make.height.equalTo(44)
|
|
|
+
|
|
|
+
|
|
|
+ goImageView.snp.makeConstraints { (make) in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.right.equalTo(-14)
|
|
|
}
|
|
|
+
|
|
|
selectedLabel.snp.makeConstraints { (make) in
|
|
|
make.centerY.equalToSuperview()
|
|
|
make.left.equalTo(14)
|
|
|
}
|
|
|
+
|
|
|
+ skuLabel.snp.makeConstraints { (make) in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.left.equalTo(selectedLabel.snp.right).offset(27)
|
|
|
+ }
|
|
|
+
|
|
|
+ skuCollectionView.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalToSuperview()
|
|
|
+ make.right.equalTo(goImageView.snp.left).offset(-10)
|
|
|
+ make.left.equalTo(selectedLabel.snp.right).offset(20)
|
|
|
+ make.height.equalTo(44)
|
|
|
+ }
|
|
|
+
|
|
|
iconCollectionView.snp.makeConstraints { (make) in
|
|
|
- make.top.equalTo(skuCollectionView.snp.bottom)
|
|
|
+ make.top.equalTo(bgView.snp.bottom)
|
|
|
make.height.equalTo(75)
|
|
|
- make.left.right.equalTo(0)
|
|
|
+ make.left.equalTo(0)
|
|
|
+ make.width.equalTo(4*(kScreenWidth/5))
|
|
|
+ }
|
|
|
+ iconImageView.snp.remakeConstraints { (make) in
|
|
|
+ make.top.equalTo(bgView.snp.bottom).offset(10)
|
|
|
+ make.left.equalTo(iconCollectionView.snp.right).offset(((kScreenWidth/5)-(32*kScaleWidth))/2)
|
|
|
+ make.size.equalTo(32*kScaleWidth)
|
|
|
+ }
|
|
|
+ titleLabel.snp.remakeConstraints { (make) in
|
|
|
+ make.top.equalTo(iconImageView.snp.bottom).offset(5)
|
|
|
+ make.centerX.equalTo(iconImageView)
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+ lazy var bgView : UIView = {
|
|
|
+ let bgView = UIView()
|
|
|
+ bgView.addTapGesture(1, target: self, action: #selector(tapSku))
|
|
|
+ return bgView
|
|
|
+ }()
|
|
|
+
|
|
|
+ @objc func tapSku() {
|
|
|
+ ProductDetailSkuView.productDetailSkuView(productDetailModel: productDetailModel!)
|
|
|
+ }
|
|
|
+
|
|
|
+ lazy var skuLabel: UILabel = {
|
|
|
+ let skuLabel = UILabel()
|
|
|
+ skuLabel.text = "请选择规格"
|
|
|
+ skuLabel.textColor = k333333Color
|
|
|
+ skuLabel.font = kRegularFont13
|
|
|
+ return skuLabel
|
|
|
+ }()
|
|
|
+
|
|
|
private lazy var skuCollectionView: UICollectionView = {
|
|
|
let skuCollectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: skuCollectionViewLayout)
|
|
|
skuCollectionView.backgroundColor = UIColor.white
|
|
@@ -80,6 +134,7 @@ class ProductDetailProductSkuTableViewCell: UITableViewCell {
|
|
|
skuCollectionView.showsHorizontalScrollIndicator = false
|
|
|
skuCollectionView.cornerRadius = 4
|
|
|
skuCollectionView.masksToBounds = true
|
|
|
+ skuCollectionView.isHidden = true
|
|
|
return skuCollectionView
|
|
|
}()
|
|
|
|
|
@@ -89,10 +144,25 @@ class ProductDetailProductSkuTableViewCell: UITableViewCell {
|
|
|
skuCollectionViewLayout.minimumInteritemSpacing = 0
|
|
|
skuCollectionViewLayout.estimatedItemSize = CGSize(width: 72, height: 25)
|
|
|
skuCollectionViewLayout.scrollDirection = .vertical
|
|
|
-
|
|
|
+
|
|
|
return skuCollectionViewLayout
|
|
|
}()
|
|
|
|
|
|
+ private lazy var selectedLabel : UILabel = {
|
|
|
+ let selectedLabel = UILabel()
|
|
|
+ selectedLabel.text = "选择"
|
|
|
+ selectedLabel.textColor = k999999Color
|
|
|
+ selectedLabel.font = kScaleRegularFont13
|
|
|
+ return selectedLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var goImageView: UIImageView = {
|
|
|
+ let goImageView = UIImageView()
|
|
|
+ goImageView.image = kImage(name: "my_arrows_unfold")
|
|
|
+ return goImageView
|
|
|
+ }()
|
|
|
+
|
|
|
+
|
|
|
private lazy var iconCollectionView: UICollectionView = {
|
|
|
let iconCollectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: iconCollectionViewLayout)
|
|
|
iconCollectionView.backgroundColor = UIColor.white
|
|
@@ -110,21 +180,24 @@ class ProductDetailProductSkuTableViewCell: UITableViewCell {
|
|
|
iconCollectionViewLayout.minimumLineSpacing = 0
|
|
|
iconCollectionViewLayout.minimumInteritemSpacing = 0
|
|
|
iconCollectionViewLayout.estimatedItemSize = CGSize(width: kScreenWidth/5, height: kScaleWidth * 55)
|
|
|
+// iconCollectionViewLayout.scrollDirection = .horizontal
|
|
|
return iconCollectionViewLayout
|
|
|
}()
|
|
|
-
|
|
|
- private lazy var topBgView: UIView = {
|
|
|
- let topBgView = UIView()
|
|
|
- return topBgView
|
|
|
+ lazy var iconImageView : UIImageView = {
|
|
|
+ let iconImageView = UIImageView()
|
|
|
+ iconImageView.image = kImage(name: "common_jiancebaogao")
|
|
|
+ return iconImageView
|
|
|
}()
|
|
|
- private lazy var selectedLabel : UILabel = {
|
|
|
- let selectedLabel = UILabel()
|
|
|
- selectedLabel.text = "已选"
|
|
|
- selectedLabel.textColor = k999999Color
|
|
|
- selectedLabel.font = kScaleRegularFont13
|
|
|
- return selectedLabel
|
|
|
+
|
|
|
+ lazy var titleLabel: UILabel = {
|
|
|
+ let titleLabel = UILabel()
|
|
|
+ titleLabel.text = "检测机构"
|
|
|
+ titleLabel.textColor = k333333Color
|
|
|
+ titleLabel.font = kRegularFont13
|
|
|
+ return titleLabel
|
|
|
}()
|
|
|
|
|
|
+
|
|
|
//加载数据
|
|
|
func reloadData() {
|
|
|
|
|
@@ -133,9 +206,11 @@ class ProductDetailProductSkuTableViewCell: UITableViewCell {
|
|
|
//更新collectionView的高度约束
|
|
|
let contentSize = self.skuCollectionView.collectionViewLayout.collectionViewContentSize
|
|
|
skuCollectionView.snp.remakeConstraints { (make) in
|
|
|
- make.top.right.equalToSuperview()
|
|
|
- make.width.equalTo(kScreenWidth - 74)
|
|
|
make.height.equalTo(contentSize.height)
|
|
|
+ make.top.equalToSuperview()
|
|
|
+ make.right.equalTo(goImageView.snp.left).offset(-10)
|
|
|
+ make.left.equalTo(selectedLabel.snp.right).offset(20)
|
|
|
+ make.bottom.equalTo(bgView)
|
|
|
}
|
|
|
self.skuCollectionView.collectionViewLayout.invalidateLayout()
|
|
|
|
|
@@ -144,9 +219,10 @@ class ProductDetailProductSkuTableViewCell: UITableViewCell {
|
|
|
//更新collectionView的高度约束
|
|
|
let contentSize1 = self.iconCollectionView.collectionViewLayout.collectionViewContentSize
|
|
|
iconCollectionView.snp.remakeConstraints { (make) in
|
|
|
- make.top.equalTo(skuCollectionView.snp.bottom)
|
|
|
+ make.top.equalTo(bgView.snp.bottom)
|
|
|
make.height.equalTo(contentSize1.height)
|
|
|
- make.left.right.equalTo(0)
|
|
|
+ make.left.equalTo(0)
|
|
|
+ make.width.equalTo(4*(kScreenWidth/5))
|
|
|
make.bottom.equalToSuperview()
|
|
|
}
|
|
|
self.iconCollectionView.collectionViewLayout.invalidateLayout()
|
|
@@ -160,13 +236,11 @@ extension ProductDetailProductSkuTableViewCell: UICollectionViewDelegateFlowLayo
|
|
|
}
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
-
|
|
|
if collectionView == skuCollectionView {
|
|
|
- return 10
|
|
|
+ return 3
|
|
|
}else {
|
|
|
- return 5
|
|
|
+ return 4
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
@@ -178,21 +252,11 @@ extension ProductDetailProductSkuTableViewCell: UICollectionViewDelegateFlowLayo
|
|
|
let cell = ProductDetailProductSkuIconCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
|
|
|
return cell
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
|
-// let productModels = productModelsArrays![indexPath.section]
|
|
|
-// let productModel = productModels[indexPath.row]
|
|
|
-// NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ProductDetailVC"), object: productModel)
|
|
|
+
|
|
|
}
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
|
|
|
-
|
|
|
- if collectionView == skuCollectionView {
|
|
|
- return UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 10)
|
|
|
- }else {
|
|
|
- return UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0)
|
|
|
- }
|
|
|
+ return UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0)
|
|
|
}
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
|
@@ -201,6 +265,7 @@ extension ProductDetailProductSkuTableViewCell: UICollectionViewDelegateFlowLayo
|
|
|
}else {
|
|
|
return 0
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
|
|
@@ -210,7 +275,6 @@ extension ProductDetailProductSkuTableViewCell: UICollectionViewDelegateFlowLayo
|
|
|
return 0
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
}
|