// // QSLActivityVipVC.swift // QuickSearchLocation // // Created by Destiny on 2025/9/23. // import UIKit import GKCycleScrollView class QSLActivityVipVC: QSLBaseController { var goodList: [QSLGoodModel] = [QSLGoodModel]() var selectGood: QSLGoodModel? { didSet { updateSelectGoodUI() } } var currentCell: QSLVipMostGoodCell? override func viewDidLoad() { super.viewDidLoad() //gravityInstance?.track(QSLGravityConst.vip_show, properties: ["id": 1001]) self.initializeView() self.requestNetwork() } @objc func payBtnAction() { } @objc func requestNetwork() { // 定义并赋值 itemListDict(根据条件变化) let itemListDict: [String: Any] = ["itemListType": 2] // 网络请求时使用 itemListDict 作为参数(关键修复) QSLNetwork().request(.vipActivityItemList(dict: itemListDict)) { response in // 后续逻辑不变... let list = response.mapArray(QSLGoodModel.self, modelKey: "data>list") self.goodList = list //TODO: 测试 self.goodList += list self.goodList += list if self.goodList.count > 0 { self.goodList[0].isSelect = true self.selectGood = self.goodList[0] var height = 200.rpx if(self.goodList.count > 2){ let row = (self.goodList.count-1)/2 + 1 height = 124.rpx + row*124.rpx } self.vipItemView.snp.updateConstraints { make in make.height.equalTo(height) } self.scrollView.snp.makeConstraints { make in make.bottom.equalTo(self.vipItemView).offset(100) } // // self.checkRenewalOfProducts() } self.goodsCollectionView.reloadData() } fail: { code, error in self.view.toast(text: "加载商品列表失败") } } @objc func resumeBtnAction() { } lazy var scrollView: UIScrollView = { let scrollView = UIScrollView() // scrollView.delegate = self scrollView.bounces = false scrollView.showsVerticalScrollIndicator = false scrollView.contentInsetAdjustmentBehavior = .never return scrollView }() lazy var vipNaviView: UIView = { let view = UIView(frame: CGRectMake(0, 0, QSLConst.qsl_kScreenW, QSLConst.qsl_kScreenH)) view.addCorner(conrners: [.topLeft,.topRight], radius: 12.rpx) view.backgroundColor = UIColor.white return view }() lazy var naviTitleIcon: UILabel = { let label = UILabel() label.text("超值优惠") label.textColor = .white label.mediumFont(17) return label }() lazy var naviResumeBtn: UIButton = { let button = UIButton() button.title("恢复购买") button.setTitleColor(.white, for: .normal) button.titleLabel?.font = UIFont.systemFont(ofSize: 11, weight: .medium) button.image(UIImage(named: "vip_resume_btn")?.withTintColor(UIColor.white)) button.setImageTitleLayout(.imgLeft, spacing: 2.rpx) button.addTarget(self, action: #selector(resumeBtnAction), for: .touchUpInside) return button }() lazy var backButton: UIButton = { let button = UIButton() button.image(UIImage(named: "vip_pay_failure_close")) button.addTarget(self, action: #selector(backBtnAction), for: .touchUpInside) return button }() lazy var vipBg: UIView = { let imageView = UIView() return imageView }() lazy var vipTopBg: UIImageView = { let imageView = UIImageView() imageView.image = UIImage(named: "vip_activity_top_bg") return imageView }() lazy var vipTopTitleView: UIImageView = { let imageView = UIImageView() imageView.image = UIImage(named: "vip_activity_top_title") return imageView }() lazy var vipDiamondView: UIButton = { let button = UIButton() button.image(UIImage(named: "vip_activity_top_diamond")) button.title("会员限时福利") button.font(14) button.textColor(.white) button.setImageTitleLayout(.imgLeft, spacing: 4.rpx) button.isUserInteractionEnabled = false return button }() lazy var vipContentView: UIView = { let view = UIView(frame: CGRectMake(0, 0, QSLConst.qsl_kScreenW, QSLConst.qsl_kScreenH)) view.addCorner(conrners: [.topLeft,.topRight], radius: 12.rpx) view.backgroundColor = UIColor.white return view }() lazy var addTitleIcon: UILabel = { let label = UILabel() label.text("功能介绍") label.textColor = .hexStringColor(hexString: "#202020") label.boldFont(15) return label }() lazy var addTitleIconBg: UIView = { let view = UIView(frame: CGRectMake(0, 0, 117.rpx, 8.rpx)) view.addRadius(radius: 4.rpx) // 创建渐变色层 let gradientLayer = CAGradientLayer() gradientLayer.colors = [ UIColor.hexStringColor(hexString: "#00DDAA",alpha: 1).cgColor, UIColor.hexStringColor(hexString: "#00DDAA",alpha: 0).cgColor ] gradientLayer.startPoint = CGPoint(x: 0, y: 0.4) // 左中 gradientLayer.endPoint = CGPoint(x: 1, y: 0.4) // 右中 gradientLayer.frame = view.bounds // 确保在布局变化时更新frame view.layer.insertSublayer(gradientLayer, at: 0) // 添加布局变化的监听 view.layoutIfNeeded() view.layoutSubviews() return view }() lazy var cycleScrollView: GKCycleScrollView = { let cycleScrollView = GKCycleScrollView() cycleScrollView.dataSource = self cycleScrollView.delegate = self cycleScrollView.isAutoScroll = true cycleScrollView.isInfiniteLoop = true cycleScrollView.isChangeAlpha = false cycleScrollView.leftRightMargin = 12 cycleScrollView.topBottomMargin = 12 cycleScrollView.pageControl = pageControl cycleScrollView.reloadData() return cycleScrollView }() lazy var pageControl: GKPageControl = { let pageControl = GKPageControl() pageControl.style = .rectangle pageControl.dotHeight = 5.rpx pageControl.dotWidth = 5.rpx pageControl.dotMargin = 4.rpx pageControl.pageIndicatorTintColor = .hexStringColor(hexString: "#EEEEEE") pageControl.currentPageIndicatorTintColor = QSLColor.themeMainColor return pageControl }() lazy var vipItemView: UIView = { let item = UIView() return item }() lazy var goodsCollectionView: UICollectionView = { let layout = UICollectionViewFlowLayout() layout.minimumLineSpacing = 0 layout.scrollDirection = .vertical let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) collectionView.backgroundColor = .clear collectionView.dataSource = self collectionView.delegate = self collectionView.showsHorizontalScrollIndicator = false collectionView.bounces = false collectionView.register(cellClass: QSLActivityVipCell.self) return collectionView }() } extension QSLActivityVipVC{ func updateSelectGoodUI(){ } func initializeView() { self.view.addSubview(scrollView) scrollView.snp.makeConstraints { make in make.bottom.top.left.right.equalTo(0) } self.view.addSubview(vipNaviView) vipNaviView.snp.makeConstraints { make in make.top.left.right.equalTo(0) make.top.equalTo(QSLConst.qsl_kNavFrameH) } vipNaviView.addSubview(backButton) backButton.snp.makeConstraints { make in make.width.equalTo(44.rpx) make.height.equalTo(44.rpx) make.left.equalTo(10.rpx) make.top.equalTo(QSLConst.qsl_kStatusBarFrameH) } vipNaviView.addSubview(naviTitleIcon) naviTitleIcon.snp.makeConstraints { make in make.centerX.equalToSuperview() make.width.equalTo(70.rpx) make.height.equalTo(20.rpx) make.centerY.equalTo(backButton.snp.centerY) } vipNaviView.addSubview(naviResumeBtn) naviResumeBtn.snp.makeConstraints { make in make.size.equalTo(CGSize(width: 70.rpx, height: 18.rpx)) make.right.equalTo(-8.rpx) make.centerY.equalTo(backButton.snp.centerY) } self.scrollView.addSubview(vipBg) vipBg.snp.makeConstraints { make in make.top.bottom.left.equalTo(0) make.width.equalTo(QSLConst.qsl_kScreenW) } vipBg.addSubview(vipTopBg) vipTopBg.snp.makeConstraints { make in make.left.top.right.equalTo(0) make.height.equalTo(185.rpx) } vipTopBg.addSubview(vipTopTitleView) vipTopTitleView.snp.makeConstraints { make in make.left.equalTo(16.rpx) make.bottom.equalTo(vipTopBg.snp.bottom).offset(-16.rpx) make.height.equalTo(22.rpx) make.width.equalTo(183.rpx) } vipTopBg.addSubview(vipDiamondView) vipDiamondView.snp.makeConstraints { make in make.left.equalTo(16.rpx) make.bottom.equalTo(vipTopTitleView.snp.top).offset(-6.rpx) make.height.equalTo(20.rpx) make.width.equalTo(105.rpx) } vipBg.addSubview(vipContentView) vipContentView.snp.makeConstraints { make in make.top.equalTo(185.rpx) make.left.right.equalTo(0.rpx) make.height.equalTo(QSLConst.qsl_kScreenH) } vipContentView.addSubview(addTitleIconBg) addTitleIconBg.snp.makeConstraints { make in make.size.equalTo(CGSize(width: 117.rpx, height: 8.rpx)) make.left.equalTo(16.rpx) make.top.equalTo(26.rpx) } vipContentView.addSubview(addTitleIcon) addTitleIcon.snp.makeConstraints { make in make.size.equalTo(CGSize(width: 157.rpx, height: 26.rpx)) make.left.equalTo(20.rpx) make.top.equalTo(12.rpx) } vipContentView.addSubview(cycleScrollView) cycleScrollView.snp.makeConstraints { make in make.left.right.equalTo(0) make.height.equalTo(150.rpx) make.top.equalTo(50.rpx) } vipContentView.addSubview(pageControl) pageControl.snp.makeConstraints { make in make.size.equalTo(CGSize(width: 68.rpx, height: 4.rpx)) make.centerX.equalToSuperview() make.top.equalTo(cycleScrollView.snp.bottom).offset(17.rpx) } vipContentView.addSubview(vipItemView) vipItemView.snp.makeConstraints { make in make.left.right.equalTo(0) make.height.equalTo(150.rpx) make.top.equalTo(pageControl.snp.bottom).offset(16.rpx) } vipItemView.addSubview(goodsCollectionView) goodsCollectionView.snp.makeConstraints { make in make.left.right.top.bottom.equalTo(0) } } } extension QSLActivityVipVC : GKCycleScrollViewDelegate, GKCycleScrollViewDataSource{ func cycleScrollView(_ cycleScrollView: GKCycleScrollView!, cellForViewAt index: Int) -> GKCycleScrollViewCell! { if let cell = cycleScrollView.dequeueReusableCell() { cell.imageView.image = UIImage(named: "vip_activity_banner_\(index+1)") return cell } let cell = GKCycleScrollViewCell() cell.imageView.image = UIImage(named: "vip_activity_banner_\(index+1)") return cell } func numberOfCells(in cycleScrollView: GKCycleScrollView!) -> Int { return 3 } func sizeForCell(in cycleScrollView: GKCycleScrollView!) -> CGSize { return CGSizeMake(QSLConst.qsl_kScreenW - 90.rpx, 150.rpx); } } extension QSLActivityVipVC: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return goodList.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(cellType: QSLActivityVipCell.self, cellForRowAt: indexPath) let model = self.goodList[indexPath.row] if (indexPath.row == 0) { cell.config(model: model, type: .top) } else { if(self.goodList.count > 2){ cell.config(model: model, type: .small) }else{ cell.config(model: model, type: .big) } } return cell } func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { for index in 0.. CGSize { if (indexPath.row == 0) { return CGSize(width: QSLConst.qsl_kScreenW-32.rpx, height: 112.rpx) } else { if(self.goodList.count == 2){ return CGSize(width: QSLConst.qsl_kScreenW-32.rpx, height: 72.rpx) }else{ return CGSize(width: (QSLConst.qsl_kScreenW-50.rpx)/2.0, height: 112.rpx) } } } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { return UIEdgeInsets(top: 0, left: 16.rpx, bottom: 0, right: 16.rpx) } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { return 10.rpx } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { if(self.goodList.count == 2){ return 10.rpx }else{ return 16.rpx } } }