QSLActivityVipVC.swift 29 KB

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