Bladeren bron

超值热卖 -- collectionView

Chris 6 jaren geleden
bovenliggende
commit
b41acb5bc5

+ 13 - 1
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -246,6 +246,7 @@
 		BDF47D7A228271F600941AB9 /* ShoppingCartView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF47D79228271F600941AB9 /* ShoppingCartView.swift */; };
 		BDF47D7E22827C3F00941AB9 /* ProductSlidingTopBottomCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF47D7D22827C3F00941AB9 /* ProductSlidingTopBottomCollectionViewCell.swift */; };
 		BDF47D80228288F900941AB9 /* ShoppingCartAccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF47D7F228288F900941AB9 /* ShoppingCartAccountView.swift */; };
+		BDF47D822282B3D100941AB9 /* ShoppingChartHotSaleTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF47D812282B3D100941AB9 /* ShoppingChartHotSaleTableViewCell.swift */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -521,6 +522,7 @@
 		BDF47D79228271F600941AB9 /* ShoppingCartView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingCartView.swift; sourceTree = "<group>"; };
 		BDF47D7D22827C3F00941AB9 /* ProductSlidingTopBottomCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductSlidingTopBottomCollectionViewCell.swift; sourceTree = "<group>"; };
 		BDF47D7F228288F900941AB9 /* ShoppingCartAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingCartAccountView.swift; sourceTree = "<group>"; };
+		BDF47D812282B3D100941AB9 /* ShoppingChartHotSaleTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingChartHotSaleTableViewCell.swift; sourceTree = "<group>"; };
 		D469F6C3768252BCB7001EDD /* Pods_RainbowPlanet.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RainbowPlanet.framework; sourceTree = BUILT_PRODUCTS_DIR; };
 /* End PBXFileReference section */
 
@@ -2116,13 +2118,22 @@
 		BDF47D782282645900941AB9 /* View */ = {
 			isa = PBXGroup;
 			children = (
+				BDF47D832282BF4300941AB9 /* ShppingCartHotSale */,
 				BDF47D79228271F600941AB9 /* ShoppingCartView.swift */,
 				BDF47D7F228288F900941AB9 /* ShoppingCartAccountView.swift */,
-				BDF47D7D22827C3F00941AB9 /* ProductSlidingTopBottomCollectionViewCell.swift */,
 			);
 			path = View;
 			sourceTree = "<group>";
 		};
