QSLActivityVipVC.swift 29 KB

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