| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- //
- // 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..<self.goodList.count{
- var submodel = self.goodList[index]
- submodel.isSelect = false
- }
-
- var model = self.goodList[indexPath.row]
- model.isSelect = !model.isSelect
-
- // switch self.selectGood?.level {
- // case 100 :
- // gravityInstance?.track(QSLGravityConst.vip_good_select, properties: ["id": 1006])
- // break
- // case 700:
- // gravityInstance?.track(QSLGravityConst.vip_good_select, properties: ["id": 1005])
- // break;
- // case 3100:
- // gravityInstance?.track(QSLGravityConst.vip_good_select, properties: ["id": 1004])
- // break;
- // case 9200:
- // gravityInstance?.track(QSLGravityConst.vip_good_select, properties: ["id": 1003])
- // break;
- // case 36600:
- // gravityInstance?.track(QSLGravityConst.vip_good_select, properties: ["id": 1002])
- // break;
- // case 3660000:
- // gravityInstance?.track(QSLGravityConst.vip_good_select, properties: ["id": 1001])
- // break;
- // default:
- // break;
- // }
-
- self.goodsCollectionView.reloadData()
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> 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
- }
- }
- }
|