|
@@ -7,15 +7,23 @@
|
|
|
//
|
|
|
|
|
|
import UIKit
|
|
|
-import RxSwift
|
|
|
-import IQKeyboardManagerSwift
|
|
|
|
|
|
class PublishEditAddPicCell: UITableViewCell {
|
|
|
|
|
|
- let disposeBag = DisposeBag()
|
|
|
+ private let maxImageCount: Int = 3
|
|
|
|
|
|
- typealias NoteTextViewClosure = (_ text: String) -> Void
|
|
|
- var noteTextViewClosure : NoteTextViewClosure?
|
|
|
+ typealias ChoosePicBlock = () -> Void
|
|
|
+ var choosePicBlock : ChoosePicBlock?
|
|
|
+
|
|
|
+ typealias DelPicTransBlock = (_ idxRow:Int?) -> Void
|
|
|
+ var delPicTransBlock : DelPicTransBlock?
|
|
|
+
|
|
|
+ var imgCount: Int = 0
|
|
|
+ var goodsImageArr: Array<UIImage>? {
|
|
|
+ didSet {
|
|
|
+ imgCount = self.goodsImageArr?.count ?? 0
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
class func cellWith(tableView:UITableView,indexPath:IndexPath) -> PublishEditAddPicCell {
|
|
|
let ID = "PublishEditAddPicCell"
|
|
@@ -40,62 +48,105 @@ class PublishEditAddPicCell: UITableViewCell {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
//MRAK: - 设置View
|
|
|
private func setupViews() {
|
|
|
self.selectionStyle = .none
|
|
|
- addSubview(titleLabel)
|
|
|
- addSubview(noteTextView)
|
|
|
+
|
|
|
+ addSubview(collectionView)
|
|
|
}
|
|
|
|
|
|
private func setupLayouts() {
|
|
|
- titleLabel.snp.makeConstraints { (make) in
|
|
|
- make.top.left.equalTo(14)
|
|
|
- make.width.equalTo(56)
|
|
|
- make.height.equalTo(20)
|
|
|
- }
|
|
|
- noteTextView.snp.remakeConstraints { (make) in
|
|
|
- make.top.equalTo(6).priority(999)
|
|
|
- make.height.greaterThanOrEqualTo(46).priority(888)
|
|
|
- make.bottom.equalTo(-6).priority(777)
|
|
|
- make.left.equalTo(titleLabel.snp_right).offset(20)
|
|
|
- make.right.equalToSuperview().offset(-14)
|
|
|
+ collectionView.snp.remakeConstraints { (make) in
|
|
|
+ make.top.equalTo(15)
|
|
|
+ make.bottom.equalTo(-15)
|
|
|
+ make.left.right.equalToSuperview()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- lazy var titleLabel: UILabel = {
|
|
|
- let titleLabel = UILabel()
|
|
|
- titleLabel.textColor = k333333Color
|
|
|
- titleLabel.font = kRegularFont14
|
|
|
- titleLabel.text = "备注信息"
|
|
|
- return titleLabel
|
|
|
+ private lazy var collectionView: UICollectionView = {
|
|
|
+ let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
|
|
|
+ collectionView.backgroundColor = kffffffColor
|
|
|
+ collectionView.delegate = self;
|
|
|
+ collectionView.dataSource = self;
|
|
|
+ collectionView.showsVerticalScrollIndicator = false
|
|
|
+ collectionView.showsHorizontalScrollIndicator = false
|
|
|
+ return collectionView
|
|
|
}()
|
|
|
|
|
|
- lazy var noteTextView: IQTextView = {
|
|
|
- let noteTextView = IQTextView()
|
|
|
- noteTextView.backgroundColor = kffffffColor
|
|
|
- noteTextView.textColor = k999999Color
|
|
|
- noteTextView.font = kRegularFont14
|
|
|
- noteTextView.placeholder = "如需部分商品退款请备注退款商品的名称和数量,如订单疑问可通过“我的”联系社长哦"
|
|
|
- noteTextView.placeholderTextColor = k999999Color
|
|
|
- noteTextView.isScrollEnabled = false
|
|
|
- noteTextView.delegate = self
|
|
|
- return noteTextView
|
|
|
+ private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
|
|
|
+ let collectionViewLayout = UICollectionViewFlowLayout.init()
|
|
|
+ collectionViewLayout.minimumInteritemSpacing = 10
|
|
|
+ return collectionViewLayout
|
|
|
}()
|
|
|
|
|
|
+ //加载数据
|
|
|
+ func reloadData() {
|
|
|
+ //collectionView重新加载数据
|
|
|
+ self.collectionView.reloadData()
|
|
|
+ //更新collectionView的高度约束
|
|
|
+ let contentSize = self.collectionView.collectionViewLayout.collectionViewContentSize
|
|
|
+ collectionView.snp.remakeConstraints { (make) in
|
|
|
+ make.top.equalTo(15)
|
|
|
+ make.bottom.equalTo(-15)
|
|
|
+ make.left.right.equalToSuperview()
|
|
|
+ }
|
|
|
+ self.collectionView.collectionViewLayout.invalidateLayout()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-extension PublishEditAddPicCell: UITextViewDelegate {
|
|
|
-
|
|
|
- func textViewDidChange(_ textView: UITextView) {
|
|
|
- if textView == noteTextView {
|
|
|
- var fullStr = textView.text ?? ""
|
|
|
- if textView.text?.count ?? 0 > 180 {
|
|
|
- fullStr = String(fullStr.prefix(150)) as String
|
|
|
- textView.text = fullStr
|
|
|
+extension PublishEditAddPicCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UICollectionViewDelegate {
|
|
|
+ func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
|
+ return 1
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
+ if imgCount < maxImageCount {
|
|
|
+ return imgCount+1
|
|
|
+ } else {
|
|
|
+ return maxImageCount
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
+ if imgCount < maxImageCount && indexPath.row == imgCount {
|
|
|
+ // 添加图片
|
|
|
+ let cell = PublishEditDefaultCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
|
|
|
+ if imgCount == 0 {
|
|
|
+ cell.noteStr = "添加图片"
|
|
|
+ } else {
|
|
|
+ cell.noteStr = "\(imgCount)/\(maxImageCount)"
|
|
|
}
|
|
|
-
|
|
|
- if let noteTextViewClosure = self.noteTextViewClosure {
|
|
|
- noteTextViewClosure(self.noteTextView.text ?? "")
|
|
|
+ return cell
|
|
|
+ } else {
|
|
|
+ // 展示图片
|
|
|
+ let pCell = PublishEditAddImgCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
|
|
|
+ if indexPath.row < imgCount {
|
|
|
+ pCell.showImage = self.goodsImageArr![indexPath.row]
|
|
|
+ }
|
|
|
+ pCell.delPicBlock = {
|
|
|
+ [weak self] (idxRow) in
|
|
|
+ if let delPicTransBlock = self?.delPicTransBlock {
|
|
|
+ delPicTransBlock(idxRow)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return pCell
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
|
|
+ return CGSize(width:100, height: 100)
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
|
|
|
+ return UIEdgeInsets(top: 0, left: 14, bottom: 0, right: -14)
|
|
|
+ }
|
|
|
+
|
|
|
+ func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
|
+ if imgCount < maxImageCount && indexPath.row == imgCount {
|
|
|
+ // 添加图片
|
|
|
+ if let choosePicBlock = self.choosePicBlock {
|
|
|
+ choosePicBlock()
|
|
|
}
|
|
|
}
|
|
|
}
|