courseDetail.vue 7.5 KB

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