无故事王国
2023-10-11 f7e33a3255d9f87b20e4a06fc32012eaad77cad5
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
//
//  SearchStoreDetailFeedbackVC.swift
//  WanPai
//
//  Created by 无故事王国 on 2023/6/30.
//
 
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()
        title = "门店评价"
        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) {
        let tag = sender.tag
 
        for v in (stackView.arrangedSubviews as! [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 items.count
    }
}
 
extension SearchStoreDetailFeedbackVC:UICollectionViewDelegateFlowLayout{
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: 60, height: 60)
    }
 
    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
    }
}