| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548 |
- <template>
- <view class="course-detail-page">
- <!-- 自定义导航栏 -->
- <view class="custom-navbar">
- <view class="navbar-left" @click="goBack">
- <text class="back-icon">←</text>
- </view>
- <view class="navbar-title">课程详情</view>
- <view class="navbar-right">
- <view class="points-info" @click="goToPointsDetail">
- <text class="points-icon">💎</text>
- <text class="points-value">{{ currentPoints }}</text>
- </view>
- </view>
- </view>
- <!-- 课程封面 -->
- <view class="course-cover">
- <image :src="course.cover_image" class="cover-image" mode="aspectFill"></image>
- <view class="cover-mask">
- <view class="points-tag">💎 {{ course.points_price || course.price * 10 }}积分</view>
- </view>
- </view>
- <!-- 课程信息 -->
- <view class="course-content">
- <view class="course-title">{{ course.name }}</view>
- <view class="teacher-info">
- <image :src="course.teacher_avatar || DEFAULT_IMAGES.avatar" class="teacher-avatar" mode="aspectFill"></image>
- <view class="teacher-detail">
- <text class="teacher-name">{{ course.teacher_name }}</text>
- <text class="teacher-desc">{{ course.teacher_desc || '资深情感导师' }}</text>
- </view>
- </view>
- <view class="course-stats">
- <view class="stat-item">
- <text class="stat-icon">👥</text>
- <text class="stat-text">{{ course.student_count || 0 }}人学习</text>
- </view>
- <view class="stat-item">
- <text class="stat-icon">⭐</text>
- <text class="stat-text">{{ course.rating || '5.0' }}分</text>
- </view>
- <view class="stat-item">
- <text class="stat-icon">📚</text>
- <text class="stat-text">{{ course.chapter_count || 0 }}个章节</text>
- </view>
- </view>
- <view class="divider"></view>
- <view class="description-section">
- <view class="section-title">课程介绍</view>
- <view class="description-text">{{ course.description || '暂无介绍' }}</view>
- </view>
- <view class="divider"></view>
- <view class="outline-section">
- <view class="section-title">课程大纲</view>
- <view class="outline-text">{{ course.outline || '敬请期待' }}</view>
- </view>
- </view>
- <!-- 底部兑换按钮 -->
- <view class="bottom-bar">
- <view class="price-info">
- <text class="price-label">兑换所需</text>
- <view class="price-value">
- <text class="points-icon">💎</text>
- <text class="price-num">{{ course.points_price || course.price * 10 }}</text>
- <text class="price-unit">积分</text>
- </view>
- </view>
- <view class="purchase-btn" :class="{ purchased: isPurchased }" @click="handleExchange">
- <text class="btn-text">{{ isPurchased ? '立即学习' : '积分兑换' }}</text>
- </view>
- </view>
- </view>
- </template>
- <script>
- import api from '@/utils/api.js'
- import { DEFAULT_IMAGES } from '@/config/index.js'
- export default {
- data() {
- return {
- courseId: null,
- course: {},
- DEFAULT_IMAGES,
- currentPoints: 0,
- makerId: null,
- isPurchased: false
- }
- },
- onLoad(options) {
-
-
- if (options.id) {
- this.courseId = options.id
- this.loadMakerInfo()
- }
- },
- onShow() {
- this.loadCurrentPoints()
- },
- methods: {
- // 加载红娘信息
- async loadMakerInfo() {
- try {
- const userInfo = uni.getStorageSync('userInfo')
- if (userInfo && userInfo.userId) {
- const matchmakerInfo = await api.matchmaker.getByUserId(userInfo.userId)
- if (matchmakerInfo) {
- this.makerId = matchmakerInfo.matchmakerId || matchmakerInfo.matchmaker_id
- this.loadCurrentPoints()
- this.loadCourseDetail()
- this.checkPurchaseStatus()
- }
- }
- } catch (error) {
-
- this.loadCourseDetail()
- }
- },
- // 加载当前积分
- async loadCurrentPoints() {
- if (!this.makerId) return
- try {
- const res = await api.pointsMall.getBalance(this.makerId)
- this.currentPoints = res || 0
- } catch (error) {
-
- }
- },
- // 加载课程详情
- async loadCourseDetail() {
- try {
- // 使用红娘课程独立API
- const data = await api.matchmakerCourse.getDetail(this.courseId)
- if (data) {
- this.course = {
- ...data,
- points_price: data.points || (data.price ? data.price * 10 : 100),
- cover_image: data.cover_image || data.coverImage || this.DEFAULT_IMAGES.course,
- teacher_name: data.teacher_name || data.instructor || '专业导师'
- }
- } else {
- this.setMockCourse()
- }
- } catch (error) {
-
- this.setMockCourse()
- }
- },
- // 设置模拟数据
- setMockCourse() {
- this.course = {
- id: this.courseId,
- name: '红娘专业培训课程',
- teacher_name: '资深导师',
- teacher_desc: '10年情感咨询经验',
- rating: 4.9,
- student_count: 128,
- chapter_count: 12,
- points_price: 1990,
- description: '本课程专为红娘设计,涵盖相亲流程、沟通技巧、客户心理分析等核心内容,帮助您成为专业的婚恋顾问。',
- outline: '第一章:红娘职业概述\n第二章:客户需求分析\n第三章:沟通技巧训练\n第四章:相亲活动组织\n第五章:成功案例分享',
- cover_image: this.DEFAULT_IMAGES.course
- }
- },
- // 检查是否已兑换
- async checkPurchaseStatus() {
- if (!this.makerId || !this.courseId) return
- try {
- // 使用红娘课程独立API
- const res = await api.matchmakerCourse.checkExchanged(this.makerId, this.courseId)
- if (res && res.exchanged !== undefined) {
- this.isPurchased = res.exchanged
- }
- } catch (error) {
-
- }
- },
- // 处理兑换
- handleExchange() {
- if (this.isPurchased) {
- uni.showToast({
- title: '学习功能开发中',
- icon: 'none'
- })
- return
- }
- const pointsNeeded = this.course.points_price || this.course.price * 10
- if (this.currentPoints < pointsNeeded) {
- uni.showModal({
- title: '积分不足',
- content: `兑换该课程需要${pointsNeeded}积分,您当前只有${this.currentPoints}积分`,
- showCancel: true,
- cancelText: '取消',
- confirmText: '去赚积分',
- success: (res) => {
- if (res.confirm) {
- uni.navigateTo({
- url: '/pages/matchmaker-workbench/earn-points'
- })
- }
- }
- })
- return
- }
- uni.showModal({
- title: '确认兑换',
- content: `确定使用${pointsNeeded}积分兑换课程"${this.course.name}"吗?`,
- success: async (res) => {
- if (res.confirm) {
- await this.doExchange(pointsNeeded)
- }
- }
- })
- },
- // 执行兑换
- async doExchange(pointsNeeded) {
- uni.showLoading({ title: '兑换中...' })
- try {
- // 使用红娘课程独立API
- const res = await api.matchmakerCourse.exchange({
- makerId: this.makerId,
- courseId: this.courseId,
- points: pointsNeeded
- })
- if (res) {
- uni.hideLoading()
- uni.showToast({
- title: '兑换成功',
- icon: 'success'
- })
- this.isPurchased = true
- this.currentPoints -= pointsNeeded
- this.course.student_count = (this.course.student_count || 0) + 1
- setTimeout(() => {
- uni.showModal({
- title: '兑换成功',
- content: '您已成功兑换此课程,现在可以开始学习了!',
- showCancel: false,
- confirmText: '开始学习',
- success: () => {
- uni.showToast({
- title: '学习功能开发中',
- icon: 'none'
- })
- }
- })
- }, 1500)
- }
- } catch (error) {
- uni.hideLoading()
-
- uni.showToast({
- title: error.msg || '兑换失败',
- icon: 'none'
- })
- }
- },
- // 跳转积分明细
- goToPointsDetail() {
- uni.navigateTo({
- url: '/pages/matchmaker-workbench/points-detail'
- })
- },
- // 返回
- goBack() {
- uni.navigateBack({
- fail: () => {
- uni.navigateTo({
- url: '/pages/matchmaker-workbench/courses'
- })
- }
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .course-detail-page {
- min-height: 100vh;
- background-color: #FFF9F9;
- padding-top: 90rpx;
- padding-bottom: 140rpx;
- }
- /* 自定义导航栏 */
- .custom-navbar {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- height: 90rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 0 20rpx;
- background: linear-gradient(135deg, #FCE4EC 0%, #F8BBD0 100%);
- z-index: 999;
- .navbar-left,
- .navbar-right {
- width: 120rpx;
- }
- .back-icon {
- font-size: 40rpx;
- color: #333333;
- font-weight: bold;
- }
- .navbar-title {
- flex: 1;
- text-align: center;
- font-size: 32rpx;
- font-weight: bold;
- color: #333333;
- }
- .points-info {
- display: flex;
- align-items: center;
- background: rgba(255, 255, 255, 0.8);
- padding: 8rpx 16rpx;
- border-radius: 30rpx;
- .points-icon {
- font-size: 24rpx;
- margin-right: 6rpx;
- }
- .points-value {
- font-size: 26rpx;
- color: #E91E63;
- font-weight: bold;
- }
- }
- }
- /* 课程封面 */
- .course-cover {
- position: relative;
- width: 100%;
- height: 400rpx;
- .cover-image {
- width: 100%;
- height: 100%;
- }
- .cover-mask {
- position: absolute;
- bottom: 0;
- left: 0;
- right: 0;
- padding: 20rpx;
- background: linear-gradient(transparent, rgba(0, 0, 0, 0.5));
- .points-tag {
- display: inline-block;
- background: linear-gradient(135deg, #E91E63 0%, #9C27B0 100%);
- color: #FFFFFF;
- font-size: 28rpx;
- font-weight: bold;
- padding: 10rpx 24rpx;
- border-radius: 30rpx;
- }
- }
- }
- /* 课程内容 */
- .course-content {
- padding: 30rpx;
- .course-title {
- font-size: 36rpx;
- font-weight: bold;
- color: #333333;
- margin-bottom: 30rpx;
- }
- .teacher-info {
- display: flex;
- align-items: center;
- margin-bottom: 30rpx;
- .teacher-avatar {
- width: 80rpx;
- height: 80rpx;
- border-radius: 50%;
- margin-right: 20rpx;
- }
- .teacher-detail {
- display: flex;
- flex-direction: column;
- .teacher-name {
- font-size: 30rpx;
- font-weight: bold;
- color: #333333;
- }
- .teacher-desc {
- font-size: 24rpx;
- color: #999999;
- margin-top: 6rpx;
- }
- }
- }
- .course-stats {
- display: flex;
- justify-content: space-around;
- padding: 20rpx 0;
- background-color: #FFF5F8;
- border-radius: 16rpx;
- margin-bottom: 30rpx;
- .stat-item {
- display: flex;
- align-items: center;
- .stat-icon {
- font-size: 28rpx;
- margin-right: 8rpx;
- }
- .stat-text {
- font-size: 26rpx;
- color: #666666;
- }
- }
- }
- .divider {
- height: 1rpx;
- background-color: #F0F0F0;
- margin: 30rpx 0;
- }
- .section-title {
- font-size: 32rpx;
- font-weight: bold;
- color: #333333;
- margin-bottom: 20rpx;
- }
- .description-text,
- .outline-text {
- font-size: 28rpx;
- color: #666666;
- line-height: 1.8;
- white-space: pre-wrap;
- }
- }
- /* 底部栏 */
- .bottom-bar {
- position: fixed;
- bottom: 0;
- left: 0;
- right: 0;
- height: 120rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 0 30rpx;
- background-color: #FFFFFF;
- box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
- .price-info {
- .price-label {
- font-size: 24rpx;
- color: #999999;
- }
- .price-value {
- display: flex;
- align-items: center;
- margin-top: 6rpx;
- .points-icon {
- font-size: 28rpx;
- margin-right: 6rpx;
- }
- .price-num {
- font-size: 40rpx;
- font-weight: bold;
- color: #E91E63;
- }
- .price-unit {
- font-size: 24rpx;
- color: #E91E63;
- margin-left: 6rpx;
- }
- }
- }
- .purchase-btn {
- width: 280rpx;
- height: 80rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- background: linear-gradient(135deg, #E91E63 0%, #9C27B0 100%);
- border-radius: 40rpx;
- &.purchased {
- background: linear-gradient(135deg, #4CAF50 0%, #8BC34A 100%);
- }
- .btn-text {
- font-size: 30rpx;
- font-weight: bold;
- color: #FFFFFF;
- }
- }
- }
- </style>
|