QSLActivityVipVC.swift 29 KB

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