//
|
// SearchStoreDetailFeedbackVC.swift
|
// WanPai
|
//
|
// Created by 无故事王国 on 2023/6/30.
|
//
|
|
import UIKit
|
import JQTools
|
import Photos
|
import QMUIKit
|
|
class SearchStoreDetailFeedbackVC: BaseVC, RatingBarDelegate {
|
func ratingDidChange(ratingBar: RatingBar, rating: CGFloat) {
|
score = rating.double
|
}
|
|
@IBOutlet weak var view_start: RatingBar!
|
@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]()
|
private var score = 0.0
|
|
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()
|
title = "门店评价"
|
collectionView.delegate = self
|
collectionView.dataSource = self
|
collectionView.register(UINib(nibName: "UploadImgCCell", bundle: nil), forCellWithReuseIdentifier: "_UploadImgCCell")
|
items.add("Empty")
|
collectionView.reloadData()
|
view_start.delegate = self
|
}
|
|
@IBAction func addAction(_ sender: UIButton) {
|
|
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: self.score)
|
} onError: { error in
|
alert(msg: error.localizedDescription)
|
}.disposed(by: disposeBag)
|
}else{
|
self.uploadData(score: self.score)
|
}
|
}
|
|
private func uploadData(score:Double){
|
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
|
cell.indexPath = indexPath
|
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()
|
}
|
|
cell.clouse = { [weak self] index in
|
guard let weakSelf = self else { return }
|
weakSelf.items.removeObject(at: index.row)
|
collectionView.reloadData()
|
}
|
return cell
|
}
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
return items.count
|
}
|
}
|
|
extension SearchStoreDetailFeedbackVC:UICollectionViewDelegateFlowLayout{
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
return CGSize(width: 70, height: 80)
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
return 0.01
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
|
return 0.01
|
}
|
}
|