detail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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"></view>
  10. </view>
  11. <!-- 课程封面 -->
  12. <view class="course-cover">
  13. <image :src="course.cover_image" class="cover-image" mode="aspectFill"></image>
  14. <view class="cover-mask">
  15. <view class="discount-tag" v-if="course.discount_rate">限时{{ course.discount_rate }}折</view>
  16. </view>
  17. </view>
  18. <!-- 课程信息 -->
  19. <view class="course-content">
  20. <view class="course-title">{{ course.name }}</view>
  21. <view class="teacher-info">
  22. <image :src="course.teacher_avatar || DEFAULT_IMAGES.avatar" class="teacher-avatar" mode="aspectFill"></image>
  23. <view class="teacher-detail">
  24. <text class="teacher-name">{{ course.teacher_name }}</text>
  25. <text class="teacher-desc">{{ course.teacher_desc || '资深情感导师' }}</text>
  26. </view>
  27. </view>
  28. <view class="course-stats">
  29. <view class="stat-item">
  30. <text class="stat-icon">👥</text>
  31. <text class="stat-text">{{ course.student_count || 0 }}人学习</text>
  32. </view>
  33. <view class="stat-item">
  34. <text class="stat-icon">⭐</text>
  35. <text class="stat-text">{{ course.rating || '5.0' }}分</text>
  36. </view>
  37. <view class="stat-item">
  38. <text class="stat-icon">📚</text>
  39. <text class="stat-text">{{ course.chapter_count || 0 }}个章节</text>
  40. </view>
  41. </view>
  42. <view class="divider"></view>
  43. <view class="description-section">
  44. <view class="section-title">课程介绍</view>
  45. <view class="description-text">{{ course.description || '暂无介绍' }}</view>
  46. </view>
  47. <view class="divider"></view>
  48. <view class="outline-section">
  49. <view class="section-title">课程大纲</view>
  50. <view class="outline-text">{{ course.outline || '敬请期待' }}</view>
  51. </view>
  52. </view>
  53. <!-- 底部购买按钮 -->
  54. <view class="bottom-bar">
  55. <view class="price-info">
  56. <text class="price-label">课程价格</text>
  57. <view class="price-value">
  58. <text class="price-symbol">¥</text>
  59. <text class="price-num">{{ course.price || 0 }}</text>
  60. <text class="original-price" v-if="course.original_price">¥{{ course.original_price }}</text>
  61. <text class="discount-text" v-if="course.discount_rate">{{ course.discount_rate }}折优惠</text>
  62. </view>
  63. </view>
  64. <view class="purchase-btn" :class="{ purchased: course.purchase_status === 1 }" @click="handlePurchase">
  65. <text class="btn-text">{{ course.purchase_status === 1 ? '已购买' : '立即购买' }}</text>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. import api from '@/utils/api.js'
  72. import { DEFAULT_IMAGES } from '@/config/index.js'
  73. export default {
  74. data() {
  75. return {
  76. courseId: null,
  77. course: {
  78. id: 1,
  79. name: '恋爱沟通技巧大师课',
  80. description: '学会有效沟通,让感情更甜蜜。本课程将教你如何在恋爱中进行有效沟通,包括倾听技巧、表达方式、冲突化解等核心内容。适合想要提升感情质量的情侣和单身朋友。',
  81. cover_image: DEFAULT_IMAGES.course,
  82. teacher_name: '张情感老师',
  83. teacher_desc: '资深情感咨询师,拥有10年丰富的情感咨询经验,帮助过千对情侣解决感情问题',
  84. teacher_avatar: DEFAULT_IMAGES.avatar,
  85. price: 299,
  86. original_price: 399,
  87. discount_rate: 7.5,
  88. student_count: 1256,
  89. rating: 4.9,
  90. chapter_count: 12,
  91. outline: `第1章:沟通的艺术 - 了解沟通的基本原理
  92. 第2章:倾听的力量 - 学会深度倾听的技巧
  93. 第3章:表达的技巧 - 如何准确表达自己的想法
  94. 第4章:冲突的化解 - 处理感情中的分歧和矛盾
  95. 第5章:情感表达 - 学会表达爱意和关怀
  96. 第6章:日常沟通 - 提升日常对话的质量
  97. 第7章:深度交流 - 如何进行深层次的心灵沟通
  98. 第8章:危机处理 - 感情危机时的沟通策略
  99. 第9章:长期维护 - 保持感情新鲜度的沟通方法
  100. 第10章:非语言沟通 - 肢体语言和表情的运用
  101. 第11章:网络沟通 - 现代恋爱中的线上沟通技巧
  102. 第12章:实战演练 - 真实案例分析和练习`,
  103. status: 1,
  104. purchase_status: 0 // 0-未购买 1-已购买
  105. },
  106. DEFAULT_IMAGES
  107. }
  108. },
  109. onLoad(options) {
  110. console.log('精品课程详情页面加载, 参数:', options)
  111. if (options.id) {
  112. this.courseId = options.id
  113. console.log('课程ID:', this.courseId)
  114. // 根据ID设置对应的课程数据
  115. this.setCourseDataById(this.courseId)
  116. this.loadCourseDetail()
  117. } else {
  118. console.log('未传入课程ID,使用默认数据')
  119. }
  120. // 数据健康检查(确保页面显示正常)
  121. setTimeout(() => {
  122. this.checkDataHealth()
  123. }, 100)
  124. },
  125. methods: {
  126. // 根据ID设置课程数据
  127. setCourseDataById(courseId) {
  128. const courseData = {
  129. '1': {
  130. id: 1,
  131. name: '恋爱沟通技巧大师课',
  132. description: '学会有效沟通,让感情更甜蜜。本课程将教你如何在恋爱中进行有效沟通,包括倾听技巧、表达方式、冲突化解等核心内容。',
  133. teacher_name: '张情感老师',
  134. teacher_desc: '资深情感咨询师,10年经验',
  135. price: 299,
  136. original_price: 399,
  137. discount_rate: 7.5,
  138. student_count: 1256,
  139. rating: 4.9,
  140. chapter_count: 12
  141. },
  142. '2': {
  143. id: 2,
  144. name: '相亲必胜宝典',
  145. description: '从形象打造到话题聊天,全方位提升相亲成功率。适合想要快速脱单的单身男女。',
  146. teacher_name: '李红娘老师',
  147. teacher_desc: '专业红娘,成功牵线300+对',
  148. price: 199,
  149. original_price: 299,
  150. discount_rate: 6.6,
  151. student_count: 2580,
  152. rating: 4.8,
  153. chapter_count: 8
  154. },
  155. '3': {
  156. id: 3,
  157. name: '婚姻经营智慧课',
  158. description: '婚后生活经营秘籍,让婚姻更加幸福美满。处理婆媳关系、夫妻沟通等实用内容。',
  159. teacher_name: '王婚姻老师',
  160. teacher_desc: '婚姻家庭咨询专家',
  161. price: 399,
  162. original_price: 599,
  163. discount_rate: 6.7,
  164. student_count: 856,
  165. rating: 5.0,
  166. chapter_count: 15
  167. }
  168. }
  169. const targetCourse = courseData[courseId]
  170. if (targetCourse) {
  171. this.course = {
  172. ...this.course,
  173. ...targetCourse,
  174. cover_image: DEFAULT_IMAGES.course,
  175. teacher_avatar: DEFAULT_IMAGES.avatar
  176. }
  177. console.log('设置课程数据:', this.course.name)
  178. }
  179. },
  180. // 加载课程详情
  181. async loadCourseDetail() {
  182. try {
  183. console.log('尝试从API加载课程详情:', this.courseId)
  184. const data = await api.course.getDetail(this.courseId)
  185. if (data) {
  186. this.course = data
  187. console.log('API课程详情加载成功')
  188. } else {
  189. console.log('API返回空数据,使用默认课程详情')
  190. }
  191. } catch (error) {
  192. console.error('加载课程详情失败:', error)
  193. console.log('API调用失败,保留默认课程详情数据')
  194. uni.showToast({
  195. title: '使用示例数据',
  196. icon: 'none',
  197. duration: 1500
  198. })
  199. }
  200. },
  201. // 处理购买
  202. handlePurchase() {
  203. // 检查是否已购买
  204. if (this.course.purchase_status === 1) {
  205. uni.showToast({
  206. title: '您已购买过此课程',
  207. icon: 'none'
  208. })
  209. return
  210. }
  211. uni.showModal({
  212. title: '确认购买',
  213. content: `确认购买"${this.course.name}"课程吗?\n价格:¥${this.course.price}`,
  214. success: async (res) => {
  215. if (res.confirm) {
  216. try {
  217. console.log('尝试购买课程:', this.courseId)
  218. // await api.course.purchase(this.courseId, {})
  219. // 模拟购买成功
  220. uni.showToast({
  221. title: '购买成功!',
  222. icon: 'success'
  223. })
  224. // 更新购买状态
  225. this.course.purchase_status = 1
  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: (modalRes) => {
  234. if (modalRes.confirm) {
  235. // TODO: 跳转到课程学习页面
  236. uni.showToast({
  237. title: '学习功能开发中',
  238. icon: 'none'
  239. })
  240. }
  241. }
  242. })
  243. }, 1500)
  244. } catch (error) {
  245. console.error('购买失败:', error)
  246. uni.showToast({
  247. title: '购买失败,请重试',
  248. icon: 'none'
  249. })
  250. }
  251. }
  252. }
  253. })
  254. },
  255. // 返回
  256. goBack() {
  257. console.log('课程详情返回上一页')
  258. uni.navigateBack({
  259. fail: () => {
  260. // 返回失败时跳转到课程列表
  261. uni.navigateTo({
  262. url: '/pages/courses/list'
  263. })
  264. }
  265. })
  266. },
  267. // 数据健康检查
  268. checkDataHealth() {
  269. console.log('=== 精品课程详情页面数据健康检查 ===')
  270. console.log('courseId:', this.courseId)
  271. console.log('course:', this.course)
  272. console.log('DEFAULT_IMAGES:', this.DEFAULT_IMAGES)
  273. // 确保关键数据不为空
  274. if (!this.course.name || this.course.name === '加载中...') {
  275. this.course.name = '恋爱沟通技巧大师课'
  276. }
  277. if (!this.course.teacher_name) {
  278. this.course.teacher_name = '张情感老师'
  279. }
  280. if (!this.course.cover_image) {
  281. this.course.cover_image = this.DEFAULT_IMAGES.course
  282. }
  283. }
  284. }
  285. }
  286. </script>
  287. <style lang="scss" scoped>
  288. .course-detail-page {
  289. min-height: 100vh;
  290. background-color: #FFF9F9;
  291. padding-top: 90rpx;
  292. padding-bottom: 120rpx;
  293. }
  294. /* 自定义导航栏 */
  295. .custom-navbar {
  296. position: fixed;
  297. top: 0;
  298. left: 0;
  299. right: 0;
  300. height: 90rpx;
  301. display: flex;
  302. align-items: center;
  303. justify-content: space-between;
  304. padding: 0 20rpx;
  305. background-color: #E91E63;
  306. z-index: 999;
  307. .navbar-left,
  308. .navbar-right {
  309. width: 80rpx;
  310. }
  311. .back-icon {
  312. font-size: 40rpx;
  313. color: #FFFFFF;
  314. font-weight: bold;
  315. }
  316. .navbar-title {
  317. flex: 1;
  318. text-align: center;
  319. font-size: 32rpx;
  320. font-weight: bold;
  321. color: #FFFFFF;
  322. }
  323. }
  324. /* 课程封面 */
  325. .course-cover {
  326. position: relative;
  327. width: 100%;
  328. height: 500rpx;
  329. .cover-image {
  330. width: 100%;
  331. height: 100%;
  332. }
  333. .cover-mask {
  334. position: absolute;
  335. top: 0;
  336. left: 0;
  337. right: 0;
  338. bottom: 0;
  339. background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), transparent);
  340. padding: 30rpx;
  341. .discount-tag {
  342. display: inline-block;
  343. padding: 10rpx 20rpx;
  344. background: linear-gradient(135deg, #FF6B6B 0%, #FF9800 100%);
  345. color: #FFFFFF;
  346. font-size: 24rpx;
  347. font-weight: bold;
  348. border-radius: 30rpx;
  349. }
  350. }
  351. }
  352. /* 课程内容 */
  353. .course-content {
  354. padding: 30rpx;
  355. background-color: #FFFFFF;
  356. margin: 20rpx;
  357. border-radius: 20rpx;
  358. .course-title {
  359. font-size: 36rpx;
  360. font-weight: bold;
  361. color: #333333;
  362. margin-bottom: 30rpx;
  363. line-height: 1.5;
  364. }
  365. .teacher-info {
  366. display: flex;
  367. align-items: center;
  368. margin-bottom: 30rpx;
  369. .teacher-avatar {
  370. width: 80rpx;
  371. height: 80rpx;
  372. border-radius: 50%;
  373. margin-right: 20rpx;
  374. }
  375. .teacher-detail {
  376. flex: 1;
  377. display: flex;
  378. flex-direction: column;
  379. gap: 5rpx;
  380. .teacher-name {
  381. font-size: 28rpx;
  382. font-weight: bold;
  383. color: #333333;
  384. }
  385. .teacher-desc {
  386. font-size: 24rpx;
  387. color: #999999;
  388. }
  389. }
  390. }
  391. .course-stats {
  392. display: flex;
  393. justify-content: space-around;
  394. padding: 20rpx 0;
  395. background-color: #FFF9F9;
  396. border-radius: 15rpx;
  397. .stat-item {
  398. display: flex;
  399. flex-direction: column;
  400. align-items: center;
  401. gap: 10rpx;
  402. .stat-icon {
  403. font-size: 32rpx;
  404. }
  405. .stat-text {
  406. font-size: 24rpx;
  407. color: #666666;
  408. }
  409. }
  410. }
  411. .divider {
  412. height: 1rpx;
  413. background-color: #F0F0F0;
  414. margin: 30rpx 0;
  415. }
  416. .section-title {
  417. font-size: 30rpx;
  418. font-weight: bold;
  419. color: #333333;
  420. margin-bottom: 20rpx;
  421. }
  422. .description-text,
  423. .outline-text {
  424. font-size: 28rpx;
  425. color: #666666;
  426. line-height: 1.8;
  427. white-space: pre-wrap;
  428. }
  429. }
  430. /* 底部购买按钮 */
  431. .bottom-bar {
  432. position: fixed;
  433. bottom: 0;
  434. left: 0;
  435. right: 0;
  436. display: flex;
  437. align-items: center;
  438. justify-content: space-between;
  439. padding: 20rpx 30rpx;
  440. background-color: #FFFFFF;
  441. border-top: 1rpx solid #F0F0F0;
  442. z-index: 999;
  443. .price-info {
  444. flex: 1;
  445. .price-label {
  446. display: block;
  447. font-size: 24rpx;
  448. color: #999999;
  449. margin-bottom: 5rpx;
  450. }
  451. .price-value {
  452. display: flex;
  453. align-items: baseline;
  454. color: #E91E63;
  455. font-weight: bold;
  456. .price-symbol {
  457. font-size: 28rpx;
  458. }
  459. .price-num {
  460. font-size: 40rpx;
  461. }
  462. .original-price {
  463. margin-left: 10rpx;
  464. font-size: 24rpx;
  465. color: #999999;
  466. text-decoration: line-through;
  467. }
  468. .discount-text {
  469. margin-left: 15rpx;
  470. font-size: 22rpx;
  471. color: #FF9800;
  472. background: rgba(255, 152, 0, 0.1);
  473. padding: 5rpx 12rpx;
  474. border-radius: 15rpx;
  475. }
  476. }
  477. }
  478. .purchase-btn {
  479. padding: 20rpx 60rpx;
  480. background: linear-gradient(135deg, #E91E63 0%, #FF6B6B 100%);
  481. border-radius: 50rpx;
  482. box-shadow: 0 8rpx 16rpx rgba(233, 30, 99, 0.3);
  483. transition: all 0.3s;
  484. .btn-text {
  485. font-size: 32rpx;
  486. font-weight: bold;
  487. color: #FFFFFF;
  488. }
  489. &.purchased {
  490. background: #4CAF50;
  491. box-shadow: 0 8rpx 16rpx rgba(76, 175, 80, 0.3);
  492. .btn-text {
  493. color: #FFFFFF;
  494. }
  495. }
  496. &:active {
  497. transform: scale(0.95);
  498. }
  499. }
  500. }
  501. </style>