You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
4.6 KiB

4 weeks ago
  1. <template>
  2. <div>
  3. <div id="aCoursesList">
  4. <!-- 直播课程 开始 -->
  5. <div>
  6. <section class="container">
  7. <header class="comm-title">
  8. <h2 class="tac">
  9. <!-- <span class="c-333">即将开播</span> -->
  10. </h2>
  11. </header>
  12. <div>
  13. <article class="comm-course-list">
  14. <ul id="bna" class="of">
  15. <li v-for="video in videoList" :key="video.id">
  16. <div class="cc-l-wrap">
  17. <section class="course-img">
  18. <img
  19. :src="video.coverImg"
  20. :alt="video.mainTitle"
  21. class="img-responsive"
  22. style="width: 315px; height: 150px;align-items: center;"
  23. >
  24. <div class="cc-mask">
  25. <a :href="'/video/'+video.id" title="即将开播" class="comm-btn c-btn-1">即将开播<br>明天{{ formatDateTime(video.publishTime) }}开播</a>
  26. </div>
  27. </section>
  28. <h3 class="hLh30 txtOf mt10">
  29. <a :href="'/video/'+video.id" :title="video.mainTitle" class="course-title fsize18 c-333">{{ video.mainTitle }}</a>
  30. </h3>
  31. <div class="fl jgAttr c-ccc f-fA" style="position: absolute;">
  32. <img :src="video.head" alt="" width="22px" height="22px" style="border-radius: 10px;display: inline-block;" >
  33. <span class="c-999 f-fA" >{{ video.description }}</span>
  34. </div>
  35. <el-button
  36. :id="'reservation'+video.id"
  37. :style="{background: video.isBooked==0 ? 'cyan' : '#f56c6c'}"
  38. style="position: absolute;margin-bottom: 120px;margin-left: 220px; height: 23px;width: 40px;padding: 1px;"
  39. type="text"
  40. size="small"
  41. @click="reservation(video.id)">{{ video.isBooked==0? '预约':'已预约' }}</el-button>
  42. <a href=""/>
  43. </div>
  44. </li>
  45. </ul>
  46. <div class="clear"/>
  47. </article>
  48. <section class="tac pt20">
  49. <a href="#" title="全部直播" class="comm-btn c-btn-2">全部直播</a>
  50. </section>
  51. </div>
  52. </section>
  53. </div>
  54. <!-- 直播课程 结束 -->
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. import indexApi from '~/api/index'
  60. import service from '../utils/request'
  61. export default {
  62. async asyncData() {
  63. // 获取课程和讲师数据
  64. const indexDataResponse = await indexApi.getVideoData()
  65. const videoList = indexDataResponse.data
  66. return {
  67. indexDataResponse,
  68. videoList
  69. }
  70. },
  71. // 幻灯片导航的定义
  72. data() {
  73. return {
  74. swiperOption: {
  75. // 配置分页
  76. pagination: {
  77. el: '.swiper-pagination'// 分页的dom节点
  78. },
  79. // 配置导航
  80. navigation: {
  81. nextEl: '.swiper-button-next', // 下一页dom节点
  82. prevEl: '.swiper-button-prev'// 前一页dom节点
  83. }
  84. }
  85. }
  86. },
  87. methods: {
  88. reservation(id, index) {
  89. service.post('video-data/api/isBookedById/' + id)
  90. .then(Response => {
  91. service.post('video-data/api/selectVideoData')
  92. .then(Response => {
  93. const data = Response.data
  94. // console.log(data)
  95. for (var i = 0; i < data.length; i++) {
  96. // console.log(data[i])
  97. if (data[i].id === id) {
  98. console.log(data[i].id)
  99. var text = '预约'
  100. // console.log(id)
  101. if (data[i].isBooked === 1) {
  102. text = '已预约'
  103. document.getElementById(`reservation` + id).style.background = '#f56c6c'
  104. } else {
  105. document.getElementById(`reservation` + id).style.background = 'cyan'
  106. }
  107. document.getElementById(`reservation` + id).textContent = text
  108. }
  109. }
  110. })
  111. })
  112. .catch(error => {
  113. console.log(error)
  114. })
  115. },
  116. formatDateTime(isoString) {
  117. const date = new Date(isoString)
  118. // const month = (date.getMonth() + 1).toString().padStart(2, 0)
  119. // const day = date.getDate().toString().padStart(2, 0)
  120. const hours = date.getHours().toString().padStart(2, 0)
  121. const minutes = date.getMinutes().toString().padStart(2, '0')
  122. return `${hours}:${minutes}`
  123. }
  124. }
  125. }
  126. </script>