Bläddra i källkod

购物车列表数据填充 -- to be continued

Chris 6 år sedan
förälder
incheckning
638d95b427

+ 5 - 6
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartList/ShoppingCartListNoneItemCell.swift

@@ -12,6 +12,8 @@ import RxCocoa
 
 class ShoppingCartListNoneItemCell: UITableViewCell {
     
+    let disposeBag = DisposeBag()
+    
     override var frame: CGRect {
         get {
             return super.frame
@@ -105,12 +107,9 @@ class ShoppingCartListNoneItemCell: UITableViewCell {
         jumpButton.titleLabel?.font = kRegularFont16
         jumpButton.cornerRadius = 18
         jumpButton.masksToBounds = true
-//        jumpButton.rx.tap.subscribe(onNext: { [weak self] (data) in
-//            //            if let forgetPasswordBlock = self?.forgetPasswordBlock {
-//            //                forgetPasswordBlock()
-//            //            }
-//            print("点击了跳转到首页")
-//        }).disposed(by: disposeBag)
+        jumpButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ChartListToHomePage"), object: nil)
+        }).disposed(by: disposeBag)
         return jumpButton
     }()
     

+ 25 - 13
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartList/ShoppingCartListTableViewCell.swift

@@ -10,6 +10,25 @@ import UIKit
 
 class ShoppingCartListTableViewCell: UITableViewCell {
     
+    var productMdl : ProductModel? {
+        didSet {
+            // 商品图片
+            iconImageView.kf.setImage(with: kURLImage(name: productMdl?.productImg ?? ""), placeholder: kImage(name: "pic_preload"))
+            // 商品名称
+            titleLabel.text = productMdl?.productName
+            // 预计配送时间
+            deliveryTime.text = "预计配送时间:次日达"
+            // 规格
+            sellScaleLabel.text = "规格:\(productMdl?.skuName ?? "")"
+            // 数量
+            sellNumberLabel.text = "x1"
+            // 价格
+            sellPriceLabel.text = "¥\(productMdl?.skuPrice ?? 0)"
+            // 数量
+            numberLabel.text = "1"
+        }
+    }
+    
     override var frame: CGRect {
         get {
             return super.frame
@@ -53,7 +72,7 @@ class ShoppingCartListTableViewCell: UITableViewCell {
 //        masksToBounds = true
         
         addSubview(selectedButton)
-        addSubview(iconImagView)
+        addSubview(iconImageView)
         addSubview(titleLabel)
         addSubview(deliveryTime)
         addSubview(sellScaleLabel)
@@ -72,13 +91,13 @@ class ShoppingCartListTableViewCell: UITableViewCell {
             make.bottom.equalTo(-80)
             make.size.equalTo(18)
         }
-        iconImagView.snp.makeConstraints { (make) in
+        iconImageView.snp.makeConstraints { (make) in
             make.left.equalToSuperview().offset(40)
             make.centerY.equalToSuperview()
             make.width.height.equalTo(92)
         }
         titleLabel.snp.makeConstraints { (make) in
-            make.left.equalTo(iconImagView.snp_right).offset(10)
+            make.left.equalTo(iconImageView.snp_right).offset(10)
             make.top.equalTo(14)
             make.right.equalTo(-26)
             make.height.equalTo(20)
@@ -130,15 +149,13 @@ class ShoppingCartListTableViewCell: UITableViewCell {
         return selectedButton
     }()
 
-    private lazy var iconImagView: UIImageView = {
-        let iconImagView = UIImageView()
-        iconImagView.image = kImage(name: "pic_preload")
-        return iconImagView
+    private lazy var iconImageView: UIImageView = {
+        let iconImageView = UIImageView()
+        return iconImageView
     }()
 
     private lazy var titleLabel: UILabel = {
         let titleLabel = UILabel()
-        titleLabel.text = "妈妈冬装外套棉袄短款"
         titleLabel.textColor = k333333Color
         titleLabel.font = kBoldFont14
         titleLabel.textAlignment = .left
@@ -148,7 +165,6 @@ class ShoppingCartListTableViewCell: UITableViewCell {
 
     private lazy var deliveryTime: UILabel = {
         let deliveryTime = UILabel()
-        deliveryTime.text = "预计配送时间:次日达"
         deliveryTime.textColor = k666666Color
         deliveryTime.font = kRegularFont12
         deliveryTime.textAlignment = .left
@@ -157,7 +173,6 @@ class ShoppingCartListTableViewCell: UITableViewCell {
 
     private lazy var sellScaleLabel: UILabel = {
         let sellScaleLabel = UILabel()
-        sellScaleLabel.text = "规格:3个装"
         sellScaleLabel.textColor = k999999Color
         sellScaleLabel.font = kRegularFont12
         return sellScaleLabel
@@ -165,7 +180,6 @@ class ShoppingCartListTableViewCell: UITableViewCell {
 
     private lazy var sellNumberLabel: UILabel = {
         let sellNumberLabel = UILabel()
-        sellNumberLabel.text = "x1"
         sellNumberLabel.textColor = k999999Color
         sellNumberLabel.font = kRegularFont12
         return sellNumberLabel
@@ -173,7 +187,6 @@ class ShoppingCartListTableViewCell: UITableViewCell {
 
     private lazy var sellPriceLabel: UILabel = {
         let sellPriceLabel = UILabel()
-        sellPriceLabel.text = "¥11.8"
         sellPriceLabel.textColor = kfe352bColor
         sellPriceLabel.font = kBoldFont15
         sellPriceLabel.textAlignment = .left
@@ -188,7 +201,6 @@ class ShoppingCartListTableViewCell: UITableViewCell {
 
     private lazy var numberLabel: UILabel = {
         let numberLabel = UILabel()
-        numberLabel.text = "1"
         numberLabel.textAlignment = .center
         numberLabel.font = kRegularFont14
         numberLabel.textColor = k333333Color

+ 6 - 1
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartList/ShoppingCartListTableViewHeader.swift

@@ -12,6 +12,12 @@ import RxCocoa
 
 class ShoppingCartListTableViewHeader: BaseView {
     
+    var shopName : String? {
+        didSet {
+            titleButton.setTitle(shopName, for: UIControl.State.normal)
+        }
+    }
+    
     override var frame: CGRect {
         get {
             return super.frame
@@ -50,7 +56,6 @@ class ShoppingCartListTableViewHeader: BaseView {
     
     private lazy var titleButton: UIButton = {
         let titleButton = UIButton(type: UIButton.ButtonType.custom)
-        titleButton.setTitle("彩虹星球专营", for: UIControl.State.normal)
         titleButton.setTitleColor(k333333Color, for: UIControl.State.normal)
         titleButton.setTitleColor(k666666Color, for: UIControl.State.selected)
         titleButton.setImage(UIImage.imageWithColor(color: kDisabledButtonColor), for: UIControl.State.selected)

+ 2 - 0
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartView.swift

@@ -97,6 +97,7 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
             if indexPath.section < cartListModelsArr!.count {
                 // 购物车列表Item
                 let cell = ShoppingCartListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
+                cell.productMdl = cartListModelsArr![indexPath.section].productList![indexPath.row]
                 return cell
                 
             } else {
@@ -124,6 +125,7 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
     func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
         if cartListModelsArr?.count ?? 0 > 0 && section < cartListModelsArr!.count {
             let headerView = ShoppingCartListTableViewHeader(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 48))
+            headerView.shopName = cartListModelsArr![section].shopName
             return headerView
         } else {
             return nil

+ 11 - 1
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/ViewController/ShoppingCartViewController.swift

@@ -15,19 +15,29 @@ class ShoppingCartViewController: BaseViewController {
         super.viewDidLoad()
         setupViews()
         setupLayouts()
+        
+        let operationQueue = OperationQueue.main
+        NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "ChartListToHomePage"), object: nil, queue: operationQueue) {
+            [weak self] (notification) in
+            self?.tabBarController?.selectedIndex = 0
+        }
     }
     
     override func viewWillAppear(_ animated: Bool) {
         setupData()
     }
     
+    deinit {
+        NotificationCenter.default.removeObserver(self)
+    }
+    
     override func setupViews() {
         navigationBar.title = "购物车"
         
     }
     
     override func setupLayouts() {
-        
+        self.tabBarController?.selectedIndex = 0
     }
     
     override func setupData() {