CourseDetail.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <script setup>
  2. import { ref, reactive, computed } from "vue";
  3. import { useRoute } from "vue-router";
  4. import axios from "axios";
  5. import moment from "moment";
  6. import Navbar from "@/components/Navbar.vue";
  7. const route = useRoute();
  8. const courseId = route.params.id; // 網址參數
  9. let groupName = ref("");
  10. let course = reactive({
  11. data: [],
  12. });
  13. let groupSort = ref("");
  14. const breadcrumbs = reactive([
  15. {
  16. title: "首頁",
  17. disabled: false,
  18. href: "/",
  19. },
  20. {
  21. title: "探索課程",
  22. disabled: false,
  23. href: "/ntcri/course-list",
  24. },
  25. {
  26. title: "課程清單",
  27. disabled: true,
  28. },
  29. ]);
  30. // 取得資料
  31. (async () => {
  32. try {
  33. const response = await axios.get(
  34. `https://cmm.ai:8088/api/get_class_name?class_name_id=${courseId}`
  35. );
  36. course.data = response.data.classes[0];
  37. groupSort.value = course.data.group_sort;
  38. console.log("groupSort.value", groupSort.value);
  39. console.log("courseData", course.data);
  40. if (course.data.group_id === 1) {
  41. groupName.value = "未來工藝學群";
  42. } else if (course.data.group_id === 2) {
  43. groupName.value = "技藝工藝學群";
  44. } else if (course.data.group_id === 3) {
  45. groupName.value = "生活工藝學群";
  46. } else if (course.data.group_id === 4) {
  47. groupName.value = "青年工藝學群";
  48. } else if (course.data.group_id === 5) {
  49. groupName.value = "世代工藝學群";
  50. } else if (course.data.group_id === 6) {
  51. groupName.value = "修護工藝學群";
  52. } else if (course.data.group_id === 7) {
  53. groupName.value = "跨域工藝學群";
  54. } else if (course.data.group_id === 8) {
  55. groupName.value = "線上工藝學群";
  56. }
  57. } catch (error) {
  58. console.error(error);
  59. }
  60. })();
  61. let session = reactive({
  62. data: [],
  63. });
  64. // 取得場次
  65. (async () => {
  66. try {
  67. const response = await axios.get(
  68. `https://cmm.ai:8088/api/get_event?class_name_id=${courseId}`
  69. );
  70. // course.data = response.data.classes[0];
  71. session.data = response.data.classes;
  72. console.log("response", response.data.classes[0]);
  73. } catch (error) {
  74. console.error(error);
  75. }
  76. })();
  77. let other = reactive({
  78. classes: [],
  79. });
  80. // 取得清單
  81. (async () => {
  82. try {
  83. const response = await axios.get("https://cmm.ai:8088/api/get_class_name");
  84. console.log("response.data.classes", response.data.classes);
  85. // other.classes = response.data.classes;
  86. // console.log('handleRandom(response.data.classes,3)',handleRandom(response.data.classes,3));
  87. other.classes = handleRandom(response.data.classes, 3);
  88. console.log("other.classes", other.classes);
  89. } catch (error) {
  90. console.error(error);
  91. }
  92. })();
  93. // 隨機取值
  94. function handleRandom(arr, length) {
  95. let newArr = [];
  96. for (let i = 0; i < length; i++) {
  97. let index = Math.floor(Math.random() * arr.length);
  98. let item = arr[index];
  99. newArr.push(item);
  100. arr.splice(index, 1);
  101. }
  102. return newArr.reverse();
  103. }
  104. const dynamicCols = computed(() => {
  105. return groupSort.value === "pinkoi" ? "5" : "8";
  106. });
  107. </script>
  108. <template>
  109. <Navbar />
  110. <v-container class="mt-16 course-detail">
  111. <v-breadcrumbs
  112. :items="breadcrumbs"
  113. divider="/"
  114. class="mt-3 mb-16 pa-0"
  115. ></v-breadcrumbs>
  116. <v-row class="justify-center">
  117. <v-col cols="3" class="title pa-0">
  118. <img src="@/assets/img/course/detail-background.png" alt="" class="bg-img" />
  119. <h2>{{ course.data.name }}</h2>
  120. </v-col>
  121. <v-col :cols="dynamicCols" class="pa-0 d-flex justify-center">
  122. <img
  123. :src="course.data.cover_img"
  124. alt=""
  125. class="cover-img"
  126. :class="{ small: groupSort === 'pinkoi' }"
  127. />
  128. </v-col>
  129. <v-col cols="12">
  130. <div class="info">
  131. <table>
  132. <thead>
  133. <tr>
  134. <th colspan="2">課程資訊</th>
  135. </tr>
  136. </thead>
  137. <tbody>
  138. <tr>
  139. <td>課程簡介</td>
  140. <td>{{ course.data.introduction }}</td>
  141. </tr>
  142. <tr v-show="course.data.category !== ''">
  143. <td>課程類別</td>
  144. <td>{{ course.data.category }}</td>
  145. </tr>
  146. <tr>
  147. <td>主辦單位</td>
  148. <td>{{ course.data.organizer }}-{{ course.data.school }}</td>
  149. </tr>
  150. <tr>
  151. <td>所屬學群</td>
  152. <td>{{ groupName }}</td>
  153. </tr>
  154. <!-- <tr>
  155. <td>報名對象</td>
  156. <td></td>
  157. </tr>
  158. <tr>
  159. <td>收費方式</td>
  160. <td></td>
  161. </tr>
  162. <tr>
  163. <td>報名方式</td>
  164. <td></td>
  165. </tr>
  166. <tr>
  167. <td>聯絡方式</td>
  168. <td></td>
  169. </tr>
  170. <tr>
  171. <td>備註</td>
  172. <td></td>
  173. </tr> -->
  174. </tbody>
  175. </table>
  176. <div class="d-flex justify-end">
  177. <v-btn rounded="xl" color="brown">附件下載</v-btn>
  178. </div>
  179. </div>
  180. </v-col>
  181. <v-col cols="12">
  182. <div class="sessions">
  183. <table>
  184. <thead>
  185. <tr>
  186. <th>場次名稱</th>
  187. <th>開始/結束時間</th>
  188. <th>課程地點</th>
  189. <th>講師</th>
  190. <th>報名截止日</th>
  191. </tr>
  192. </thead>
  193. <tbody>
  194. <tr v-for="(item, index) in session.data" :key="index">
  195. <td>{{ item.class_name }}</td>
  196. <td>
  197. {{ moment(`${item.start_time}`).format("YYYY/MM/DD H:mm") }}
  198. <br />
  199. ~ <br />
  200. {{ moment(`${item.end_time}`).format("YYYY/MM/DD H:mm") }}
  201. </td>
  202. <td></td>
  203. <td></td>
  204. <td></td>
  205. <td style="width: 0; padding: 0; border: none">
  206. <div class="signup-btn">
  207. <v-btn rounded="xl" color="brown" :href="item.URL">
  208. 點我報名
  209. </v-btn>
  210. </div>
  211. </td>
  212. </tr>
  213. </tbody>
  214. </table>
  215. </div>
  216. </v-col>
  217. <v-col cols="12" class="my-16">
  218. <p class="other-title">其他推薦課程</p>
  219. <v-row>
  220. <v-col
  221. sm="6"
  222. md="4"
  223. cols="12"
  224. v-for="(item, index) in other.classes"
  225. :key="index"
  226. class="pa-5"
  227. >
  228. <div class="main-card">
  229. <section class="card-title">
  230. <h3>{{ item.name }}</h3>
  231. </section>
  232. <div class="card-info">
  233. <a
  234. :href="
  235. $router.resolve(`/course-detail/${item.class_name_id}`).href
  236. "
  237. >
  238. <img :src="item.cover_img" alt="" class="cover-img" />
  239. </a>
  240. <!-- <img :src="item.cover_img" alt="" class="cover-img" /> -->
  241. <span class="d-flex align-center py-3">
  242. <img src="@/assets/img/icon/location_icon.png" alt="" />
  243. <p class="mb-0 ms-3">
  244. {{ item.school }}
  245. </p>
  246. </span>
  247. </div>
  248. </div>
  249. </v-col>
  250. </v-row>
  251. </v-col>
  252. </v-row>
  253. </v-container>
  254. </template>
  255. <style lang="scss">
  256. .course-detail {
  257. .cover-img {
  258. width: 100%;
  259. height: 500px;
  260. object-fit: cover;
  261. &.small {
  262. width: auto;
  263. height: auto;
  264. }
  265. }
  266. .title {
  267. position: relative;
  268. display: flex;
  269. flex-direction: column;
  270. align-items: center;
  271. justify-content: center;
  272. h2 {
  273. margin-top: -35px;
  274. margin-left: 5px;
  275. font-size: 24px;
  276. font-weight: 500;
  277. line-height: 32px;
  278. letter-spacing: 1px;
  279. color: #201715;
  280. }
  281. .bg-img {
  282. width: 250px;
  283. position: absolute;
  284. z-index: -1;
  285. right: -15px;
  286. bottom: -100px;
  287. }
  288. }
  289. .info {
  290. margin: 50px auto;
  291. padding: 25px 50px;
  292. table {
  293. td {
  294. padding: 10px 20px;
  295. line-height: 32px;
  296. letter-spacing: 1px;
  297. vertical-align: top;
  298. &:first-child {
  299. border-right: 1px solid #333;
  300. }
  301. }
  302. th {
  303. padding-bottom: 20px;
  304. border-bottom: 1px solid #333;
  305. }
  306. th,
  307. td:first-child {
  308. width: 117px;
  309. font-size: 18px;
  310. font-weight: 500;
  311. }
  312. }
  313. }
  314. .info,
  315. .sessions {
  316. background-color: #f2f2f4;
  317. table {
  318. width: 100%;
  319. border-collapse: collapse;
  320. td {
  321. line-height: 22px;
  322. }
  323. }
  324. }
  325. .sessions {
  326. padding: 25px 50px 70px;
  327. table {
  328. position: relative;
  329. th {
  330. width: 117px;
  331. font-size: 18px;
  332. font-weight: 500;
  333. padding-bottom: 20px;
  334. }
  335. td {
  336. padding: 20px;
  337. vertical-align: middle;
  338. }
  339. tbody {
  340. background-color: #fff;
  341. }
  342. }
  343. .signup-btn {
  344. position: absolute;
  345. bottom: -53px;
  346. right: 0;
  347. }
  348. }
  349. @media (max-width: 960px) {
  350. width: 100%;
  351. }
  352. .other-title {
  353. margin: 30px 0;
  354. padding-bottom: 30px;
  355. font-size: 26px;
  356. text-align: center;
  357. border-bottom: 1px solid;
  358. }
  359. }
  360. </style>