+		BDF47D832282BF4300941AB9 /* ShppingCartHotSale */ = {
+			isa = PBXGroup;
+			children = (
+				BDF47D812282B3D100941AB9 /* ShoppingChartHotSaleTableViewCell.swift */,
+				BDF47D7D22827C3F00941AB9 /* ProductSlidingTopBottomCollectionViewCell.swift */,
+			);
+			path = ShppingCartHotSale;
+			sourceTree = "<group>";
+		};
 		FA8AAFBADE8BD144A5C36FDB /* Frameworks */ = {
 			isa = PBXGroup;
 			children = (
@@ -2613,6 +2624,7 @@
 				A7CC751F227190C5003C4F38 /* AccountSecurityViewController.swift in Sources */,
 				A7284440224DFACD00F82F30 /* InfoModel.swift in Sources */,
 				A72A72B522321DE000B21995 /* Extension+UITextView.swift in Sources */,
+				BDF47D822282B3D100941AB9 /* ShoppingChartHotSaleTableViewCell.swift in Sources */,
 				A757C92E22744ACE00226355 /* AddressManagerListModel.swift in Sources */,
 				A7541502224C5ECB002480B5 /* BaiduMapManager.swift in Sources */,
 				A757C9342274882E00226355 /* UIScrollView+MJRefreshEX.m in Sources */,

+ 1 - 1
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartView.swift

@@ -83,7 +83,7 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
             cell.reloadData()
             return cell
         case 2:
-            let cell = ShoppingMallBarChartTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+            let cell = ShoppingChartHotSaleTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
             cell.frame = tableView.bounds
             cell.layoutIfNeeded()
             cell.reloadData()

+ 64 - 25
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ProductSlidingTopBottomCollectionViewCell.swift

@@ -25,8 +25,12 @@ class ProductSlidingTopBottomCollectionViewCell: UICollectionViewCell {
     //MARK: - 初始化
     override init(frame: CGRect) {
         super.init(frame: frame)
+        backgroundColor = UIColor.white
+        cornerRadius = 4
+        masksToBounds = true
         setupViews()
         setupLayouts()
+        
     }
     
     required init?(coder aDecoder: NSCoder) {
@@ -37,40 +41,50 @@ class ProductSlidingTopBottomCollectionViewCell: UICollectionViewCell {
     private func setupViews() {
         addSubview(iconImagView)
         addSubview(titleLabel)
-        addSubview(detailTitleLabel)
+        addSubview(sellNumberLabel)
         addSubview(sellPriceLabel)
         addSubview(markPriceLabel)
         addSubview(plusButton)
+        addSubview(shopingCarButton)
     }
     
     private func setupLayouts() {
         iconImagView.snp.makeConstraints { (make) in
             make.top.left.right.equalToSuperview()
-            make.height.equalTo(120)
+            make.height.equalTo(150 * kScaleWidth)
         }
         titleLabel.snp.makeConstraints { (make) in
-            make.top.equalTo(iconImagView.snp.bottom).offset(4)
-            make.left.equalTo(5)
-            make.right.equalTo(-5)
-            make.height.equalTo(15)
+            make.left.equalTo(10)
+            make.top.equalTo(iconImagView.snp.bottom).offset(10)
+            make.right.equalTo(-10)
+            make.height.equalTo(23)
         }
-        detailTitleLabel.snp.makeConstraints { (make) in
-            make.top.equalTo(titleLabel.snp.bottom).offset(5)
-            make.right.left.equalTo(titleLabel)
-            make.height.equalTo(12)
+        sellNumberLabel.snp.makeConstraints { (make) in
+            make.top.equalTo(titleLabel.snp.bottom).offset(15)
+            make.left.right.equalTo(titleLabel)
+            make.height.equalTo(13)
         }
         sellPriceLabel.snp.remakeConstraints { (make) in
             make.left.equalTo(titleLabel)
-            make.bottom.equalTo(5)
+            make.bottom.equalTo(-10)
+            make.height.equalTo(19)
         }
         markPriceLabel.snp.remakeConstraints { (make) in
-            make.left.equalTo(sellPriceLabel.snp.right).offset(3)
-            make.bottom.equalTo(5)
+            make.left.equalTo(sellPriceLabel.snp.right).offset(5)
+            make.bottom.equalTo(-10)
+            make.height.equalTo(13)
         }
         plusButton.snp.makeConstraints { (make) in
-            make.bottom.equalTo(5)
-            make.right.equalTo(-5)
-            make.size.equalTo(22)
+            make.right.equalTo(-10)
+            make.bottom.equalTo(-10)
+            make.size.equalTo(25)
+        }
+        
+        shopingCarButton.snp.makeConstraints { (make) in
+            make.right.equalTo(-10)
+            make.bottom.equalTo(-10)
+            make.width.equalTo(100)
+            make.height.equalTo(31)
         }
         
     }
@@ -91,20 +105,19 @@ class ProductSlidingTopBottomCollectionViewCell: UICollectionViewCell {
         return titleLabel
     }()
     
-    private lazy var detailTitleLabel: UILabel = {
-        let detailTitleLabel = UILabel()
-        detailTitleLabel.text = "酸甜可口营养无限"
-        detailTitleLabel.textColor = k999999Color
-        detailTitleLabel.font = kScaleRegularFont12
-        detailTitleLabel.textAlignment = .left
-        return detailTitleLabel
+    private lazy var sellNumberLabel: UILabel = {
+        let sellNumberLabel = UILabel()
+        sellNumberLabel.text = "已售2400件"
+        sellNumberLabel.textColor = k999999Color
+        sellNumberLabel.font = kScaleRegularFont12
+        return sellNumberLabel
     }()
     
     private lazy var sellPriceLabel: UILabel = {
         let sellPriceLabel = UILabel()
         sellPriceLabel.text = "¥11.8"
         sellPriceLabel.textColor = kfe352bColor
-        sellPriceLabel.font = kScaleBoldFont14
+        sellPriceLabel.font = kScaleBoldFont15
         sellPriceLabel.textAlignment = .left
         return sellPriceLabel
     }()
@@ -113,7 +126,7 @@ class ProductSlidingTopBottomCollectionViewCell: UICollectionViewCell {
         let markPriceLabel = UILabel()
         markPriceLabel.text = "¥24.4"
         markPriceLabel.textColor = kbbbbbbColor
-        markPriceLabel.font = kScaleRegularFont11
+        markPriceLabel.font = kScaleRegularFont13
         let attrString = NSMutableAttributedString(string: "¥24.4")
         attrString.changeStrikethrough(atAllStyle: NSUnderlineStyle.single, color: kbbbbbbColor)
         markPriceLabel.attributedText = attrString
@@ -126,4 +139,30 @@ class ProductSlidingTopBottomCollectionViewCell: UICollectionViewCell {
         return plusButton
     }()
     
+    private lazy var shopingCarButton: UIButton = {
+        let shopingCarButton = UIButton(type: UIButton.ButtonType.custom)
+        shopingCarButton.setTitle("加入购物车", for: UIControl.State.normal)
+        shopingCarButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
+        shopingCarButton.titleLabel?.font = kMediumFont14
+        shopingCarButton.backgroundColor = kFFAC33Color
+        shopingCarButton.cornerRadius = 31/2
+        shopingCarButton.masksToBounds = true
+        shopingCarButton.isHidden = true
+        return shopingCarButton
+    }()
+    
+    //    var productSearchModel: ProductSearchModel? {
+    //        didSet {
+    //            iconImagView.kf.setImage(with: kURLImage(name: productSearchModel?.img ?? "pic_preload"), placeholder: kImage(name: "pic_preload"))
+    //            titleLabel.text = productSearchModel?.nameSkuName
+    //            detailTitleLabel.text = productSearchModel?.saleName
+    //            sellNumberLabel.text = "已售\(productSearchModel?.totalCount ?? 0)件"
+    //            sellPriceLabel.text = "¥\(productSearchModel?.price ?? 0)"
+    //            let attributeString = NSMutableAttributedString(string:"¥\(productSearchModel?.originPrice ?? 0)")
+    //            attributeString.changeStrikethrough(atAllStyle: NSUnderlineStyle.single, color: kbbbbbbColor)
+    //            markPriceLabel.attributedText = attributeString
+    //
+    //        }
+    //    }
+    
 }

+ 137 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShppingCartHotSale/ShoppingChartHotSaleTableViewCell.swift

@@ -0,0 +1,137 @@
+//
+//  ShoppingChartHotSaleTableViewCell.swift
+//  RainbowPlanet
+//
+//  Created by Christopher on 2019/5/8.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+
+class ShoppingChartHotSaleTableViewCell: UITableViewCell {
+    
+    override var frame: CGRect {
+        get {
+            return super.frame
+        }
+        set {
+            var frame = newValue
+            frame.origin.x += 14 * kScaleWidth
+            frame.size.width -= 14 * kScaleWidth * 2
+            super.frame = frame
+        }
+    }
+    
+    class func cellWith(tableView:UITableView,indexPath:IndexPath) -> ShoppingChartHotSaleTableViewCell {
+        let ID = "ShoppingChartHotSaleTableViewCell"
+        tableView.register(ShoppingChartHotSaleTableViewCell.self, forCellReuseIdentifier: ID)
+        let cell : ShoppingChartHotSaleTableViewCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! ShoppingChartHotSaleTableViewCell
+        cell.indexPath = indexPath
+        return cell
+    }
+    
+    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
+        super.init(style: style, reuseIdentifier: reuseIdentifier)
+        setupViews()
+        setupLayouts()
+    }
+    
+    required init?(coder aDecoder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+    
+    var indexPath: IndexPath? {
+        didSet {
+            
+        }
+    }
+    //MRAK: - 设置View
+    private func setupViews() {
+        self.selectionStyle = .none
+        cornerRadius = 4
+        masksToBounds = true
+        backgroundColor = kf7f8faColor
+        addSubview(titleView)
+        addSubview(collectionView)
+    }
+    
+    private func setupLayouts() {
+        titleView.snp.remakeConstraints { (make) in
+            make.top.left.right.equalToSuperview()
+            make.height.equalTo(63)
+        }
+    }
+    
+    private lazy var titleView: UIView = {
+        let titleView = UIView()
+        
+        let titleLabel = UILabel()
+        titleLabel.textColor = k333333Color
+        titleLabel.font = kMediumFont18
+        titleLabel.text = "超值热卖"
+        titleView.addSubview(titleLabel)
+        titleLabel.snp.makeConstraints { (make) in
+            make.center.equalToSuperview()
+            make.height.equalTo(25)
+        }
+        return titleView
+    }()
+    
+    private lazy var collectionView: UICollectionView = {
+        let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
+        collectionView.backgroundColor = kf7f8faColor
+        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
+    }()
+    
+    //加载数据
+    func reloadData() {
+        
+        //collectionView重新加载数据
+        self.collectionView.reloadData()
+        //更新collectionView的高度约束
+        let contentSize = self.collectionView.collectionViewLayout.collectionViewContentSize
+        collectionView.snp.remakeConstraints { (make) in
+            make.top.equalTo(63)
+            make.left.right.equalToSuperview()
+            make.height.equalTo(contentSize.height)
+            make.bottom.equalToSuperview()
+        }
+        self.collectionView.collectionViewLayout.invalidateLayout()
+    }
+    
+}
+
+extension ShoppingChartHotSaleTableViewCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
+    func numberOfSections(in collectionView: UICollectionView) -> Int {
+        return 1
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
+        return 7
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
+        let cell = ProductSlidingTopBottomCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
+        return cell
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
+        return CGSize(width:170 * kScaleWidth, height: 170 * kScaleWidth + 80)
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
+        return UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0)
+    }
+    
+}