123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- //
- // SelfRecommendationView.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/4/19.
- // Copyright © 2019 南鑫林. All rights reserved.
- //
- import UIKit
- class SelfRecommendationView: BaseView {
-
- typealias GoShoppingBlock = () -> Void
- var goShoppingBlock : GoShoppingBlock?
-
- typealias DidSelectGoShoppingBlock = (_ indexPath: IndexPath) -> Void
- var didSelectGoShoppingBlock : DidSelectGoShoppingBlock?
-
- typealias ChangeLocationBlock = (_ locationAddress: String) ->Void
- var changeLocationBlock : ChangeLocationBlock?
-
- var locationAddress: String? {
- didSet {
- locationAddressLable.text = locationAddress
- }
- }
-
- var selfMentionAddressArray : Array<SelfMentionAddressModel>?{
- didSet {
- if selfMentionAddressArray?.isEmpty ?? true {
- collectionView.endFooterNoMoreData()
- }else {
- collectionView.isHiddenFooter(false)
- }
- collectionView.reloadData()
- }
- }
-
- override func setupViews() {
- backgroundColor = kf7f8faColor
- addSubview(locationBgImageView)
- locationBgImageView.addSubview(locationTitleLable)
- locationBgImageView.addSubview(locationAddressLable)
- locationBgImageView.addSubview(changeLocationButton)
-
- addSubview(collectionView)
- let emptyView = DIYEmptyView.emptyActionView(withImageStr: "default_page_location", titleStr: "当前位置没有自提点,先进商城逛逛吧", detailStr: nil, btnTitleStr: "去商城") {
- [weak self] in
- /// 跳转到商场
- if let goShoppingBlock = self?.goShoppingBlock {
- goShoppingBlock()
- }
- }
- emptyView?.subViewMargin = 25
- emptyView?.actionBtnFont = kRegularFont16
- emptyView?.actionBtnHeight = 36
- emptyView?.actionBtnHorizontalMargin = 56
- emptyView?.actionBtnCornerRadius = 36/2
- emptyView?.actionBtnTitleColor = kffffffColor
- emptyView?.actionBtnBackGroundColor = kFFA42FColor
- emptyView?.contentViewY = kScaleValue(value: 60)
- collectionView.ly_emptyView = emptyView
- collectionView.ly_startLoading()
- }
-
- override func setupLayouts() {
- locationTitleLable.snp.makeConstraints { (make) in
- make.top.equalToSuperview().offset(kScaleValue(value: 22))
- make.centerX.equalToSuperview()
- }
- locationAddressLable.snp.makeConstraints { (make) in
- make.top.equalTo(locationTitleLable.snp.bottom).offset(kScaleValue(value: 12))
- make.left.equalToSuperview().offset(kScaleValue(value: 20))
- make.right.equalToSuperview().offset(kScaleValue(value: -20))
- }
- changeLocationButton.snp.makeConstraints { (make) in
- make.top.equalTo(locationAddressLable.snp.bottom).offset(kScaleValue(value: 16))
- make.width.equalTo(kScaleValue(value: 80))
- make.height.equalTo(kScaleValue(value: 24))
- make.centerX.equalToSuperview()
- }
-
- locationBgImageView.snp.makeConstraints { (make) in
- make.top.left.right.equalToSuperview()
- make.bottom.equalTo(changeLocationButton).offset(kScaleValue(value: 22))
- }
-
- collectionView.snp.makeConstraints { (make) in
- make.top.equalTo(locationBgImageView.snp.bottom)
- make.left.right.bottom.equalToSuperview()
- }
- }
-
- private lazy var locationBgImageView: UIImageView = {
- let locationBgImageView = UIImageView()
- locationBgImageView.image = kImage(name: "my_bg")
- locationBgImageView.isUserInteractionEnabled = true
- return locationBgImageView
- }()
-
- private lazy var locationTitleLable: UILabel = {
- let locationTitleLable = UILabel()
- locationTitleLable.text = "当前位置"
- locationTitleLable.textColor = kffffffColor
- locationTitleLable.font = kScaleRegularFont14
- return locationTitleLable
- }()
-
- private lazy var locationAddressLable: UILabel = {
- let locationAddressLable = UILabel()
- let locationModel = LocationModel.shared().object()
- locationAddressLable.text = locationModel!.toString()
- locationAddressLable.textColor = kffffffColor
- locationAddressLable.font = kScaleBoldFont16
- locationAddressLable.textAlignment = .center
- locationAddressLable.numberOfLines = 0
- return locationAddressLable
- }()
-
- private lazy var changeLocationButton: UIButton = {
- let changeLocationButton = UIButton(type: UIButton.ButtonType.custom)
- changeLocationButton.setTitle("修改位置", for: UIControl.State.normal)
- changeLocationButton.setBackgroundImage(UIImage.imageWithColor(color: kffffffColor), for: UIControl.State.normal)
- changeLocationButton.setTitleColor(kffb04AColor, for: UIControl.State.normal)
- changeLocationButton.titleLabel?.font = kScaleRegularFont13
- changeLocationButton.cornerRadius = kScaleValue(value: 12)
- changeLocationButton.masksToBounds = true
- changeLocationButton.rx.tap.subscribe(onNext: {
- [weak self] in
-
- if let changeLocationBlock = self?.changeLocationBlock {
- changeLocationBlock(self?.locationAddressLable.text ?? "")
- }
-
- }).disposed(by: disposeBag)
- return changeLocationButton
- }()
-
- lazy var collectionView: UICollectionView = {
- let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
- collectionView.backgroundColor = kf7f8faColor
- collectionView.delegate = self;
- collectionView.dataSource = self;
- collectionView.showsVerticalScrollIndicator = false
- collectionView.showsHorizontalScrollIndicator = false
- return collectionView
- }()
-
- private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
- let collectionViewLayout = UICollectionViewFlowLayout.init()
- collectionViewLayout.minimumLineSpacing = 0
- collectionViewLayout.minimumInteritemSpacing = 0
- collectionViewLayout.estimatedItemSize = CGSize(width:kScreenWidth-kScaleValue(value: 28), height: kScaleValue(value: 110))
- collectionViewLayout.sectionHeadersPinToVisibleBounds = true
- return collectionViewLayout
- }()
-
-
- }
- extension SelfRecommendationView : UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
- func numberOfSections(in collectionView: UICollectionView) -> Int {
- return selfMentionAddressArray?.isEmpty ?? true ? 0 : 1
- }
-
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- switch section {
- case 0:
- return selfMentionAddressArray?.isEmpty ?? true ? 0 : selfMentionAddressArray?.count ?? 0
- default:
- return 0
- }
- }
-
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- switch indexPath.section {
- case 0:
- let cell = SelfRecommendationCollectionViewCell.cellWith(collectionView: collectionView, indexPath: indexPath)
- cell.selfMentionAddressModel = selfMentionAddressArray![indexPath.row]
- return cell
- default:
- return UICollectionViewCell()
- }
-
- }
-
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- if let didSelectGoShoppingBlock = self.didSelectGoShoppingBlock {
- didSelectGoShoppingBlock(indexPath)
- }
-
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
- switch section {
- case 0:
- return UIEdgeInsets(top: 0, left: kScaleValue(value: 10), bottom: kScaleValue(value: 10), right: kScaleValue(value: 10))
- default:
- return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
- }
-
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
- switch section {
- case 0:
- return kScaleValue(value: 10)
- default:
- return 0
- }
- }
-
- func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
-
- if kind == UICollectionView.elementKindSectionHeader {
- switch indexPath.section {
- case 0:
- let headerView = SelfRecommendationHeaderCollectionReusableView.headerWith(collectionView: collectionView, kind: UICollectionView.elementKindSectionHeader, indexPath: indexPath)
- return headerView
- default:
- return UICollectionReusableView()
- }
- }else {
- return UICollectionReusableView()
- }
- }
-
- // 返回HeadView的宽高
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
- switch section {
- case 0:
- return CGSize(width:kScreenWidth, height: kScaleValue(value: 57))
- default:
- return CGSize(width:kScreenWidth, height: 0)
- }
- }
-
- }
|