courseDetail.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view>
  3. <view class="container">
  4. <view style="height: 500rpx;display: flex;
  5. flex-direction: column;
  6. justify-content: space-between;;">
  7. <view style="height: 400rpx;width: 100%;background-color: aliceblue;flex: 0 0 auto;"></view>
  8. <view class="course-tab-list">
  9. <view class="course-tab-item" v-for="(data, index) in items" :key="index"
  10. @click="onClickItem(index)" :class="currentTab === index ? 'tab-active' : ''">
  11. {{ data }}
  12. </view>
  13. </view>
  14. </view>
  15. <view class="content">
  16. <courseDesc v-if="currentTab === 0" :paddingBottom="100" showType="image"
  17. :content="courseDetail.imgUrl?courseDetail.imgUrl:''"></courseDesc>
  18. <courseCredits v-if="currentTab === 1" :credit="courseDetail.courseCredits"></courseCredits>
  19. <courseComment v-if="currentTab === 2" :paddingBottom="100" :commentList="commentList"></courseComment>
  20. </view>
  21. </view>
  22. <view v-if="currentTab === 0" class="section-bottom" @click="toBuy">
  23. <text>点击购买</text>
  24. </view>
  25. <view v-if="currentTab === 2" class="section-bottom " style="background-color: #f2f2f2;">
  26. <view class="comment-input-box">
  27. <u-input :custom-style="inputStyle"
  28. class="comment-input" v-model="comment" :border="false" placeholder="写留言" height="60" adjust-position/>
  29. <u-button class="comment-button" :hair-line="false"
  30. :custom-style="customStyle" @click="toSend">发送</u-button>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script setup>
  36. import courseDesc from './component/courseDesc/courseDesc.vue';
  37. import courseCredits from './component/courseCredits/courseCredits.vue';
  38. import courseComment from './component/courseComment/courseComment.vue';
  39. import { loadCourseDetail, loadCommentList, sendComment } from "@/api/edu.js"
  40. import {
  41. ref
  42. } from 'vue'
  43. import {
  44. onLoad
  45. } from '@dcloudio/uni-app'
  46. const courseDetail = ref({});
  47. const courseId = ref(null);
  48. const items = ref(['课程简介', '课程学分', '观看评论']);
  49. const currentTab = ref(0);
  50. const comment = ref("");
  51. // 评论发送按钮样式
  52. const customStyle = ref({
  53. backgroundColor: '#e6e6e6',
  54. color: '#333333',
  55. fontWeight: 'bold',
  56. height: '60rpx',
  57. marginLeft: '20rpx',
  58. border: 'none',
  59. fontSize: '26rpx'
  60. })
  61. // 评论输入框样式
  62. const inputStyle = ref({
  63. backgroundColor: '#e6e6e6',
  64. color: '#333333',
  65. borderRadius: '5px',
  66. padding: '0 20rpx',
  67. fontSize: '26rpx'
  68. })
  69. // 评论列表
  70. const commentList = ref([
  71. {
  72. commentId: "01",
  73. username: "用户名123",
  74. iocn: "",
  75. content:"评论内容评论内容评容,大赛冠军的",
  76. commentTime: "2023-10-10 19:00:00"
  77. },
  78. {
  79. commentId: "02",
  80. username: "用户名567",
  81. iocn: "",
  82. content:"hajdkhd dhasjhd 等哈十九点按时鉴定会撒低级,撒谎客户端喝酒侃大山哈吉斯肯定会大会开始觉得暗黑界的是客户,大赛冠军的",
  83. commentTime: "2023-10-11 19:00:00"
  84. },
  85. {
  86. commentId: "03",
  87. username: "用户名567",
  88. iocn: "",
  89. content:"hajdkhd dhasjhd ,,大赛冠军的",
  90. commentTime: "2023-10-12 19:00:00"
  91. },
  92. {
  93. commentId: "04",
  94. username: "用户名567",
  95. iocn: "",
  96. content:"hajdkhd dhasjhd 等哈十九点按时鉴定会撒低级,撒谎客户端喝酒侃大山哈吉斯肯定会大会开始觉得暗黑界的是客户,大赛冠军的",
  97. commentTime: "2023-10-13 19:00:00"
  98. },
  99. {
  100. commentId: "05",
  101. username: "用户名567",
  102. iocn: "",
  103. content:"hajdkhd dhasjhd 等哈十九点按时鉴定会撒低级,撒谎客户端喝酒侃大山哈吉斯肯定会大会开始觉得暗黑界的是客户,大赛冠军的",
  104. commentTime: "2023-10-14 19:00:00"
  105. },
  106. {
  107. commentId: "06",
  108. username: "用户名567",
  109. iocn: "",
  110. content:"hajdkhd dhasjhd 等哈十九点按时鉴定会撒低级,撒谎客户端喝酒侃大山哈吉斯肯定会大会开始觉得暗黑界的是客户,大赛冠军的",
  111. commentTime: "2025-01-17 12:00:00"
  112. },
  113. {
  114. commentId: "07",
  115. username: "用户名567",
  116. iocn: "",
  117. content:"hajdkhd dhasjhd 等哈十九点按时鉴定会撒低级,撒谎客户端喝酒侃大山哈吉斯肯定会大会开始觉得暗黑界的是客户,大赛冠军的",
  118. commentTime: "2025-01-17 15:30:00"
  119. }
  120. ])
  121. // 点击tabs,切换
  122. function onClickItem(e) {
  123. if (currentTab.value != e) {
  124. currentTab.value = e;
  125. if(e===2){
  126. getComment(courseId.value)
  127. }
  128. }
  129. }
  130. // 初始化
  131. function init(id) {
  132. loadCourseDetail(id).then(res=>{
  133. if(res?.data){
  134. courseDetail.value = res.data;
  135. }
  136. })
  137. }
  138. function getComment(id){
  139. loadCommentList(id).then(res=>{
  140. if(res?.data){
  141. commentList.value = res.data;
  142. }
  143. })
  144. }
  145. // 购买课程
  146. function toBuy() {
  147. uni.navigateTo({
  148. url: "/pages/goOnEdu/course/courseDetail/courseOrder?id=" + courseId.value
  149. })
  150. // console.log("购买该课程", courseDetail.value.id)
  151. }
  152. function toSend() {
  153. sendComment({
  154. courseId: courseId.value,
  155. content: comment.value,
  156. commentTime: formatDate(new Date())
  157. }).then(res=>{
  158. getComment(courseId.value)
  159. comment.value = ""
  160. })
  161. }
  162. function formatDate(date) {
  163. const pad = (num) => num.toString().padStart(2, '0');
  164. const year = date.getFullYear();
  165. const month = pad(date.getMonth() + 1); // 月份从0开始,需加1
  166. const day = pad(date.getDate());
  167. const hours = pad(date.getHours());
  168. const minutes = pad(date.getMinutes());
  169. const seconds = pad(date.getSeconds());
  170. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  171. }
  172. // 初始化页面
  173. onLoad((option) => {
  174. const {
  175. id,
  176. name
  177. } = option;
  178. // courseDetail.value.id = id
  179. // console.log(courseDetail.value, 90)
  180. courseId.value = id
  181. init(id)
  182. getComment(id)
  183. uni.setNavigationBarTitle({
  184. title: name
  185. });
  186. })
  187. </script>
  188. <style lang="scss" scoped>
  189. .container {
  190. height: 100vh;
  191. width: 100vw;
  192. background-color: #fff;
  193. padding: 0 20rpx;
  194. // display: flex;
  195. // flex-direction: column;
  196. }
  197. .course-tab-list {
  198. // margin: 15rpx 0;
  199. display: flex;
  200. background-color: #f2f2f2;
  201. flex: 0 0 auto;
  202. .course-tab-item {
  203. width: 100%;
  204. height: 80rpx;
  205. line-height: 80rpx;
  206. text-align: center;
  207. }
  208. .tab-active {
  209. border-bottom: 1px solid #0069f6;
  210. }
  211. }
  212. .content {
  213. overflow: scroll;
  214. height: calc(100vh - 500rpx - env(safe-area-inset-bottom, 0));
  215. // flex: 1;
  216. // padding-bottom: ;
  217. }
  218. .section-bottom {
  219. height: 90rpx;
  220. color: #fff;
  221. font-size: 34rpx;
  222. text-align: center;
  223. line-height: 80rpx;
  224. background-color: #fe0000;
  225. width: 100%;
  226. position: fixed;
  227. bottom: 0;
  228. box-sizing: content-box;
  229. padding-bottom: env(safe-area-inset-bottom, 0);
  230. }
  231. .comment-input-box {
  232. width: 100%;
  233. height: 100%;
  234. display: flex;
  235. box-sizing: border-box;
  236. padding: 0 20rpx;
  237. align-items: center;
  238. .comment-input {
  239. flex: 1;
  240. }
  241. .comment-button {
  242. flex: 0 0 auto;
  243. }
  244. }
  245. </style>