|
@@ -0,0 +1,148 @@
|
|
|
+//
|
|
|
+// ProductCartHotSaleCollectionCell.swift
|
|
|
+// RainbowPlanet
|
|
|
+//
|
|
|
+// Created by Christopher on 2019/5/13.
|
|
|
+// Copyright © 2019 RainbowPlanet. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+import UIKit
|
|
|
+import RxSwift
|
|
|
+import RxCocoa
|
|
|
+
|
|
|
+class ProductCartHotSaleCollectionCell: UICollectionViewCell {
|
|
|
+
|
|
|
+ let disposeBag = DisposeBag()
|
|
|
+
|
|
|
+ var hotProductModel: ProductSearchModel? {
|
|
|
+ didSet {
|
|
|
+ iconImagView.kf.setImage(with: kURLImage(name: hotProductModel?.img ?? "pic_preload"), placeholder: kImage(name: "pic_preload"))
|
|
|
+ titleLabel.text = hotProductModel?.saleName
|
|
|
+ sellNumberLabel.text = "已售\(hotProductModel?.totalCount ?? 0)件"
|
|
|
+ sellPriceLabel.text = "¥\(hotProductModel?.price ?? 0)"
|
|
|
+ let attrString = NSMutableAttributedString(string:"¥\(hotProductModel?.originPrice ?? 0)")
|
|
|
+ attrString.changeStrikethrough(atAllStyle: NSUnderlineStyle.single, color: kbbbbbbColor)
|
|
|
+ markPriceLabel.attributedText = attrString
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ class func cellWith(collectionView:UICollectionView,indexPath:IndexPath) -> ProductCartHotSaleCollectionCell {
|
|
|
+ let ID = "ProductCartHotSaleCollectionCell"
|
|
|
+ collectionView.register(ProductCartHotSaleCollectionCell.self, forCellWithReuseIdentifier: ID)
|
|
|
+ let cell : ProductCartHotSaleCollectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: ID, for: indexPath) as! ProductCartHotSaleCollectionCell
|
|
|
+ cell.indexPath = indexPath
|
|
|
+ return cell
|
|
|
+ }
|
|
|
+ //MARK: - indexPath
|
|
|
+ var indexPath: IndexPath?{
|
|
|
+ didSet {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //MARK: - 初始化
|
|
|
+ override init(frame: CGRect) {
|
|
|
+ super.init(frame: frame)
|
|
|
+ backgroundColor = UIColor.white
|
|
|
+ cornerRadius = 4
|
|
|
+ masksToBounds = true
|
|
|
+ setupViews()
|
|
|
+ setupLayouts()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ required init?(coder aDecoder: NSCoder) {
|
|
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
+ }
|
|
|
+
|
|
|
+ //MRAK: - 设置View
|
|
|
+ private func setupViews() {
|
|
|
+ addSubview(iconImagView)
|
|
|
+ addSubview(titleLabel)
|
|
|
+ addSubview(sellNumberLabel)
|
|
|
+ addSubview(sellPriceLabel)
|
|
|
+ addSubview(markPriceLabel)
|
|
|
+ addSubview(plusButton)
|
|
|
+ }
|
|
|
+
|
|
|
+ private func setupLayouts() {
|
|
|
+ iconImagView.snp.makeConstraints { (make) in
|
|
|
+ make.top.left.right.equalToSuperview()
|
|
|
+ make.height.equalTo(150 * kScaleWidth)
|
|
|
+ }
|
|
|
+ titleLabel.snp.makeConstraints { (make) in
|
|
|
+ make.left.equalTo(10)
|
|
|
+ make.top.equalTo(iconImagView.snp.bottom).offset(10)
|
|
|
+ make.right.equalTo(-10)
|
|
|
+ make.height.equalTo(23)
|
|
|
+ }
|
|
|
+ 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(-10)
|
|
|
+ make.height.equalTo(19)
|
|
|
+ }
|
|
|
+ markPriceLabel.snp.remakeConstraints { (make) in
|
|
|
+ make.left.equalTo(sellPriceLabel.snp.right).offset(5)
|
|
|
+ make.centerY.equalTo(sellPriceLabel)
|
|
|
+ make.height.equalTo(13)
|
|
|
+ }
|
|
|
+ plusButton.snp.makeConstraints { (make) in
|
|
|
+ make.right.equalTo(-10)
|
|
|
+ make.bottom.equalTo(-10)
|
|
|
+ make.size.equalTo(25)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private lazy var iconImagView: UIImageView = {
|
|
|
+ let iconImagView = UIImageView()
|
|
|
+ iconImagView.image = kImage(name: "pic_preload")
|
|
|
+ return iconImagView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var titleLabel: UILabel = {
|
|
|
+ let titleLabel = UILabel()
|
|
|
+ titleLabel.textColor = k333333Color
|
|
|
+ titleLabel.font = kScaleMediumFont15
|
|
|
+ titleLabel.textAlignment = .left
|
|
|
+ titleLabel.numberOfLines = 1
|
|
|
+ return titleLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var sellNumberLabel: UILabel = {
|
|
|
+ let sellNumberLabel = UILabel()
|
|
|
+ sellNumberLabel.textColor = k999999Color
|
|
|
+ sellNumberLabel.font = kScaleRegularFont12
|
|
|
+ return sellNumberLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var sellPriceLabel: UILabel = {
|
|
|
+ let sellPriceLabel = UILabel()
|
|
|
+ sellPriceLabel.textColor = kfe352bColor
|
|
|
+ sellPriceLabel.font = kScaleBoldFont15
|
|
|
+ sellPriceLabel.textAlignment = .left
|
|
|
+ return sellPriceLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var markPriceLabel: UILabel = {
|
|
|
+ let markPriceLabel = UILabel()
|
|
|
+ markPriceLabel.textColor = kbbbbbbColor
|
|
|
+ markPriceLabel.font = kScaleRegularFont13
|
|
|
+ return markPriceLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var plusButton: UIButton = {
|
|
|
+ let plusButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ plusButton.setImage(kImage(name: "shopping_mall_plus"), for: UIControl.State.normal)
|
|
|
+ plusButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
+ print("添加购物车")
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+
|
|
|
+ return plusButton
|
|
|
+ }()
|
|
|
+
|
|
|
+}
|