course-detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. <template>
  2. <view class="course-detail-page">
  3. <!-- 自定义导航栏 -->
  4. <view class="custom-navbar">
  5. <view class="navbar-left" @click="goBack">
  6. <text class="back-icon">←</text>
  7. </view>
  8. <view class="navbar-title">课程详情</view>
  9. <view class="navbar-right">
  10. <view class="points-info" @click="goToPointsDetail">
  11. <text class="points-icon">💎</text>
  12. <text class="points-value">{{ currentPoints }}</text>
  13. </view>
  14. </view>
  15. </view>
  16. <!-- 课程封面 -->
  17. <view class="course-cover">
  18. <image :src="course.cover_image" class="cover-image" mode="aspectFill"></image>
  19. <view class="cover-mask">
  20. <view class="points-tag">💎 {{ course.points_price || course.price * 10 }}积分</view>
  21. </view>
  22. </view>
  23. <!-- 课程信息 -->
  24. <view class="course-content">
  25. <view class="course-title">{{ course.name }}</view>
  26. <view class="teacher-info">
  27. <image :src="course.teacher_avatar || DEFAULT_IMAGES.avatar" class="teacher-avatar" mode="aspectFill"></image>
  28. <view class="teacher-detail">
  29. <text class="teacher-name">{{ course.teacher_name }}</text>
  30. <text class="teacher-desc">{{ course.teacher_desc || '资深情感导师' }}</text>
  31. </view>
  32. </view>
  33. <view class="course-stats">
  34. <view class="stat-item">
  35. <text class="stat-icon">👥</text>
  36. <text class="stat-text">{{ course.student_count || 0 }}人学习</text>
  37. </view>
  38. <view class="stat-item">
  39. <text class="stat-icon">⭐</text>
  40. <text class="stat-text">{{ course.rating || '5.0' }}分</text>
  41. </view>
  42. <view class="stat-item">
  43. <text class="stat-icon">📚</text>
  44. <text class="stat-text">{{ course.chapter_count || 0 }}个章节</text>
  45. </view>
  46. </view>
  47. <view class="divider"></view>
  48. <view class="description-section">
  49. <view class="section-title">课程介绍</view>
  50. <view class="description-text">{{ course.description || '暂无介绍' }}</view>
  51. </view>
  52. <view class="divider"></view>
  53. <view class="outline-section">
  54. <view class="section-title">课程大纲</view>
  55. <view class="outline-text">{{ course.outline || '敬请期待' }}</view>
  56. </view>
  57. </view>
  58. <!-- 底部兑换按钮 -->
  59. <view class="bottom-bar">
  60. <view class="price-info">
  61. <text class="price-label">兑换所需</text>
  62. <view class="price-value">
  63. <text class="points-icon">💎</text>
  64. <text class="price-num">{{ course.points_price || course.price * 10 }}</text>
  65. <text class="price-unit">积分</text>
  66. </view>
  67. </view>
  68. <view class="purchase-btn" :class="{ purchased: isPurchased }" @click="handleExchange">
  69. <text class="btn-text">{{ isPurchased ? '立即学习' : '积分兑换' }}</text>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. import api from '@/utils/api.js'
  76. import { DEFAULT_IMAGES } from '@/config/index.js'
  77. export default {
  78. data() {
  79. return {
  80. courseId: null,
  81. course: {},
  82. DEFAULT_IMAGES,
  83. currentPoints: 0,
  84. makerId: null,
  85. isPurchased: false
  86. }
  87. },
  88. onLoad(options) {
  89. console.log('红娘课程详情页面加载, 参数:', options)
  90. if (options.id) {
  91. this.courseId = options.id
  92. this.loadMakerInfo()
  93. }
  94. },
  95. onShow() {
  96. this.loadCurrentPoints()
  97. },
  98. methods: {
  99. // 加载红娘信息
  100. async loadMakerInfo() {
  101. try {
  102. const userInfo = uni.getStorageSync('userInfo')
  103. if (userInfo && userInfo.userId) {
  104. const matchmakerInfo = await api.matchmaker.getByUserId(userInfo.userId)
  105. if (matchmakerInfo) {
  106. this.makerId = matchmakerInfo.matchmakerId || matchmakerInfo.matchmaker_id
  107. this.loadCurrentPoints()
  108. this.loadCourseDetail()
  109. this.checkPurchaseStatus()
  110. }
  111. }
  112. } catch (error) {
  113. console.error('获取红娘信息失败:', error)
  114. this.loadCourseDetail()
  115. }
  116. },
  117. // 加载当前积分
  118. async loadCurrentPoints() {
  119. if (!this.makerId) return
  120. try {
  121. const res = await api.pointsMall.getBalance(this.makerId)
  122. this.currentPoints = res || 0
  123. } catch (error) {
  124. console.error('获取积分失败:', error)
  125. }
  126. },
  127. // 加载课程详情
  128. async loadCourseDetail() {
  129. try {
  130. // 使用红娘课程独立API
  131. const data = await api.matchmakerCourse.getDetail(this.courseId)
  132. if (data) {
  133. this.course = {
  134. ...data,
  135. points_price: data.points || (data.price ? data.price * 10 : 100),
  136. cover_image: data.cover_image || data.coverImage || this.DEFAULT_IMAGES.course,
  137. teacher_name: data.teacher_name || data.instructor || '专业导师'
  138. }
  139. } else {
  140. this.setMockCourse()
  141. }
  142. } catch (error) {
  143. console.error('加载课程详情失败:', error)
  144. this.setMockCourse()
  145. }
  146. },
  147. // 设置模拟数据
  148. setMockCourse() {
  149. this.course = {
  150. id: this.courseId,
  151. name: '红娘专业培训课程',
  152. teacher_name: '资深导师',
  153. teacher_desc: '10年情感咨询经验',
  154. rating: 4.9,
  155. student_count: 128,
  156. chapter_count: 12,
  157. points_price: 1990,
  158. description: '本课程专为红娘设计,涵盖相亲流程、沟通技巧、客户心理分析等核心内容,帮助您成为专业的婚恋顾问。',
  159. outline: '第一章:红娘职业概述\n第二章:客户需求分析\n第三章:沟通技巧训练\n第四章:相亲活动组织\n第五章:成功案例分享',
  160. cover_image: this.DEFAULT_IMAGES.course
  161. }
  162. },
  163. // 检查是否已兑换
  164. async checkPurchaseStatus() {
  165. if (!this.makerId || !this.courseId) return
  166. try {
  167. // 使用红娘课程独立API
  168. const res = await api.matchmakerCourse.checkExchanged(this.makerId, this.courseId)
  169. if (res && res.exchanged !== undefined) {
  170. this.isPurchased = res.exchanged
  171. }
  172. } catch (error) {
  173. console.log('检查兑换状态失败:', error)
  174. }
  175. },
  176. // 处理兑换
  177. handleExchange() {
  178. if (this.isPurchased) {
  179. uni.showToast({
  180. title: '学习功能开发中',
  181. icon: 'none'
  182. })
  183. return
  184. }
  185. const pointsNeeded = this.course.points_price || this.course.price * 10
  186. if (this.currentPoints < pointsNeeded) {
  187. uni.showModal({
  188. title: '积分不足',
  189. content: `兑换该课程需要${pointsNeeded}积分,您当前只有${this.currentPoints}积分`,
  190. showCancel: true,
  191. cancelText: '取消',
  192. confirmText: '去赚积分',
  193. success: (res) => {
  194. if (res.confirm) {
  195. uni.navigateTo({
  196. url: '/pages/matchmaker-workbench/earn-points'
  197. })
  198. }
  199. }
  200. })
  201. return
  202. }
  203. uni.showModal({
  204. title: '确认兑换',
  205. content: `确定使用${pointsNeeded}积分兑换课程"${this.course.name}"吗?`,
  206. success: async (res) => {
  207. if (res.confirm) {
  208. await this.doExchange(pointsNeeded)
  209. }
  210. }
  211. })
  212. },
  213. // 执行兑换
  214. async doExchange(pointsNeeded) {
  215. uni.showLoading({ title: '兑换中...' })
  216. try {
  217. // 使用红娘课程独立API
  218. const res = await api.matchmakerCourse.exchange({
  219. makerId: this.makerId,
  220. courseId: this.courseId,
  221. points: pointsNeeded
  222. })
  223. if (res) {
  224. uni.hideLoading()
  225. uni.showToast({
  226. title: '兑换成功',
  227. icon: 'success'
  228. })
  229. this.isPurchased = true
  230. this.currentPoints -= pointsNeeded
  231. this.course.student_count = (this.course.student_count || 0) + 1
  232. setTimeout(() => {
  233. uni.showModal({
  234. title: '兑换成功',
  235. content: '您已成功兑换此课程,现在可以开始学习了!',
  236. showCancel: false,
  237. confirmText: '开始学习',
  238. success: () => {
  239. uni.showToast({
  240. title: '学习功能开发中',
  241. icon: 'none'
  242. })
  243. }
  244. })
  245. }, 1500)
  246. }
  247. } catch (error) {
  248. uni.hideLoading()
  249. console.error('兑换失败:', error)
  250. uni.showToast({
  251. title: error.msg || '兑换失败',
  252. icon: 'none'
  253. })
  254. }
  255. },
  256. // 跳转积分明细
  257. goToPointsDetail() {
  258. uni.navigateTo({
  259. url: '/pages/matchmaker-workbench/points-detail'
  260. })
  261. },
  262. // 返回
  263. goBack() {
  264. uni.navigateBack({
  265. fail: () => {
  266. uni.navigateTo({
  267. url: '/pages/matchmaker-workbench/courses'
  268. })
  269. }
  270. })
  271. }
  272. }
  273. }
  274. </script>
  275. <style lang="scss" scoped>
  276. .course-detail-page {
  277. min-height: 100vh;
  278. background-color: #FFF9F9;
  279. padding-top: 90rpx;
  280. padding-bottom: 140rpx;
  281. }
  282. /* 自定义导航栏 */
  283. .custom-navbar {
  284. position: fixed;
  285. top: 0;
  286. left: 0;
  287. right: 0;
  288. height: 90rpx;
  289. display: flex;
  290. align-items: center;
  291. justify-content: space-between;
  292. padding: 0 20rpx;
  293. background: linear-gradient(135deg, #FCE4EC 0%, #F8BBD0 100%);
  294. z-index: 999;
  295. .navbar-left,
  296. .navbar-right {
  297. width: 120rpx;
  298. }
  299. .back-icon {
  300. font-size: 40rpx;
  301. color: #333333;
  302. font-weight: bold;
  303. }
  304. .navbar-title {
  305. flex: 1;
  306. text-align: center;
  307. font-size: 32rpx;
  308. font-weight: bold;
  309. color: #333333;
  310. }
  311. .points-info {
  312. display: flex;
  313. align-items: center;
  314. background: rgba(255, 255, 255, 0.8);
  315. padding: 8rpx 16rpx;
  316. border-radius: 30rpx;
  317. .points-icon {
  318. font-size: 24rpx;
  319. margin-right: 6rpx;
  320. }
  321. .points-value {
  322. font-size: 26rpx;
  323. color: #E91E63;
  324. font-weight: bold;
  325. }
  326. }
  327. }
  328. /* 课程封面 */
  329. .course-cover {
  330. position: relative;
  331. width: 100%;
  332. height: 400rpx;
  333. .cover-image {
  334. width: 100%;
  335. height: 100%;
  336. }
  337. .cover-mask {
  338. position: absolute;
  339. bottom: 0;
  340. left: 0;
  341. right: 0;
  342. padding: 20rpx;
  343. background: linear-gradient(transparent, rgba(0, 0, 0, 0.5));
  344. .points-tag {
  345. display: inline-block;
  346. background: linear-gradient(135deg, #E91E63 0%, #9C27B0 100%);
  347. color: #FFFFFF;
  348. font-size: 28rpx;
  349. font-weight: bold;
  350. padding: 10rpx 24rpx;
  351. border-radius: 30rpx;
  352. }
  353. }
  354. }
  355. /* 课程内容 */
  356. .course-content {
  357. padding: 30rpx;
  358. .course-title {
  359. font-size: 36rpx;
  360. font-weight: bold;
  361. color: #333333;
  362. margin-bottom: 30rpx;
  363. }
  364. .teacher-info {
  365. display: flex;
  366. align-items: center;
  367. margin-bottom: 30rpx;
  368. .teacher-avatar {
  369. width: 80rpx;
  370. height: 80rpx;
  371. border-radius: 50%;
  372. margin-right: 20rpx;
  373. }
  374. .teacher-detail {
  375. display: flex;
  376. flex-direction: column;
  377. .teacher-name {
  378. font-size: 30rpx;
  379. font-weight: bold;
  380. color: #333333;
  381. }
  382. .teacher-desc {
  383. font-size: 24rpx;
  384. color: #999999;
  385. margin-top: 6rpx;
  386. }
  387. }
  388. }
  389. .course-stats {
  390. display: flex;
  391. justify-content: space-around;
  392. padding: 20rpx 0;
  393. background-color: #FFF5F8;
  394. border-radius: 16rpx;
  395. margin-bottom: 30rpx;
  396. .stat-item {
  397. display: flex;
  398. align-items: center;
  399. .stat-icon {
  400. font-size: 28rpx;
  401. margin-right: 8rpx;
  402. }
  403. .stat-text {
  404. font-size: 26rpx;
  405. color: #666666;
  406. }
  407. }
  408. }
  409. .divider {
  410. height: 1rpx;
  411. background-color: #F0F0F0;
  412. margin: 30rpx 0;
  413. }
  414. .section-title {
  415. font-size: 32rpx;
  416. font-weight: bold;
  417. color: #333333;
  418. margin-bottom: 20rpx;
  419. }
  420. .description-text,
  421. .outline-text {
  422. font-size: 28rpx;
  423. color: #666666;
  424. line-height: 1.8;
  425. white-space: pre-wrap;
  426. }
  427. }
  428. /* 底部栏 */
  429. .bottom-bar {
  430. position: fixed;
  431. bottom: 0;
  432. left: 0;
  433. right: 0;
  434. height: 120rpx;
  435. display: flex;
  436. align-items: center;
  437. justify-content: space-between;
  438. padding: 0 30rpx;
  439. background-color: #FFFFFF;
  440. box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
  441. .price-info {
  442. .price-label {
  443. font-size: 24rpx;
  444. color: #999999;
  445. }
  446. .price-value {
  447. display: flex;
  448. align-items: center;
  449. margin-top: 6rpx;
  450. .points-icon {
  451. font-size: 28rpx;
  452. margin-right: 6rpx;
  453. }
  454. .price-num {
  455. font-size: 40rpx;
  456. font-weight: bold;
  457. color: #E91E63;
  458. }
  459. .price-unit {
  460. font-size: 24rpx;
  461. color: #E91E63;
  462. margin-left: 6rpx;
  463. }
  464. }
  465. }
  466. .purchase-btn {
  467. width: 280rpx;
  468. height: 80rpx;
  469. display: flex;
  470. align-items: center;
  471. justify-content: center;
  472. background: linear-gradient(135deg, #E91E63 0%, #9C27B0 100%);
  473. border-radius: 40rpx;
  474. &.purchased {
  475. background: linear-gradient(135deg, #4CAF50 0%, #8BC34A 100%);
  476. }
  477. .btn-text {
  478. font-size: 30rpx;
  479. font-weight: bold;
  480. color: #FFFFFF;
  481. }
  482. }
  483. }
  484. </style>