杨锴
2025-04-16 09a372bc45fde16fd42257ab6f78b8deeecf720b
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//
//  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()
 
                                Services.getTag().subscribe(onNext: { data in
                                                self.items = Array<TagModel>.splitArray((data.data ?? []), subArraySize: 3)
 
 
            //分成3:4:3
            if let item = self.items[2]?.first{
                self.items[1]?.append(item)
                self.items[2]?.removeFirst()
 
                if let m = self.items[3]?.first{
                    self.items[2]?.append(m)
                    self.items[3]?.removeAll()
                }
            }
 
                                                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)
 
                                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
                }
 
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        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)
    }
 
                @IBAction func nextAction(_ sender: UIButton) {
        responseUserAnswerModel.tagIds = selectModels.map({"\($0.id)"}).joined(separator: ",")
 
        if UserViewModel.getLoginInfo()?.accessToken.isEmpty ?? true{
            UserDefaults.standard.set(responseUserAnswerModel.toJSONString(), forKey: "saveUserAnswers")
            UserDefaults.standard.synchronize()
            NotificationCenter.default.post(name: PlantGuideQuit_Noti, object: true)
        }else{
            Services.saveUserAnswers(responseUserAnswerModel, device: UserViewModel.DeviceUUID).subscribe(onNext: { data in
                NotificationCenter.default.post(name: PlantGuideQuit_Noti, object: true)
            }).disposed(by: disposeBag)
        }
                }
 
                @IBAction func previousAction(_ sender: UIButton) {
        NotificationCenter.default.post(name: AnswerAgain_Noti, object: nil)
                                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")
                }
}