detail.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <view class="course-detail-container">
  3. <!-- 顶部轮播图 -->
  4. <swiper class="swiper" circular :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
  5. <swiper-item v-for="(image, index) in parsedImages" :key="index">
  6. <image :src="image.imageUrl" class="swiper-image" mode="aspectFill" />
  7. </swiper-item>
  8. </swiper>
  9. <!-- 商品信息 -->
  10. <view class="header">
  11. <view class="title">{{ course.name }}</view>
  12. <view class="subtitle">{{ course.subtitle }}</view>
  13. <view class="price-row">
  14. <text class="price">¥{{ course.price?.toFixed(2) }}</text>
  15. <text class="original-price">¥{{ course.originalPrice?.toFixed(2) }}</text>
  16. </view>
  17. <view class="stock">库存: {{ course.stock }}</view>
  18. </view>
  19. <!-- 评价区 -->
  20. <view class="section">
  21. <view class="section-title">评价 ({{ comments.length }})</view>
  22. <view v-if="comments.length === 0" class="empty-comment">暂无评价</view>
  23. <view v-else class="comment-list">
  24. <view class="comment-item" v-for="item in comments" :key="item.id">
  25. <image :src="item.avatar || defaultAvatar" class="comment-avatar" />
  26. <view class="comment-main">
  27. <view class="comment-user">{{ item.user }}</view>
  28. <view class="comment-stars">
  29. <text v-for="n in 5" :key="n" class="star" :class="{active: n <= item.star}">★</text>
  30. </view>
  31. <view class="comment-content">{{ item.content || '此用户没有填写评价' }}</view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- tab切换 -->
  37. <view class="tabs">
  38. <view :class="['tab', tabIndex===0?'active':'']" @click="tabIndex=0">详情</view>
  39. <view :class="['tab', tabIndex===1?'active':'']" @click="tabIndex=1">目录</view>
  40. <view :class="['tab', tabIndex===2?'active':'']" @click="tabIndex=2">课堂互动</view>
  41. </view>
  42. <view v-if="tabIndex===0" class="tab-content">
  43. <view class="detail-section">
  44. <view class="section-title">课程介绍</view>
  45. <view class="detail-content">
  46. <view v-for="(image, index) in parsedImages" :key="index" class="detail-item">
  47. <image :src="image.imageUrl" class="detail-image" mode="widthFix" />
  48. <view class="detail-info">
  49. <view class="detail-title">{{ image.courseTitle }}</view>
  50. <view class="detail-desc">{{ image.courseDesc }}</view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <view v-else-if="tabIndex===1" class="tab-content">
  57. <view v-for="item in catalog" :key="item.id" class="catalog-item">
  58. <image :src="item.icon || lockIcon" class="catalog-icon" />
  59. <view class="catalog-main">
  60. <view class="catalog-title">{{ item.title }}</view>
  61. <view class="catalog-meta">{{ item.type }} {{ item.date }} | {{ item.count }}次学习</view>
  62. </view>
  63. <view v-if="item.trial" class="trial">试学</view>
  64. </view>
  65. </view>
  66. <view v-else class="tab-content">
  67. <view class="empty-interact">
  68. <image src="/static/empty-box.png" class="empty-img" />
  69. <view class="empty-tip">该课程暂无互动内容</view>
  70. </view>
  71. </view>
  72. <!-- 底部按钮 -->
  73. <view class="footer">
  74. <button class="service-btn">客服</button>
  75. <button class="order-btn">立即购买</button>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. export default {
  81. data() {
  82. return {
  83. course: {},
  84. comments: [],
  85. catalog: [],
  86. tabIndex: 0,
  87. defaultCover: '/static/default-course.png',
  88. defaultAvatar: '/static/1.jpg',
  89. lockIcon: '/static/lock.png'
  90. }
  91. },
  92. computed: {
  93. parsedImages() {
  94. try {
  95. if (this.course.images) {
  96. return JSON.parse(this.course.images)
  97. }
  98. return []
  99. } catch (e) {
  100. console.error('解析图片数据失败:', e)
  101. return []
  102. }
  103. }
  104. },
  105. onLoad(options) {
  106. this.fetchDetail(options.id)
  107. },
  108. methods: {
  109. async fetchDetail(id) {
  110. try {
  111. const res = await uni.request({
  112. url: `http://localhost:9527/product/findOne?productId=${id}`,
  113. method: 'GET'
  114. })
  115. if (res.statusCode === 200) {
  116. this.course = res.data.data
  117. this.comments = res.data.data.comments || []
  118. this.catalog = res.data.data.catalog || []
  119. } else {
  120. throw new Error(res.data.message || '获取数据失败')
  121. }
  122. } catch (err) {
  123. uni.showToast({
  124. title: err.message || '加载失败',
  125. icon: 'none'
  126. })
  127. }
  128. }
  129. }
  130. }
  131. </script>
  132. <style scoped>
  133. .course-detail-container {
  134. min-height: 100vh;
  135. background: #f7f8fa;
  136. padding-bottom: 120rpx;
  137. }
  138. .swiper {
  139. width: 100%;
  140. height: 500rpx;
  141. }
  142. .swiper-image {
  143. width: 100%;
  144. height: 100%;
  145. }
  146. .header {
  147. background: #fff;
  148. padding: 24rpx;
  149. margin-bottom: 20rpx;
  150. }
  151. .title {
  152. font-size: 36rpx;
  153. font-weight: bold;
  154. margin-bottom: 12rpx;
  155. }
  156. .subtitle {
  157. font-size: 28rpx;
  158. color: #666;
  159. margin-bottom: 16rpx;
  160. }
  161. .price-row {
  162. display: flex;
  163. align-items: baseline;
  164. margin-bottom: 12rpx;
  165. }
  166. .price {
  167. color: #ff6600;
  168. font-size: 40rpx;
  169. font-weight: bold;
  170. margin-right: 16rpx;
  171. }
  172. .original-price {
  173. color: #999;
  174. font-size: 28rpx;
  175. text-decoration: line-through;
  176. }
  177. .stock {
  178. font-size: 26rpx;
  179. color: #666;
  180. }
  181. .section {
  182. background: #fff;
  183. border-radius: 20rpx;
  184. margin: 24rpx 24rpx 0 24rpx;
  185. padding: 24rpx;
  186. box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.04);
  187. }
  188. .section-title {
  189. font-size: 28rpx;
  190. font-weight: bold;
  191. margin-bottom: 16rpx;
  192. }
  193. .empty-comment {
  194. color: #bbb;
  195. text-align: center;
  196. font-size: 26rpx;
  197. }
  198. .comment-list {
  199. display: flex;
  200. flex-direction: column;
  201. gap: 24rpx;
  202. }
  203. .comment-item {
  204. display: flex;
  205. align-items: flex-start;
  206. }
  207. .comment-avatar {
  208. width: 56rpx;
  209. height: 56rpx;
  210. border-radius: 50%;
  211. margin-right: 16rpx;
  212. }
  213. .comment-main {
  214. flex: 1;
  215. }
  216. .comment-user {
  217. font-size: 26rpx;
  218. color: #333;
  219. font-weight: 600;
  220. }
  221. .comment-stars {
  222. color: #ffb400;
  223. font-size: 24rpx;
  224. margin: 4rpx 0 8rpx 0;
  225. }
  226. .star.active {
  227. color: #ffb400;
  228. }
  229. .star {
  230. color: #eee;
  231. }
  232. .comment-content {
  233. font-size: 24rpx;
  234. color: #666;
  235. }
  236. .tabs {
  237. display: flex;
  238. background: #fff;
  239. padding: 0 24rpx;
  240. border-bottom: 1rpx solid #eee;
  241. }
  242. .tab {
  243. flex: 1;
  244. text-align: center;
  245. padding: 24rpx 0;
  246. font-size: 30rpx;
  247. color: #666;
  248. position: relative;
  249. }
  250. .tab.active {
  251. color: #ff6600;
  252. font-weight: bold;
  253. }
  254. .tab.active::after {
  255. content: '';
  256. position: absolute;
  257. left: 50%;
  258. bottom: 0;
  259. transform: translateX(-50%);
  260. width: 40rpx;
  261. height: 6rpx;
  262. background: #ff6600;
  263. border-radius: 3rpx;
  264. }
  265. .tab-content {
  266. background: #fff;
  267. padding: 24rpx;
  268. }
  269. .detail-section {
  270. margin-bottom: 24rpx;
  271. }
  272. .detail-item {
  273. margin-bottom: 30rpx;
  274. }
  275. .detail-image {
  276. width: 100%;
  277. border-radius: 12rpx;
  278. margin-bottom: 16rpx;
  279. }
  280. .detail-info {
  281. padding: 0 12rpx;
  282. }
  283. .detail-title {
  284. font-size: 30rpx;
  285. font-weight: bold;
  286. margin-bottom: 8rpx;
  287. }
  288. .detail-desc {
  289. font-size: 26rpx;
  290. color: #666;
  291. line-height: 1.6;
  292. }
  293. .catalog-item {
  294. display: flex;
  295. align-items: center;
  296. padding: 18rpx 0;
  297. border-bottom: 1rpx solid #f0f0f0;
  298. }
  299. .catalog-icon {
  300. width: 36rpx;
  301. height: 36rpx;
  302. margin-right: 16rpx;
  303. }
  304. .catalog-main {
  305. flex: 1;
  306. }
  307. .catalog-title {
  308. font-size: 26rpx;
  309. color: #222;
  310. font-weight: 600;
  311. }
  312. .catalog-meta {
  313. font-size: 22rpx;
  314. color: #888;
  315. margin-top: 4rpx;
  316. }
  317. .trial {
  318. color: #ff6600;
  319. font-size: 22rpx;
  320. border: 1rpx solid #ff6600;
  321. border-radius: 8rpx;
  322. padding: 2rpx 12rpx;
  323. margin-left: 8rpx;
  324. }
  325. .empty-interact {
  326. display: flex;
  327. flex-direction: column;
  328. align-items: center;
  329. justify-content: center;
  330. min-height: 200rpx;
  331. }
  332. .empty-img {
  333. width: 120rpx;
  334. height: 120rpx;
  335. margin-bottom: 16rpx;
  336. opacity: 0.7;
  337. }
  338. .empty-tip {
  339. color: #bbb;
  340. font-size: 26rpx;
  341. }
  342. .footer {
  343. position: fixed;
  344. bottom: 0;
  345. left: 0;
  346. right: 0;
  347. display: flex;
  348. padding: 16rpx 24rpx;
  349. background: #fff;
  350. box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.05);
  351. }
  352. .service-btn, .order-btn {
  353. flex: 1;
  354. height: 80rpx;
  355. line-height: 80rpx;
  356. text-align: center;
  357. border-radius: 40rpx;
  358. font-size: 28rpx;
  359. }
  360. .service-btn {
  361. background: #f5f5f5;
  362. color: #666;
  363. margin-right: 20rpx;
  364. }
  365. .order-btn {
  366. background: #ff6600;
  367. color: #fff;
  368. }
  369. </style>