|
@@ -10,6 +10,12 @@ import UIKit
|
|
|
|
|
|
class ShoppingCartView: BaseView {
|
|
class ShoppingCartView: BaseView {
|
|
|
|
|
|
|
|
+ var cartListModelsArr : Array<CartProductListModel>? {
|
|
|
|
+ didSet {
|
|
|
|
+ tableView.reloadData()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
override func setupViews() {
|
|
override func setupViews() {
|
|
self.backgroundColor = kf7f8faColor
|
|
self.backgroundColor = kf7f8faColor
|
|
addSubview(accountView)
|
|
addSubview(accountView)
|
|
@@ -26,8 +32,8 @@ class ShoppingCartView: BaseView {
|
|
make.height.equalTo(48)
|
|
make.height.equalTo(48)
|
|
}
|
|
}
|
|
tableView.snp.makeConstraints { (make) in
|
|
tableView.snp.makeConstraints { (make) in
|
|
- make.edges.equalToSuperview()
|
|
|
|
- make.bottom.equalTo(accountView.snp_top).offset(-20)
|
|
|
|
|
|
+ make.top.left.right.equalToSuperview()
|
|
|
|
+ make.bottom.equalTo(accountView.snp_top).offset(0)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -52,78 +58,75 @@ class ShoppingCartView: BaseView {
|
|
|
|
|
|
extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
|
|
extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
|
|
func numberOfSections(in tableView: UITableView) -> Int {
|
|
func numberOfSections(in tableView: UITableView) -> Int {
|
|
- return 4
|
|
|
|
|
|
+ // 购物车列表 + 超值热卖
|
|
|
|
+ return cartListModelsArr?.isEmpty ?? true ? 2 : cartListModelsArr!.count + 1
|
|
}
|
|
}
|
|
|
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
- switch section {
|
|
|
|
- case 0:
|
|
|
|
- return 1
|
|
|
|
- case 1:
|
|
|
|
- return 3
|
|
|
|
- case 2:
|
|
|
|
- return 2
|
|
|
|
- case 3:
|
|
|
|
- return 1
|
|
|
|
- default:
|
|
|
|
|
|
+ if cartListModelsArr?.isEmpty ?? true {
|
|
return 1
|
|
return 1
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ if section < cartListModelsArr!.count {
|
|
|
|
+ return cartListModelsArr![section].productList?.isEmpty ?? true ? 0 : cartListModelsArr![section].productList!.count
|
|
|
|
+ } else {
|
|
|
|
+ return 1
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
- switch indexPath.section {
|
|
|
|
- case 0:
|
|
|
|
- let cell = ShoppingCartListNoneItemCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
|
- return cell
|
|
|
|
- case 1:
|
|
|
|
- let cell = ShoppingCartListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
|
- return cell
|
|
|
|
- case 2:
|
|
|
|
- let cell = ShoppingCartListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
|
- return cell
|
|
|
|
- case 3:
|
|
|
|
- let cell = ShoppingCartHotSaleTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
|
- cell.frame = tableView.bounds
|
|
|
|
- cell.layoutIfNeeded()
|
|
|
|
- cell.reloadData()
|
|
|
|
- return cell
|
|
|
|
|
|
+ if cartListModelsArr?.count == 0 {
|
|
|
|
+ switch indexPath.section {
|
|
|
|
+ case 0:
|
|
|
|
+ // 购物车列表为空
|
|
|
|
+ let cell = ShoppingCartListNoneItemCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
|
+ return cell
|
|
|
|
+ case 1:
|
|
|
|
+ // 超值热卖
|
|
|
|
+ let cell = ShoppingCartHotSaleTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
|
+ cell.frame = tableView.bounds
|
|
|
|
+ cell.layoutIfNeeded()
|
|
|
|
+ cell.reloadData()
|
|
|
|
+ return cell
|
|
|
|
+ default:
|
|
|
|
+ return UITableViewCell()
|
|
|
|
+ }
|
|
|
|
|
|
- default:
|
|
|
|
- return UITableViewCell()
|
|
|
|
|
|
+ } else {
|
|
|
|
+ if indexPath.section < cartListModelsArr!.count {
|
|
|
|
+ // 购物车列表Item
|
|
|
|
+ let cell = ShoppingCartListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
|
+ return cell
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ let cell = ShoppingCartHotSaleTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
|
+ cell.frame = tableView.bounds
|
|
|
|
+ cell.layoutIfNeeded()
|
|
|
|
+ cell.reloadData()
|
|
|
|
+ return cell
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
- switch indexPath.section {
|
|
|
|
- case 0:
|
|
|
|
- return UITableView.automaticDimension
|
|
|
|
- case 1:
|
|
|
|
- return UITableView.automaticDimension
|
|
|
|
- case 2:
|
|
|
|
- return UITableView.automaticDimension
|
|
|
|
- case 3:
|
|
|
|
- return UITableView.automaticDimension
|
|
|
|
- default:
|
|
|
|
- return 0
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ return UITableView.automaticDimension
|
|
}
|
|
}
|
|
|
|
|
|
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
- if section == 0 || section == 3 {
|
|
|
|
- return 10
|
|
|
|
- } else {
|
|
|
|
|
|
+ if cartListModelsArr?.count ?? 0 > 0 && section < cartListModelsArr!.count {
|
|
return 48
|
|
return 48
|
|
|
|
+ } else {
|
|
|
|
+ return 10
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
|
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
|
- if section == 3 || section == 0 {
|
|
|
|
- return nil
|
|
|
|
- } else {
|
|
|
|
|
|
+ if cartListModelsArr?.count ?? 0 > 0 && section < cartListModelsArr!.count {
|
|
let headerView = ShoppingCartListTableViewHeader(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 48))
|
|
let headerView = ShoppingCartListTableViewHeader(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 48))
|
|
return headerView
|
|
return headerView
|
|
|
|
+ } else {
|
|
|
|
+ return nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|