ShoppingCartOrderPayView.swift 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //
  2. // ShoppingCartOrderPayView.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/5/9.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. // 购物车--订单支付View
  8. import UIKit
  9. class ShoppingCartOrderPayView: BaseView {
  10. typealias CommitOrderTransBlock = () -> Void
  11. var commitOrderTransBlock : CommitOrderTransBlock?
  12. // 全部已选总价
  13. var totalProductPrice: Int = 0 {
  14. didSet {
  15. self.accountView.tPrice = totalProductPrice
  16. }
  17. }
  18. // 已选商品ModelArr
  19. var proListModelArr : Array<CartProductListModel>? {
  20. didSet {
  21. tableView.reloadData()
  22. }
  23. }
  24. override func setupViews() {
  25. self.backgroundColor = kf7f8faColor
  26. addSubview(accountView)
  27. addSubview(tableView)
  28. let emptyView = EmptyView.shared.diyCustomEmptyViewStyle2(iconStr: "page04", titleStr: "当前暂无数据")
  29. emptyView.contentViewY = kScaleValue(value: 182)
  30. tableView.ly_emptyView = emptyView
  31. tableView.ly_startLoading()
  32. }
  33. override func setupLayouts() {
  34. accountView.snp.makeConstraints { (make) in
  35. make.left.right.equalToSuperview()
  36. make.bottom.equalTo(-kSafeTabBarHeight)
  37. make.height.equalTo(48)
  38. }
  39. tableView.snp.makeConstraints { (make) in
  40. make.edges.equalToSuperview()
  41. make.bottom.equalTo(accountView.snp_top).offset(-20)
  42. }
  43. }
  44. lazy var accountView: OrderPayAcountView = {
  45. let accountView = OrderPayAcountView()
  46. accountView.commitOrderBlock = {
  47. [weak self] in
  48. if let commitOrderTransBlock = self?.commitOrderTransBlock {
  49. commitOrderTransBlock()
  50. }
  51. }
  52. return accountView
  53. }()
  54. lazy var tableView: UITableView = {
  55. let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
  56. tableView.separatorStyle = .none
  57. tableView.backgroundColor = kf7f8faColor
  58. tableView.dataSource = self
  59. tableView.delegate = self
  60. tableView.estimatedRowHeight = 0.000001
  61. tableView.estimatedSectionFooterHeight = 0.000001
  62. tableView.estimatedSectionHeaderHeight = 0.000001
  63. return tableView
  64. }()
  65. }
  66. // MARK: - tableView dataSource && delegate
  67. extension ShoppingCartOrderPayView : UITableViewDelegate, UITableViewDataSource {
  68. func numberOfSections(in tableView: UITableView) -> Int {
  69. return proListModelArr!.count + 1
  70. }
  71. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  72. if section == 0 {
  73. return 1
  74. } else {
  75. return proListModelArr![section-1].productList!.count
  76. }
  77. }
  78. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  79. if indexPath.section == 0 {
  80. // 快递添加地址
  81. // let cell = OrderPayExpressAddInfoCell.cellWith(tableView: tableView, indexPath: indexPath)
  82. // 自提添加收货人信息
  83. // let cell = OrderPaySelfPickAddInfoCell.cellWith(tableView: tableView, indexPath: indexPath)
  84. // 自提地址信息
  85. // let cell = OrderPaySelfPickAddressCell.cellWith(tableView: tableView, indexPath: indexPath)
  86. // 自提个人信息
  87. // let cell = OrderPaySelfPickInfoCell.cellWith(tableView: tableView, indexPath: indexPath)
  88. // 快递
  89. let cell = OrderPayExpressInfoShowCell.cellWith(tableView: tableView, indexPath: indexPath)
  90. return cell
  91. } else {
  92. // 购物车列表Item
  93. let cell = ShoppingCartPayOrderItemCell.cellWith(tableView: tableView, indexPath: indexPath)
  94. cell.productMdl = proListModelArr![indexPath.section-1].productList![indexPath.row]
  95. return cell
  96. }
  97. }
  98. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  99. return UITableView.automaticDimension
  100. }
  101. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  102. if section == 0 {
  103. return 10
  104. } else {
  105. return 58
  106. }
  107. }
  108. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  109. if section == 0 {
  110. return nil
  111. } else {
  112. let headerView = ShoppingCartPayOrderHeader(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 58))
  113. headerView.shopName = proListModelArr![section-1].shopName
  114. return headerView
  115. }
  116. }
  117. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  118. if section == 0 {
  119. return 0.000001
  120. } else {
  121. return 88
  122. }
  123. }
  124. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  125. if section == 0 {
  126. return nil
  127. } else {
  128. let footerView = ShoppingCartPayOrderFooter(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 88))
  129. let cartProListMdl: CartProductListModel = proListModelArr![section-1]
  130. let secNum: Int = cartProListMdl.productList!.count
  131. footerView.tPrice = self.calculateSectionPrice(section-1)
  132. footerView.tNumber = secNum
  133. footerView.buyerNoteBlock = { [weak self]
  134. (buyerNotes) in
  135. self?.proListModelArr![section-1].buyerNotes = buyerNotes
  136. }
  137. return footerView
  138. }
  139. }
  140. }
  141. // 购物车计算
  142. extension ShoppingCartOrderPayView {
  143. // 计算Section数据,刷新结算View
  144. func calculateSectionPrice(_ section: Int) -> Int {
  145. var totalPrice: Int = 0
  146. let cartProListMdl: CartProductListModel = proListModelArr![section]
  147. for productMdl in cartProListMdl.productList! {
  148. totalPrice += productMdl.skuPrice! * productMdl.amount!
  149. }
  150. return totalPrice
  151. }
  152. }