MVMineProductCell.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // MVMineProductCell.swift
  3. // MusicVideoPlus
  4. //
  5. // Created by SanW on 2021/6/22.
  6. //
  7. import BFFramework
  8. import UIKit
  9. class MVMineProductCell: UICollectionViewCell {
  10. var btnClickHandle: ((_ sender: UIButton, _ videoData: PQVideoListModel?) -> Void)?
  11. lazy var coverImageView: UIImageView = {
  12. let coverImageView = UIImageView()
  13. // coverImageView.contentMode = .scaleAspectFill
  14. // coverImageView.clipsToBounds = true
  15. coverImageView.isUserInteractionEnabled = false
  16. // coverImageView.tag = cCellTag
  17. coverImageView.backgroundColor = UIColor.white
  18. coverImageView.addCorner(corner: 6)
  19. return coverImageView
  20. }()
  21. lazy var marksView: UIImageView = {
  22. let marksView = UIImageView(image: UIImage(named: "home_marks"))
  23. // marksView.contentMode = .scaleAspectFill
  24. // marksView.clipsToBounds = true
  25. marksView.isUserInteractionEnabled = false
  26. return marksView
  27. }()
  28. lazy var moreBtn: UIButton = {
  29. let moreBtn = UIButton(type: .custom)
  30. let image: UIImage = UIImage(named: "icon_video_point")!
  31. moreBtn.setImage(UIImage(cgImage: image.cgImage!, scale: image.scale, orientation: .left), for: .normal)
  32. moreBtn.tag = 1
  33. moreBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
  34. return moreBtn
  35. }()
  36. lazy var titleLabel: UILabel = {
  37. let titleLabel = UILabel()
  38. titleLabel.textAlignment = .left
  39. titleLabel.textColor = .white
  40. titleLabel.numberOfLines = 1
  41. titleLabel.font = UIFont.systemFont(ofSize: 16, weight: .bold)
  42. return titleLabel
  43. }()
  44. lazy var statusBtn: UIButton = {
  45. let statusBtn = UIButton(type: .custom)
  46. statusBtn.backgroundColor = cShadowColor
  47. statusBtn.titleLabel?.font = UIFont.systemFont(ofSize: 17, weight: .medium)
  48. statusBtn.setTitleColor(UIColor.white, for: .normal)
  49. statusBtn.tag = 2
  50. statusBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
  51. return statusBtn
  52. }()
  53. override init(frame: CGRect) {
  54. super.init(frame: frame)
  55. contentView.addSubview(coverImageView)
  56. coverImageView.addSubview(marksView)
  57. contentView.addSubview(statusBtn)
  58. contentView.addSubview(moreBtn)
  59. contentView.addSubview(titleLabel)
  60. }
  61. required init?(coder _: NSCoder) {
  62. fatalError("init(coder:) has not been implemented")
  63. }
  64. @objc class func productCell(collectionView: UICollectionView, indexPath: IndexPath) -> MVMineProductCell {
  65. let cell: MVMineProductCell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: MVMineProductCell.self), for: indexPath) as! MVMineProductCell
  66. return cell
  67. }
  68. var videoData: PQVideoListModel? {
  69. didSet {
  70. addData()
  71. addLayout()
  72. }
  73. }
  74. func addData() {
  75. let coverImg = (videoData?.videoCoverSnapshotPath != nil && (videoData?.videoCoverSnapshotPath?.count ?? 0) > 0) ? videoData?.videoCoverSnapshotPath ?? "" : videoData?.coverImg?["coverImgPath"] as! String
  76. coverImageView.setNetImage(url: coverImg)
  77. titleLabel.text = videoData?.title ?? ""
  78. statusBtn.isHidden = (videoData?.auditStatus == 5 && videoData?.transcodeStatus == 3 && (videoData?.transcodeStatus == 1 || videoData?.transcodeStatus == 3))
  79. if videoData?.transcodeStatus == 2 {
  80. statusBtn.setTitle("转码中", for: .normal)
  81. } else {
  82. statusBtn.setTitle("制作中", for: .normal)
  83. }
  84. }
  85. func addLayout() {
  86. let margin: CGFloat = 12
  87. let moreH: CGFloat = 30
  88. coverImageView.snp.remakeConstraints { make in
  89. make.size.equalToSuperview()
  90. }
  91. statusBtn.snp.makeConstraints { make in
  92. make.size.equalToSuperview()
  93. }
  94. marksView.snp.remakeConstraints { make in
  95. make.width.left.bottom.equalToSuperview()
  96. }
  97. moreBtn.snp.remakeConstraints { make in
  98. make.width.height.equalTo(moreH)
  99. make.right.equalToSuperview()
  100. make.bottom.equalToSuperview().offset(-cDefaultMargin)
  101. }
  102. titleLabel.snp.remakeConstraints { make in
  103. make.centerY.equalTo(moreBtn)
  104. make.left.equalToSuperview().offset(margin)
  105. make.right.equalTo(moreBtn.snp_left).offset(cDefaultMargin / 2)
  106. }
  107. }
  108. @objc func btnClick(sender: UIButton) {
  109. if btnClickHandle != nil {
  110. btnClickHandle!(sender, videoData)
  111. }
  112. }
  113. }