| | |
| | | import JQTools |
| | | |
| | | class SearchVC: BaseVC { |
| | | @IBOutlet weak var scrollView: UIScrollView! |
| | | @IBOutlet weak var banner_collectionView: UICollectionView! |
| | | @IBOutlet weak var label_empty: UILabel! |
| | | @IBOutlet weak var view_container: UIView! |
| | | // @IBOutlet weak var btn_special: UIButton! |
| | | @IBOutlet weak var btn_userLocal: UIButton! |
| | | // @IBOutlet weak var cons_CollectionAspect: NSLayoutConstraint! |
| | | @IBOutlet weak var scrollView: UIScrollView! |
| | | @IBOutlet weak var banner_collectionView: UICollectionView! |
| | | @IBOutlet weak var func_collectionView: UICollectionView! |
| | | @IBOutlet weak var user_avarImg: UIImageView! |
| | | @IBOutlet weak var label_userName: UILabel! |
| | | @IBOutlet weak var label_vip: UILabel! |
| | | @IBOutlet weak var img_vipMedal: UIImageView! |
| | | @IBOutlet weak var label_wpCoin: UILabel! |
| | | @IBOutlet weak var label_coin: UILabel! |
| | | var benefitHomeModel:BenefitHomeModel? |
| | | private var models = [StartClouseExploreModel]() |
| | | |
| | | private var models = [StartClouseExploreModel]() |
| | | private lazy var mapView:MAMapView = { |
| | | let map = MAMapView() |
| | | map.delegate = self |
| | | map.isShowsUserLocation = true |
| | | map.userTrackingMode = .none |
| | | map.isZoomEnabled = true |
| | | map.isScrollEnabled = true |
| | | return map |
| | | }() |
| | | private var items = ["我的二维码","我的预约","社区世界杯","已报名活动","我的运动营","人员管理","我的券包","兑换记录","消费记录","积分明细","我的玩湃币","裁判入口"] |
| | | |
| | | override func viewDidDisappear(_ animated: Bool) { |
| | | super.viewDidDisappear(animated) |
| | | } |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | scrollView.contentInsetAdjustmentBehavior = .never |
| | | |
| | | Services.exploreHome().subscribe(onNext: {[weak self] data in |
| | | if let models = data.data,models.count > 0{ |
| | | self?.models = models |
| | | self?.loadMap() |
| | | self?.banner_collectionView.reloadData() |
| | | }else{ |
| | | |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | |
| | | override func setUI() { |
| | | banner_collectionView.delegate = self |
| | | banner_collectionView.dataSource = self |
| | | banner_collectionView.register(UINib(nibName: "SearchBannerCCell", bundle: nil), forCellWithReuseIdentifier: "_SearchBannerCCell") |
| | | } |
| | | |
| | | |
| | | private func loadMap(){ |
| | | label_empty.isHidden = true |
| | | view_container.addSubview(mapView) |
| | | mapView.frame = CGRect(origin: .zero, size: view_container.size) |
| | | |
| | | for (index,v) in models.enumerated(){ |
| | | let point = CustomPointAnnotation() |
| | | point.coordinate = CLLocationCoordinate2D(latitude: v.latitude, longitude:v.longitude) |
| | | point.title = v.storeAddr |
| | | point.index = index |
| | | v.index = index |
| | | v.annotation = point |
| | | } |
| | | |
| | | let points = models.map({$0.annotation}) as! [CustomPointAnnotation] |
| | | mapView.addAnnotations(points) |
| | | mapView.showAnnotations(points, animated: true) |
| | | mapView.selectAnnotation(points.first!, animated: true) |
| | | view_container.bringSubviewToFront(btn_userLocal) |
| | | } |
| | | |
| | | override func viewDidLayoutSubviews() { |
| | | super.viewDidLayoutSubviews() |
| | | view_container.cornerRadius = 10 |
| | | } |
| | | |
| | | @IBAction func customerAction(_ sender: Any) { |
| | | let vc = CustomerListVC() |
| | | push(vc: vc) |
| | | } |
| | | |
| | | @IBAction func privilegeAction(_ sender: UIButton) { |
| | | let vc = JoinMemberIntroduceVC() |
| | | push(vc: vc) |
| | | } |
| | | |
| | | @IBAction func userLocationAction(_ sender: Any) { |
| | | let userCoordinate = mapView.userLocation.coordinate |
| | | mapView.setCenter(userCoordinate, animated: true) |
| | | } |
| | | |
| | | |
| | | @IBAction func aboutMinProgram(_ sender: Any) { |
| | | |
| | | CommonAlertView.show(title: "提示", content: "即将打开小程序,是否继续?") { status in |
| | | if status{ |
| | | let miniProgam = WXLaunchMiniProgramReq.object() |
| | | miniProgam.userName = WeChatMinProgram |
| | | #if DEBUG |
| | | miniProgam.miniProgramType = .preview |
| | | #else |
| | | miniProgam.miniProgramType = .release |
| | | #endif |
| | | miniProgam.path = WeChatMinProgramPath |
| | | WXApi.send(miniProgam) { s in |
| | | if !s{ |
| | | alert(msg: "打开失败") |
| | | } |
| | | override func viewDidDisappear(_ animated: Bool) { |
| | | super.viewDidDisappear(animated) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | override var preferredStatusBarStyle: UIStatusBarStyle{ |
| | | return .darkContent |
| | | } |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | scrollView.contentInsetAdjustmentBehavior = .never |
| | | |
| | | Services.exploreHome().subscribe(onNext: {[weak self] data in |
| | | if let models = data.data,models.count > 0{ |
| | | self?.models = models |
| | | self?.banner_collectionView.reloadData() |
| | | }else{ |
| | | |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | |
| | | override func viewDidAppear(_ animated: Bool) { |
| | | super.viewDidAppear(animated) |
| | | getData() |
| | | } |
| | | |
| | | override func setUI() { |
| | | banner_collectionView.delegate = self |
| | | banner_collectionView.dataSource = self |
| | | banner_collectionView.register(UINib(nibName: "SearchBannerCCell", bundle: nil), forCellWithReuseIdentifier: "_SearchBannerCCell") |
| | | func_collectionView.delegate = self |
| | | func_collectionView.dataSource = self |
| | | func_collectionView.register(UINib(nibName: "FindItemCCell", bundle: nil), forCellWithReuseIdentifier: "_FindItemCCell") |
| | | func_collectionView.contentInset = UIEdgeInsets(top: 25, left: 0, bottom: 25, right: 0) |
| | | } |
| | | |
| | | |
| | | override func viewDidLayoutSubviews() { |
| | | super.viewDidLayoutSubviews() |
| | | } |
| | | |
| | | private func getData(){ |
| | | Services.benefitHome().subscribe(onNext: {[weak self] data in |
| | | if let model = data.data{ |
| | | self?.benefitHomeModel = model |
| | | self?.user_avarImg.sd_setImage(with: URL(string: model.userHeadImg)) |
| | | self?.label_userName.text = model.userName.isEmpty ? "未命名":model.userName |
| | | self?.label_vip.text = model.isMember |
| | | self?.label_wpCoin.text = model.wpCoin.currencyNotPrefix() |
| | | self?.label_coin.text = "\(model.userIntegral)" |
| | | |
| | | } |
| | | }) { error in |
| | | |
| | | }.disposed(by: disposeBag) |
| | | } |
| | | |
| | | @IBAction func customerAction(_ sender: Any) { |
| | | let vc = CustomerListVC() |
| | | push(vc: vc) |
| | | } |
| | | |
| | | @IBAction func wpCoinDetailAction(_ sender: Any) { |
| | | let vc = RechargeRecordVC(coin: benefitHomeModel?.wpCoin ?? 0,subtype: .coin) |
| | | push(vc: vc) |
| | | } |
| | | |
| | | @IBAction func coinDetailAction(_ sender: Any) { |
| | | let vc = RechargeRecordVC(coin: benefitHomeModel?.userIntegral ?? 0,subtype: .integral) |
| | | push(vc: vc) |
| | | } |
| | | |
| | | |
| | | @IBAction func settingAction(_ sender: Any) { |
| | | let vc = ProfileVC() |
| | | push(vc: vc) |
| | | } |
| | | |
| | | |
| | | @IBAction func aboutMinProgram(_ sender: Any) { |
| | | |
| | | CommonAlertView.show(title: "提示", content: "即将打开小程序,是否继续?") { status in |
| | | if status{ |
| | | let miniProgam = WXLaunchMiniProgramReq.object() |
| | | miniProgam.userName = WeChatMinProgram |
| | | #if DEBUG |
| | | miniProgam.miniProgramType = .preview |
| | | #else |
| | | miniProgam.miniProgramType = .release |
| | | #endif |
| | | miniProgam.path = WeChatMinProgramPath |
| | | WXApi.send(miniProgam) { s in |
| | | if !s{ |
| | | alert(msg: "打开失败") |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | override var preferredStatusBarStyle: UIStatusBarStyle{ |
| | | return .darkContent |
| | | } |
| | | } |
| | | |
| | | extension SearchVC:UICollectionViewDelegate{ |
| | | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| | | let model = models[indexPath.row] |
| | | let vc = SearchStoreDetailVC(id: model.storeId) |
| | | push(vc: vc) |
| | | } |
| | | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| | | if collectionView == func_collectionView{ |
| | | switch items[indexPath.row] |
| | | { |
| | | case "我的二维码": |
| | | let vc = MeQRCodeVC() |
| | | push(vc: vc) |
| | | case "我的预约": |
| | | let vc = YardBookingListVC() |
| | | push(vc: vc) |
| | | case "社区世界杯": |
| | | let vc = WorldCupVC() |
| | | push(vc: vc) |
| | | case "已报名活动": |
| | | let vc = ActivitySignupListVC() |
| | | push(vc: vc) |
| | | case "我的运动营": |
| | | self.tabBarController?.selectedIndex = 1 |
| | | case "人员管理": |
| | | break |
| | | case "我的券包": |
| | | let vc = WelfareCouponsListVC() |
| | | push(vc: vc) |
| | | case "兑换记录": |
| | | let vc = WelfareExchangeRecordListVC() |
| | | push(vc: vc) |
| | | case "消费记录": |
| | | let vc = WelfareBillListVC() |
| | | push(vc: vc) |
| | | case "积分明细": |
| | | let vc = RechargeRecordVC(coin: benefitHomeModel?.userIntegral ?? 0,subtype: .integral) |
| | | push(vc: vc) |
| | | case "我的玩湃币": |
| | | let vc = RechargeRecordVC(coin: benefitHomeModel?.wpCoin ?? 0,subtype: .coin) |
| | | push(vc: vc) |
| | | case "裁判入口": |
| | | break |
| | | default: |
| | | break |
| | | } |
| | | |
| | | |
| | | func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { |
| | | let page = Int(scrollView.contentOffset.x / JQ_ScreenW) |
| | | let model = models[page] |
| | | mapView.selectAnnotation(model.annotation, animated: true) |
| | | } |
| | | } |
| | | |
| | | if collectionView == banner_collectionView{ |
| | | let model = models[indexPath.row] |
| | | let vc = SearchStoreDetailVC(id: model.storeId) |
| | | push(vc: vc) |
| | | } |
| | | } |
| | | } |
| | | |
| | | extension SearchVC:UICollectionViewDataSource{ |
| | | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { |
| | | return models.count |
| | | } |
| | | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { |
| | | if collectionView == func_collectionView{ |
| | | return items.count |
| | | } |
| | | return models.count |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { |
| | | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_SearchBannerCCell", for: indexPath) as! SearchBannerCCell |
| | | let model = models[indexPath.row] |
| | | cell.startClouseExploreItemModel = model |
| | | return cell |
| | | } |
| | | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { |
| | | |
| | | if collectionView == func_collectionView{ |
| | | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_FindItemCCell", for: indexPath) as! FindItemCCell |
| | | cell.label_title.text = items[indexPath.row] |
| | | return cell |
| | | } |
| | | |
| | | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_SearchBannerCCell", for: indexPath) as! SearchBannerCCell |
| | | let model = models[indexPath.row] |
| | | cell.startClouseExploreItemModel = model |
| | | return cell |
| | | } |
| | | } |
| | | |
| | | |
| | | extension SearchVC:UICollectionViewDelegateFlowLayout{ |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { |
| | | return 0 |
| | | } |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { |
| | | return 0 |
| | | } |
| | | if collectionView == func_collectionView{ |
| | | return 0 |
| | | } |
| | | return 0 |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { |
| | | return CGSize(width: JQ_ScreenW, height: JQ_ScreenW * 0.6541) |
| | | } |
| | | } |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { |
| | | if collectionView == func_collectionView{ |
| | | return 0 |
| | | } |
| | | return 0 |
| | | } |
| | | |
| | | extension SearchVC:MAMapViewDelegate{ |
| | | |
| | | func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! { |
| | | if annotation is CustomPointAnnotation{ |
| | | var pointView = mapView.dequeueReusableAnnotationView(withIdentifier: "point") as? CustomPointAnnotationView |
| | | if pointView == nil{ |
| | | pointView = CustomPointAnnotationView(annotation: annotation, reuseIdentifier: "point") |
| | | } |
| | | pointView?.canShowCallout = true |
| | | pointView?.label.text = "\((annotation as! CustomPointAnnotation).index + 1)" |
| | | pointView?.image = UIImage(named: "icon_point")?.withTintColor(UIColor(hexStr: "#f54444")) |
| | | return pointView |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func mapView(_ mapView: MAMapView!, didSelect view: MAAnnotationView!) { |
| | | view.image = UIImage(named: "icon_point")?.withTintColor(UIColor(hexStr: "#2980ff")) |
| | | } |
| | | |
| | | func mapView(_ mapView: MAMapView!, didDeselect view: MAAnnotationView!) { |
| | | view.image = UIImage(named: "icon_point")?.withTintColor(UIColor(hexStr: "#f54444")) |
| | | } |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { |
| | | if collectionView == func_collectionView{ |
| | | return CGSize(width: JQ_ScreenW/4, height: 120) |
| | | } |
| | | return CGSize(width: JQ_ScreenW, height: JQ_ScreenW * 0.6541) |
| | | } |
| | | } |