| | |
| | | |
| | | import UIKit |
| | | import JQTools |
| | | import RxSwift |
| | | import RxRelay |
| | | import CoreLocation |
| | | |
| | | class PavilionViewModel:RefreshInnerModel<PavilionDetailModel>{ |
| | | var location = BehaviorRelay<CLLocationCoordinate2D?>(value: nil) |
| | | var search = BehaviorRelay<String?>(value: nil) |
| | | |
| | | override func api() -> (Observable<BaseResponse<BaseResponseList<PavilionDetailModel>>>)? { |
| | | return Services.getPavlilonPage(location: location.value, search: search.value, page: page) |
| | | } |
| | | } |
| | | |
| | | class PavilionVC: BaseVC { |
| | | @IBOutlet weak var collectionView: UICollectionView! |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | |
| | | } |
| | | private var viewModel = PavilionViewModel() |
| | | private var locationTool = JQ_LocationTool.instance() |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | |
| | | viewModel.configure(collectionView) |
| | | viewModel.beginRefresh() |
| | | |
| | | locationTool.startLocation { location in |
| | | self.viewModel.location.accept(location.coordinate) |
| | | self.viewModel.beginRefresh() |
| | | } errorClouse: { error in |
| | | } |
| | | } |
| | | |
| | | override func setUI() { |
| | | super.setUI() |
| | |
| | | collectionView.backgroundColor = .clear |
| | | collectionView.showsVerticalScrollIndicator = false |
| | | collectionView.backgroundColor = .clear |
| | | collectionView.contentInset = UIEdgeInsets(top: 52.5, left: 28.5, bottom: 0, right: 28.5) |
| | | collectionView.contentInset = UIEdgeInsets(top: 0, left: 28.5, bottom: 0, right: 28.5) |
| | | collectionView.register(UINib(nibName: "PavilionItemCell", bundle: nil), forCellWithReuseIdentifier: "_PavilionItemCell") |
| | | } |
| | | |
| | | |
| | | @IBAction func searchAction(_ sender: Any) { |
| | | let searchVC = PavilionSearchVC() |
| | | searchVC.viewModel = viewModel |
| | | push(vc: searchVC) |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | extension PavilionVC:UICollectionViewDelegate{ |
| | | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| | | let detailVC = PavilionDetailVC() |
| | | let model = viewModel.dataSource.value!.list[indexPath.row] |
| | | let detailVC = PavilionDetailVC(id: model.id) |
| | | push(vc: detailVC) |
| | | } |
| | | } |
| | | |
| | | extension PavilionVC:UICollectionViewDataSource{ |
| | | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { |
| | | |
| | | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_PavilionItemCell", for: indexPath) as! PavilionItemCell |
| | | 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 10 |
| | | return viewModel.dataSource.value?.list.count ?? 0 |
| | | } |
| | | } |
| | | |