杨锴
2024-09-14 6912d657ec6bb1db9683d5b5be8f0777f001ba11
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
132
133
134
135
136
137
138
139
140
141
142
143
144
//
//  PlanGuide_3_VC.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/30.
//
 
import UIKit
import JQTools
 
class PlanGuide_3_VC: BaseVC {
 
                @IBOutlet weak var label_title: UILabel!
                @IBOutlet weak var btn_previous: UIButton!
                @IBOutlet weak var btn_next: UIButton!
                @IBOutlet weak var view_content: UIView!
                @IBOutlet weak var collectionVIew: UICollectionView!
                private var selectModels = Set<TagModel>()
 
                var responseUserAnswerModel:ResponseUserAnswerModel!
                private var items = [[TagModel]?]()
 
 
                override func viewWillAppear(_ animated: Bool) {
                                super.viewWillAppear(animated)
                                let btn = navigationItem.leftBarButtonItem?.customView as! UIButton
                                btn.isHidden = true
                }
 
                override func viewDidLoad() {
                                super.viewDidLoad()
 
                                var topIndex = 0
                                Services.getTag().subscribe(onNext: { data in
                                                self.items = Array<TagModel>.splitArray((data.data ?? []), subArraySize: 3)
                                                self.collectionVIew.reloadData()
                                }).disposed(by: disposeBag)
                }
 
                override func setUI() {
                                label_title.font = Def_SourceHanSerif_Medium(fontSize: 16)
                                label_title.textColor = UIColor(hexString: "#304D1F")
 
                                btn_previous.titleLabel?.font = Def_SourceHanSerif_Medium(fontSize: 13)
                                btn_next.titleLabel?.font = Def_SourceHanSerif_Medium(fontSize: 13)
 
                                view_content.jq_gradientColor(colorArr: [UIColor(hexString: "#D2EDE4")!.cgColor,UIColor.white.withAlphaComponent(0.8).cgColor], cornerRadius: 20, startPoint: CGPoint(x: 0, y: 1), endPoint: CGPoint(x: 0, y: 0), bounds: nil, locations:nil)
 
                                collectionVIew.delegate = self
                                collectionVIew.dataSource = self
                                collectionVIew.backgroundColor = .clear
                                collectionVIew.register(Planguide_3_CCell.self, forCellWithReuseIdentifier: "cell")
                                let flowLayout = EqualCellSpaceFlowLayout(.center, 5.5)
                                flowLayout.headerReferenceSize = CGSize(width: JQ_ScreenW, height: 2)
                                flowLayout.itemSize = CGSize(width: 75, height: 38)
                                collectionVIew.collectionViewLayout = flowLayout
                }
 
                @IBAction func nextAction(_ sender: UIButton) {
                                responseUserAnswerModel.tagsId = selectModels.map({"\($0.id)"}).joined(separator: ",")
                                Services.saveUserAnswers(responseUserAnswerModel).subscribe(onNext: { data in
                                                NotificationCenter.default.post(name: PlantGuideQuit_Noti, object: true)
                                }).disposed(by: disposeBag)
                }
 
                @IBAction func previousAction(_ sender: UIButton) {
                                self.navigationController?.popViewController()
                }
 
 
                @IBAction func backAction(_ sender: UIButton) {
                                NotificationCenter.default.post(name: PlantGuideQuit_Noti, object: nil)
                }
}
 
extension PlanGuide_3_VC:UICollectionViewDelegate & UICollectionViewDataSource{
 
                func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
                                let m = items[indexPath.section]![indexPath.row]
 
                                if selectModels.contains(m){
                                                selectModels.remove(m)
                                }else{
                                                selectModels.insert(m)
                                }
                                collectionView.reloadData()
                }
 
                func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                                return items[section]?.count ?? 0
                }
 
                func numberOfSections(in collectionView: UICollectionView) -> Int {
                                return items.count
                }
 
                func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! Planguide_3_CCell
                                let m = items[indexPath.section]![indexPath.row]
                                cell.label_title.text = m.tagName
                                cell.isSelect(selectModels.contains(m))
                                return cell
                }
}
 
 
class Planguide_3_CCell:UICollectionViewCell{
 
                var label_title:UILabel!
 
                override init(frame: CGRect) {
                                super.init(frame: frame)
 
                                jq_cornerRadius = 20
                                jq_borderWidth = 0.8
                                jq_borderColor = UIColor(hexString: "#304D1F")
 
                                label_title = UILabel()
                                label_title.textColor = UIColor(hexString: "#304D1F")
                                label_title.font = Def_SourceHanSerif_Medium(fontSize: 12)
                                label_title.textAlignment = .center
                                addSubview(label_title)
                                label_title.snp.makeConstraints { make in
                                                make.edges.equalToSuperview()
                                }
                }
 
                func isSelect(_ status:Bool){
                                if status{
                                                label_title.textColor = .white
                                                label_title.backgroundColor = UIColor(hexString: "#5E9456")
                                                label_title.jq_borderWidth = 0
                                }else{
                                                label_title.textColor = UIColor(hexString: "#304D1F")
                                                label_title.backgroundColor = .clear
                                                label_title.font = Def_SourceHanSerif_Medium(fontSize: 12)
                                                label_title.jq_borderWidth = 0.8
                                }
                }
 
                required init?(coder: NSCoder) {
                                fatalError("init(coder:) has not been implemented")
                }
}