杨锴
2025-05-11 7453d2d0cef415b34323d1b91e6cfa4a6ba31178
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
//  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
    }
}