//
|
// 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")
|
}
|
}
|