| | |
| | | // |
| | | |
| | | import UIKit |
| | | import JQTools |
| | | import Photos |
| | | import QMUIKit |
| | | |
| | | class SearchStoreDetailFeedbackVC: BaseVC { |
| | | |
| | | @IBOutlet weak var stackView: UIStackView! |
| | | @IBOutlet weak var collectionView: UICollectionView! |
| | | @IBOutlet weak var textView: QMUITextView! |
| | | private var id:Int! |
| | | private var items = NSMutableArray() |
| | | private var imgs = [UIImage]() |
| | | private var imgUrls = [String]() |
| | | |
| | | init(id:Int) { |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.id = id |
| | | } |
| | | |
| | | required init?(coder: NSCoder) { |
| | | fatalError("init(coder:) has not been implemented") |
| | | } |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | |
| | | collectionView.delegate = self |
| | | collectionView.dataSource = self |
| | | collectionView.register(UINib(nibName: "UploadImgCCell", bundle: nil), forCellWithReuseIdentifier: "_UploadImgCCell") |
| | | items.add("Empty") |
| | | collectionView.reloadData() |
| | | } |
| | | |
| | | @IBAction func startAction(_ sender: UIButton) { |
| | |
| | | v.isSelected = v.tag <= tag |
| | | } |
| | | } |
| | | |
| | | @IBAction func addAction(_ sender: UIButton) { |
| | | let score = ((stackView.arrangedSubviews as! [UIButton]).filter({$0.isSelected}).last?.tag ?? 9) - 9 |
| | | guard score != 0 else {alertError(msg: "请先为门店评分");return} |
| | | |
| | | guard !textView.text.isEmpty else { |
| | | alertError(msg: "请输入评论内容");return |
| | | } |
| | | |
| | | if imgs.count > 0{ |
| | | showHUD("图片上传中") |
| | | imgs.uploadImgToService(needCompress: true).subscribe { texts in |
| | | self.imgUrls = texts |
| | | self.uploadData(score: score) |
| | | } onError: { error in |
| | | alert(msg: error.localizedDescription) |
| | | }.disposed(by: disposeBag) |
| | | }else{ |
| | | self.uploadData(score: score) |
| | | } |
| | | } |
| | | |
| | | private func uploadData(score:Int){ |
| | | Services.evaluationStore(id: id, content: textView.text, imgs: imgUrls.joined(separator: ","), score: score).subscribe(onNext: {data in |
| | | alertSuccess(msg: "评价成功") |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+1) { |
| | | self.navigationController?.popViewController(animated: true) |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | } |
| | | |
| | | extension SearchStoreDetailFeedbackVC:UICollectionViewDelegate{ |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| | | JQ_ImagePickerTool.getSharedInstance().multiImage({ images, objs in |
| | | self.imgs = images |
| | | let temp = NSMutableArray(array: ["Empty"]) |
| | | for obj in objs{ |
| | | temp.insert(obj, at: 0) |
| | | } |
| | | self.items = temp |
| | | self.collectionView.reloadData() |
| | | }, max: 5, selectAsstes: NSMutableArray(array: items.filter({!($0 is String)}))) |
| | | } |
| | | } |
| | | |
| | | extension SearchStoreDetailFeedbackVC:UICollectionViewDataSource{ |
| | | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { |
| | | let item = items[indexPath.row] |
| | | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_UploadImgCCell", for: indexPath) as! UploadImgCCell |
| | | if item is String{ |
| | | cell.btn_del.isHidden = true |
| | | cell.img_cover.image = UIImage(named: "btn_evaluate_add") |
| | | }else{ |
| | | cell.btn_del.isHidden = false |
| | | cell.img_cover.image = (item as? PHAsset)?.toImage() |
| | | } |
| | | return cell |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { |
| | | return 2 |
| | | return items.count |
| | | } |
| | | } |
| | | |