123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- //
- // ShoppingCartOrderPayView.swift
- // RainbowPlanet
- //
- // Created by Christopher on 2019/5/9.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- // 购物车--订单支付View
- import UIKit
- class ShoppingCartOrderPayView: BaseView {
-
- typealias CommitOrderTransBlock = () -> Void
- var commitOrderTransBlock : CommitOrderTransBlock?
-
- // 全部已选总价
- var totalProductPrice: Int = 0 {
- didSet {
- self.accountView.tPrice = totalProductPrice
- }
- }
-
- // 已选商品ModelArr
- var proListModelArr : Array<CartProductListModel>? {
- didSet {
- tableView.reloadData()
- }
- }
-
- override func setupViews() {
- self.backgroundColor = kf7f8faColor
- addSubview(accountView)
- addSubview(tableView)
- let emptyView = EmptyView.shared.diyCustomEmptyViewStyle2(iconStr: "page04", titleStr: "当前暂无数据")
- emptyView.contentViewY = kScaleValue(value: 182)
- tableView.ly_emptyView = emptyView
- tableView.ly_startLoading()
- }
-
- override func setupLayouts() {
- accountView.snp.makeConstraints { (make) in
- make.left.right.equalToSuperview()
- make.bottom.equalTo(-kSafeTabBarHeight)
- make.height.equalTo(48)
- }
- tableView.snp.makeConstraints { (make) in
- make.edges.equalToSuperview()
- make.bottom.equalTo(accountView.snp_top).offset(-20)
- }
- }
-
- lazy var accountView: OrderPayAcountView = {
- let accountView = OrderPayAcountView()
- accountView.commitOrderBlock = {
- [weak self] in
- if let commitOrderTransBlock = self?.commitOrderTransBlock {
- commitOrderTransBlock()
- }
- }
- return accountView
- }()
-
- lazy var tableView: UITableView = {
- let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
- tableView.separatorStyle = .none
- tableView.backgroundColor = kf7f8faColor
- tableView.dataSource = self
- tableView.delegate = self
- tableView.estimatedRowHeight = 0.000001
- tableView.estimatedSectionFooterHeight = 0.000001
- tableView.estimatedSectionHeaderHeight = 0.000001
- return tableView
- }()
-
- }
- // MARK: - tableView dataSource && delegate
- extension ShoppingCartOrderPayView : UITableViewDelegate, UITableViewDataSource {
- func numberOfSections(in tableView: UITableView) -> Int {
- return proListModelArr!.count + 1
- }
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- if section == 0 {
- return 1
- } else {
- return proListModelArr![section-1].productList!.count
- }
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- if indexPath.section == 0 {
- // 快递添加地址
- // let cell = OrderPayExpressAddInfoCell.cellWith(tableView: tableView, indexPath: indexPath)
- // 自提添加收货人信息
- // let cell = OrderPaySelfPickAddInfoCell.cellWith(tableView: tableView, indexPath: indexPath)
- // 自提地址信息
- // let cell = OrderPaySelfPickAddressCell.cellWith(tableView: tableView, indexPath: indexPath)
- // 自提个人信息
- // let cell = OrderPaySelfPickInfoCell.cellWith(tableView: tableView, indexPath: indexPath)
- // 快递
- let cell = OrderPayExpressInfoShowCell.cellWith(tableView: tableView, indexPath: indexPath)
-
-
- return cell
-
- } else {
- // 购物车列表Item
- let cell = ShoppingCartPayOrderItemCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.productMdl = proListModelArr![indexPath.section-1].productList![indexPath.row]
- return cell
- }
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return UITableView.automaticDimension
- }
-
- func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
- if section == 0 {
- return 10
- } else {
- return 58
- }
- }
-
- func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
- if section == 0 {
- return nil
- } else {
- let headerView = ShoppingCartPayOrderHeader(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 58))
- headerView.shopName = proListModelArr![section-1].shopName
- return headerView
-
- }
- }
-
- func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
- if section == 0 {
- return 0.000001
- } else {
- return 88
- }
- }
-
- func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
- if section == 0 {
- return nil
- } else {
- let footerView = ShoppingCartPayOrderFooter(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 88))
-
- let cartProListMdl: CartProductListModel = proListModelArr![section-1]
- let secNum: Int = cartProListMdl.productList!.count
-
- footerView.tPrice = self.calculateSectionPrice(section-1)
- footerView.tNumber = secNum
-
- footerView.buyerNoteBlock = { [weak self]
- (buyerNotes) in
- self?.proListModelArr![section-1].buyerNotes = buyerNotes
- }
-
- return footerView
- }
- }
-
- }
- // 购物车计算
- extension ShoppingCartOrderPayView {
-
- // 计算Section数据,刷新结算View
- func calculateSectionPrice(_ section: Int) -> Int {
- var totalPrice: Int = 0
-
- let cartProListMdl: CartProductListModel = proListModelArr![section]
- for productMdl in cartProListMdl.productList! {
- totalPrice += productMdl.skuPrice! * productMdl.amount!
- }
- return totalPrice
- }
-
- }
|