QSLActivityVipVC.swift 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. //
  2. // QSLActivityVipVC.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2025/9/23.
  6. //
  7. import UIKit
  8. import GKCycleScrollView
  9. import YYText
  10. class QSLActivityVipVC: QSLBaseController {
  11. var goodList: [QSLGoodModel] = [QSLGoodModel]()
  12. var selectGood: QSLGoodModel?
  13. var currentCell: QSLVipMostGoodCell?
  14. var dismissHandler: ((Bool) -> Void)?
  15. var isCancel = false
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18. gravityInstance?.track(QSLGravityConst.activity_vip_show, properties: [:])
  19. self.initializeView()
  20. self.requestNetwork()
  21. self.updateServiceLabelText(showSubscribe: false)
  22. // if(QSLBaseManager.shared.isLogin()){
  23. // self.naviResumeBtn.isHidden = false
  24. // }else{
  25. // self.naviResumeBtn.isHidden = true
  26. // }
  27. }
  28. @objc func privacyAction() {
  29. let vc = QSLWebViewController()
  30. vc.webUrl = QSLConfig.AppPrivacyAgreementLink
  31. vc.title = "隐私政策"
  32. self.present(vc, animated: true)
  33. }
  34. @objc func serviceAction() {
  35. let vc = QSLWebViewController()
  36. vc.webUrl = QSLConfig.AppServiceAgreementLink
  37. vc.title = "服务协议"
  38. self.present(vc, animated: true)
  39. }
  40. @objc func subscibeAction() {
  41. let vc = QSLWebViewController()
  42. vc.webUrl = QSLConfig.AppSubscibeAgreementLink
  43. vc.title = "续订说明"
  44. self.present(vc, animated: true)
  45. }
  46. @objc func payBtnAction() {
  47. if let curGood = self.selectGood {
  48. QSLCountdownManager.shared.selectGood = curGood
  49. }
  50. switch self.selectGood?.level {
  51. case 100 :
  52. gravityInstance?.track(QSLGravityConst.activity_vip_click, properties: ["package_type": "day"])
  53. break
  54. case 700:
  55. gravityInstance?.track(QSLGravityConst.activity_vip_click, properties: ["package_type": "weekly"])
  56. break;
  57. case 3100:
  58. gravityInstance?.track(QSLGravityConst.activity_vip_click, properties: ["package_type": "monthly"])
  59. break;
  60. case 9200:
  61. gravityInstance?.track(QSLGravityConst.activity_vip_click, properties: ["package_type": "quarterly"])
  62. break;
  63. case 36600:
  64. gravityInstance?.track(QSLGravityConst.activity_vip_click, properties: ["package_type": "yearly"])
  65. break;
  66. case 3660000:
  67. gravityInstance?.track(QSLGravityConst.activity_vip_click, properties: ["package_type": "lifetime"])
  68. break;
  69. default:
  70. break;
  71. }
  72. let memberModel = QSLBaseManager.shared.userModel.memberModel
  73. if let subscriptionExpired = memberModel.subscriptionExpired, !subscriptionExpired {
  74. self.view.toast(text: "你已经订阅了")
  75. return
  76. }
  77. if goodList.count > 0, let selectGood = self.selectGood {
  78. QSLLoading.showWithCancel()
  79. QSLVipManager.shared.startPay(goods: selectGood) { [self] status, outTradeNo in
  80. QSLVipManager.shared.isPaying = false
  81. if status == .success {
  82. QSLLoading.success(text: "支付成功")
  83. //弹出是否好评的弹窗
  84. //QSLGuideusersToCommentManager.commentShare.manageWhetherTriggerPopUpWindow(QSLGuideusersToCommentType.member)
  85. // 引力传递支付事件
  86. if let selectGood = self.selectGood {
  87. gravityInstance?.trackPayEvent(withAmount: Int32(selectGood.amount), withPayType: "CNY", withOrderId: outTradeNo, withPayReason: selectGood.name, withPayMethod: "apple")
  88. }
  89. #if DEBUG
  90. #else
  91. //苹果广告奇异果传递支付事件
  92. QSWikiHandle.shared.addEventResultAttribution(eventDict: ["event_name": "pay", "event_val": selectGood.amount])
  93. #endif
  94. gravityInstance?.track(QSLGravityConst.activity_vip_result, properties: ["purchase_result": "success","pay_amount":Int32(selectGood.amount)])
  95. DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
  96. self.dismiss(animated: false)
  97. NotificationCenter.default.post(name: QSLNotification.QSLRefreshMember, object: nil)
  98. DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
  99. if(!QSLBaseManager.shared.isLogin()){
  100. QSLJumpManager.shared.pushToLogin(type: .member)
  101. }
  102. }
  103. }
  104. } else if status == .cancel {
  105. gravityInstance?.track(QSLGravityConst.activity_vip_result, properties: ["purchase_result": "cancel","pay_amount":Int32(selectGood.amount)])
  106. QSLLoading.error(text: "支付取消")
  107. // payFailAlertTip()
  108. self.isCancel = true
  109. } else if status == .fail {
  110. gravityInstance?.track(QSLGravityConst.activity_vip_result, properties: ["purchase_result": "fail","pay_amount":Int32(selectGood.amount)])
  111. gravityInstance?.track(QSLGravityConst.vip_fail)
  112. QSLLoading.error(text: "支付失败")
  113. // payFailAlertTip()
  114. self.isCancel = true
  115. }
  116. }
  117. }
  118. }
  119. func payFailAlertTip() {
  120. // gravityInstance?.track(QSLGravityConst.activity_vip_retention_show, properties: ["trigger_type":"cancel_payment"])
  121. if let currentWindow = UIApplication.keyWindow {
  122. QSLRetainPopUpAlertView.alert(view: currentWindow, isOneBtn: true, oneBtnText: "继续支付", oneBtnClosure: { [weak self] in
  123. self?.payBtnAction()
  124. // gravityInstance?.track(QSLGravityConst.activity_vip_retention_click, properties: ["button":"continue_payment"])
  125. },secondBtnClosure: {
  126. // gravityInstance?.track(QSLGravityConst.activity_vip_retention_click, properties: ["button":"close"])
  127. })
  128. }
  129. }
  130. @objc func requestNetwork() {
  131. // 定义并赋值 itemListDict(根据条件变化)
  132. let itemListDict: [String: Any] = ["itemListType": 2]
  133. // 网络请求时使用 itemListDict 作为参数(关键修复)
  134. QSLNetwork().request(.vipActivityItemList(dict: itemListDict)) { response in
  135. // 后续逻辑不变...
  136. let list = response.mapArray(QSLGoodModel.self, modelKey: "data>list")
  137. self.goodList = list
  138. if self.goodList.count > 0 {
  139. self.goodList[0].isSelect = true
  140. self.selectGood = self.goodList[0]
  141. var height = 140.rpx
  142. if self.goodList.count == 2 {
  143. height = 200.rpx
  144. } else {
  145. let remainingItems = self.goodList.count - 1
  146. let remainingRows = (remainingItems + 1) / 2
  147. height = Int(134.rpx + CGFloat(remainingRows) * 124.rpx)
  148. }
  149. self.goodsCollectionView.snp.updateConstraints { make in
  150. make.height.equalTo(height)
  151. }
  152. self.scrollView.contentSize = CGSize(width: 0.0, height: self.goodsCollectionView.qsl_y+CGFloat(height)+100+QSLConst.qsl_kTabbarBottom/2+12)
  153. QSLCountdownManager.shared.selectGood = self.goodList[0]
  154. QSLCountdownManager.shared.updateHandler1 = { [weak self] timeString in
  155. self?.countdownLabel.updateCountdownText(timeString)
  156. }
  157. QSLCountdownManager.shared.startCountdown()
  158. NotificationCenter.default.post(
  159. name: Notification.Name("QSLHomeUpdateCouponViewNoti"),
  160. object: nil,
  161. userInfo: ["showCoupon": true]
  162. )
  163. }
  164. self.goodsCollectionView.reloadData()
  165. } fail: { code, error in
  166. self.view.toast(text: "加载商品列表失败")
  167. }
  168. }
  169. override func backBtnAction() {
  170. self.dismissHandler?(self.isCancel)
  171. super.backBtnAction()
  172. }
  173. // 恢复按钮点击
  174. @objc func resumeBtnAction() {
  175. let memberModel = QSLBaseManager.shared.userModel.memberModel
  176. let expired = memberModel.expired
  177. if !expired {
  178. QSLLoading.success(text: "您已经在订阅中,无需恢复")
  179. return
  180. }
  181. QSLLoading.show()
  182. QSLVipManager.shared.restoreAction { isSuccess in
  183. QSLVipManager.shared.isPaying = false
  184. if isSuccess {
  185. QSLNetwork().request(.userMember(dict: [:])) { response in
  186. let model = response.mapObject(QSLMemberModel.self, modelKey: "data")
  187. QSLBaseManager.shared.userModel.memberModel = model
  188. if model.expired {
  189. QSLBaseManager.shared.saveVipExpiredTime(time: 0)
  190. } else {
  191. QSLBaseManager.shared.saveVipExpiredTime(time: model.endTimestamp)
  192. }
  193. QSLBaseManager.shared.saveUserId(id: model.userId)
  194. if model.endTimestamp > memberModel.endTimestamp {
  195. QSLLoading.success(text: "恢复成功")
  196. // 支付成功通知
  197. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3) {
  198. self.navigationController?.popViewController(animated: true)
  199. }
  200. } else {
  201. QSLLoading.error(text: "没有可供恢复的订阅")
  202. }
  203. } fail: { code, error in
  204. QSLLoading.error(text: "没有可供恢复的订阅")
  205. }
  206. } else {
  207. QSLLoading.error(text: "没有可供恢复的订阅")
  208. }
  209. }
  210. }
  211. // 更新服务条款文本内容
  212. func updateServiceLabelText(showSubscribe: Bool) {
  213. let attr = NSMutableAttributedString()
  214. // 固定部分:购买即同意
  215. let firstAttr = NSMutableAttributedString(string: "购买前请先阅读")
  216. firstAttr.font(11)
  217. firstAttr.color(UIColor.init(white: 0, alpha: 0.4))
  218. attr.append(firstAttr)
  219. // 《隐私权政策》
  220. let privacyHL = YYTextHighlight()
  221. let privacyStr = "隐私政策"
  222. let privacyText = NSMutableAttributedString(string: privacyStr)
  223. privacyText.font(11)
  224. privacyText.color(UIColor.init(white: 0, alpha: 0.7))
  225. privacyText.yy_setTextHighlight(privacyHL, range: NSRange(location: 0, length: privacyStr.count))
  226. privacyHL.tapAction = { [weak self] containerView, text, range, rect in
  227. self?.privacyAction()
  228. }
  229. let underline1 = YYTextDecoration(style: .single, width: 1, color: UIColor(white: 0, alpha: 0.7))
  230. privacyText.yy_textUnderline = underline1
  231. attr.append(privacyText)
  232. let blankAttr = NSMutableAttributedString(string: "&")
  233. blankAttr.color(UIColor.init(white: 0, alpha: 0.4))
  234. blankAttr.font(11)
  235. attr.append(blankAttr)
  236. // 《用户协议》
  237. let serviceHL = YYTextHighlight()
  238. let serviceStr = "服务条款"
  239. let serviceText = NSMutableAttributedString(string: serviceStr)
  240. serviceText.font(11)
  241. serviceText.color(UIColor.init(white: 0, alpha: 0.7))
  242. serviceText.yy_setTextHighlight(serviceHL, range: NSRange(location: 0, length: serviceStr.count))
  243. serviceHL.tapAction = { [weak self] containerView, text, range, rect in
  244. self?.serviceAction()
  245. }
  246. let underline = YYTextDecoration(style: .single, width: 1, color: UIColor(white: 0, alpha: 0.7))
  247. serviceText.yy_textUnderline = underline
  248. attr.append(serviceText)
  249. // 根据条件决定是否添加《续订说明》相关内容
  250. if showSubscribe {
  251. attr.append(blankAttr)
  252. let andAttr = NSMutableAttributedString(string: "和")
  253. andAttr.font(10)
  254. andAttr.color(.hexStringColor(hexString: "#A7A7A7"))
  255. attr.append(andAttr)
  256. attr.append(blankAttr)
  257. let subcribeHL = YYTextHighlight()
  258. let subcribeStr = "《续订说明》"
  259. let subcribeText = NSMutableAttributedString(string: subcribeStr)
  260. subcribeText.font(10)
  261. subcribeText.color(.hexStringColor(hexString: "#E7B983"))
  262. subcribeText.yy_setTextHighlight(subcribeHL, range: NSRange(location: 0, length: subcribeStr.count))
  263. subcribeHL.tapAction = { [weak self] containerView, text, range, rect in
  264. self?.subscibeAction()
  265. }
  266. attr.append(subcribeText)
  267. }
  268. serviceLabel.attributedText = attr
  269. serviceLabel.textAlignment = .center
  270. }
  271. lazy var scrollView: UIScrollView = {
  272. let scrollView = UIScrollView()
  273. // scrollView.delegate = self
  274. scrollView.bounces = false
  275. scrollView.backgroundColor = UIColor.white
  276. scrollView.showsVerticalScrollIndicator = false
  277. scrollView.contentInsetAdjustmentBehavior = .never
  278. return scrollView
  279. }()
  280. lazy var vipNaviView: UIView = {
  281. let view = UIView(frame: CGRectMake(0, 0, QSLConst.qsl_kScreenW, QSLConst.qsl_kScreenH))
  282. view.addCorner(conrners: [.topLeft,.topRight], radius: 12.rpx)
  283. view.backgroundColor = UIColor.clear
  284. return view
  285. }()
  286. lazy var naviTitleIcon: UILabel = {
  287. let label = UILabel()
  288. label.text("超值优惠")
  289. label.textColor = .white
  290. label.mediumFont(17)
  291. label.textAlignment = .center
  292. return label
  293. }()
  294. lazy var naviResumeBtn: UIButton = {
  295. let button = UIButton()
  296. button.title("恢复购买")
  297. button.setTitleColor(.white, for: .normal)
  298. button.titleLabel?.font = UIFont.systemFont(ofSize: 11, weight: .medium)
  299. button.image(UIImage(named: "vip_resume_btn")?.withTintColor(UIColor.white))
  300. button.setImageTitleLayout(.imgLeft, spacing: 2.rpx)
  301. button.addTarget(self, action: #selector(resumeBtnAction), for: .touchUpInside)
  302. return button
  303. }()
  304. lazy var backButton: UIButton = {
  305. let button = UIButton()
  306. button.image(UIImage(named: "vip_pay_failure_close"))
  307. button.addTarget(self, action: #selector(backBtnAction), for: .touchUpInside)
  308. return button
  309. }()
  310. lazy var vipTopBg: UIImageView = {
  311. let imageView = UIImageView()
  312. imageView.image = UIImage(named: "vip_activity_top_bg")
  313. return imageView
  314. }()
  315. lazy var vipTopTitleView: UIImageView = {
  316. let imageView = UIImageView()
  317. imageView.image = UIImage(named: "vip_activity_top_title")
  318. return imageView
  319. }()
  320. lazy var vipDiamondView: UIButton = {
  321. let button = UIButton()
  322. button.image(UIImage(named: "vip_activity_top_diamond"))
  323. button.title("会员限时福利")
  324. button.font(14)
  325. button.textColor(.white)
  326. button.setImageTitleLayout(.imgLeft, spacing: 4.rpx)
  327. button.isUserInteractionEnabled = false
  328. return button
  329. }()
  330. lazy var vipContentView: UIView = {
  331. let view = UIView(frame: CGRectMake(0, 0, QSLConst.qsl_kScreenW, QSLConst.qsl_kScreenH))
  332. view.addCorner(conrners: [.topLeft,.topRight], radius: 12.rpx)
  333. view.backgroundColor = UIColor.white
  334. return view
  335. }()
  336. lazy var addTitleIcon: UILabel = {
  337. let label = UILabel()
  338. label.text("功能介绍")
  339. label.textColor = .hexStringColor(hexString: "#202020")
  340. label.boldFont(15)
  341. return label
  342. }()
  343. lazy var addTitleIconBg: UIView = {
  344. let view = UIView(frame: CGRectMake(0, 0, 117.rpx, 8.rpx))
  345. view.addRadius(radius: 4.rpx)
  346. // 创建渐变色层
  347. let gradientLayer = CAGradientLayer()
  348. gradientLayer.colors = [
  349. UIColor.hexStringColor(hexString: "#00DDAA",alpha: 1).cgColor,
  350. UIColor.hexStringColor(hexString: "#00DDAA",alpha: 0).cgColor
  351. ]
  352. gradientLayer.startPoint = CGPoint(x: 0, y: 0.4) // 左中
  353. gradientLayer.endPoint = CGPoint(x: 1, y: 0.4) // 右中
  354. gradientLayer.frame = view.bounds
  355. // 确保在布局变化时更新frame
  356. view.layer.insertSublayer(gradientLayer, at: 0)
  357. // 添加布局变化的监听
  358. view.layoutIfNeeded()
  359. view.layoutSubviews()
  360. return view
  361. }()
  362. lazy var cycleScrollView: GKCycleScrollView = {
  363. let cycleScrollView = GKCycleScrollView()
  364. cycleScrollView.dataSource = self
  365. cycleScrollView.delegate = self
  366. cycleScrollView.isAutoScroll = true
  367. cycleScrollView.isInfiniteLoop = true
  368. cycleScrollView.isChangeAlpha = false
  369. cycleScrollView.leftRightMargin = 12
  370. cycleScrollView.topBottomMargin = 12
  371. cycleScrollView.pageControl = pageControl
  372. cycleScrollView.reloadData()
  373. return cycleScrollView
  374. }()
  375. lazy var pageControl: GKPageControl = {
  376. let pageControl = GKPageControl()
  377. pageControl.style = .sizeDot
  378. pageControl.dotHeight = 5.rpx
  379. pageControl.dotWidth = 5.rpx
  380. pageControl.dotMargin = 4.rpx
  381. pageControl.pageIndicatorTintColor = .hexStringColor(hexString: "#EEEEEE")
  382. pageControl.currentPageIndicatorTintColor = QSLColor.themeMainColor
  383. return pageControl
  384. }()
  385. lazy var goodsCollectionView: UICollectionView = {
  386. let layout = UICollectionViewFlowLayout()
  387. layout.minimumLineSpacing = 0
  388. layout.scrollDirection = .vertical
  389. let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
  390. collectionView.backgroundColor = .white
  391. collectionView.dataSource = self
  392. collectionView.delegate = self
  393. collectionView.showsHorizontalScrollIndicator = false
  394. collectionView.bounces = false
  395. collectionView.register(cellClass: QSLActivityVipCell.self)
  396. return collectionView
  397. }()
  398. lazy var bottomView: UIView = {
  399. let view = UIView()
  400. view.backgroundColor = UIColor.white
  401. return view
  402. }()
  403. lazy var countdownView: UIView = {
  404. let view = UIView(frame: CGRectMake(0, 0, QSLConst.qsl_kScreenW - 24.rpx, 47.rpx))
  405. view.addCorner(conrners: [.topLeft,.topRight], radius: 30.rpx)
  406. view.backgroundColor = .hexStringColor(hexString: "#FFFED8")
  407. return view
  408. }()
  409. lazy var countdownLabel: QSLCountdownView = {
  410. let label = QSLCountdownView(frame: CGRectMake(0, 0, QSLConst.qsl_kScreenW - 24.rpx, 17.rpx),type: 2)
  411. return label
  412. }()
  413. lazy var unlockBtn: UIButton = {
  414. let btn = UIButton()
  415. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#0E5E61"), color2: .hexStringColor(hexString: "#00434E"), width: QSLConst.qsl_kScreenW - 24.rpx, height: 50.rpx, direction: .horizontal)
  416. btn.addRadius(radius: 25.rpx)
  417. btn.title("立即解锁")
  418. btn.textColor(.hexStringColor(hexString: "#FFF8EF"))
  419. btn.mediumFont(18)
  420. btn.addTarget(self, action: #selector(payBtnAction), for: .touchUpInside)
  421. return btn
  422. }()
  423. lazy var serviceLabel: YYLabel = {
  424. let label = YYLabel()
  425. label.textAlignment = .center
  426. return label
  427. }()
  428. }
  429. extension QSLActivityVipVC{
  430. func initializeView() {
  431. self.view.addSubview(scrollView)
  432. scrollView.snp.makeConstraints { make in
  433. make.top.left.equalTo(0)
  434. make.width.equalTo(QSLConst.qsl_kScreenW)
  435. make.height.equalTo(QSLConst.qsl_kScreenH)
  436. }
  437. self.view.addSubview(vipNaviView)
  438. vipNaviView.snp.makeConstraints { make in
  439. make.top.left.right.equalTo(0)
  440. make.height.equalTo(QSLConst.qsl_kNavFrameH)
  441. }
  442. vipNaviView.addSubview(backButton)
  443. backButton.snp.makeConstraints { make in
  444. make.width.equalTo(44.rpx)
  445. make.height.equalTo(44.rpx)
  446. make.left.equalTo(10.rpx)
  447. make.top.equalTo(QSLConst.qsl_kStatusBarFrameH)
  448. }
  449. vipNaviView.addSubview(naviTitleIcon)
  450. naviTitleIcon.snp.makeConstraints { make in
  451. make.centerX.equalToSuperview()
  452. make.width.equalTo(100.rpx)
  453. make.height.equalTo(20.rpx)
  454. make.centerY.equalTo(backButton.snp.centerY)
  455. }
  456. vipNaviView.addSubview(naviResumeBtn)
  457. naviResumeBtn.snp.makeConstraints { make in
  458. make.size.equalTo(CGSize(width: 70.rpx, height: 18.rpx))
  459. make.right.equalTo(-8.rpx)
  460. make.centerY.equalTo(backButton.snp.centerY)
  461. }
  462. self.scrollView.addSubview(vipTopBg)
  463. vipTopBg.snp.makeConstraints { make in
  464. make.left.top.equalTo(0)
  465. make.width.equalTo(QSLConst.qsl_kScreenW)
  466. make.height.equalTo(185.rpx)
  467. }
  468. vipTopBg.addSubview(vipTopTitleView)
  469. vipTopTitleView.snp.makeConstraints { make in
  470. make.left.equalTo(16.rpx)
  471. make.bottom.equalTo(vipTopBg.snp.bottom).offset(-16.rpx)
  472. make.height.equalTo(22.rpx)
  473. make.width.equalTo(183.rpx)
  474. }
  475. vipTopBg.addSubview(vipDiamondView)
  476. vipDiamondView.snp.makeConstraints { make in
  477. make.left.equalTo(16.rpx)
  478. make.bottom.equalTo(vipTopTitleView.snp.top).offset(-6.rpx)
  479. make.height.equalTo(20.rpx)
  480. make.width.equalTo(105.rpx)
  481. }
  482. self.scrollView.addSubview(vipContentView)
  483. vipContentView.snp.makeConstraints { make in
  484. make.top.equalTo(185.rpx)
  485. make.left.equalTo(0)
  486. make.width.equalTo(QSLConst.qsl_kScreenW)
  487. make.height.equalTo(230.rpx)
  488. }
  489. vipContentView.addSubview(addTitleIconBg)
  490. addTitleIconBg.snp.makeConstraints { make in
  491. make.size.equalTo(CGSize(width: 117.rpx, height: 8.rpx))
  492. make.left.equalTo(16.rpx)
  493. make.top.equalTo(26.rpx)
  494. }
  495. vipContentView.addSubview(addTitleIcon)
  496. addTitleIcon.snp.makeConstraints { make in
  497. make.size.equalTo(CGSize(width: 157.rpx, height: 26.rpx))
  498. make.left.equalTo(20.rpx)
  499. make.top.equalTo(12.rpx)
  500. }
  501. vipContentView.addSubview(cycleScrollView)
  502. cycleScrollView.snp.makeConstraints { make in
  503. make.left.right.equalTo(0)
  504. make.height.equalTo(150.rpx)
  505. make.top.equalTo(50.rpx)
  506. }
  507. vipContentView.addSubview(pageControl)
  508. pageControl.snp.makeConstraints { make in
  509. make.size.equalTo(CGSize(width: 68.rpx, height: 4.rpx))
  510. make.centerX.equalToSuperview()
  511. make.top.equalTo(cycleScrollView.snp.bottom).offset(17.rpx)
  512. }
  513. self.scrollView.addSubview(goodsCollectionView)
  514. goodsCollectionView.snp.makeConstraints { make in
  515. make.left.equalTo(0)
  516. make.height.equalTo(150.rpx)
  517. make.width.equalTo(QSLConst.qsl_kScreenW)
  518. make.top.equalTo(vipContentView.snp.bottom).offset(0)
  519. }
  520. self.view.addSubview(bottomView)
  521. bottomView.snp.makeConstraints { make in
  522. make.right.equalTo(-12.rpx)
  523. make.left.equalTo(12.rpx)
  524. make.height.equalTo(100.rpx)
  525. make.bottom.equalTo(-QSLConst.qsl_kTabbarBottom/2)
  526. }
  527. bottomView.addSubview(countdownView)
  528. countdownView.snp.makeConstraints { make in
  529. make.right.left.top.equalTo(0)
  530. make.height.equalTo(47.rpx)
  531. }
  532. countdownView.addSubview(countdownLabel)
  533. countdownLabel.snp.makeConstraints { make in
  534. make.left.right.equalTo(0)
  535. make.top.equalTo(5.rpx)
  536. make.height.equalTo(17.rpx)
  537. }
  538. bottomView.addSubview(unlockBtn)
  539. unlockBtn.snp.makeConstraints { make in
  540. make.right.left.equalTo(0)
  541. make.height.equalTo(50.rpx)
  542. make.top.equalTo(25.rpx)
  543. }
  544. bottomView.addSubview(serviceLabel)
  545. serviceLabel.snp.makeConstraints { make in
  546. make.right.left.equalTo(0)
  547. make.height.equalTo(17.rpx)
  548. make.bottom.equalTo(0)
  549. }
  550. }
  551. }
  552. extension QSLActivityVipVC : GKCycleScrollViewDelegate, GKCycleScrollViewDataSource{
  553. func cycleScrollView(_ cycleScrollView: GKCycleScrollView!, cellForViewAt index: Int) -> GKCycleScrollViewCell! {
  554. if let cell = cycleScrollView.dequeueReusableCell() {
  555. cell.imageView.image = UIImage(named: "vip_activity_banner_\(index+1)")
  556. return cell
  557. }
  558. let cell = GKCycleScrollViewCell()
  559. cell.imageView.image = UIImage(named: "vip_activity_banner_\(index+1)")
  560. return cell
  561. }
  562. func numberOfCells(in cycleScrollView: GKCycleScrollView!) -> Int {
  563. return 3
  564. }
  565. func sizeForCell(in cycleScrollView: GKCycleScrollView!) -> CGSize {
  566. return CGSizeMake(QSLConst.qsl_kScreenW - 90.rpx, 150.rpx);
  567. }
  568. }
  569. extension QSLActivityVipVC: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
  570. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  571. return goodList.count
  572. }
  573. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  574. let cell = collectionView.dequeueReusableCell(cellType: QSLActivityVipCell.self, cellForRowAt: indexPath)
  575. let model = self.goodList[indexPath.row]
  576. if (indexPath.row == 0) {
  577. cell.config(model: model, type: .top)
  578. } else {
  579. if(self.goodList.count > 2){
  580. cell.config(model: model, type: .small)
  581. }else{
  582. cell.config(model: model, type: .big)
  583. }
  584. }
  585. return cell
  586. }
  587. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  588. var list = [QSLGoodModel]()
  589. for index in 0..<self.goodList.count{
  590. var submodel = self.goodList[index]
  591. if(indexPath.row == index){
  592. submodel.isSelect = true
  593. self.selectGood = submodel
  594. }else{
  595. submodel.isSelect = false
  596. }
  597. list.append(submodel)
  598. }
  599. self.goodList = list
  600. self.goodsCollectionView.reloadData()
  601. self.payBtnAction()
  602. }
  603. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  604. if (indexPath.row == 0) {
  605. return CGSize(width: QSLConst.qsl_kScreenW-32.rpx, height: 112.rpx)
  606. } else {
  607. if(self.goodList.count == 2){
  608. return CGSize(width: QSLConst.qsl_kScreenW-32.rpx, height: 72.rpx)
  609. }else{
  610. return CGSize(width: (QSLConst.qsl_kScreenW-50.rpx)/2.0, height: 112.rpx)
  611. }
  612. }
  613. }
  614. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
  615. return UIEdgeInsets(top: 0, left: 16.rpx, bottom: 0, right: 16.rpx)
  616. }
  617. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
  618. return 10.rpx
  619. }
  620. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
  621. if(self.goodList.count == 2){
  622. return 10.rpx
  623. }else{
  624. return 16.rpx
  625. }
  626. }
  627. }