QSLVipGoodCollectionViewCell.swift 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // QSLVipGoodCollectionViewCell.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2024/11/28.
  6. //
  7. import UIKit
  8. class QSLVipGoodCollectionViewCell: UICollectionViewCell {
  9. var goodModel: QSLGoodModel?
  10. lazy var bgView: UIView = {
  11. let view = UIView()
  12. view.backgroundColor = .white
  13. view.addRadius(radius: 8.rpx)
  14. view.addBorder(borderWidth: 2.rpx, borderColor: .hexStringColor(hexString: "#EEEEEE"))
  15. return view
  16. }()
  17. lazy var tagIcon: UIImageView = {
  18. let imageView = UIImageView()
  19. imageView.image = UIImage(named: "vip_goods_tag_icon")
  20. return imageView
  21. }()
  22. lazy var goodNameLabel: UILabel = {
  23. let label = UILabel()
  24. label.text("年度会员")
  25. label.boldFont(13)
  26. label.textColor = .hexStringColor(hexString: "#404040")
  27. return label
  28. }()
  29. lazy var goodDailyPriceLabel: UILabel = {
  30. let label = UILabel()
  31. label.textAlignment = .center
  32. label.addRadius(radius: 12.rpx)
  33. label.backgroundColor = .hexStringColor(hexString: "#FFFEFC")
  34. let text = "0.35元/天"
  35. label.text(text)
  36. label.font(9)
  37. label.textColor = .hexStringColor(hexString: "#818181")
  38. // if let range = text.range(of: "/") {
  39. // let nsRange = NSRange(text.startIndex..<range.lowerBound, in: text)
  40. // label.setRangeFontText(font: .textM(20), range: nsRange)
  41. // }
  42. return label
  43. }()
  44. lazy var priceLabel: UILabel = {
  45. let label = UILabel()
  46. label.textAlignment = .center
  47. // label.addRadius(radius: 12.rpx)
  48. // label.backgroundColor = .hexStringColor(hexString: "#F6F6F6")
  49. label.text("¥128")
  50. label.mediumFont(24)
  51. label.textColor = .hexStringColor(hexString: "#F12A1D")
  52. label.setSpecificTextColorFont("¥", color: .hexStringColor(hexString: "#F12A1D"), font: UIFont.systemFont(ofSize: 14, weight: .medium))
  53. return label
  54. }()
  55. lazy var originPriceLabel: UILabel = {
  56. let label = UILabel()
  57. label.text("¥299")
  58. label.font(13)
  59. label.textColor = .hexStringColor(hexString: "#A7A7A7")
  60. label.centerLineText(lineValue: 1, underlineColor: .hexStringColor(hexString: "#A7A7A7"))
  61. return label
  62. }()
  63. override init(frame: CGRect) {
  64. super.init(frame: frame)
  65. initView()
  66. }
  67. required init?(coder: NSCoder) {
  68. fatalError("init(coder:) has not been implemented")
  69. }
  70. func config(model: QSLGoodModel) {
  71. self.goodModel = model
  72. if model.isSelect {
  73. self.bgView.layer.borderColor = UIColor.hexStringColor(hexString: "#E7B983").cgColor
  74. self.bgView.backgroundColor = .hexStringColor(hexString: "#FFF8EF")
  75. } else {
  76. self.bgView.layer.borderColor = UIColor.hexStringColor(hexString: "#EEEEEE").cgColor
  77. self.bgView.backgroundColor = .white
  78. }
  79. self.tagIcon.isHidden = !model.popular
  80. self.goodNameLabel.text = model.name
  81. // self.goodDailyPriceLabel.text = "0.001元/天"
  82. self.goodDailyPriceLabel.text = model.content
  83. let width = model.content.singleLineWidth(font: .textF(10)) + 24.rpx
  84. self.goodDailyPriceLabel.snp.updateConstraints { make in
  85. make.width.equalTo(width)
  86. }
  87. // if let range = model.content.range(of: "/") {
  88. // let nsRange = NSRange(model.content.startIndex..<range.lowerBound, in: model.content)
  89. // self.goodDailyPriceLabel.setRangeFontText(font: .textM(20), range: nsRange)
  90. // }
  91. var priceText = ""
  92. if model.amount.truncatingRemainder(dividingBy: 100) == 0 {
  93. priceText = "¥\(Int(model.amount / 100))"
  94. } else {
  95. priceText = String(format: "¥%.2lf", model.amount / 100 )
  96. }
  97. self.priceLabel.text = priceText
  98. self.priceLabel.setSpecificTextColorFont("¥", color: .hexStringColor(hexString: "#F12A1D"), font: UIFont.systemFont(ofSize: 14, weight: .medium))
  99. // let width = priceText.singleLineWidth(font: .textF(12)) + 28.rpx
  100. // self.priceLabel.snp.updateConstraints { make in
  101. // make.width.equalTo(width)
  102. // }
  103. var orinalPriceText = ""
  104. if model.originalAmount.truncatingRemainder(dividingBy: 100) == 0 {
  105. orinalPriceText = "¥\(Int(model.originalAmount / 100))"
  106. } else {
  107. orinalPriceText = String(format: "¥%.2lf", model.originalAmount / 100 )
  108. }
  109. self.originPriceLabel.text = orinalPriceText
  110. }
  111. }
  112. extension QSLVipGoodCollectionViewCell {
  113. func initView() {
  114. self.contentView.addSubview(bgView)
  115. bgView.snp.makeConstraints { make in
  116. make.right.bottom.equalTo(0)
  117. make.left.equalTo(6.rpx)
  118. make.top.equalTo(11.rpx)
  119. }
  120. self.contentView.addSubview(tagIcon)
  121. tagIcon.snp.makeConstraints { make in
  122. make.left.equalTo(0)
  123. make.top.equalTo(0)
  124. make.size.equalTo(CGSize(width: 79.rpx, height: 29.rpx))
  125. }
  126. self.bgView.addSubview(goodNameLabel)
  127. goodNameLabel.snp.makeConstraints { make in
  128. make.centerX.equalToSuperview()
  129. make.top.equalTo(16.rpx)
  130. }
  131. self.bgView.addSubview(priceLabel)
  132. // let width = "¥128".singleLineWidth(font: .textF(12)) + 28.rpx
  133. priceLabel.snp.makeConstraints { make in
  134. // make.width.equalTo(width)
  135. // make.height.equalTo(21.rpx)
  136. make.top.equalTo(goodNameLabel.snp.bottom).offset(5.rpx)
  137. make.top.equalTo(45.rpx)
  138. make.centerX.equalToSuperview()
  139. }
  140. self.bgView.addSubview(originPriceLabel)
  141. originPriceLabel.snp.makeConstraints { make in
  142. make.centerX.equalToSuperview()
  143. make.top.equalTo(priceLabel.snp.bottom).offset(5.rpx)
  144. }
  145. let width = "0.001元/天".singleLineWidth(font: .textF(10)) + 24.rpx
  146. self.bgView.addSubview(goodDailyPriceLabel)
  147. goodDailyPriceLabel.snp.makeConstraints { make in
  148. make.centerX.equalToSuperview()
  149. make.bottom.equalTo(-8.rpx)
  150. make.height.equalTo(21.rpx)
  151. make.width.equalTo(width)
  152. }
  153. }
  154. }