OrderShopAndStatusTableViewCell.swift 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // OrderShopAndStatusTableViewCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/5/15.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. import RxSwift
  10. class OrderShopAndStatusTableViewCell: UITableViewCell {
  11. let disposeBag = DisposeBag()
  12. typealias ShopClosure = (_ orderModel: OrderModel) -> Void
  13. var shopClosure : ShopClosure?
  14. class func cellWith(tableView:UITableView,indexPath:IndexPath) -> OrderShopAndStatusTableViewCell {
  15. let ID = "OrderShopAndStatusTableViewCell"
  16. tableView.register(OrderShopAndStatusTableViewCell.self, forCellReuseIdentifier: ID)
  17. let cell : OrderShopAndStatusTableViewCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! OrderShopAndStatusTableViewCell
  18. cell.indexPath = indexPath
  19. return cell
  20. }
  21. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  22. super.init(style: style, reuseIdentifier: reuseIdentifier)
  23. setupViews()
  24. setupLayouts()
  25. }
  26. required init?(coder aDecoder: NSCoder) {
  27. fatalError("init(coder:) has not been implemented")
  28. }
  29. var indexPath: IndexPath? {
  30. didSet {
  31. }
  32. }
  33. //MRAK: - 设置View
  34. private func setupViews() {
  35. self.selectionStyle = .none
  36. addSubview(shopButton)
  37. addSubview(statusLabel)
  38. addSubview(lineLabel)
  39. }
  40. private func setupLayouts() {
  41. shopButton.snp.makeConstraints { (make) in
  42. make.centerY.equalToSuperview()
  43. make.left.equalTo(14)
  44. }
  45. shopButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.right, imageTitleSpace: 5)
  46. statusLabel.snp.makeConstraints { (make) in
  47. make.centerY.equalToSuperview()
  48. make.right.equalTo(-14)
  49. }
  50. lineLabel.snp.makeConstraints { (make) in
  51. make.bottom.equalToSuperview()
  52. make.height.equalTo(1)
  53. make.left.equalTo(14)
  54. make.right.equalTo(-14)
  55. }
  56. }
  57. private lazy var shopButton: UIButton = {
  58. let shopButton = UIButton(type: UIButton.ButtonType.custom)
  59. shopButton.setTitleColor(k333333Color, for: UIControl.State.normal)
  60. shopButton.titleLabel?.font = kRegularFont14
  61. shopButton.setImage(kImage(name: "my_arrows_unfold"), for: UIControl.State.normal)
  62. shopButton.rx.tap.subscribe(onNext: {
  63. [weak self] (data) in
  64. if self?.orderModel != nil {
  65. if let shopClosure = self?.shopClosure {
  66. shopClosure((self?.orderModel)!)
  67. }
  68. }
  69. if self?.orderDetailModel != nil {
  70. if let shopClosure = self?.shopClosure {
  71. shopClosure((self?.orderDetailModel)!)
  72. }
  73. }
  74. }).disposed(by: disposeBag)
  75. return shopButton
  76. }()
  77. private lazy var statusLabel: UILabel = {
  78. let statusLabel = UILabel()
  79. statusLabel.font = kRegularFont14
  80. return statusLabel
  81. }()
  82. private lazy var lineLabel: UILabel = {
  83. let lineLabel = UILabel()
  84. lineLabel.backgroundColor = kf5f5f5Color
  85. return lineLabel
  86. }()
  87. var orderModel: OrderModel? {
  88. didSet {
  89. shopButton.setTitle(orderModel?.shopName ?? "", for: UIControl.State.normal)
  90. shopButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.right, imageTitleSpace: 5)
  91. if orderModel?.feedbackStatus == 0 { //未维权
  92. switch orderModel?.status {
  93. case 0: //待付款
  94. statusLabel.text = "待付款"
  95. statusLabel.textColor = kFFA42FColor
  96. break
  97. case 1: //待发货
  98. statusLabel.text = "待发货"
  99. statusLabel.textColor = kFFA42FColor
  100. case 2: //已发货/待收货
  101. statusLabel.text = "待收货"
  102. statusLabel.textColor = k333333Color
  103. case 3: //配送中
  104. statusLabel.text = "配送中"
  105. statusLabel.textColor = kFFA42FColor
  106. case 4: //待自提
  107. statusLabel.text = "待自提"
  108. statusLabel.textColor = kFFA42FColor
  109. case 5: //已自提
  110. statusLabel.text = "已自提"
  111. statusLabel.textColor = k333333Color
  112. case 6: //已完成
  113. statusLabel.text = "已完成"
  114. statusLabel.textColor = k333333Color
  115. case 7: //已关闭
  116. statusLabel.text = "已关闭"
  117. statusLabel.textColor = k333333Color
  118. default:
  119. break
  120. }
  121. }else {
  122. switch orderModel?.feedbackStatus {
  123. case 1: //1-退款处理中
  124. statusLabel.text = "退款中"
  125. statusLabel.textColor = kFFA42FColor
  126. case 2: //2-退款完成
  127. statusLabel.text = "退款完成"
  128. statusLabel.textColor = k333333Color
  129. case 3: //3-拒绝退款
  130. statusLabel.text = "退款失败"
  131. statusLabel.textColor = k333333Color
  132. default:
  133. break
  134. }
  135. }
  136. }
  137. }
  138. var orderDetailModel: OrderModel? {
  139. didSet {
  140. shopButton.setTitle(orderDetailModel?.shopName ?? "", for: UIControl.State.normal)
  141. shopButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.right, imageTitleSpace: 5)
  142. }
  143. }
  144. }