杨锴
2024-09-12 e15c976316feef72ff9bcabce38e0a078f9505db
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
//
//  PavilionSearchVC.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/19.
//
 
import UIKit
import JQTools
import RxSwift
import RxRelay
import CoreLocation
 
class PavilionSearchVC: BaseVC {
 
                @IBOutlet weak var tf_search: UITextField!
                @IBOutlet weak var collectionView: UICollectionView!
 
                var viewModel:PavilionViewModel?
 
                override func viewDidLoad() {
        super.viewDidLoad()
                                title = "疗愈馆"
                                tf_search.delegate = self
                                tf_search.returnKeyType = .search
                                viewModel?.configure(collectionView)
    }
 
                override func setUI() {
                                super.setUI()
                                view.backgroundColor = UIColor(hexString: "#f6f6f6")
 
                                collectionView.delegate = self
                                collectionView.dataSource = self
                                collectionView.backgroundColor = .clear
                                collectionView.showsVerticalScrollIndicator = false
                                collectionView.backgroundColor = .clear
                                collectionView.contentInset = UIEdgeInsets(top: 0, left: 28.5, bottom: 0, right: 28.5)
                                collectionView.register(UINib(nibName: "PavilionItemCell", bundle: nil), forCellWithReuseIdentifier: "_PavilionItemCell")
                }
 
                @IBAction func cancelAction(_ sender: UIButton) {
                                self.navigationController?.popViewController()
                }
}
 
extension PavilionSearchVC:UITextFieldDelegate{
                func textFieldShouldReturn(_ textField: UITextField) -> Bool {
                                textField.resignFirstResponder()
                                viewModel?.search.accept(textField.text!)
                                viewModel?.beginRefresh()
                                return true
                }
}
 
extension PavilionSearchVC:UICollectionViewDataSource{
 
                func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
                                let model = viewModel!.dataSource.value!.list[indexPath.row]
                                let detailVC = PavilionDetailVC(id: model.id)
                                push(vc: detailVC)
                }
                func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                                let model = viewModel!.dataSource.value!.list[indexPath.row]
                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_PavilionItemCell", for: indexPath) as! PavilionItemCell
                                cell.backgroundColor = .jq_randomColor
                                cell.jq_cornerRadius = 16
                                cell.setPavilionDetailModel(model)
                                return cell
                }
 
                func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                                return viewModel?.dataSource.value?.list.count ?? 0
                }
}
 
extension PavilionSearchVC:UICollectionViewDelegateFlowLayout{
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
                                return 25.5
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
                                return 19
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
                                let w = (JQ_ScreenW - 28.5 * 2 - 19) / 2.0
                                let h = w * 1.2681
                                return CGSizeMake(w, h)
                }
}