QSLVipController.swift 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. //
  2. // QSLVipController.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2024/11/27.
  6. //
  7. import UIKit
  8. import YYText
  9. enum QSLVipJumpType: Int {
  10. case homeRoad // 定位查看轨迹
  11. case add // 添加好友
  12. case friendRoad // 好友列表查看轨迹
  13. case contact // 添加紧急联系人
  14. case mine //
  15. }
  16. class QSLVipController: QSLBaseController {
  17. var type: QSLVipJumpType?
  18. var goodList: [QSLGoodModel] = [QSLGoodModel]()
  19. var selectGood: QSLGoodModel? {
  20. didSet {
  21. updateSelectGoodUI()
  22. }
  23. }
  24. lazy var vipBg: UIImageView = {
  25. let imageView = UIImageView()
  26. imageView.image = UIImage(named: "vip_bg")
  27. return imageView
  28. }()
  29. lazy var backButton: UIButton = {
  30. let button = UIButton()
  31. button.image(UIImage(named: "public_back_btn_white"))
  32. button.title("会员中心")
  33. button.mediumFont(17)
  34. button.textColor(.white)
  35. button.setImageTitleLayout(.imgLeft, spacing: 4.rpx)
  36. button.addTarget(self, action: #selector(backBtnAction), for: .touchUpInside)
  37. return button
  38. }()
  39. lazy var peopleCountView: UIView = {
  40. let view = UIView()
  41. view.layer.cornerRadius = 12.rpx
  42. view.layer.borderColor = UIColor.white.withAlphaComponent(0.16).cgColor
  43. view.layer.borderWidth = 1.rpx
  44. return view
  45. }()
  46. lazy var peopleAvatarImageView: UIImageView = {
  47. let imageView = UIImageView()
  48. imageView.image = UIImage(named: "vip_avatars_icon")
  49. return imageView
  50. }()
  51. lazy var peopleCountLabel: UILabel = {
  52. let label = UILabel()
  53. label.text("1456488人 已开通VIP")
  54. label.color("#FFE6C0")
  55. label.font(12)
  56. return label
  57. }()
  58. lazy var scrollView: UIScrollView = {
  59. let scrollView = UIScrollView()
  60. // scrollView.delegate = self
  61. scrollView.bounces = false
  62. scrollView.showsVerticalScrollIndicator = false
  63. scrollView.contentInsetAdjustmentBehavior = .never
  64. return scrollView
  65. }()
  66. lazy var cardBannerImageView: UIImageView = {
  67. let imageView = UIImageView()
  68. imageView.image = UIImage(named: "vip_banner_card")
  69. return imageView
  70. }()
  71. lazy var vipTimeLabel: UILabel = {
  72. let label = UILabel()
  73. label.text("升级VIP会员,解锁全部功能")
  74. label.font(13)
  75. label.textColor = .hexStringColor(hexString: "#AF7655")
  76. return label
  77. }()
  78. lazy var funcBannerImageView: UIImageView = {
  79. let imageView = UIImageView()
  80. imageView.image = UIImage(named: "vip_banner_func")
  81. return imageView
  82. }()
  83. lazy var mainView: UIView = {
  84. let view = UIView()
  85. view.backgroundColor = QSLColor.backGroundColor
  86. view.addRadius(radius: 12.rpx)
  87. return view
  88. }()
  89. lazy var goodsBgView: UIView = {
  90. let view = UIView()
  91. view.gradientBackgroundColor(color1: .hexStringColor(hexString: "#FFF8F2"), color2: .hexStringColor(hexString: "#FFFFFF"), width: QSLConst.qsl_kScreenW, height: 255.rpx, direction: .vertical)
  92. return view
  93. }()
  94. lazy var vipGoodsTitleIcon: UIImageView = {
  95. let imageView = UIImageView()
  96. imageView.image = UIImage(named: "vip_title_icon")
  97. return imageView
  98. }()
  99. lazy var resumeBtn: UIButton = {
  100. let button = UIButton()
  101. button.title("恢复购买")
  102. button.setTitleColor(.hexStringColor(hexString: "#000000").withAlphaComponent(0.5), for: .normal)
  103. button.titleLabel?.font = UIFont.systemFont(ofSize: 13, weight: .medium)
  104. button.image(UIImage(named: "vip_resume_btn"))
  105. button.setImageTitleLayout(.imgLeft, spacing: 2.rpx)
  106. button.addTarget(self, action: #selector(resumeBtnAction), for: .touchUpInside)
  107. return button
  108. }()
  109. lazy var goodsCollectionView: UICollectionView = {
  110. let layout = UICollectionViewFlowLayout()
  111. layout.minimumLineSpacing = 0
  112. layout.scrollDirection = .horizontal
  113. let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
  114. collectionView.backgroundColor = .clear
  115. collectionView.dataSource = self
  116. collectionView.delegate = self
  117. collectionView.showsHorizontalScrollIndicator = false
  118. collectionView.bounces = false
  119. collectionView.register(cellClass: QSLVipGoodCollectionViewCell.self)
  120. return collectionView
  121. }()
  122. lazy var selectBtn: UIButton = {
  123. let btn = UIButton()
  124. btn.image(UIImage(named: "public_select_btn_false"), .normal)
  125. btn.image(UIImage(named: "public_select_btn_true"), .selected)
  126. btn.addTarget(self, action: #selector(selectBtnAction), for: .touchUpInside)
  127. return btn
  128. }()
  129. lazy var serviceLabel: YYLabel = {
  130. let label = YYLabel()
  131. let attr = NSMutableAttributedString()
  132. let firstAttr = NSMutableAttributedString(string: "购买即同意")
  133. firstAttr.font(12)
  134. firstAttr.color(.hexStringColor(hexString: "#A7A7A7"))
  135. attr.append(firstAttr)
  136. let blankAttr = NSMutableAttributedString(string: " ")
  137. blankAttr.font(12)
  138. attr.append(blankAttr)
  139. let privacyHL = YYTextHighlight()
  140. var privacyStr = "《隐私权政策》"
  141. let privacyText = NSMutableAttributedString(string: privacyStr)
  142. privacyText.font(12)
  143. privacyText.color(.hexStringColor(hexString: "#E7B983"))
  144. privacyText.yy_setTextHighlight(privacyHL, range: NSRange(location: 0, length: privacyStr.count))
  145. privacyHL.tapAction = { [weak self] containerView, text, range, rect in
  146. self?.privacyAction()
  147. }
  148. attr.append(privacyText)
  149. attr.append(blankAttr)
  150. let andAttr = NSMutableAttributedString(string: "和")
  151. andAttr.font(12)
  152. andAttr.color(.hexStringColor(hexString: "#A7A7A7"))
  153. attr.append(andAttr)
  154. attr.append(blankAttr)
  155. let serviceHL = YYTextHighlight()
  156. var serviceStr = "《用户协议》"
  157. let serviceText = NSMutableAttributedString(string: serviceStr)
  158. serviceText.font(12)
  159. serviceText.color(.hexStringColor(hexString: "#E7B983"))
  160. serviceText.yy_setTextHighlight(serviceHL, range: NSRange(location: 0, length: serviceStr.count))
  161. serviceHL.tapAction = { [weak self] containerView, text, range, rect in
  162. self?.serviceAction()
  163. }
  164. attr.append(serviceText)
  165. label.attributedText = attr
  166. return label
  167. }()
  168. lazy var commentView: UIView = {
  169. let view = UIView()
  170. view.backgroundColor = .white
  171. return view
  172. }()
  173. lazy var commentTitleIcon: UIImageView = {
  174. let imageView = UIImageView()
  175. imageView.image = UIImage(named: "vip_comment_title_icon")
  176. return imageView
  177. }()
  178. lazy var comment1: QSLVipCommentCellView = {
  179. let view = QSLVipCommentCellView()
  180. view.config(name: "用户189****7913", comment: "上班没时间,远程遛娃,非常方便很好用。")
  181. return view
  182. }()
  183. lazy var comment2: QSLVipCommentCellView = {
  184. let view = QSLVipCommentCellView()
  185. view.config(name: "用户189****7913", comment: "用了之后,才发现真的可以找到他。")
  186. return view
  187. }()
  188. lazy var comment3: QSLVipCommentCellView = {
  189. let view = QSLVipCommentCellView()
  190. view.config(name: "用户189****7913", comment: "轨迹很准,一目了然,奶奶出门遇到危险直接一键报警,我就收到信息了")
  191. return view
  192. }()
  193. lazy var bottomView: UIView = {
  194. let view = UIView()
  195. view.gradientBackgroundColor(color1: .hexStringColor(hexString: "#00434E"), color2: .hexStringColor(hexString: "#0E5E61"), width: QSLConst.qsl_kScreenW - 24.rpx, height: 50.rpx, direction: .horizontal)
  196. view.addRadius(radius: 25.rpx)
  197. return view
  198. }()
  199. lazy var unlockBtn: UIButton = {
  200. let btn = UIButton()
  201. btn.setBackgroundImage(UIImage(named: "vip_unlock_btn_bg"), for: .normal)
  202. btn.title("立即解锁")
  203. btn.textColor(.hexStringColor(hexString: "#9B3800"))
  204. btn.mediumFont(18)
  205. btn.titleEdgeInsets = UIEdgeInsets(top: 0, left: 30.rpx, bottom: 0, right: 0)
  206. btn.addTarget(self, action: #selector(unlockBtnAction), for: .touchUpInside)
  207. return btn
  208. }()
  209. lazy var priceIconLabel: UILabel = {
  210. let label = UILabel()
  211. label.text("¥")
  212. label.textColor = .hexStringColor(hexString: "#FFF8EF")
  213. label.font(14)
  214. return label
  215. }()
  216. lazy var priceLabel: UILabel = {
  217. let label = UILabel()
  218. label.text("168")
  219. label.textColor = .hexStringColor(hexString: "#FFF8EF")
  220. label.font(24)
  221. return label
  222. }()
  223. lazy var goodTypeLabel: UILabel = {
  224. let label = UILabel()
  225. label.text("/ 永久会员")
  226. label.textColor = .hexStringColor(hexString: "#FFF8EF")
  227. label.font(12)
  228. return label
  229. }()
  230. override func viewDidLoad() {
  231. super.viewDidLoad()
  232. initializeView()
  233. updateUI()
  234. requestItemList()
  235. calculateBuyCount()
  236. if let type = self.type {
  237. switch type {
  238. case .homeRoad:
  239. gravityInstance?.track(QSLGravityConst.vip_show, properties: ["id": 1001])
  240. case .add:
  241. gravityInstance?.track(QSLGravityConst.vip_show, properties: ["id": 1002])
  242. case .friendRoad:
  243. gravityInstance?.track(QSLGravityConst.vip_show, properties: ["id": 1003])
  244. case .contact:
  245. gravityInstance?.track(QSLGravityConst.vip_show, properties: ["id": 1004])
  246. case .mine:
  247. gravityInstance?.track(QSLGravityConst.vip_show, properties: ["id": 1006])
  248. }
  249. }
  250. }
  251. }
  252. extension QSLVipController {
  253. @objc func privacyAction() {
  254. let vc = QSLWebViewController()
  255. vc.webUrl = QSLConfig.AppPrivacyAgreementLink
  256. vc.title = "隐私政策"
  257. self.navigationController?.pushViewController(vc, animated: true)
  258. }
  259. @objc func serviceAction() {
  260. let vc = QSLWebViewController()
  261. vc.webUrl = QSLConfig.AppServiceAgreementLink
  262. vc.title = "服务协议"
  263. self.navigationController?.pushViewController(vc, animated: true)
  264. }
  265. @objc func selectBtnAction() {
  266. selectBtn.isSelected = !selectBtn.isSelected
  267. }
  268. // 恢复按钮点击
  269. @objc func resumeBtnAction() {
  270. let memberModel = QSLBaseManager.shared.userModel.memberModel
  271. let expired = memberModel.expired
  272. if !expired {
  273. QSLLoading.success(text: "您已经在订阅中,无需恢复")
  274. return
  275. }
  276. QSLLoading.show()
  277. QSLVipManager.shared.restoreAction { isSuccess in
  278. QSLVipManager.shared.isPaying = false
  279. if isSuccess {
  280. QSLNetwork().request(.userMember(dict: [:])) { response in
  281. let model = response.mapObject(QSLMemberModel.self, modelKey: "data")
  282. QSLBaseManager.shared.userModel.memberModel = model
  283. if model.expired {
  284. QSLBaseManager.shared.saveVipExpiredTime(time: 0)
  285. } else {
  286. QSLBaseManager.shared.saveVipExpiredTime(time: model.endTimestamp)
  287. }
  288. QSLBaseManager.shared.saveUserId(id: model.userId)
  289. if model.endTimestamp > memberModel.endTimestamp {
  290. QSLLoading.success(text: "恢复成功")
  291. // 支付成功通知
  292. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3) {
  293. self.navigationController?.popViewController(animated: true)
  294. }
  295. } else {
  296. QSLLoading.error(text: "没有可供恢复的订阅")
  297. }
  298. } fail: { code, error in
  299. QSLLoading.error(text: "没有可供恢复的订阅")
  300. }
  301. } else {
  302. QSLLoading.error(text: "没有可供恢复的订阅")
  303. }
  304. }
  305. }
  306. @objc func unlockBtnAction() {
  307. switch self.selectGood?.level {
  308. case 100 :
  309. gravityInstance?.track(QSLGravityConst.vip_buy_click, properties: ["id": 1006])
  310. break
  311. case 700:
  312. gravityInstance?.track(QSLGravityConst.vip_buy_click, properties: ["id": 1005])
  313. break;
  314. case 3100:
  315. gravityInstance?.track(QSLGravityConst.vip_buy_click, properties: ["id": 1004])
  316. break;
  317. case 9200:
  318. gravityInstance?.track(QSLGravityConst.vip_buy_click, properties: ["id": 1003])
  319. break;
  320. case 36600:
  321. gravityInstance?.track(QSLGravityConst.vip_buy_click, properties: ["id": 1002])
  322. break;
  323. case 3660000:
  324. gravityInstance?.track(QSLGravityConst.vip_buy_click, properties: ["id": 1001])
  325. break;
  326. default:
  327. break;
  328. }
  329. if !selectBtn.isSelected {
  330. self.view.toast(text: "请先同意《隐私权政策》和《用户协议》")
  331. return
  332. }
  333. let memberModel = QSLBaseManager.shared.userModel.memberModel
  334. if let subscriptionExpired = memberModel.subscriptionExpired, !subscriptionExpired {
  335. self.view.toast(text: "你已经订阅了")
  336. return
  337. }
  338. if goodList.count > 0, let selectGood = self.selectGood {
  339. QSLLoading.show()
  340. QSLVipManager.shared.startPay(goods: selectGood) { status, outTradeNo in
  341. QSLVipManager.shared.isPaying = false
  342. if status == .success {
  343. QSLLoading.success(text: "支付成功")
  344. // NSLocalizedString("Payment successful", comment: "支付成功")
  345. // if let payType = self.payType {
  346. // geInstance?.track(HolaGravityConst.vip_open_success, properties: ["id": payType])
  347. //
  348. // if payType == 1004 {
  349. // geInstance?.track(HolaGravityConst.vip_alert_pay, properties: ["id": 1002])
  350. // }
  351. // }
  352. // let val: Float = 0.1
  353. // HolaSaManager.shared.addEventAttribution(eventDict: ["event_name": "pay", "event_val": val])
  354. // 引力传递支付事件
  355. if let selectGood = self.selectGood {
  356. gravityInstance?.trackPayEvent(withAmount: Int32(selectGood.amount), withPayType: "CNY", withOrderId: outTradeNo, withPayReason: selectGood.name, withPayMethod: "apple")
  357. }
  358. if let type = self.type {
  359. switch type {
  360. case .homeRoad:
  361. gravityInstance?.track(QSLGravityConst.vip_success_page, properties: ["id": 1001])
  362. case .add:
  363. gravityInstance?.track(QSLGravityConst.vip_success_page, properties: ["id": 1002])
  364. case .friendRoad:
  365. gravityInstance?.track(QSLGravityConst.vip_success_page, properties: ["id": 1003])
  366. case .contact:
  367. gravityInstance?.track(QSLGravityConst.vip_success_page, properties: ["id": 1004])
  368. case .mine:
  369. gravityInstance?.track(QSLGravityConst.vip_success_page, properties: ["id": 1006])
  370. }
  371. }
  372. switch self.selectGood?.level {
  373. case 100 :
  374. gravityInstance?.track(QSLGravityConst.vip_success_good, properties: ["id": 1])
  375. break
  376. case 700:
  377. gravityInstance?.track(QSLGravityConst.vip_success_good, properties: ["id": 5])
  378. break;
  379. case 3100:
  380. gravityInstance?.track(QSLGravityConst.vip_success_good, properties: ["id": 9])
  381. break;
  382. case 9200:
  383. gravityInstance?.track(QSLGravityConst.vip_success_good, properties: ["id": 13])
  384. break;
  385. case 36600:
  386. gravityInstance?.track(QSLGravityConst.vip_success_good, properties: ["id": 17])
  387. break;
  388. case 3660000:
  389. gravityInstance?.track(QSLGravityConst.vip_success_good, properties: ["id": 21])
  390. break;
  391. default:
  392. break;
  393. }
  394. DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
  395. self.navigationController?.popViewController(animated: true)
  396. NotificationCenter.default.post(name: QSLNotification.QSLRefreshMember, object: nil)
  397. }
  398. } else if status == .cancel {
  399. QSLLoading.error(text: "支付取消")
  400. } else if status == .fail {
  401. gravityInstance?.track(QSLGravityConst.vip_fail)
  402. QSLLoading.error(text: "支付失败")
  403. } else if status == .searchFail {
  404. QSLLoading.error(text: "查询订单失败,请稍后重试")
  405. }
  406. }
  407. }
  408. }
  409. }
  410. extension QSLVipController {
  411. // 请求商品列表
  412. func requestItemList() {
  413. QSLNetwork().request(.vipItemList(dict: ["itemListType": 1])) { response in
  414. let list = response.mapArray(QSLGoodModel.self, modelKey: "data>list")
  415. self.goodList = list
  416. if self.goodList.count > 0 {
  417. self.goodList[0].isSelect = true
  418. self.selectGood = self.goodList[0]
  419. }
  420. self.goodsCollectionView.reloadData()
  421. } fail: { code, error in
  422. self.view.toast(text: "加载商品列表失败")
  423. }
  424. }
  425. // 计算购买人数
  426. func calculateBuyCount() {
  427. var num = 145883
  428. if let localNum = UserDefaults.standard.value(forKey: QSLConfig.user_default_local_buy_count) as? Int {
  429. num = localNum
  430. }
  431. let randomAddCount = Int.random(in: 1...10)
  432. num = num + randomAddCount
  433. UserDefaults.standard.setValue(num, forKey: QSLConfig.user_default_local_buy_count)
  434. self.peopleCountLabel.text("\(num)人 已开通VIP")
  435. }
  436. }
  437. // MARK: - 设置 CollectionView
  438. extension QSLVipController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
  439. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  440. return goodList.count
  441. }
  442. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  443. let cell = collectionView.dequeueReusableCell(cellType: QSLVipGoodCollectionViewCell.self, cellForRowAt: indexPath)
  444. let model = self.goodList[indexPath.row]
  445. cell.config(model: model)
  446. return cell
  447. }
  448. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  449. for i in 0..<self.goodList.count {
  450. self.goodList[i].isSelect = false
  451. }
  452. self.goodList[indexPath.row].isSelect = true
  453. self.selectGood = self.goodList[indexPath.row]
  454. switch self.selectGood?.level {
  455. case 100 :
  456. gravityInstance?.track(QSLGravityConst.vip_good_select, properties: ["id": 1006])
  457. break
  458. case 700:
  459. gravityInstance?.track(QSLGravityConst.vip_good_select, properties: ["id": 1005])
  460. break;
  461. case 3100:
  462. gravityInstance?.track(QSLGravityConst.vip_good_select, properties: ["id": 1004])
  463. break;
  464. case 9200:
  465. gravityInstance?.track(QSLGravityConst.vip_good_select, properties: ["id": 1003])
  466. break;
  467. case 36600:
  468. gravityInstance?.track(QSLGravityConst.vip_good_select, properties: ["id": 1002])
  469. break;
  470. case 3660000:
  471. gravityInstance?.track(QSLGravityConst.vip_good_select, properties: ["id": 1001])
  472. break;
  473. default:
  474. break;
  475. }
  476. self.goodsCollectionView.reloadData()
  477. }
  478. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  479. return CGSize(width: 104.rpx, height: 143.rpx)
  480. }
  481. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
  482. return 4.rpx
  483. }
  484. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
  485. return 0
  486. }
  487. }
  488. extension QSLVipController {
  489. func updateUI() {
  490. if QSLBaseManager.shared.isLogin() && QSLBaseManager.shared.isVip() {
  491. let model = QSLBaseManager.shared.userModel.memberModel
  492. if model.permanent {
  493. self.vipTimeLabel.text("您已是尊贵的永久会员")
  494. self.bottomView.isHidden = true
  495. } else {
  496. let level = model.memberLevelString()
  497. let endTime = model.endTimestampString()
  498. self.vipTimeLabel.text("\(level):\(endTime)到期")
  499. }
  500. } else {
  501. self.vipTimeLabel.text("升级VIP会员,解锁全部功能")
  502. }
  503. }
  504. func updateSelectGoodUI() {
  505. var priceText = ""
  506. if let selectGood = self.selectGood {
  507. if selectGood.amount.truncatingRemainder(dividingBy: 100) == 0 {
  508. priceText = "\(Int(selectGood.amount / 100))"
  509. } else {
  510. priceText = String(format: "%.2lf", selectGood.amount / 100 )
  511. }
  512. }
  513. self.priceLabel.text(priceText)
  514. self.goodTypeLabel.text("/ \(self.selectGood?.name ?? "")")
  515. }
  516. func initializeView() {
  517. self.view.addSubview(vipBg)
  518. vipBg.snp.makeConstraints { make in
  519. make.left.top.right.equalTo(0)
  520. }
  521. self.view.addSubview(backButton)
  522. backButton.snp.makeConstraints { make in
  523. make.size.equalTo(100.rpx)
  524. make.height.equalTo(25.rpx)
  525. make.left.equalTo(12.rpx)
  526. make.top.equalTo(QSLConst.qsl_kStatusBarFrameH)
  527. }
  528. self.view.addSubview(peopleCountView)
  529. peopleCountView.snp.makeConstraints { make in
  530. make.size.equalTo(CGSize(width: 212.rpx, height: 24.rpx))
  531. make.right.equalTo(-13.rpx)
  532. make.centerY.equalTo(backButton.snp.centerY)
  533. }
  534. peopleCountView.addSubview(peopleAvatarImageView)
  535. peopleAvatarImageView.snp.makeConstraints { make in
  536. make.size.equalTo(CGSize(width: 72.rpx, height: 16.6.rpx))
  537. make.left.equalTo(3.rpx)
  538. make.centerY.equalTo(peopleCountView.snp.centerY)
  539. }
  540. peopleCountView.addSubview(peopleCountLabel)
  541. peopleCountLabel.snp.makeConstraints { make in
  542. make.left.equalTo(peopleAvatarImageView.snp.right).offset(7.rpx)
  543. make.centerY.equalTo(peopleCountView.snp.centerY)
  544. }
  545. self.view.addSubview(scrollView)
  546. scrollView.snp.makeConstraints { make in
  547. make.left.right.equalTo(0)
  548. make.top.equalTo(QSLConst.qsl_kNavFrameH)
  549. make.bottom.equalTo(0)
  550. }
  551. scrollView.addSubview(cardBannerImageView)
  552. cardBannerImageView.snp.makeConstraints { make in
  553. make.top.equalTo(0)
  554. make.centerX.equalToSuperview()
  555. make.width.equalTo(336.rpx)
  556. make.height.equalTo(108.rpx)
  557. }
  558. cardBannerImageView.addSubview(vipTimeLabel)
  559. vipTimeLabel.snp.makeConstraints { make in
  560. make.left.equalTo(23.rpx)
  561. make.bottom.equalTo(-19.rpx)
  562. }
  563. scrollView.addSubview(funcBannerImageView)
  564. funcBannerImageView.snp.makeConstraints { make in
  565. make.size.equalTo(CGSize(width: 336.rpx, height: 172.rpx))
  566. make.centerX.equalToSuperview()
  567. make.top.equalTo(cardBannerImageView.snp.bottom).offset(14.rpx)
  568. }
  569. scrollView.addSubview(mainView)
  570. mainView.snp.makeConstraints { make in
  571. make.left.right.bottom.equalTo(0)
  572. make.top.equalTo(funcBannerImageView.snp.bottom).offset(-24.rpx)
  573. make.width.equalTo(QSLConst.qsl_kScreenW)
  574. make.height.equalTo(700.rpx)
  575. }
  576. mainView.addSubview(goodsBgView)
  577. goodsBgView.snp.makeConstraints { make in
  578. make.top.left.right.equalTo(0)
  579. make.width.equalTo(QSLConst.qsl_kScreenW)
  580. make.height.equalTo(255.rpx)
  581. }
  582. goodsBgView.addSubview(vipGoodsTitleIcon)
  583. vipGoodsTitleIcon.snp.makeConstraints { make in
  584. make.size.equalTo(CGSize(width: 117.rpx, height: 26.rpx))
  585. make.left.equalTo(20.rpx)
  586. make.top.equalTo(16.rpx)
  587. }
  588. goodsBgView.addSubview(resumeBtn)
  589. resumeBtn.snp.makeConstraints { make in
  590. make.size.equalTo(CGSize(width: 75.rpx, height: 16.rpx))
  591. make.right.equalTo(-18.rpx)
  592. make.centerY.equalTo(vipGoodsTitleIcon.snp.centerY)
  593. }
  594. goodsBgView.addSubview(goodsCollectionView)
  595. goodsCollectionView.snp.makeConstraints { make in
  596. make.left.equalTo(18.rpx)
  597. make.right.equalTo(-22.rpx)
  598. make.height.equalTo(143.rpx)
  599. make.top.equalTo(vipGoodsTitleIcon.snp.bottom).offset(10.rpx)
  600. }
  601. goodsBgView.addSubview(selectBtn)
  602. selectBtn.snp.makeConstraints { make in
  603. make.size.equalTo(CGSize(width: 12.rpx, height: 12.rpx))
  604. make.left.equalTo(23.rpx)
  605. make.top.equalTo(goodsCollectionView.snp.bottom).offset(16.rpx)
  606. }
  607. goodsBgView.addSubview(serviceLabel)
  608. serviceLabel.snp.makeConstraints { make in
  609. make.left.equalTo(selectBtn.snp.right).offset(2.rpx)
  610. make.centerY.equalTo(selectBtn.snp.centerY)
  611. }
  612. mainView.addSubview(commentView)
  613. commentView.snp.makeConstraints { make in
  614. make.left.right.equalTo(0)
  615. make.top.equalTo(goodsBgView.snp.bottom).offset(8.rpx)
  616. make.bottom.equalTo(0)
  617. }
  618. commentView.addSubview(commentTitleIcon)
  619. commentTitleIcon.snp.makeConstraints { make in
  620. make.size.equalTo(CGSize(width: 83.rpx, height: 26.rpx))
  621. make.top.equalTo(16.rpx)
  622. make.left.equalTo(12.rpx)
  623. }
  624. let commentHeight1 = "上班没时间,远程遛娃,非常方便很好用。".heightAccording(width: QSLConst.qsl_kScreenW - 52.rpx - 12.rpx, font: .textF(15), lineSpacing: 2) + 35.rpx
  625. commentView.addSubview(comment1)
  626. comment1.snp.makeConstraints { make in
  627. make.left.right.equalTo(0)
  628. make.top.equalTo(commentTitleIcon.snp.bottom).offset(16.rpx)
  629. make.height.equalTo(commentHeight1)
  630. }
  631. let commentHeight2 = "用了之后,才发现真的可以找到他。".heightAccording(width: QSLConst.qsl_kScreenW - 52.rpx - 12.rpx, font: .textF(15), lineSpacing: 2) + 35.rpx
  632. commentView.addSubview(comment2)
  633. comment2.snp.makeConstraints { make in
  634. make.left.right.equalTo(0)
  635. make.top.equalTo(comment1.snp.bottom).offset(30.rpx)
  636. make.height.equalTo(commentHeight2)
  637. }
  638. let commentHeight3 = "轨迹很准,一目了然,奶奶出门遇到危险直接一键报警,我就收到信息了".heightAccording(width: QSLConst.qsl_kScreenW - 52.rpx - 12.rpx, font: .textF(15), lineSpacing: 2) + 35.rpx
  639. commentView.addSubview(comment3)
  640. comment3.snp.makeConstraints { make in
  641. make.left.right.equalTo(0)
  642. make.top.equalTo(comment2.snp.bottom).offset(30.rpx)
  643. make.height.equalTo(commentHeight3)
  644. }
  645. scrollView.snp.makeConstraints { make in
  646. make.bottom.equalTo(mainView)
  647. }
  648. self.view.addSubview(bottomView)
  649. bottomView.snp.makeConstraints { make in
  650. make.left.equalTo(12.rpx)
  651. make.right.equalTo(-12.rpx)
  652. make.bottom.equalTo(-QSLConst.qsl_kTabbarBottom)
  653. make.height.equalTo(50.rpx)
  654. }
  655. bottomView.addSubview(unlockBtn)
  656. unlockBtn.snp.makeConstraints { make in
  657. make.right.top.bottom.equalTo(0)
  658. make.width.equalTo(165.rpx)
  659. }
  660. bottomView.addSubview(priceIconLabel)
  661. priceIconLabel.snp.makeConstraints { make in
  662. make.left.equalTo(20.rpx)
  663. make.bottom.equalTo(-12.rpx)
  664. }
  665. bottomView.addSubview(priceLabel)
  666. priceLabel.snp.makeConstraints { make in
  667. make.left.equalTo(priceIconLabel.snp.right).offset(2.rpx)
  668. make.bottom.equalTo(-10.rpx)
  669. }
  670. bottomView.addSubview(goodTypeLabel)
  671. goodTypeLabel.snp.makeConstraints { make in
  672. make.left.equalTo(priceLabel.snp.right).offset(2.rpx)
  673. make.bottom.equalTo(-14.rpx)
  674. }
  675. }
  676. }