四零语境前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

519 lines
12 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
  1. <template>
  2. <view class="container">
  3. <view class="header">
  4. <view class="header-bg">
  5. <image src="/static/member-background.png" class="header-img" mode="scaleToFill" />
  6. <!-- #ifndef H5 -->
  7. <text class="header-title">会员开通</text>
  8. <!-- 加一个推出箭头 -->
  9. <view class="header-icon" @click="goBack">
  10. <uv-icon name="arrow-left" color="#000" size="20" />
  11. </view>
  12. <!-- #endif -->
  13. <!-- 轮播容器 -->
  14. <view class="uv-demo-block swiper-container">
  15. <uv-swiper bgColor="transparent" :list="list" :loading="!list.length" @change="changeSwiper"
  16. keyName="img" previousMargin="70" nextMargin="70" acceleration height="75" circular
  17. :autoplay="false" radius="5">
  18. </uv-swiper>
  19. <button class="swiper-btn">
  20. 已选择
  21. </button>
  22. <image class="swiper-arrow" src="/static/decorative-arrow.png" mode="aspectFill" />
  23. </view>
  24. </view>
  25. </view>
  26. <!-- 会员套餐选择容器 -->
  27. <view class="membership-container">
  28. <!-- 套餐选择 -->
  29. <view class="package-list">
  30. <view class="package-item" :class="{ 'active': selectedPackage === index }"
  31. v-for="(item, index) in packageList" :key="index" @click="selectPackage(index)">
  32. <view class="info">
  33. <!-- 赠送标识 -->
  34. <view class="gift-tag" v-if="item.content">
  35. {{ item.content }}
  36. </view>
  37. <view class="package-title">{{ item.title }}</view>
  38. <view class="package-price">¥{{ getInt(item.discountedprice) }}.<text
  39. class="package-decimal">{{ getDecimal(item.discountedprice) }}</text></view>
  40. <view class="package-original">¥{{ item.originalprice }}</view>
  41. </view>
  42. <view class="package-btn" :class="{ 'active': selectedPackage === index }">
  43. {{ selectedPackage === index ? '已选择' : '点击选择' }}
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 优惠券选择 -->
  48. <view class="coupon-section">
  49. <view class="coupon-title">选择优惠券</view>
  50. <view class="coupon-selector" @click="selectCoupon">
  51. <view v-if="!selectedCoupon" class="coupon-placeholder">
  52. <text class="coupon-text">请选择</text>
  53. <uv-icon name="arrow-right" color="#999" size="16" />
  54. </view>
  55. <view v-else class="coupon-selected">
  56. <view class="coupon-info">
  57. <text class="coupon-name">{{ selectedCoupon.name }}</text>
  58. <text class="coupon-amount">-¥{{ selectedCoupon.money }}</text>
  59. </view>
  60. <uv-icon name="arrow-right" color="#999" size="16" />
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. <!-- 立即开通会员按钮 -->
  66. <view class="member-button-section">
  67. <uv-button type="primary" text="立即开通会员" :custom-style="{
  68. width: '100%',
  69. height: '82rpx',
  70. borderRadius: '44rpx',
  71. backgroundColor: '#06DADC',
  72. fontSize: '36rpx',
  73. fontWeight: '500',
  74. border: '1px solid #06DADC'
  75. }" @click="handleRecharge"></uv-button>
  76. </view>
  77. <!-- 会员权益 -->
  78. <view class="benefits-section">
  79. <view class="benefits-title">会员权益</view>
  80. <view class="benefits-list">
  81. <!-- 碎片学习 系统掌握 -->
  82. <!-- <view class="benefit-item" v-for="item in packageList" :key="item.id"> -->
  83. <uv-parse :content="list[selectedMember].content" />
  84. <!-- </view> -->
  85. <!-- 匹配水平 -->
  86. <!-- <view class="benefit-item">
  87. <view class="benefit-content">
  88. <view class="benefit-title">匹配水平</view>
  89. <view class="benefit-desc">依据水平精准推课不做无用功快速提升</view>
  90. </view>
  91. <view class="benefit-icon">
  92. <image src="/static/会员图片2.png" mode="aspectFit"></image>
  93. </view>
  94. </view>
  95. 科学闭环测 讲练结合
  96. <view class="benefit-item">
  97. <view class="benefit-content">
  98. <view class="benefit-title">科学闭环测 讲练结合</view>
  99. <view class="benefit-desc">精心设计科学的学习流程 测试-讲解-练习-检验知识掌握更牢固</view>
  100. </view>
  101. <view class="benefit-icon">
  102. <image src="/static/会员图片3.png" mode="aspectFit"></image>
  103. </view>
  104. </view> -->
  105. </view>
  106. </view>
  107. </view>
  108. </template>
  109. <script>
  110. export default {
  111. data() {
  112. return {
  113. list: [
  114. ],
  115. selectedPackage: 0, // 默认选择第一个套餐
  116. selectedMember: 0, // 默认选择第一个会员
  117. defaultPackageList: [
  118. ],
  119. couponId: '',
  120. selectedCoupon: null // 选中的优惠券信息
  121. }
  122. },
  123. computed: {
  124. packageList() {
  125. return this.list[this.selectedMember]?.setmeals ? this.list[this.selectedMember].setmeals : this
  126. .defaultPackageList
  127. }
  128. },
  129. methods: {
  130. handleCouponSelected(coupon) {
  131. // 处理选中的优惠券
  132. this.selectedCoupon = coupon
  133. this.couponId = coupon.id
  134. uni.showToast({
  135. title: `已选择优惠券:¥${coupon.money}`,
  136. icon: 'success'
  137. })
  138. },
  139. async handleRecharge() {
  140. // console.log('选中的会员id是:', this.packageList[this.selectedPackage]);
  141. const object = {
  142. // #ifdef H5
  143. type: 'official',
  144. // #endif
  145. memberId: this.list[this.selectedMember].id,
  146. setmealId: this.packageList[this.selectedPackage].id
  147. }
  148. if (this.couponId) {
  149. object.couponId = this.couponId
  150. }
  151. const res = await this.$api.member.openMember({
  152. ...object
  153. })
  154. if (res.code === 200) {
  155. if (res.result === 0) {
  156. // 零元购
  157. uni.showToast({
  158. title: '充值成功',
  159. icon: 'success'
  160. })
  161. this.goBack()
  162. } else {
  163. // 调起微信支付
  164. this.$utils.wxPay(res.result, (res) => {
  165. setTimeout(() => {
  166. this.goBack()
  167. }, 1000)
  168. })
  169. }
  170. }
  171. },
  172. goBack() {
  173. uni.navigateBack()
  174. },
  175. // 截取价格的整数与小数部分
  176. getInt(pri) {
  177. const price = String(pri)
  178. if (price.indexOf('.') === -1) {
  179. return price
  180. }
  181. if (price === null) {
  182. return '0'
  183. }
  184. return String(price).split('.')[0]
  185. },
  186. getDecimal(pri) {
  187. const price = String(pri)
  188. if (price === null) return '00'
  189. const parts = price.split('.')
  190. return parts[1] ? parts[1].padEnd(2, '0') : '00'
  191. },
  192. selectPackage(index) {
  193. this.selectedPackage = index
  194. },
  195. selectCoupon() {
  196. uni.navigateTo({
  197. url: '/subPages/user/discount?from=recharge'
  198. })
  199. },
  200. async getMemberList() {
  201. const memberRes = await this.$api.member.getMemberList()
  202. if (memberRes.code === 200) {
  203. this.list = memberRes.result
  204. }
  205. },
  206. changeSwiper(e) {
  207. this.selectedMember = e.current
  208. this.selectedPackage = 0
  209. }
  210. },
  211. onShow() {
  212. // 监听优惠券选择事件
  213. uni.$on('couponSelected', this.handleCouponSelected)
  214. this.getMemberList()
  215. },
  216. onUnload() {
  217. // 移除事件监听
  218. uni.$off('couponSelected', this.handleCouponSelected)
  219. console.log('接触监听');
  220. },
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. .container {
  225. min-height: 100%;
  226. }
  227. .header {
  228. width: 100%;
  229. .header-bg {
  230. position: relative;
  231. width: 100%;
  232. height: 500rpx;
  233. /* #ifdef H5 */
  234. margin-top: -100rpx;
  235. /* #endif */
  236. // background: red;
  237. .header-img {
  238. width: 100%;
  239. height: 500rpx;
  240. }
  241. .header-title {
  242. font-size: 32rpx;
  243. color: black;
  244. position: absolute;
  245. top: 100rpx;
  246. font-weight: 500;
  247. left: 50%;
  248. transform: translateX(-50%);
  249. }
  250. .header-icon {
  251. position: absolute;
  252. top: 100rpx;
  253. left: 30rpx;
  254. }
  255. .swiper-container {
  256. margin-top: -300rpx;
  257. .swiper-arrow {
  258. width: 100%;
  259. height: 22rpx;
  260. }
  261. .swiper-btn {
  262. margin: 35rpx auto 15rpx;
  263. width: 150rpx;
  264. height: 52rpx;
  265. border-radius: 999px;
  266. background: #06DADC;
  267. color: white;
  268. font-size: 28rpx;
  269. font-weight: 500;
  270. text-align: center;
  271. line-height: 52rpx;
  272. }
  273. }
  274. }
  275. }
  276. /* 立即开通会员按钮样式 */
  277. .member-button-section {
  278. margin: 0 50rpx 40rpx;
  279. }
  280. // 会员套餐选择容器
  281. .membership-container {
  282. background: linear-gradient(180deg, #DEFFFF 0%, #FBFEFF 22.65%, #FFFFFF 100%);
  283. padding: 40rpx 30rpx;
  284. margin-top: 20rpx;
  285. .package-list {
  286. display: flex;
  287. justify-content: space-between;
  288. gap: 16rpx;
  289. margin-bottom: 20rpx;
  290. .package-item {
  291. position: relative;
  292. flex: 1;
  293. background: #fff;
  294. border-radius: 20rpx;
  295. text-align: center;
  296. border: 2rpx solid #EEEEEE;
  297. transition: all 0.3s;
  298. // width: 119;
  299. height: 210rpx;
  300. // width: 238rpx;
  301. .info {
  302. padding: 16rpx 16rpx 0 16rpx;
  303. }
  304. &.active {
  305. border-color: $primary-color;
  306. // box-shadow: 0 4rpx 20rpx rgba(34, 242, 235, 0.2);
  307. }
  308. .gift-tag {
  309. position: absolute;
  310. top: -10rpx;
  311. left: 0%;
  312. // transform: translateX(-50%);
  313. background: #FF6B6B;
  314. color: #fff;
  315. font-size: 20rpx;
  316. padding: 8rpx 16rpx;
  317. border-radius: 20rpx 20rpx 20rpx 0;
  318. white-space: nowrap;
  319. }
  320. .package-title {
  321. font-size: 28rpx;
  322. color: #000;
  323. margin-bottom: 16rpx;
  324. font-weight: 500;
  325. }
  326. .package-price {
  327. font-size: 36rpx;
  328. color: #FF4800;
  329. font-weight: 500;
  330. margin-bottom: 8rpx;
  331. .package-decimal {
  332. font-size: 24rpx;
  333. }
  334. }
  335. .package-original {
  336. font-size: 24rpx;
  337. color: #8B8B8B;
  338. line-height: 1.4;
  339. text-decoration: line-through;
  340. margin-bottom: 8rpx;
  341. }
  342. .package-btn {
  343. background: #E4E7EB;
  344. color: #191919;
  345. font-size: 28rpx;
  346. // padding: 12rpx 20rpx;
  347. width: 100%;
  348. // border-radius: 30rpx;
  349. transition: all 0.3s;
  350. height: 52rpx;
  351. line-height: 52rpx;
  352. border-radius: 0 0 24rpx 24rpx;
  353. &.active {
  354. background: $primary-color;
  355. color: #fff;
  356. }
  357. }
  358. }
  359. }
  360. .coupon-section {
  361. .coupon-title {
  362. font-size: 26rpx;
  363. color: #181818;
  364. margin-bottom: 10rpx;
  365. // font-weight: 500;
  366. }
  367. .coupon-selector {
  368. background: #fff;
  369. border-radius: 16rpx;
  370. padding: 10rpx 0;
  371. display: flex;
  372. justify-content: space-between;
  373. align-items: center;
  374. border-bottom: 2rpx solid #f0f0f0;
  375. .coupon-placeholder {
  376. display: flex;
  377. justify-content: space-between;
  378. align-items: center;
  379. width: 100%;
  380. .coupon-text {
  381. font-size: 32rpx;
  382. color: #C6C6C6;
  383. }
  384. }
  385. .coupon-selected {
  386. display: flex;
  387. justify-content: space-between;
  388. align-items: center;
  389. width: 100%;
  390. .coupon-info {
  391. display: flex;
  392. // flex-direction: column;
  393. align-items: center;
  394. justify-content: space-between;
  395. .coupon-name {
  396. font-size: 28rpx;
  397. color: #181818;
  398. margin-bottom: 4rpx;
  399. }
  400. .coupon-amount {
  401. font-size: 28rpx;
  402. color: red;
  403. font-weight: 500;
  404. }
  405. }
  406. }
  407. }
  408. }
  409. }
  410. /* 会员权益样式 */
  411. .benefits-section {
  412. margin-top: 40rpx;
  413. padding: 0 30rpx;
  414. }
  415. .benefits-title {
  416. font-size: 36rpx;
  417. font-weight: bold;
  418. color: #191919;
  419. margin-bottom: 32rpx;
  420. }
  421. .benefits-list {
  422. display: flex;
  423. flex-direction: column;
  424. gap: 32rpx;
  425. }
  426. .benefit-item {
  427. background: #F8F8F8;
  428. border: 1px solid #FFFFFF;
  429. border-radius: 48rpx;
  430. padding: 27rpx 40rpx;
  431. display: flex;
  432. align-items: center;
  433. justify-content: space-between;
  434. }
  435. .benefit-content {
  436. flex: 1;
  437. margin-right: 40rpx;
  438. }
  439. .benefit-title {
  440. font-size: 32rpx;
  441. font-weight: 600;
  442. color: #333;
  443. margin-bottom: 16rpx;
  444. }
  445. .benefit-desc {
  446. font-size: 24rpx;
  447. color: #09B1B3;
  448. line-height: 36rpx;
  449. }
  450. .benefit-icon {
  451. width: 152rpx;
  452. height: 152rpx;
  453. // flex-shrink: 0;
  454. }
  455. .benefit-icon image {
  456. width: 100%;
  457. height: 100%;
  458. }
  459. </style>