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