|
@@ -1,4 +1,4 @@
|
|
|
-//
|
|
|
+
|
|
|
// ProductDetailView.swift
|
|
|
// RainbowPlanet
|
|
|
//
|
|
@@ -15,6 +15,13 @@ class ProductDetailView: BaseView {
|
|
|
typealias LookAllCommentClosure = () -> Void
|
|
|
var lookAllCommentClosure : LookAllCommentClosure?
|
|
|
|
|
|
+ typealias AddCartClosure = (ProductDetailSkuModel) -> Void
|
|
|
+ var addCartClosure : AddCartClosure?
|
|
|
+
|
|
|
+ typealias BuyNowClosure = (ProductDetailSkuModel) -> Void
|
|
|
+ var buyNowClosure : BuyNowClosure?
|
|
|
+
|
|
|
+ var productDetailSkuModel : ProductDetailSkuModel?
|
|
|
|
|
|
var titles = ["","","商品评价","","热销排行","商品参数","商品详情"]
|
|
|
|
|
@@ -27,7 +34,7 @@ class ProductDetailView: BaseView {
|
|
|
let rect = tableView.rect(forSection: reloadSection)
|
|
|
tableView.setContentOffset(CGPoint(x: 0, y: rect.origin.y - kNavBarTotalHeight), animated: true)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -39,7 +46,7 @@ class ProductDetailView: BaseView {
|
|
|
|
|
|
if productDetailModel?.commentNumber != 0 && productDetailModel?.commentNumber != nil {
|
|
|
titles[2] = "商品评价" + "(" + "\(productDetailModel?.commentNumber ?? 0)" + ")"
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
if productDetailModel?.imgs?.isEmpty ?? true {
|
|
|
tableView.tableHeaderView = nil
|
|
@@ -64,7 +71,7 @@ class ProductDetailView: BaseView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
override func setupViews() {
|
|
|
addSubview(bottomBgView)
|
|
|
bottomBgView.addSubview(cartButton)
|
|
@@ -145,9 +152,6 @@ class ProductDetailView: BaseView {
|
|
|
private lazy var cartImageView: UIImageView = {
|
|
|
let cartImageView = UIImageView()
|
|
|
cartImageView.image = kImage(name: "tabbar_shopping")
|
|
|
- cartImageView.pp.addBadge(number: 2)
|
|
|
- // shoppingCarButton.pp.setBadge(height: 14)
|
|
|
- // shoppingCarButton.pp.badgeView.font = kRegularFont10
|
|
|
cartImageView.pp.badgeView.backgroundColor = kfe352bColor
|
|
|
cartImageView.pp.moveBadge(x: -2, y: 2)
|
|
|
return cartImageView
|
|
@@ -159,6 +163,12 @@ class ProductDetailView: BaseView {
|
|
|
addCartButton.setTitleColor(UIColor.white, for: UIControl.State.normal)
|
|
|
addCartButton.backgroundColor = k404040Color
|
|
|
addCartButton.titleLabel?.font = kRegularFont16
|
|
|
+ addCartButton.rx.tap.subscribe(onNext: {
|
|
|
+ [weak self] (data) in
|
|
|
+ self?.view.productDetailSkuViewType = ProductDetailSkuViewType.addCart
|
|
|
+ self?.view.productDetailModel = self?.productDetailModel
|
|
|
+ self?.view.show()
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
return addCartButton
|
|
|
}()
|
|
|
|
|
@@ -170,7 +180,9 @@ class ProductDetailView: BaseView {
|
|
|
buyButton.titleLabel?.font = kRegularFont16
|
|
|
buyButton.rx.tap.subscribe(onNext: {
|
|
|
[weak self] (data) in
|
|
|
- ProductDetailSkuView.productDetailSkuView(productDetailModel: (self?.productDetailModel!)!)
|
|
|
+ self?.view.productDetailSkuViewType = ProductDetailSkuViewType.buyNow
|
|
|
+ self?.view.productDetailModel = self?.productDetailModel
|
|
|
+ self?.view.show()
|
|
|
}).disposed(by: disposeBag)
|
|
|
return buyButton
|
|
|
}()
|
|
@@ -184,6 +196,61 @@ class ProductDetailView: BaseView {
|
|
|
return topButton
|
|
|
}()
|
|
|
|
|
|
+
|
|
|
+ lazy var view: ProductDetailSkuView = {
|
|
|
+ let view = ProductDetailSkuView(frame: CGRect(x: 0, y: 0, width: kScreenWidth , height: kScreenHeight - 76 - kNavBarTotalHeight))
|
|
|
+ let vProperty1 = FWPopupViewProperty()
|
|
|
+ vProperty1.popupCustomAlignment = .bottomCenter
|
|
|
+ vProperty1.popupAnimationType = .frame
|
|
|
+ vProperty1.maskViewColor = UIColor(white: 0, alpha: 0.5)
|
|
|
+ vProperty1.touchWildToHide = "0"
|
|
|
+ vProperty1.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
|
|
|
+ vProperty1.animationDuration = 0.1
|
|
|
+ view.vProperty = vProperty1
|
|
|
+ view.sureClosure = {
|
|
|
+ [weak self] (productDetailSkuViewType,productDetailSkuModel) in
|
|
|
+ self?.productDetailSkuModel = productDetailSkuModel
|
|
|
+ switch productDetailSkuViewType {
|
|
|
+ case .selectSku:
|
|
|
+ self?.tableView.reloadRows(at: [IndexPath(row: 0, section: 1)], with: UITableView.RowAnimation.none)
|
|
|
+ view.hide()
|
|
|
+ break
|
|
|
+ case .buyNow:
|
|
|
+ view.hide(popupDidDisappearBlock: { (FWPopupView) in
|
|
|
+
|
|
|
+ })
|
|
|
+ break
|
|
|
+ case .addCart:
|
|
|
+
|
|
|
+ if let addCartClosure = self?.addCartClosure {
|
|
|
+ addCartClosure((self?.productDetailSkuModel)!)
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return view
|
|
|
+ }()
|
|
|
+
|
|
|
+ var cartAmountModel : CartAmountModel? {
|
|
|
+ didSet {
|
|
|
+ if cartAmountModel != nil {
|
|
|
+ self.tableView.reloadRows(at: [IndexPath(row: 0, section: 1)], with: UITableView.RowAnimation.none)
|
|
|
+ cartImageView.pp.addBadge(number: cartAmountModel?.amount ?? 0)
|
|
|
+ self.view.hide()
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var productCartCountModel : ProductCartCountModel? {
|
|
|
+ didSet {
|
|
|
+ if productCartCountModel != nil {
|
|
|
+ cartImageView.pp.addBadge(number: productCartCountModel?.count ?? 0)
|
|
|
+// self.view.hide()
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
|
|
@@ -225,7 +292,7 @@ extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
|
|
|
}
|
|
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
-
|
|
|
+
|
|
|
|
|
|
switch indexPath.section {
|
|
|
case 0:
|
|
@@ -236,6 +303,9 @@ extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
|
|
|
if !(productDetailModel?.spec?.isEmpty ?? true) && !(productDetailModel?.label?.isEmpty ?? true) {
|
|
|
if indexPath.row == 0 {
|
|
|
let cell = ProcuctDetailSelectSkuTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
+ if self.productDetailSkuModel != nil {
|
|
|
+ cell.productDetailSkuModel = self.productDetailSkuModel
|
|
|
+ }
|
|
|
return cell
|
|
|
}else {
|
|
|
let cell = ProductDetailProductLabelTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
@@ -258,6 +328,9 @@ extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
|
|
|
|
|
|
if !(productDetailModel?.spec?.isEmpty ?? true) && (productDetailModel?.label?.isEmpty ?? true) {
|
|
|
let cell = ProcuctDetailSelectSkuTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
+ if self.productDetailSkuModel != nil {
|
|
|
+ cell.productDetailSkuModel = self.productDetailSkuModel
|
|
|
+ }
|
|
|
return cell
|
|
|
}
|
|
|
return UITableViewCell()
|
|
@@ -283,12 +356,29 @@ extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
|
|
|
return cell
|
|
|
|
|
|
default:
|
|
|
-
|
|
|
+
|
|
|
return UITableViewCell()
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
+ if indexPath.section == 1 {
|
|
|
+ if !(productDetailModel?.spec?.isEmpty ?? true) && !(productDetailModel?.label?.isEmpty ?? true) {
|
|
|
+ if indexPath.row == 0 {
|
|
|
+ self.view.productDetailSkuViewType = ProductDetailSkuViewType.selectSku
|
|
|
+ self.view.productDetailModel = self.productDetailModel
|
|
|
+ self.view.show()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !(productDetailModel?.spec?.isEmpty ?? true) && (productDetailModel?.label?.isEmpty ?? true) {
|
|
|
+ self.view.productDetailSkuViewType = ProductDetailSkuViewType.selectSku
|
|
|
+ self.view.productDetailModel = self.productDetailModel
|
|
|
+ self.view.show()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
|
switch indexPath.section {
|
|
@@ -357,25 +447,29 @@ extension ProductDetailView : UITableViewDelegate, UITableViewDataSource {
|
|
|
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
|
|
var offset = scrollView.contentOffset
|
|
|
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ProductDetailView"), object: offset)
|
|
|
-
|
|
|
+
|
|
|
if (!(scrollView.isTracking || scrollView.isDecelerating)) {
|
|
|
//不是用户滚动的,比如setContentOffset等方法,引起的滚动不需要处理。
|
|
|
return;
|
|
|
}
|
|
|
offset.y = offset.y + kNavBarTotalHeight
|
|
|
-
|
|
|
+
|
|
|
if offset.y > 251 + kSafeTabBarHeight {
|
|
|
|
|
|
let indexPath = tableView.indexPathForRow(at: offset)
|
|
|
if indexPath != nil {
|
|
|
var rect = tableView.rect(forSection: (indexPath?.section)!)
|
|
|
+
|
|
|
if rect.size.height + kNavBarTotalHeight - tableView.frame.size.height < 0 {
|
|
|
+
|
|
|
rect.size.height = tableView.frame.size.height - kNavBarTotalHeight - rect.size.height
|
|
|
+
|
|
|
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: rect.size.height, right: 0)
|
|
|
}
|
|
|
+
|
|
|
if indexPath!.section % 2 == 0 {
|
|
|
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ProductDetailViewSection"), object: indexPath!.section)
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|