123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- //
- // ShoppingCartPayOrderFooter.swift
- // RainbowPlanet
- //
- // Created by Christopher on 2019/5/9.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- // 订单支付--商品列表Footer
- import UIKit
- import RxSwift
- import RxCocoa
- class ShoppingCartPayOrderFooter: BaseView {
-
- typealias BuyerNoteBlock = (_ note: String) -> Void
- var buyerNoteBlock : BuyerNoteBlock?
-
- var tPrice: Int? {
- didSet {
- let priceStr = priceConversion(price: tPrice ?? 0)
- let originStr = "合计 \(priceStr)"
- let attrStr = NSMutableAttributedString(string:originStr)
- attrStr.changeForegroundColor(kfe352bColor, range: NSRange(location: 2, length: originStr.count-2))
- priceLabel.attributedText = attrStr
- }
- }
-
- var tNumber: Int? {
- didSet {
- let originStr = "共\(tNumber ?? 0)件商品,"
- let attrStr = NSMutableAttributedString(string:originStr)
- attrStr.changeForegroundColor(k333333Color, range: NSRange(location: 1, length: originStr.count-5))
- numberLabel.attributedText = attrStr
- }
- }
-
- override var frame: CGRect {
- get {
- return super.frame
- }
- set {
- var frame = newValue
- frame.origin.x += 14 * kScaleWidth
- frame.size.width -= 14 * kScaleWidth * 2
- super.frame = frame
- }
- }
-
- override func setupViews() {
- self.backgroundColor = kffffffColor
- addSubview(msgLabel)
- addSubview(msgTextField)
- addSubview(priceLabel)
- addSubview(numberLabel)
- }
-
- override func setupLayouts() {
- msgLabel.snp.makeConstraints { (make) in
- make.left.top.equalToSuperview().offset(14)
- make.width.equalTo(56)
- make.height.equalTo(20)
- }
-
- msgTextField.snp.makeConstraints { (make) in
- make.centerY.equalTo(msgLabel)
- make.left.equalTo(msgLabel.snp_right).offset(11)
- make.right.equalTo(-14)
- make.height.equalTo(28)
- }
-
- priceLabel.snp.makeConstraints { (make) in
- make.top.equalTo(msgTextField.snp_bottom).offset(20)
- make.right.equalTo(msgTextField)
- make.height.equalTo(20)
- }
-
- numberLabel.snp.makeConstraints { (make) in
- make.right.equalTo(priceLabel.snp_left)
- make.centerY.equalTo(priceLabel)
- make.height.equalTo(priceLabel)
- }
- }
-
- private lazy var msgLabel: UILabel = {
- let msgLabel = UILabel()
- msgLabel.text = "买家留言"
- msgLabel.textColor = k333333Color
- msgLabel.font = kRegularFont14
- msgLabel.textAlignment = .left
- return msgLabel
- }()
-
- private lazy var msgTextField : UITextField = {
- let msgTextField = UITextField()
- msgTextField.placeholder = "单行输入"
- msgTextField.borderStyle = .roundedRect
- msgTextField.textColor = k666666Color
- msgTextField.font = kRegularFont12
- msgTextField.clearButtonMode = .whileEditing
- msgTextField.sizeToFit()
- msgTextField.tintColor = kFFA42FColor
- msgTextField.delegate = self
- return msgTextField
- }()
-
- private lazy var priceLabel: UILabel = {
- let priceLabel = UILabel()
- priceLabel.textColor = k999999Color
- priceLabel.font = kRegularFont14
- priceLabel.textAlignment = .right
- return priceLabel
- }()
-
- private lazy var numberLabel: UILabel = {
- let numberLabel = UILabel()
- numberLabel.textColor = k999999Color
- numberLabel.font = kRegularFont14
- numberLabel.textAlignment = .right
- return numberLabel
- }()
-
- }
- extension ShoppingCartPayOrderFooter: UITextFieldDelegate {
-
- func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
- if textField == msgTextField {
- var fullStr = textField.text ?? ""
- if textField.text?.count ?? 0 > 80 {
- fullStr = String(fullStr.prefix(50)) as String
- textField.text = fullStr
- }
-
- if let buyerNoteBlock = self.buyerNoteBlock {
- buyerNoteBlock(self.msgTextField.text ?? "")
- }
- }
- return true
- }
-
- }
|