From 858bd6df13a6a6415d12d8e60141575574646f58 Mon Sep 17 00:00:00 2001
From: younger_times <841720330@qq.com>
Date: 星期一, 24 七月 2023 18:23:48 +0800
Subject: [PATCH] 新增

---
 WanPai/Root/Search/VC/SearchStoreDetailFeedbackVC.swift |   73 +++++++++++++++++++++++++++++++++++-
 1 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/WanPai/Root/Search/VC/SearchStoreDetailFeedbackVC.swift b/WanPai/Root/Search/VC/SearchStoreDetailFeedbackVC.swift
index 9443a50..2027d4c 100644
--- a/WanPai/Root/Search/VC/SearchStoreDetailFeedbackVC.swift
+++ b/WanPai/Root/Search/VC/SearchStoreDetailFeedbackVC.swift
@@ -6,10 +6,28 @@
 //
 
 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()
@@ -17,6 +35,8 @@
         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) {
@@ -26,20 +46,69 @@
             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
     }
 }
 

--
Gitblit v1.7.1