QSLActivityVipVC.swift 29 KB

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