|
@@ -14,11 +14,19 @@ class ShoppingCartListTableViewCell: UITableViewCell {
|
|
|
|
|
|
let disposeBag = DisposeBag()
|
|
|
|
|
|
+ // 选中商品
|
|
|
+ typealias ProductSelBlock = (_ isProductSelected: Int) -> Void
|
|
|
+ var productSelBlock : ProductSelBlock?
|
|
|
+
|
|
|
+ // 加/减购物车数量
|
|
|
typealias ChangeProductBlock = (_ id: Int,_ type : Int) -> Void
|
|
|
var changeProductBlock : ChangeProductBlock?
|
|
|
|
|
|
var productMdl : ProductModel? {
|
|
|
didSet {
|
|
|
+ // 选中状态
|
|
|
+ let selStatus = productMdl?.isSelect == 1 ? true : false
|
|
|
+ selectedButton.isSelected = selStatus
|
|
|
// 商品图片
|
|
|
iconImageView.kf.setImage(with: kURLImage(name: productMdl?.productImg ?? ""), placeholder: kImage(name: "pic_preload"))
|
|
|
// 商品名称
|
|
@@ -75,8 +83,6 @@ class ShoppingCartListTableViewCell: UITableViewCell {
|
|
|
//MRAK: - 设置View
|
|
|
private func setupViews() {
|
|
|
self.selectionStyle = .none
|
|
|
-// cornerRadius = 4
|
|
|
-// masksToBounds = true
|
|
|
|
|
|
addSubview(selectedButton)
|
|
|
addSubview(iconImageView)
|
|
@@ -88,15 +94,13 @@ class ShoppingCartListTableViewCell: UITableViewCell {
|
|
|
addSubview(plusButton)
|
|
|
addSubview(numberLabel)
|
|
|
addSubview(reduceButton)
|
|
|
-
|
|
|
}
|
|
|
|
|
|
private func setupLayouts() {
|
|
|
selectedButton.snp.makeConstraints { (make) in
|
|
|
- make.left.equalTo(10)
|
|
|
- make.top.equalTo(50)
|
|
|
- make.bottom.equalTo(-80)
|
|
|
- make.size.equalTo(18)
|
|
|
+ make.left.top.bottom.equalToSuperview()
|
|
|
+ make.width.equalTo(40)
|
|
|
+ make.height.equalTo(148)
|
|
|
}
|
|
|
iconImageView.snp.makeConstraints { (make) in
|
|
|
make.left.equalToSuperview().offset(40)
|
|
@@ -153,6 +157,14 @@ class ShoppingCartListTableViewCell: UITableViewCell {
|
|
|
let selectedButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
selectedButton.setImage(kImage(name: "common_uncheck_icon"), for: UIControl.State.normal)
|
|
|
selectedButton.setImage(kImage(name: "common_check_icon"), for: UIControl.State.selected)
|
|
|
+ selectedButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
+ selectedButton.isSelected = !selectedButton.isSelected
|
|
|
+ if let productSelBlock = self?.productSelBlock {
|
|
|
+ let isSel: Int = selectedButton.isSelected == true ? 1 : 0
|
|
|
+ productSelBlock(isSel)
|
|
|
+ }
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+
|
|
|
return selectedButton
|
|
|
}()
|
|
|
|