QSLActivityVipVC.swift 30 KB

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