ShoppingCartPayOrderFooter.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // ShoppingCartPayOrderFooter.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/5/9.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. // 订单支付--商品列表Footer
  8. import UIKit
  9. import RxSwift
  10. import RxCocoa
  11. class ShoppingCartPayOrderFooter: BaseView {
  12. typealias BuyerNoteBlock = (_ note: String) -> Void
  13. var buyerNoteBlock : BuyerNoteBlock?
  14. var tPrice: Int? {
  15. didSet {
  16. let priceStr = priceConversion(price: tPrice ?? 0)
  17. let originStr = "合计 \(priceStr)"
  18. let attrStr = NSMutableAttributedString(string:originStr)
  19. attrStr.changeForegroundColor(kfe352bColor, range: NSRange(location: 2, length: originStr.count-2))
  20. priceLabel.attributedText = attrStr
  21. }
  22. }
  23. var tNumber: Int? {
  24. didSet {
  25. let originStr = "共\(tNumber ?? 0)件商品,"
  26. let attrStr = NSMutableAttributedString(string:originStr)
  27. attrStr.changeForegroundColor(k333333Color, range: NSRange(location: 1, length: originStr.count-5))
  28. numberLabel.attributedText = attrStr
  29. }
  30. }
  31. override var frame: CGRect {
  32. get {
  33. return super.frame
  34. }
  35. set {
  36. var frame = newValue
  37. frame.origin.x += 14 * kScaleWidth
  38. frame.size.width -= 14 * kScaleWidth * 2
  39. super.frame = frame
  40. }
  41. }
  42. override func setupViews() {
  43. self.backgroundColor = kffffffColor
  44. addSubview(msgLabel)
  45. addSubview(msgTextField)
  46. addSubview(priceLabel)
  47. addSubview(numberLabel)
  48. }
  49. override func setupLayouts() {
  50. msgLabel.snp.makeConstraints { (make) in
  51. make.left.top.equalToSuperview().offset(14)
  52. make.width.equalTo(56)
  53. make.height.equalTo(20)
  54. }
  55. msgTextField.snp.makeConstraints { (make) in
  56. make.centerY.equalTo(msgLabel)
  57. make.left.equalTo(msgLabel.snp_right).offset(11)
  58. make.right.equalTo(-14)
  59. make.height.equalTo(28)
  60. }
  61. priceLabel.snp.makeConstraints { (make) in
  62. make.top.equalTo(msgTextField.snp_bottom).offset(20)
  63. make.right.equalTo(msgTextField)
  64. make.height.equalTo(20)
  65. }
  66. numberLabel.snp.makeConstraints { (make) in
  67. make.right.equalTo(priceLabel.snp_left)
  68. make.centerY.equalTo(priceLabel)
  69. make.height.equalTo(priceLabel)
  70. }
  71. }
  72. private lazy var msgLabel: UILabel = {
  73. let msgLabel = UILabel()
  74. msgLabel.text = "买家留言"
  75. msgLabel.textColor = k333333Color
  76. msgLabel.font = kRegularFont14
  77. msgLabel.textAlignment = .left
  78. return msgLabel
  79. }()
  80. private lazy var msgTextField : UITextField = {
  81. let msgTextField = UITextField()
  82. msgTextField.placeholder = "单行输入"
  83. msgTextField.borderStyle = .roundedRect
  84. msgTextField.textColor = k666666Color
  85. msgTextField.font = kRegularFont12
  86. msgTextField.clearButtonMode = .whileEditing
  87. msgTextField.sizeToFit()
  88. msgTextField.tintColor = kFFA42FColor
  89. msgTextField.delegate = self
  90. return msgTextField
  91. }()
  92. private lazy var priceLabel: UILabel = {
  93. let priceLabel = UILabel()
  94. priceLabel.textColor = k999999Color
  95. priceLabel.font = kRegularFont14
  96. priceLabel.textAlignment = .right
  97. return priceLabel
  98. }()
  99. private lazy var numberLabel: UILabel = {
  100. let numberLabel = UILabel()
  101. numberLabel.textColor = k999999Color
  102. numberLabel.font = kRegularFont14
  103. numberLabel.textAlignment = .right
  104. return numberLabel
  105. }()
  106. }
  107. extension ShoppingCartPayOrderFooter: UITextFieldDelegate {
  108. func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
  109. if textField == msgTextField {
  110. var fullStr = textField.text ?? ""
  111. if textField.text?.count ?? 0 > 80 {
  112. fullStr = String(fullStr.prefix(50)) as String
  113. textField.text = fullStr
  114. }
  115. if let buyerNoteBlock = self.buyerNoteBlock {
  116. buyerNoteBlock(self.msgTextField.text ?? "")
  117. }
  118. }
  119. return true
  120. }
  121. }