From 6912d657ec6bb1db9683d5b5be8f0777f001ba11 Mon Sep 17 00:00:00 2001 From: 杨锴 <841720330@qq.com> Date: 星期六, 14 九月 2024 18:24:10 +0800 Subject: [PATCH] fix API --- XQMuse/Root/Plans/PlanGuide_3_VC.swift | 30 +++++++++++++++++++++--------- 1 files changed, 21 insertions(+), 9 deletions(-) diff --git a/XQMuse/Root/Plans/PlanGuide_3_VC.swift b/XQMuse/Root/Plans/PlanGuide_3_VC.swift index 5e7dac1..6ecd191 100644 --- a/XQMuse/Root/Plans/PlanGuide_3_VC.swift +++ b/XQMuse/Root/Plans/PlanGuide_3_VC.swift @@ -15,9 +15,10 @@ @IBOutlet weak var btn_next: UIButton! @IBOutlet weak var view_content: UIView! @IBOutlet weak var collectionVIew: UICollectionView! - private var setIndex = Set<IndexPath>() + private var selectModels = Set<TagModel>() - private var items = [["原生家庭","亲子关系","夫妻关系"],["情感纠结","思念亲人","优质睡眠","提升能量"],["高维智慧","清理净化","情绪稳定"]] + var responseUserAnswerModel:ResponseUserAnswerModel! + private var items = [[TagModel]?]() override func viewWillAppear(_ animated: Bool) { @@ -29,6 +30,11 @@ 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() { @@ -51,7 +57,10 @@ } @IBAction func nextAction(_ sender: UIButton) { - NotificationCenter.default.post(name: PlantGuideQuit_Noti, object: true) + 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) { @@ -67,16 +76,18 @@ extension PlanGuide_3_VC:UICollectionViewDelegate & UICollectionViewDataSource{ func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - if setIndex.contains(indexPath){ - setIndex.remove(indexPath) + let m = items[indexPath.section]![indexPath.row] + + if selectModels.contains(m){ + selectModels.remove(m) }else{ - setIndex.insert(indexPath) + selectModels.insert(m) } collectionView.reloadData() } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return items[section].count + return items[section]?.count ?? 0 } func numberOfSections(in collectionView: UICollectionView) -> Int { @@ -85,8 +96,9 @@ func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! Planguide_3_CCell - cell.label_title.text = items[indexPath.section][indexPath.row] - cell.isSelect(setIndex.contains(indexPath)) + let m = items[indexPath.section]![indexPath.row] + cell.label_title.text = m.tagName + cell.isSelect(selectModels.contains(m)) return cell } } -- Gitblit v1.7.1