OrderApplyRefundPhotoCell.swift 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //
  2. // OrderApplyRefundPhotoCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/5/17.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. class OrderApplyRefundPhotoCell: UITableViewCell {
  10. private let maxImageCount: Int = 3
  11. typealias ChoosePicBlock = () -> Void
  12. var choosePicBlock : ChoosePicBlock?
  13. typealias DelPicTransBlock = (_ idxRow:Int?) -> Void
  14. var delPicTransBlock : DelPicTransBlock?
  15. var imgCount: Int = 0
  16. var goodsImageArr: Array<UIImage>? {
  17. didSet {
  18. imgCount = self.goodsImageArr?.count ?? 0
  19. }
  20. }
  21. class func cellWith(tableView:UITableView,indexPath:IndexPath) -> OrderApplyRefundPhotoCell {
  22. let ID = "OrderApplyRefundPhotoCell"
  23. tableView.register(OrderApplyRefundPhotoCell.self, forCellReuseIdentifier: ID)
  24. let cell : OrderApplyRefundPhotoCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! OrderApplyRefundPhotoCell
  25. cell.indexPath = indexPath
  26. return cell
  27. }
  28. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  29. super.init(style: style, reuseIdentifier: reuseIdentifier)
  30. setupViews()
  31. setupLayouts()
  32. }
  33. required init?(coder aDecoder: NSCoder) {
  34. fatalError("init(coder:) has not been implemented")
  35. }
  36. var indexPath: IndexPath? {
  37. didSet {
  38. }
  39. }
  40. //MRAK: - 设置View
  41. private func setupViews() {
  42. self.selectionStyle = .none
  43. addSubview(titleLabel)
  44. addSubview(collectionView)
  45. addSubview(rmdBackView)
  46. rmdBackView.addSubview(remindLabel)
  47. }
  48. private func setupLayouts() {
  49. titleLabel.snp.makeConstraints { (make) in
  50. make.left.top.equalTo(14)
  51. make.height.equalTo(20)
  52. }
  53. collectionView.snp.makeConstraints { (make) in
  54. make.top.equalTo(titleLabel.snp_bottom)
  55. make.left.right.equalToSuperview()
  56. make.height.equalTo(200)
  57. make.bottom.equalToSuperview().offset(-69)
  58. }
  59. rmdBackView.snp.makeConstraints { (make) in
  60. make.top.equalTo(collectionView.snp_bottom)
  61. make.left.right.equalToSuperview()
  62. make.height.equalTo(69)
  63. }
  64. remindLabel.snp.makeConstraints { (make) in
  65. make.top.equalTo(20)
  66. make.centerX.equalToSuperview()
  67. make.height.equalTo(20)
  68. }
  69. }
  70. private lazy var titleLabel: UILabel = {
  71. let titleLabel = UILabel()
  72. titleLabel.text = "拍照上传问题"
  73. titleLabel.textColor = k333333Color
  74. titleLabel.font = kBoldFont14
  75. titleLabel.textAlignment = .left
  76. return titleLabel
  77. }()
  78. private lazy var rmdBackView: UIView = {
  79. let rmdBackView = UIView()
  80. rmdBackView.backgroundColor = kf7f8faColor
  81. return rmdBackView
  82. }()
  83. private lazy var remindLabel: UILabel = {
  84. let remindLabel = UILabel()
  85. remindLabel.text = "退款将根据支付方式原路返回"
  86. remindLabel.textColor = k333333Color
  87. remindLabel.font = kBoldFont13
  88. return remindLabel
  89. }()
  90. private lazy var collectionView: UICollectionView = {
  91. let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
  92. collectionView.backgroundColor = kffffffColor
  93. collectionView.delegate = self;
  94. collectionView.dataSource = self;
  95. collectionView.showsVerticalScrollIndicator = false
  96. collectionView.showsHorizontalScrollIndicator = false
  97. return collectionView
  98. }()
  99. private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
  100. let collectionViewLayout = UICollectionViewFlowLayout.init()
  101. collectionViewLayout.minimumLineSpacing = 10
  102. collectionViewLayout.minimumInteritemSpacing = 0
  103. return collectionViewLayout
  104. }()
  105. //加载数据
  106. func reloadData() {
  107. //collectionView重新加载数据
  108. self.collectionView.reloadData()
  109. //更新collectionView的高度约束
  110. let contentSize = self.collectionView.collectionViewLayout.collectionViewContentSize
  111. collectionView.snp.remakeConstraints { (make) in
  112. make.top.equalTo(titleLabel.snp_bottom)
  113. make.left.right.equalToSuperview()
  114. make.height.equalTo(contentSize.height)
  115. make.bottom.equalToSuperview().offset(-69)
  116. }
  117. self.collectionView.collectionViewLayout.invalidateLayout()
  118. }
  119. }
  120. extension OrderApplyRefundPhotoCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UICollectionViewDelegate {
  121. func numberOfSections(in collectionView: UICollectionView) -> Int {
  122. return 1
  123. }
  124. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  125. if imgCount < maxImageCount {
  126. return imgCount+1
  127. } else {
  128. return maxImageCount
  129. }
  130. }
  131. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  132. if imgCount < maxImageCount && indexPath.row == imgCount {
  133. // 添加图片
  134. let cell = OrderCommentDefaultCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
  135. if imgCount == 0 {
  136. cell.noteStr = "上传凭证"
  137. } else {
  138. cell.noteStr = "\(imgCount)/\(maxImageCount)"
  139. }
  140. return cell
  141. } else {
  142. // 展示图片
  143. let pCell = OrderCommentAddImgCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
  144. if indexPath.row < imgCount {
  145. pCell.showImage = self.goodsImageArr![indexPath.row]
  146. }
  147. pCell.delPicBlock = {
  148. [weak self] (idxRow) in
  149. if let delPicTransBlock = self?.delPicTransBlock {
  150. delPicTransBlock(idxRow)
  151. }
  152. }
  153. return pCell
  154. }
  155. }
  156. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  157. return CGSize(width:(kScreenWidth-30-5*3)/4, height: (kScreenWidth-30-5*3)/4)
  158. }
  159. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
  160. return UIEdgeInsets(top: 10, left: 15, bottom: 20, right: 15)
  161. }
  162. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  163. if imgCount < maxImageCount && indexPath.row == imgCount {
  164. // 添加图片
  165. if let choosePicBlock = self.choosePicBlock {
  166. choosePicBlock()
  167. }
  168. }
  169. }
  170. }