QSLActivityVipVC.swift 29 KB

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