CourseList.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <div>
  3. <loading :active.sync="isLoad"
  4. :is-full-page="fullPage"
  5. background-color="#000"
  6. :opacity="opacity">
  7. <template slot="default">
  8. <svg-icon icon-class="loader" class="loader-icon" />
  9. </template>
  10. </loading>
  11. <div class="course-list"
  12. :class="{ courselistEn: this.$store.getters.getCurrentLaguage == 'en-us' }"
  13. >
  14. <!--課程加入成功-->
  15. <div class="warmMessage"
  16. v-if=" this.$store.getters.getMycID.coureseMessageOpen == true &&
  17. this.$store.getters.getMycID.addSuccess == true "
  18. >
  19. <div class="messageCard animate__animated animate__fadeInDown">
  20. <div>
  21. <h3>課程加入成功</h3>
  22. <svg-icon icon-class="addCourseSuc" class="addCourseIcon" />
  23. <h3>
  24. <span class="typeMark">{{ this.$store.getters.getMycID.myCourseID[ this.$store.getters.getMycID.myCourseID.length - 1 ] }}</span>
  25. <span>新加課程名稱</span>
  26. </h3>
  27. <p>可於左側課程清單檢視課程簡介</p>
  28. </div>
  29. </div>
  30. </div>
  31. <!--課程已經加入-->
  32. <div class="warmMessage"
  33. v-if="this.$store.getters.getMycID.coureseMessageOpen == true &&
  34. this.$store.getters.getMycID.addSuccess == 'exist'"
  35. >
  36. <div class="messageCard animate__animated animate__fadeInDown">
  37. <div>
  38. <h3>課程已經加入</h3>
  39. <svg-icon icon-class="addCoursefail" class="addCourseIcon" />
  40. <p>可於左側課程清單檢視該課程簡介</p>
  41. </div>
  42. </div>
  43. </div>
  44. <!--課程加入失敗-->
  45. <div class="warmMessage"
  46. v-if="this.$store.getters.getMycID.coureseMessageOpen == true &&
  47. this.$store.getters.getMycID.addSuccess == false"
  48. >
  49. <div class="messageCard animate__animated animate__fadeInDown">
  50. <div>
  51. <h3>課程加入失敗</h3>
  52. <svg-icon icon-class="addCoursefail" class="addCourseIcon" />
  53. <p>查無所輸入代碼之課程,或該課程您未獲教師授權參與</p>
  54. </div>
  55. </div>
  56. </div>
  57. <div class="list">
  58. <ul class="list-block">
  59. <Tabs :value="onlyStu ? (this.$store.getters.getMycID.addSuccess == true ? 'tab2' : 'tab1') : 'tab2' ">
  60. <!-- 表定课程 -->
  61. <TabPane :label="$t('studentWeb.defaultClass')"
  62. name="tab1"
  63. :align="currentView=='table'?'center':'left'"
  64. v-if="onlyStu"
  65. >
  66. <!-- <div class="listViewBtn" @click="changeView('list')" :class="{chooseView:currentView=='list'}">
  67. <svg-icon icon-class="list-text" />
  68. </div>
  69. <div class="tableViewBtn" @click="changeView('table')" :class="{chooseView:currentView=='table'}">
  70. <svg-icon icon-class="table" />
  71. </div> -->
  72. <div class="list-table">
  73. <Table :columns="courseTime"
  74. border
  75. :data="timeTable"
  76. v-show="currentView == 'table'"
  77. :disabled-hover="true"
  78. >
  79. <template slot-scope="{ row }" slot="time">
  80. <p class="list-name">{{ row.time }}</p>
  81. <p>{{ row.label }}</p>
  82. </template>
  83. <template slot-scope="{ row }" slot="Mon">
  84. <div v-for="(item, index) in row.fixList" :key="index">
  85. <div v-if="item.timeWeek == 'MON'"
  86. class="table-item"
  87. @click="clickCell(row, index)"
  88. :class="{'table-item-selected': unique == item.unique }"
  89. >
  90. <p class="list-name">{{ item.name}}</p>
  91. <p>({{ item.teaName}})</p>
  92. </div>
  93. </div>
  94. </template>
  95. <template slot-scope="{ row }" slot="Tue">
  96. <div v-for="(item, index) in row.fixList" :key="index">
  97. <div v-if="item.timeWeek == 'TUE'"
  98. class="table-item"
  99. @click="clickCell(row, index)"
  100. :class="{'table-item-selected': unique == item.unique }"
  101. >
  102. <p class="list-name">{{ item.name}}</p>
  103. <p>({{ item.teaName}})</p>
  104. </div>
  105. </div>
  106. </template>
  107. <template slot-scope="{ row }" slot="Wed">
  108. <div v-for="(item, index) in row.fixList" :key="index">
  109. <div v-if="item.timeWeek == 'WED'"
  110. class="table-item"
  111. @click="clickCell(row, index)"
  112. :class="{'table-item-selected': unique == item.unique }"
  113. >
  114. <p class="list-name">{{ item.name}}</p>
  115. <p>({{ item.teaName}})</p>
  116. </div>
  117. </div>
  118. </template>
  119. <template slot-scope="{ row }" slot="Thu">
  120. <div v-for="(item, index) in row.fixList" :key="index">
  121. <div v-if="item.timeWeek == 'THU'"
  122. class="table-item"
  123. @click="clickCell(row, index)"
  124. :class="{'table-item-selected': unique == item.unique }"
  125. >
  126. <p class="list-name">{{ item.name}}</p>
  127. <p>({{ item.teaName}})</p>
  128. </div>
  129. </div>
  130. </template>
  131. <template slot-scope="{ row }" slot="Fri">
  132. <div v-for="(item, index) in row.fixList" :key="index">
  133. <div v-if="item.timeWeek == 'FRI'"
  134. class="table-item"
  135. @click="clickCell(row, index)"
  136. :class="{'table-item-selected': unique == item.unique }"
  137. >
  138. <p class="list-name">{{ item.name}}</p>
  139. <p>({{ item.teaName}})</p>
  140. </div>
  141. </div>
  142. </template>
  143. </Table>
  144. </div>
  145. <!-- 表定 -->
  146. <!-- <li class="list-item"
  147. v-for="(item, index) in fixList"
  148. @click="sentSelectedEventTitle(item)"
  149. :class="{ 'list-item-selected': unique == item.unique }"
  150. :key="index"
  151. v-show="currentView == 'list'"
  152. >
  153. <ul>
  154. <li class="list-item-info">
  155. <p class="list-item-title">
  156. <span class="list-item-typeMark">{{ item.no }}</span>
  157. {{ item.name }}
  158. </p>
  159. </li>
  160. </ul>
  161. </li> -->
  162. </TabPane>
  163. <!-- 临时课程 -->
  164. <TabPane :label="$t('studentWeb.tempClass')" name="tab2">
  165. <!--剛加入的課程-->
  166. <!-- <li
  167. class="list-item"
  168. @click="
  169. sentSelectedEventTitle(
  170. courseList[courseList.length - index - 2]
  171. )
  172. "
  173. :class="{
  174. 'list-item-selected': selectedCondition(
  175. courseList[courseList.length - index - 2]
  176. ),
  177. }"
  178. v-for="(item,
  179. index) in this.$store.getters.getMycID.myCourseID
  180. .slice()
  181. .reverse()"
  182. :key="`c+${index}`"
  183. >
  184. <ul>
  185. <li class="list-item-info">
  186. <p class="list-item-title">
  187. <span class="list-item-typeMark">{{ item }}</span>
  188. {{ "新加課程名稱" }}
  189. </p>
  190. </li>
  191. </ul>
  192. </li> -->
  193. <!--剛加入的課程-->
  194. <div v-if="personList.length > 0">
  195. <div v-for="(item, index) in timeTable" :key="index">
  196. <li
  197. class="list-item"
  198. v-for="(person, num) in item.personList"
  199. @click="clickCell(item, num, 'list')"
  200. :class="{ 'list-item-selected': unique == person.unique }"
  201. :key="`j+${num}`"
  202. >
  203. <ul>
  204. <li class="list-item-info">
  205. <p class="list-item-title">
  206. <span class="list-item-typeMark">{{ person.no }}</span>
  207. {{ person.name }}({{ person.teaName }})
  208. </p>
  209. </li>
  210. </ul>
  211. </li>
  212. </div>
  213. </div>
  214. <div v-else class="list-item-no">
  215. 暂无课程
  216. </div>
  217. </TabPane>
  218. </Tabs>
  219. </ul>
  220. </div>
  221. </div>
  222. </div>
  223. </template>
  224. <script>
  225. import Loading from "vue-loading-overlay";
  226. import "vue-loading-overlay/dist/vue-loading.css";
  227. export default {
  228. name: "CourseList",
  229. components: {
  230. Loading
  231. },
  232. data() {
  233. return {
  234. isLoad: false,
  235. fullPage: true,
  236. opacity: 0.6,
  237. currentView: 'table',
  238. onlyStu: true, //是不是学生
  239. courseTime: [
  240. {
  241. title: this.$t("studentWeb.week.time"),
  242. slot: "time",
  243. width: "140"
  244. },
  245. {
  246. title: this.$t("studentWeb.week.mon"),
  247. slot: "Mon",
  248. width: "115"
  249. },
  250. {
  251. title: this.$t("studentWeb.week.tue"),
  252. slot: "Tue",
  253. width: "115"
  254. },
  255. {
  256. title: this.$t("studentWeb.week.wed"),
  257. slot: "Wed",
  258. width: "115"
  259. },
  260. {
  261. title: this.$t("studentWeb.week.thu"),
  262. slot: "Thu",
  263. width: "115"
  264. },
  265. {
  266. title: this.$t("studentWeb.week.fri"),
  267. slot: "Fri",
  268. width: "115"
  269. },
  270. {
  271. title: this.$t("studentWeb.week.sat"),
  272. // slot: "Fri",
  273. width: "100"
  274. },
  275. {
  276. title: this.$t("studentWeb.week.sun"),
  277. // slot: "Fri",
  278. width: "100"
  279. }
  280. ],
  281. courseList: this.$api.studentWeb.courseList, //moke数据
  282. fixList: [],
  283. personList: [],
  284. nowClassInfor: {},
  285. timeTable: [],
  286. unique: '',
  287. };
  288. },
  289. props: {
  290. period: {
  291. type: Array,
  292. default: []
  293. },
  294. teaList: {
  295. type: Array,
  296. default: []
  297. }
  298. },
  299. created() {
  300. this.$store.state.userInfo.roles.map(item => {
  301. if(item == "teacher") {
  302. this.onlyStu = false
  303. }
  304. })
  305. this.getClassList()
  306. },
  307. mounted () {
  308. // console.log(this.timeTable);
  309. },
  310. methods: {
  311. getClassList() {
  312. this.isLoad = true
  313. let param = {
  314. userid: this.$store.state.userInfo.sub,
  315. school: this.$store.state.userInfo.azp
  316. }
  317. this.$api.studentWeb.getClassList(param).then(res => {
  318. if(res.courses.length > 0) {
  319. // 表定课程
  320. var fixList = []
  321. // 临时课程
  322. var personList = []
  323. var list = res.courses
  324. for (let i = 0; i < list.length; i++) {
  325. if(list[i].course) {
  326. for (let j = 0; j < list[i].course.schedule.length; j++) {
  327. // 有classId,表定课程
  328. if(list[i].course.schedule[j].classId == list[i].stuCourse.classId[0]) {
  329. if(list[i].course.schedule[j].time.length > 0) {
  330. for (let m = 0; m < list[i].course.schedule[j].time.length; m++) {
  331. var data = this._.cloneDeep(list[i].course)
  332. delete data.schedule
  333. data.school = list[i].stuCourse.school
  334. data.scope = list[i].stuCourse.scope
  335. // 拼接得到一个唯一的标识(目前有同一天的同一节数的课程,所以加入j 和m 来区分)
  336. data.unique = 'class' + list[i].course.no + list[i].course.schedule[j].time[m].week + list[i].course.schedule[j].time[m].id + j + m
  337. fixList.push(this.getNewClass(data, list[i].course.schedule[j], m))
  338. }
  339. }
  340. }
  341. // 有stulist,临时课程
  342. else if (list[i].course.schedule[j].stulist) {
  343. if(list[i].course.schedule[j].time.length > 0) {
  344. for (let m = 0; m < list[i].course.schedule[j].time.length; m++) {
  345. var data = this._.cloneDeep(list[i].course)
  346. delete data.schedule
  347. data.school = list[i].stuCourse.school
  348. data.scope = list[i].stuCourse.scope
  349. data.unique = 'person' + list[i].course.no + list[i].course.schedule[j].time[m].week + list[i].course.schedule[j].time[m].id + j + m
  350. personList.push(this.getNewClass(data, list[i].course.schedule[j], m))
  351. }
  352. }
  353. }
  354. }
  355. }
  356. }
  357. console.log(fixList)
  358. console.log(personList)
  359. this.fixList = fixList
  360. this.personList = personList
  361. this.getClassTime()
  362. }
  363. }).finally(()=>{
  364. this.isLoad = false
  365. })
  366. },
  367. /* getNewClass(nowCourse, j) {
  368. if(nowCourse.course.schedule[j].time.length > 0) {
  369. var list = []
  370. for (let m = 0; m < nowCourse.course.schedule[j].time.length; m++) {
  371. var data = this._.cloneDeep(nowCourse.course)
  372. delete data.schedule
  373. data.school = nowCourse.stuCourse.school
  374. data.scope = nowCourse.stuCourse.scope
  375. // 拼接得到一个唯一的标识
  376. data.unique = nowCourse.course.no + nowCourse.course.schedule[j].time[m].week + nowCourse.course.schedule[j].time[m].id
  377. data.classId = nowCourse.course.schedule[j].classId
  378. data.room = nowCourse.course.schedule[j].room
  379. data.teacherId = nowCourse.course.schedule[j].teacherId
  380. data.notice = nowCourse.course.schedule[j].notice
  381. data.stuList = nowCourse.course.schedule[j].stulist
  382. data.timeId = nowCourse.course.schedule[j].time[m].id
  383. data.timeWeek = nowCourse.course.schedule[j].time[m].week
  384. list.push(data)
  385. }
  386. console.log(list);
  387. return list
  388. }
  389. }, */
  390. // 新增数组
  391. getNewClass(data, schedule, m) {
  392. data.classId = schedule.classId
  393. data.room = schedule.room
  394. data.teacherId = schedule.teacherId
  395. data.notice = schedule.notice
  396. data.stuList = schedule.stulist
  397. data.timeId = schedule.time[m].id
  398. data.timeWeek = schedule.time[m].week
  399. data.teaName = ""
  400. // 获取老师名单
  401. if(this.teaList.length > 0) {
  402. this.teaList.map(item => {
  403. if(item.id == schedule.teacherId) {
  404. data.teaName = item.name
  405. }
  406. })
  407. }
  408. return data
  409. },
  410. // 处理上课时间
  411. getClassTime() {
  412. if(this.period != undefined) {
  413. // 选出该年级的上课时间
  414. var grades = this._.cloneDeep(this.period)
  415. for (let i = 0; i < grades.length; i++) {
  416. // 所有的period.id 都一样,选定fixList[0]
  417. if(grades[i].id == this.fixList[0].period.id) {
  418. this.timeTable = grades[i].timetable
  419. }
  420. }
  421. // 在时间中加入对应的课程
  422. for (let j = 0; j < this.timeTable.length; j++) {
  423. var newfixLis = []
  424. var newpersonList = []
  425. for (let i = 0; i < this.fixList.length; i++) {
  426. if(this.timeTable[j].id == this.fixList[i].timeId) {
  427. newfixLis.push(this.fixList[i])
  428. }
  429. }
  430. for (let i = 0; i < this.personList.length; i++) {
  431. if(this.timeTable[j].id == this.personList[i].timeId) {
  432. newpersonList.push(this.personList[i])
  433. }
  434. }
  435. this.timeTable[j].fixList = newfixLis
  436. this.timeTable[j].personList = newpersonList
  437. }
  438. }
  439. },
  440. // 点击单节课,显示基本信息
  441. /* row:timeTable的某一个
  442. index:fixList/personList中的当前这一数据的下标
  443. type:传'list'就是临时课程,不传就是表定课程
  444. */
  445. clickCell(row, index, type) {
  446. this.nowClassInfor = this._.cloneDeep(row)
  447. if(type) {
  448. this.nowClassInfor.course = this._.cloneDeep(row.personList[index])
  449. } else {
  450. this.nowClassInfor.course = this._.cloneDeep(row.fixList[index])
  451. }
  452. this.unique = this.nowClassInfor.course.unique
  453. this.sentSelectedEventTitle(this.nowClassInfor)
  454. },
  455. changeView(type) {
  456. this.currentView = type
  457. },
  458. // 跳转到当前课程
  459. sentSelectedEventTitle: function (item) {
  460. // 改變ItemName的狀態 vuex mutations
  461. this.$store.commit("ChangeItemName", item);
  462. // 螢幕寬度<767px時,直接關掉sidebar
  463. if (window.innerWidth <= 991) {
  464. this.$store.commit("ToggleSidebar", false);
  465. }
  466. },
  467. },
  468. };
  469. </script>
  470. <style scoped>
  471. @import "~@/assets/student-web/component_styles/course-list.css";
  472. </style>