|
@@ -0,0 +1,326 @@
|
|
|
+//
|
|
|
+// ProductDetailSkuView.swift
|
|
|
+// RainbowPlanet
|
|
|
+//
|
|
|
+// Created by 南鑫林 on 2019/5/13.
|
|
|
+// Copyright © 2019 RainbowPlanet. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+import UIKit
|
|
|
+import FWPopupView
|
|
|
+import RxSwift
|
|
|
+import RxCocoa
|
|
|
+
|
|
|
+class ProductDetailSkuView: FWPopupView {
|
|
|
+
|
|
|
+ let disposeBag = DisposeBag()
|
|
|
+
|
|
|
+
|
|
|
+ override init(frame: CGRect) {
|
|
|
+ super.init(frame: frame)
|
|
|
+ setupViews()
|
|
|
+ setupLayouts()
|
|
|
+ }
|
|
|
+
|
|
|
+ required init?(coder aDecoder: NSCoder) {
|
|
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
+ }
|
|
|
+
|
|
|
+ private func setupViews() {
|
|
|
+
|
|
|
+
|
|
|
+ addSubview(topBgView)
|
|
|
+ topBgView.addSubview(productImageView)
|
|
|
+ topBgView.addSubview(priceLabel)
|
|
|
+ topBgView.addSubview(stockLabel)
|
|
|
+ topBgView.addSubview(oneLineLabel)
|
|
|
+
|
|
|
+ addSubview(closeButton)
|
|
|
+
|
|
|
+ addSubview(sureButton)
|
|
|
+
|
|
|
+ addSubview(bottomBgView)
|
|
|
+ bottomBgView.addSubview(twoLineLabel)
|
|
|
+ bottomBgView.addSubview(buyNumberLabel)
|
|
|
+ bottomBgView.addSubview(limitLabel)
|
|
|
+
|
|
|
+ bottomBgView.addSubview(buyNumberBgView)
|
|
|
+ buyNumberBgView.addSubview(plusButton)
|
|
|
+ buyNumberBgView.addSubview(oneVLine)
|
|
|
+ buyNumberBgView.addSubview(twoVLine)
|
|
|
+ buyNumberBgView.addSubview(numberLabel)
|
|
|
+ buyNumberBgView.addSubview(reduceButton)
|
|
|
+
|
|
|
+ addSubview(collectionView)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private func setupLayouts() {
|
|
|
+
|
|
|
+ closeButton.snp.makeConstraints { (make) in
|
|
|
+ make.top.right.equalToSuperview()
|
|
|
+ make.size.equalTo(46)
|
|
|
+ }
|
|
|
+
|
|
|
+ topBgView.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalToSuperview()
|
|
|
+ make.left.equalTo(14)
|
|
|
+ make.right.equalTo(-15)
|
|
|
+ make.height.equalTo(115)
|
|
|
+ }
|
|
|
+ productImageView.snp.makeConstraints { (make
|
|
|
+ ) in
|
|
|
+ make.top.left.equalToSuperview()
|
|
|
+ make.size.equalTo(100)
|
|
|
+ }
|
|
|
+ stockLabel.snp.makeConstraints { (make) in
|
|
|
+ make.left.equalTo(productImageView.snp.right).offset(22)
|
|
|
+ make.bottom.equalTo(productImageView)
|
|
|
+ }
|
|
|
+ priceLabel.snp.makeConstraints { (make) in
|
|
|
+ make.left.equalTo(stockLabel)
|
|
|
+ make.bottom.equalTo(stockLabel.snp.top).offset(-7)
|
|
|
+ }
|
|
|
+ oneLineLabel.snp.makeConstraints { (make) in
|
|
|
+ make.bottom.left.right.equalToSuperview()
|
|
|
+ make.height.equalTo(1)
|
|
|
+ }
|
|
|
+ sureButton.snp.makeConstraints { (make) in
|
|
|
+ make.bottom.equalTo(-kSafeTabBarHeight)
|
|
|
+ make.left.right.equalToSuperview()
|
|
|
+ make.height.equalTo(50)
|
|
|
+ }
|
|
|
+ bottomBgView.snp.makeConstraints { (make) in
|
|
|
+ make.bottom.equalTo(sureButton.snp.top).offset(-13)
|
|
|
+ make.left.equalTo(14)
|
|
|
+ make.right.equalTo(-14)
|
|
|
+ make.height.equalTo(50)
|
|
|
+ }
|
|
|
+ twoLineLabel.snp.makeConstraints { (make) in
|
|
|
+ make.top.left.right.equalToSuperview()
|
|
|
+ make.height.equalTo(1)
|
|
|
+ }
|
|
|
+ buyNumberLabel.snp.makeConstraints { (make) in
|
|
|
+ make.centerY.left.equalToSuperview()
|
|
|
+ }
|
|
|
+ limitLabel.snp.makeConstraints { (make) in
|
|
|
+ make.centerY.left.equalTo(buyNumberLabel)
|
|
|
+ }
|
|
|
+
|
|
|
+ plusButton.snp.makeConstraints { (make) in
|
|
|
+ make.top.bottom.right.equalToSuperview()
|
|
|
+ make.width.equalTo(buyNumberBgView.height)
|
|
|
+ }
|
|
|
+ oneVLine.snp.makeConstraints { (make) in
|
|
|
+ make.top.bottom.equalToSuperview()
|
|
|
+ make.width.equalTo(1)
|
|
|
+ make.right.equalTo(plusButton.snp.left)
|
|
|
+ }
|
|
|
+
|
|
|
+ numberLabel.snp.makeConstraints { (make) in
|
|
|
+ make.top.bottom.equalToSuperview()
|
|
|
+ make.width.greaterThanOrEqualTo(36)
|
|
|
+ make.right.equalTo(oneVLine.snp.left)
|
|
|
+ }
|
|
|
+
|
|
|
+ twoVLine.snp.makeConstraints { (make) in
|
|
|
+ make.top.bottom.equalToSuperview()
|
|
|
+ make.width.equalTo(1)
|
|
|
+ make.right.equalTo(numberLabel.snp.left)
|
|
|
+ }
|
|
|
+ reduceButton.snp.makeConstraints { (make) in
|
|
|
+ make.top.bottom.equalToSuperview()
|
|
|
+ make.right.equalTo(twoVLine.snp.left)
|
|
|
+ make.width.equalTo(22)
|
|
|
+ }
|
|
|
+
|
|
|
+ buyNumberBgView.snp.makeConstraints { (make) in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.height.equalTo(22)
|
|
|
+ make.right.equalTo(plusButton)
|
|
|
+ make.left.equalTo(reduceButton)
|
|
|
+ }
|
|
|
+ collectionView.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(topBgView.snp.bottom)
|
|
|
+ make.bottom.equalTo(bottomBgView.snp.top)
|
|
|
+ make.left.right.equalToSuperview()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private lazy var closeButton : UIButton = {
|
|
|
+ let closeButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ closeButton.setImage(kImage(name: "common_sku_cancel"), for: UIControl.State.normal)
|
|
|
+ closeButton.rx.tap.subscribe(onNext: {
|
|
|
+ [weak self] (data) in
|
|
|
+ self?.hide()
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+ return closeButton
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var topBgView: UIView = {
|
|
|
+ let topBgView = UIView()
|
|
|
+ return topBgView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var productImageView: UIImageView = {
|
|
|
+ let productImageView = UIImageView()
|
|
|
+ productImageView.image = kImage(name: "pic_preload")
|
|
|
+ return productImageView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var priceLabel: UILabel = {
|
|
|
+ let priceLabel = UILabel()
|
|
|
+ priceLabel.text = "¥16.8"
|
|
|
+ priceLabel.textColor = kfe352bColor
|
|
|
+ priceLabel.font = kMediumFont18
|
|
|
+ return priceLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var stockLabel: UILabel = {
|
|
|
+ let stockLabel = UILabel()
|
|
|
+ stockLabel.text = "库存2300件"
|
|
|
+ stockLabel.textColor = k333333Color
|
|
|
+ stockLabel.font = kMediumFont13
|
|
|
+ return stockLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var oneLineLabel: UILabel = {
|
|
|
+ let oneLineLabel = UILabel()
|
|
|
+ oneLineLabel.backgroundColor = kf5f5f5Color
|
|
|
+ return oneLineLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var collectionView: UICollectionView = {
|
|
|
+ let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
|
|
|
+ collectionView.backgroundColor = UIColor.white
|
|
|
+ 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
|
|
|
+ collectionViewLayout.estimatedItemSize = CGSize(width: 72, height: 25)
|
|
|
+ return collectionViewLayout
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var bottomBgView: UIView = {
|
|
|
+ let bottomBgView = UIView()
|
|
|
+ return bottomBgView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var twoLineLabel: UILabel = {
|
|
|
+ let twoLineLabel = UILabel()
|
|
|
+ twoLineLabel.backgroundColor = kf5f5f5Color
|
|
|
+ return twoLineLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var buyNumberLabel: UILabel = {
|
|
|
+ let buyNumberLabel = UILabel()
|
|
|
+ buyNumberLabel.text = "购买数量"
|
|
|
+ buyNumberLabel.textColor = k333333Color
|
|
|
+ buyNumberLabel.font = kRegularFont15
|
|
|
+ return buyNumberLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var limitLabel: UILabel = {
|
|
|
+ let limitLabel = UILabel()
|
|
|
+ limitLabel.text = "(每人限购3件)"
|
|
|
+ limitLabel.textColor = k999999Color
|
|
|
+ limitLabel.font = kRegularFont13
|
|
|
+ return limitLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var buyNumberBgView: UIView = {
|
|
|
+ let buyNumberBgView = UIView()
|
|
|
+ buyNumberBgView.cornerRadius = 2
|
|
|
+ buyNumberBgView.masksToBounds = true
|
|
|
+ return buyNumberBgView
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var plusButton : UIButton = {
|
|
|
+ let plusButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ plusButton.setTitle("+", for: UIControl.State.normal)
|
|
|
+ plusButton.setTitleColor(k333333Color, for: UIControl.State.normal)
|
|
|
+ plusButton.titleLabel?.font = kMediumFont13
|
|
|
+ return plusButton
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var reduceButton : UIButton = {
|
|
|
+ let reduceButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ reduceButton.setTitle("-", for: UIControl.State.normal)
|
|
|
+ reduceButton.setTitleColor(k333333Color, for: UIControl.State.normal)
|
|
|
+ reduceButton.titleLabel?.font = kMediumFont13
|
|
|
+ return reduceButton
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var numberLabel : UILabel = {
|
|
|
+ let numberLabel = UILabel()
|
|
|
+ numberLabel.text = " 99 "
|
|
|
+ numberLabel.textColor = k333333Color
|
|
|
+ numberLabel.font = kMediumFont13
|
|
|
+ return numberLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var oneVLine: UILabel = {
|
|
|
+ let oneVLine = UILabel()
|
|
|
+ oneVLine.backgroundColor = kE6E6E6Color
|
|
|
+ return oneVLine
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var twoVLine: UILabel = {
|
|
|
+ let twoVLine = UILabel()
|
|
|
+ twoVLine.backgroundColor = kE6E6E6Color
|
|
|
+ return twoVLine
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var sureButton: UIButton = {
|
|
|
+ let sureButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ sureButton.backgroundColor = kFFA42FColor
|
|
|
+ sureButton.setTitle("确 认", for: UIControl.State.normal)
|
|
|
+ sureButton.setTitleColor(UIColor.white, for: UIControl.State.normal)
|
|
|
+ sureButton.titleLabel?.font = kRegularFont16
|
|
|
+ return sureButton
|
|
|
+ }()
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+extension ProductDetailSkuView: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
|
|
|
+ func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
|
+ return 3
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
+ return 6
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
+ let cell = ProductDetailProductSkuLabelCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
|
|
|
+ return cell
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
|
|
|
+ return UIEdgeInsets(top: 0, left: 14, bottom: 10, right: 14)
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
|
|
|
+ if kind == UICollectionView.elementKindSectionHeader {
|
|
|
+
|
|
|
+ let headerView = ProductDetailSkuSectionHeaerCollectionReusableView.headerWith(collectionView: collectionView, kind: UICollectionView.elementKindSectionHeader, indexPath: indexPath)
|
|
|
+ return headerView
|
|
|
+ }
|
|
|
+ return UICollectionReusableView()
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
|
|
|
+ return CGSize(width:kScreenWidth, height:41)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|