courseDetail.vue 8.1 KB

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