OrderApplyRefundProductCell.swift 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //
  2. // OrderApplyRefundProductCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/5/17.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. // 申请退款--商品详情Cell
  8. import UIKit
  9. import RxSwift
  10. import RxCocoa
  11. import Kingfisher
  12. class OrderApplyRefundProductCell: UITableViewCell {
  13. let disposeBag = DisposeBag()
  14. // 选中商品
  15. typealias ProductSelBlock = (_ isProductSelected: Int) -> Void
  16. var productSelBlock : ProductSelBlock?
  17. class func cellWith(tableView:UITableView,indexPath:IndexPath) -> OrderApplyRefundProductCell {
  18. let ID = "OrderApplyRefundProductCell"
  19. tableView.register(OrderApplyRefundProductCell.self, forCellReuseIdentifier: ID)
  20. let cell : OrderApplyRefundProductCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! OrderApplyRefundProductCell
  21. cell.indexPath = indexPath
  22. return cell
  23. }
  24. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  25. super.init(style: style, reuseIdentifier: reuseIdentifier)
  26. setupViews()
  27. setupLayouts()
  28. }
  29. required init?(coder aDecoder: NSCoder) {
  30. fatalError("init(coder:) has not been implemented")
  31. }
  32. var indexPath: IndexPath? {
  33. didSet {
  34. }
  35. }
  36. //MRAK: - 设置View
  37. private func setupViews() {
  38. self.selectionStyle = .none
  39. addSubview(productImageView)
  40. addSubview(selectBtn)
  41. addSubview(priceLabel)
  42. addSubview(titleLabel)
  43. addSubview(timeLabel)
  44. addSubview(skuLabel)
  45. addSubview(numberLabel)
  46. addSubview(lineLabel)
  47. }
  48. private func setupLayouts() {
  49. productImageView.snp.makeConstraints { (make) in
  50. make.left.equalToSuperview().offset(34)
  51. make.top.equalToSuperview().offset(14)
  52. make.bottom.equalToSuperview().offset(-14)
  53. make.size.equalTo(80)
  54. }
  55. selectBtn.snp.makeConstraints { (make) in
  56. make.left.equalToSuperview().offset(14)
  57. make.size.equalTo(18)
  58. make.centerY.equalTo(productImageView)
  59. }
  60. priceLabel.snp.remakeConstraints { (make) in
  61. make.top.equalToSuperview().offset(21)
  62. make.right.equalTo(-14)
  63. make.width.lessThanOrEqualTo(60)
  64. make.height.equalTo(20)
  65. }
  66. titleLabel.snp.remakeConstraints { (make) in
  67. make.left.equalTo(productImageView.snp.right).offset(12)
  68. make.top.equalTo(20)
  69. make.right.equalTo(priceLabel.snp.left).offset(-11)
  70. make.height.equalTo(20)
  71. }
  72. timeLabel.snp.makeConstraints { (make) in
  73. make.top.equalTo(titleLabel.snp.bottom).offset(8)
  74. make.left.equalTo(titleLabel)
  75. make.height.equalTo(17)
  76. }
  77. skuLabel.snp.makeConstraints { (make) in
  78. make.top.equalTo(timeLabel.snp.bottom).offset(8)
  79. make.left.equalTo(titleLabel)
  80. make.height.equalTo(17)
  81. }
  82. numberLabel.snp.makeConstraints { (make) in
  83. make.centerY.equalTo(timeLabel)
  84. make.right.equalTo(-14)
  85. }
  86. lineLabel.snp.makeConstraints { (make) in
  87. make.bottom.equalToSuperview()
  88. make.height.equalTo(1)
  89. make.left.equalTo(14)
  90. make.right.equalTo(-14)
  91. }
  92. }
  93. private lazy var selectBtn: UIButton = {
  94. let selectBtn = UIButton(type: UIButton.ButtonType.custom)
  95. selectBtn.setImage(kImage(name: "common_uncheck_icon"), for: UIControl.State.normal)
  96. selectBtn.setImage(kImage(name: "common_check_icon"), for: UIControl.State.selected)
  97. selectBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
  98. self?.selectBtn.isSelected = !(self?.selectBtn.isSelected)!
  99. if let productSelBlock = self?.productSelBlock {
  100. let isSel: Int = self?.selectBtn.isSelected == true ? 1 : 0
  101. productSelBlock(isSel)
  102. }
  103. }).disposed(by: disposeBag)
  104. return selectBtn
  105. }()
  106. private lazy var productImageView: UIImageView = {
  107. let productImageView = UIImageView()
  108. productImageView.image = kImage(name: "default_pic")
  109. productImageView.contentMode = .scaleAspectFill
  110. productImageView.masksToBounds = true
  111. return productImageView
  112. }()
  113. private lazy var titleLabel: UILabel = {
  114. let titleLabel = UILabel()
  115. titleLabel.textColor = k333333Color
  116. titleLabel.font = kBoldFont14
  117. return titleLabel
  118. }()
  119. private lazy var timeLabel: UILabel = {
  120. let timeLabel = UILabel()
  121. timeLabel.textColor = k666666Color
  122. timeLabel.font = kRegularFont12
  123. return timeLabel
  124. }()
  125. private lazy var skuLabel: UILabel = {
  126. let skuLabel = UILabel()
  127. skuLabel.textColor = k999999Color
  128. skuLabel.font = kRegularFont12
  129. return skuLabel
  130. }()
  131. private lazy var priceLabel: UILabel = {
  132. let priceLabel = UILabel()
  133. priceLabel.textColor = k333333Color
  134. priceLabel.font = kRegularFont14
  135. priceLabel.textAlignment = .right
  136. return priceLabel
  137. }()
  138. private lazy var numberLabel: UILabel = {
  139. let numberLabel = UILabel()
  140. numberLabel.textColor = k999999Color
  141. numberLabel.font = kRegularFont13
  142. return numberLabel
  143. }()
  144. private lazy var lineLabel: UILabel = {
  145. let lineLabel = UILabel()
  146. lineLabel.backgroundColor = kf5f5f5Color
  147. return lineLabel
  148. }()
  149. var orderModelDetailModel: OrderModelDetailModel? {
  150. didSet {
  151. // 选中状态
  152. let selStatus = orderModelDetailModel?.isSelect == 1 ? true : false
  153. selectBtn.isSelected = selStatus
  154. productImageView.kf.setImage(with: kURLImage(name: orderModelDetailModel?.productImg ?? "default_pic"), placeholder: kImage(name: "default_pic"))
  155. KingfisherManager.shared.cache.clearMemoryCache()
  156. titleLabel.text = orderModelDetailModel?.productName
  157. timeLabel.text = "预计配送时间:\(orderModelDetailModel?.receiveTime ?? "")"
  158. skuLabel.text = "规格:\(orderModelDetailModel?.skuName ?? "")"
  159. priceLabel.text = "\(priceConversion(price: orderModelDetailModel?.productPrice ?? 0))"
  160. numberLabel.text = "x\(orderModelDetailModel?.amount ?? 0)"
  161. }
  162. }
  163. }