| | |
| | | |
| | | import UIKit |
| | | import JQTools |
| | | import QMUIKit |
| | | |
| | | class WelfareVC: BaseVC { |
| | | |
| | | @IBOutlet weak var img_userProfile: UIImageView! |
| | | @IBOutlet weak var label_username: UILabel! |
| | | @IBOutlet weak var btn_vip: QMUIButton! |
| | | @IBOutlet weak var label_coin: UILabel! |
| | | @IBOutlet weak var label_score: UILabel! |
| | | @IBOutlet weak var scrollView: UIScrollView! |
| | | @IBOutlet weak var coinCollectionView: UICollectionView! |
| | | @IBOutlet weak var btn_coupon: UIButton! |
| | | @IBOutlet weak var btn_shoppping: UIButton! |
| | | @IBOutlet weak var btn_weekly: UIButton! |
| | | @IBOutlet weak var btn_todayFree: UIButton! |
| | | |
| | | private var timer:Timer? |
| | | private var timerOffsetX:Double = 0 |
| | | private let cellW = JQ_ScreenW * 0.3794 |
| | | private var benefitHomeModel:BenefitHomeModel? |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | |
| | | Services.benefitHome().subscribe(onNext: {[weak self] data in |
| | | if let model = data.data{ |
| | | self?.benefitHomeModel = model |
| | | self?.img_userProfile.sd_setImage(with: URL(string: model.userHeadImg)) |
| | | self?.label_username.text = model.userName |
| | | self?.btn_vip.isHidden = model.isMember == "年度会员" |
| | | self?.label_coin.text = "\(model.wpCoin)" |
| | | self?.label_score.text = "\(model.userIntegral)" |
| | | self?.coinCollectionView.reloadData() |
| | | |
| | | if let coupon = model.image?.myConpons{ |
| | | self?.btn_coupon.sd_setImage(with: URL(string: coupon), for: .normal, placeholderImage: nil,context: nil) |
| | | } |
| | | |
| | | if let onlineShop = model.image?.onlineShop{ |
| | | self?.btn_shoppping.sd_setImage(with: URL(string: onlineShop), for: .normal, placeholderImage: nil, context: nil) |
| | | } |
| | | |
| | | if let weeksBenefit = model.image?.weeksBenefit{ |
| | | self?.btn_weekly.sd_setImage(with: URL(string: weeksBenefit), for: .normal, placeholderImage: nil, context: nil) |
| | | } |
| | | |
| | | if let todayFree = model.image?.todayFree{ |
| | | self?.btn_todayFree.sd_setImage(with: URL(string: todayFree), for: .normal, placeholderImage: nil, context: nil) |
| | | } |
| | | |
| | | if model.commodities.count > 0{ |
| | | self?.autoScroll() |
| | | } |
| | | } |
| | | }) { error in |
| | | |
| | | }.disposed(by: disposeBag) |
| | | } |
| | | |
| | | override func viewDidDisappear(_ animated: Bool) { |
| | |
| | | } |
| | | |
| | | @IBAction func rechargeAction(_ sender: UIButton) { |
| | | let vc = RechargeRecordVC() |
| | | let vc = RechargeRecordVC(coin: benefitHomeModel?.wpCoin ?? 0) |
| | | push(vc: vc) |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | private func autoScroll(){ |
| | | guard benefitHomeModel != nil else {return} |
| | | timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(runTimer), userInfo: nil, repeats: true) |
| | | timer?.fire() |
| | | RunLoop.current.add(timer!, forMode: .common) |
| | | } |
| | | |
| | | @objc func runTimer(){ |
| | | if timerOffsetX >= (JQ_ScreenW - cellW * (4 - 3)){ |
| | | if timerOffsetX >= (JQ_ScreenW - cellW * Double(benefitHomeModel!.commodities.count - 3)){ |
| | | timerOffsetX = 0 |
| | | coinCollectionView.setContentOffset(CGPoint.zero, animated: true) |
| | | timer?.invalidate() |
| | |
| | | } |
| | | |
| | | private func recoverTimer(){ |
| | | guard benefitHomeModel != nil else {return} |
| | | timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(runTimer), userInfo: nil, repeats: true) |
| | | } |
| | | |
| | |
| | | |
| | | extension WelfareVC:UICollectionViewDelegate{ |
| | | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| | | let model = benefitHomeModel!.commodities[indexPath.row] |
| | | let vc = WelfareRedeemGoodsDetailVC() |
| | | push(vc: vc) |
| | | } |
| | |
| | | |
| | | extension WelfareVC:UICollectionViewDataSource{ |
| | | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { |
| | | return 4 |
| | | return benefitHomeModel?.commodities.count ?? 0 |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { |
| | | let model = benefitHomeModel!.commodities[indexPath.row] |
| | | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_WelfareCoinCCell", for: indexPath) as! WelfareCoinCCell |
| | | cell.label_name.text = "\(indexPath.row)" |
| | | cell.label_name.text = model.commodityName |
| | | cell.label_price.text = model.commodityPrice.currency() |
| | | cell.img_cover.sd_setImage(with: URL(string: model.commodityImg), placeholderImage: UIImage(named: "test_1")) |
| | | return cell |
| | | } |
| | | } |