四零语境前端代码仓库
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.

531 lines
12 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months 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="filterList" :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. memberId : '',
  114. list: [
  115. ],
  116. selectedPackage: 0, // 默认选择第一个套餐
  117. selectedMember: 0, // 默认选择第一个会员
  118. defaultPackageList: [
  119. ],
  120. couponId: '',
  121. selectedCoupon: null // 选中的优惠券信息
  122. }
  123. },
  124. computed: {
  125. packageList() {
  126. return this.list[this.selectedMember]?.setmeals ? this.list[this.selectedMember].setmeals : this
  127. .defaultPackageList
  128. },
  129. filterList(){
  130. return this.list.filter(a => {
  131. if(!this.memberId) {
  132. return true
  133. }
  134. return a.id == this.memberId
  135. })
  136. },
  137. },
  138. onLoad(query) {
  139. this.memberId = query.id
  140. },
  141. methods: {
  142. handleCouponSelected(coupon) {
  143. // 处理选中的优惠券
  144. this.selectedCoupon = coupon
  145. this.couponId = coupon.id
  146. uni.showToast({
  147. title: `已选择优惠券:¥${coupon.money}`,
  148. icon: 'success'
  149. })
  150. },
  151. async handleRecharge() {
  152. // console.log('选中的会员id是:', this.packageList[this.selectedPackage]);
  153. const object = {
  154. // #ifdef H5
  155. type: 'official',
  156. // #endif
  157. memberId: this.list[this.selectedMember].id,
  158. setmealId: this.packageList[this.selectedPackage].id
  159. }
  160. if (this.couponId) {
  161. object.couponId = this.couponId
  162. }
  163. const res = await this.$api.member.openMember({
  164. ...object
  165. })
  166. if (res.code === 200) {
  167. if (res.result === 0) {
  168. // 零元购
  169. uni.showToast({
  170. title: '充值成功',
  171. icon: 'success'
  172. })
  173. this.goBack()
  174. } else {
  175. // 调起微信支付
  176. this.$utils.wxPay(res.result, (res) => {
  177. setTimeout(() => {
  178. this.goBack()
  179. }, 1000)
  180. })
  181. }
  182. }
  183. },
  184. goBack() {
  185. uni.navigateBack()
  186. },
  187. // 截取价格的整数与小数部分
  188. getInt(pri) {
  189. const price = String(pri)
  190. if (price.indexOf('.') === -1) {
  191. return price
  192. }
  193. if (price === null) {
  194. return '0'
  195. }
  196. return String(price).split('.')[0]
  197. },
  198. getDecimal(pri) {
  199. const price = String(pri)
  200. if (price === null) return '00'
  201. const parts = price.split('.')
  202. return parts[1] ? parts[1].padEnd(2, '0') : '00'
  203. },
  204. selectPackage(index) {
  205. this.selectedPackage = index
  206. },
  207. selectCoupon() {
  208. uni.navigateTo({
  209. url: '/subPages/user/discount?from=recharge'
  210. })
  211. },
  212. async getMemberList() {
  213. const memberRes = await this.$api.member.getMemberList()
  214. if (memberRes.code === 200) {
  215. this.list = memberRes.result
  216. }
  217. },
  218. changeSwiper(e) {
  219. this.selectedMember = e.current
  220. this.selectedPackage = 0
  221. }
  222. },
  223. onShow() {
  224. // 监听优惠券选择事件
  225. uni.$on('couponSelected', this.handleCouponSelected)
  226. this.getMemberList()
  227. },
  228. onUnload() {
  229. // 移除事件监听
  230. uni.$off('couponSelected', this.handleCouponSelected)
  231. console.log('接触监听');
  232. },
  233. }
  234. </script>
  235. <style lang="scss" scoped>
  236. .container {
  237. min-height: 100%;
  238. }
  239. .header {
  240. width: 100%;
  241. .header-bg {
  242. position: relative;
  243. width: 100%;
  244. height: 500rpx;
  245. /* #ifdef H5 */
  246. margin-top: -100rpx;
  247. /* #endif */
  248. // background: red;
  249. .header-img {
  250. width: 100%;
  251. height: 500rpx;
  252. }
  253. .header-title {
  254. font-size: 32rpx;
  255. color: black;
  256. position: absolute;
  257. top: 100rpx;
  258. font-weight: 500;
  259. left: 50%;
  260. transform: translateX(-50%);
  261. }
  262. .header-icon {
  263. position: absolute;
  264. top: 100rpx;
  265. left: 30rpx;
  266. }
  267. .swiper-container {
  268. margin-top: -300rpx;
  269. .swiper-arrow {
  270. width: 100%;
  271. height: 22rpx;
  272. }
  273. .swiper-btn {
  274. margin: 35rpx auto 15rpx;
  275. width: 150rpx;
  276. height: 52rpx;
  277. border-radius: 999px;
  278. background: #06DADC;
  279. color: white;
  280. font-size: 28rpx;
  281. font-weight: 500;
  282. text-align: center;
  283. line-height: 52rpx;
  284. }
  285. }
  286. }
  287. }
  288. /* 立即开通会员按钮样式 */
  289. .member-button-section {
  290. margin: 0 50rpx 40rpx;
  291. }
  292. // 会员套餐选择容器
  293. .membership-container {
  294. background: linear-gradient(180deg, #DEFFFF 0%, #FBFEFF 22.65%, #FFFFFF 100%);
  295. padding: 40rpx 30rpx;
  296. margin-top: 20rpx;
  297. .package-list {
  298. display: flex;
  299. justify-content: space-between;
  300. gap: 16rpx;
  301. margin-bottom: 20rpx;
  302. .package-item {
  303. position: relative;
  304. flex: 1;
  305. background: #fff;
  306. border-radius: 20rpx;
  307. text-align: center;
  308. border: 2rpx solid #EEEEEE;
  309. transition: all 0.3s;
  310. // width: 119;
  311. height: 210rpx;
  312. // width: 238rpx;
  313. .info {
  314. padding: 16rpx 16rpx 0 16rpx;
  315. }
  316. &.active {
  317. border-color: $primary-color;
  318. // box-shadow: 0 4rpx 20rpx rgba(34, 242, 235, 0.2);
  319. }
  320. .gift-tag {
  321. position: absolute;
  322. top: -10rpx;
  323. left: 0%;
  324. // transform: translateX(-50%);
  325. background: #FF6B6B;
  326. color: #fff;
  327. font-size: 20rpx;
  328. padding: 8rpx 16rpx;
  329. border-radius: 20rpx 20rpx 20rpx 0;
  330. white-space: nowrap;
  331. }
  332. .package-title {
  333. font-size: 28rpx;
  334. color: #000;
  335. margin-bottom: 16rpx;
  336. font-weight: 500;
  337. }
  338. .package-price {
  339. font-size: 36rpx;
  340. color: #FF4800;
  341. font-weight: 500;
  342. margin-bottom: 8rpx;
  343. .package-decimal {
  344. font-size: 24rpx;
  345. }
  346. }
  347. .package-original {
  348. font-size: 24rpx;
  349. color: #8B8B8B;
  350. line-height: 1.4;
  351. text-decoration: line-through;
  352. margin-bottom: 8rpx;
  353. }
  354. .package-btn {
  355. background: #E4E7EB;
  356. color: #191919;
  357. font-size: 28rpx;
  358. // padding: 12rpx 20rpx;
  359. width: 100%;
  360. // border-radius: 30rpx;
  361. transition: all 0.3s;
  362. height: 52rpx;
  363. line-height: 52rpx;
  364. border-radius: 0 0 24rpx 24rpx;
  365. &.active {
  366. background: $primary-color;
  367. color: #fff;
  368. }
  369. }
  370. }
  371. }
  372. .coupon-section {
  373. .coupon-title {
  374. font-size: 26rpx;
  375. color: #181818;
  376. margin-bottom: 10rpx;
  377. // font-weight: 500;
  378. }
  379. .coupon-selector {
  380. background: #fff;
  381. border-radius: 16rpx;
  382. padding: 10rpx 0;
  383. display: flex;
  384. justify-content: space-between;
  385. align-items: center;
  386. border-bottom: 2rpx solid #f0f0f0;
  387. .coupon-placeholder {
  388. display: flex;
  389. justify-content: space-between;
  390. align-items: center;
  391. width: 100%;
  392. .coupon-text {
  393. font-size: 32rpx;
  394. color: #C6C6C6;
  395. }
  396. }
  397. .coupon-selected {
  398. display: flex;
  399. justify-content: space-between;
  400. align-items: center;
  401. width: 100%;
  402. .coupon-info {
  403. display: flex;
  404. // flex-direction: column;
  405. align-items: center;
  406. justify-content: space-between;
  407. .coupon-name {
  408. font-size: 28rpx;
  409. color: #181818;
  410. margin-bottom: 4rpx;
  411. }
  412. .coupon-amount {
  413. font-size: 28rpx;
  414. color: red;
  415. font-weight: 500;
  416. }
  417. }
  418. }
  419. }
  420. }
  421. }
  422. /* 会员权益样式 */
  423. .benefits-section {
  424. margin-top: 40rpx;
  425. padding: 0 30rpx;
  426. }
  427. .benefits-title {
  428. font-size: 36rpx;
  429. font-weight: bold;
  430. color: #191919;
  431. margin-bottom: 32rpx;
  432. }
  433. .benefits-list {
  434. display: flex;
  435. flex-direction: column;
  436. gap: 32rpx;
  437. }
  438. .benefit-item {
  439. background: #F8F8F8;
  440. border: 1px solid #FFFFFF;
  441. border-radius: 48rpx;
  442. padding: 27rpx 40rpx;
  443. display: flex;
  444. align-items: center;
  445. justify-content: space-between;
  446. }
  447. .benefit-content {
  448. flex: 1;
  449. margin-right: 40rpx;
  450. }
  451. .benefit-title {
  452. font-size: 32rpx;
  453. font-weight: 600;
  454. color: #333;
  455. margin-bottom: 16rpx;
  456. }
  457. .benefit-desc {
  458. font-size: 24rpx;
  459. color: #09B1B3;
  460. line-height: 36rpx;
  461. }
  462. .benefit-icon {
  463. width: 152rpx;
  464. height: 152rpx;
  465. // flex-shrink: 0;
  466. }
  467. .benefit-icon image {
  468. width: 100%;
  469. height: 100%;
  470. }
  471. </style>