| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- //
- // QSLVipGoodCollectionViewCell.swift
- // QuickSearchLocation
- //
- // Created by Destiny on 2024/11/28.
- //
- import UIKit
- class QSLVipGoodCollectionViewCell: UICollectionViewCell {
-
- var goodModel: QSLGoodModel?
-
- lazy var bgView: UIView = {
-
- let view = UIView()
- view.backgroundColor = .white
- view.addRadius(radius: 8.rpx)
- view.addBorder(borderWidth: 2.rpx, borderColor: .hexStringColor(hexString: "#EEEEEE"))
- return view
- }()
-
- lazy var tagIcon: UIImageView = {
-
- let imageView = UIImageView()
- imageView.image = UIImage(named: "vip_goods_tag_icon")
- return imageView
- }()
-
- lazy var goodNameLabel: UILabel = {
-
- let label = UILabel()
- label.text("年度会员")
- label.boldFont(13)
- label.textColor = .hexStringColor(hexString: "#404040")
- return label
- }()
-
- lazy var goodDailyPriceLabel: UILabel = {
-
- let label = UILabel()
- let text = "0.35元/天"
- label.text(text)
- label.font(13)
- label.textColor = .hexStringColor(hexString: "#F12A1D")
- if let range = text.range(of: "/") {
- let nsRange = NSRange(text.startIndex..<range.lowerBound, in: text)
- label.setRangeFontText(font: .textM(20), range: nsRange)
- }
- return label
- }()
-
- lazy var priceLabel: UILabel = {
-
- let label = UILabel()
- label.textAlignment = .center
- label.addRadius(radius: 12.rpx)
- label.backgroundColor = .hexStringColor(hexString: "#F6F6F6")
- label.text("¥128")
- label.font(12)
- label.textColor = .hexStringColor(hexString: "#404040")
- return label
- }()
-
- lazy var originPriceLabel: UILabel = {
-
- let label = UILabel()
- label.text("¥299")
- label.font(13)
- label.textColor = .hexStringColor(hexString: "#A7A7A7")
- label.centerLineText(lineValue: 1, underlineColor: .hexStringColor(hexString: "#A7A7A7"))
- return label
- }()
-
- override init(frame: CGRect) {
- super.init(frame: frame)
-
- initView()
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- func config(model: QSLGoodModel) {
- self.goodModel = model
-
- if model.isSelect {
- self.bgView.layer.borderColor = UIColor.hexStringColor(hexString: "#E7B983").cgColor
- self.bgView.backgroundColor = .hexStringColor(hexString: "#FFF8EF")
- } else {
- self.bgView.layer.borderColor = UIColor.hexStringColor(hexString: "#EEEEEE").cgColor
- self.bgView.backgroundColor = .white
- }
-
- self.tagIcon.isHidden = !model.popular
-
- self.goodNameLabel.text = model.name
- self.goodDailyPriceLabel.text = model.content
-
- if let range = model.content.range(of: "/") {
- let nsRange = NSRange(model.content.startIndex..<range.lowerBound, in: model.content)
- self.goodDailyPriceLabel.setRangeFontText(font: .textM(20), range: nsRange)
- }
- var priceText = ""
- if model.amount.truncatingRemainder(dividingBy: 100) == 0 {
- priceText = "¥\(Int(model.amount / 100))"
- } else {
- priceText = String(format: "¥%.2lf", model.amount / 100 )
- }
- self.priceLabel.text = priceText
- let width = priceText.singleLineWidth(font: .textF(12)) + 28.rpx
- self.priceLabel.snp.updateConstraints { make in
- make.width.equalTo(width)
- }
-
- var orinalPriceText = ""
- if model.originalAmount.truncatingRemainder(dividingBy: 100) == 0 {
- orinalPriceText = "¥\(Int(model.originalAmount / 100))"
- } else {
- orinalPriceText = String(format: "¥%.2lf", model.originalAmount / 100 )
- }
- self.originPriceLabel.text = orinalPriceText
- }
- }
- extension QSLVipGoodCollectionViewCell {
-
- func initView() {
-
- self.contentView.addSubview(bgView)
- bgView.snp.makeConstraints { make in
- make.right.bottom.equalTo(0)
- make.left.equalTo(6.rpx)
- make.top.equalTo(11.rpx)
- }
-
- self.contentView.addSubview(tagIcon)
- tagIcon.snp.makeConstraints { make in
- make.left.equalTo(0)
- make.top.equalTo(0)
- make.size.equalTo(CGSize(width: 79.rpx, height: 29.rpx))
- }
-
- self.bgView.addSubview(goodNameLabel)
- goodNameLabel.snp.makeConstraints { make in
- make.centerX.equalToSuperview()
- make.top.equalTo(16.rpx)
- }
-
- self.bgView.addSubview(goodDailyPriceLabel)
- goodDailyPriceLabel.snp.makeConstraints { make in
- make.centerX.equalToSuperview()
- make.top.equalTo(43.rpx)
- }
-
- self.bgView.addSubview(priceLabel)
- let width = "¥128".singleLineWidth(font: .textF(12)) + 28.rpx
- priceLabel.snp.makeConstraints { make in
- make.width.equalTo(width)
- make.height.equalTo(21.rpx)
- make.bottom.equalTo(-26.rpx)
- make.centerX.equalToSuperview()
- }
-
- self.bgView.addSubview(originPriceLabel)
- originPriceLabel.snp.makeConstraints { make in
- make.centerX.equalToSuperview()
- make.bottom.equalTo(-6.rpx)
- }
- }
- }
|