CreateTask.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. <template>
  2. <div class="task">
  3. <step-bar :step-number="2" />
  4. <!--课程基本信息-->
  5. <div class="task-course-info">
  6. <div class="cover"><el-image fit="fill" :src="picture_url" alt="封面" /></div>
  7. <div class="info">
  8. <div class="name">{{ name }}</div>
  9. <div class="date">{{ begin_date }}<span>-</span>{{ end_date }}</div>
  10. </div>
  11. </div>
  12. <!--按钮-->
  13. <div class="task-button">
  14. <el-button class="prev-step" @click="preStep"><i class="el-icon-back" />选择教材</el-button>
  15. <el-button><router-link to="/create_course">关闭</router-link></el-button>
  16. </div>
  17. <!--任务课节-->
  18. <div class="task-item">
  19. <!--课节列表-->
  20. <div class="task-item-list">
  21. <template v-if="cs_item_list.length > 0">
  22. <div
  23. v-for="item in cs_item_list"
  24. :key="item.id"
  25. :class="['task-item-list-title', { selected: item.id === curItemID }]"
  26. @click="curItemID = item.id"
  27. >
  28. <span>{{ item.name }}</span>
  29. <el-dropdown placement="bottom" trigger="click" @command="deleteCSItem">
  30. <i class="el-icon-more"></i>
  31. <el-dropdown-menu slot="dropdown">
  32. <el-dropdown-item class="delete-menu" :command="item.id">
  33. <span>删除</span><svg-icon icon-class="delete" />
  34. </el-dropdown-item>
  35. </el-dropdown-menu>
  36. </el-dropdown>
  37. </div>
  38. </template>
  39. <div v-else class="task-item-list-title">新课节</div>
  40. <el-button class="create-item selected" type="primary" @click="dialogVisible = true">
  41. <svg-icon icon-class="create-white" /> 创建新课节
  42. </el-button>
  43. </div>
  44. <!--课节信息-->
  45. <div class="task-item-container">
  46. <div class="item-info">
  47. <div class="title">课节信息</div>
  48. <div class="item-info-name">
  49. <div>课节名称</div>
  50. <el-input v-model="itemInfoBox.name" readonly />
  51. </div>
  52. <div class="item-info-date">
  53. <div>时间</div>
  54. <el-date-picker
  55. v-model="itemInfoBox.date"
  56. readonly
  57. type="datetimerange"
  58. range-separator="~"
  59. value-format="yyyy-MM-dd HH:mm:ss"
  60. unlink-panels
  61. />
  62. </div>
  63. </div>
  64. <div class="item-task">
  65. <div class="title">
  66. <span class="number-tag">{{ taskLength }}</span>
  67. <span>课节任务</span>
  68. </div>
  69. <div class="item-task-pre task-container">
  70. <!--课前任务-->
  71. <div class="item-task-pre-title">
  72. <span class="number-tag pre">{{ itemInfoBox.pre_task_list.length }}</span>
  73. <span>课前任务</span>
  74. </div>
  75. <div class="item-task-pre-list item-task-list">
  76. <el-card v-for="(item, i) in itemInfoBox.pre_task_list" :key="item.id">
  77. <el-collapse>
  78. <el-collapse-item>
  79. <template slot="title">
  80. <div class="card-title">
  81. <div class="name">{{ i + 1 }}. {{ item.name }}</div>
  82. <div class="info">
  83. {{ item.time_space_view_txt }}
  84. </div>
  85. </div>
  86. </template>
  87. <div class="task-info">
  88. <div>
  89. <span class="label">要求</span>
  90. <div>{{ item.content }}</div>
  91. </div>
  92. <div>
  93. <span class="label">课件</span>
  94. <div>
  95. <el-tag
  96. v-for="li in item.courseware_list"
  97. :key="li.courseware_id"
  98. color="#fff"
  99. >
  100. {{ li.courseware_name }}
  101. </el-tag>
  102. </div>
  103. </div>
  104. <div>
  105. <span class="label">其他文件</span>
  106. <div>
  107. <el-tag v-for="li in item.accessory_list" :key="li.file_id" color="#fff">
  108. <a target="_blank" :href="li.file_url">
  109. {{ li.file_name }} {{ li.file_url }}
  110. </a>
  111. </el-tag>
  112. </div>
  113. </div>
  114. </div>
  115. </el-collapse-item>
  116. </el-collapse>
  117. </el-card>
  118. <el-button @click="newTask(0)"><i class="el-icon-plus" /> 新建任务</el-button>
  119. </div>
  120. </div>
  121. <!--课中任务-->
  122. <div class="item-task-mid task-container">
  123. <div class="item-task-mid-title">
  124. <span class="number-tag mid">{{ itemInfoBox.mid_task_list.length }}</span>
  125. <span>课中任务</span>
  126. </div>
  127. <div class="item-task-mid-list item-task-list">
  128. <el-card v-for="(item, i) in itemInfoBox.mid_task_list" :key="item.id">
  129. <el-collapse>
  130. <el-collapse-item>
  131. <template slot="title">
  132. <div class="card-title">
  133. <div class="name">
  134. {{ itemInfoBox.pre_task_list.length + i + 1 }}. {{ item.name }}
  135. </div>
  136. <div class="info">
  137. {{ item.time_space_view_txt }}
  138. </div>
  139. </div>
  140. </template>
  141. <div class="task-info">
  142. <div>
  143. <span class="label">要求</span>
  144. <div>{{ item.content }}</div>
  145. </div>
  146. <div>
  147. <span class="label">课件</span>
  148. <div>
  149. <el-tag
  150. v-for="li in item.courseware_list"
  151. :key="li.courseware_id"
  152. color="#fff"
  153. >
  154. {{ li.courseware_name }}
  155. </el-tag>
  156. </div>
  157. </div>
  158. <div>
  159. <span class="label">其他文件</span>
  160. <div>
  161. <el-tag v-for="li in item.accessory_list" :key="li.file_id" color="#fff">
  162. <a target="_blank" :href="li.file_url">
  163. {{ li.file_name }} {{ li.file_url }}
  164. </a>
  165. </el-tag>
  166. </div>
  167. </div>
  168. </div>
  169. </el-collapse-item>
  170. </el-collapse>
  171. </el-card>
  172. <el-button @click="newTask(1)"><i class="el-icon-plus" /> 新建任务</el-button>
  173. </div>
  174. </div>
  175. <!--课后任务-->
  176. <div class="item-task-after task-container">
  177. <div class="item-task-after-title">
  178. <span class="number-tag after">{{ itemInfoBox.after_task_list.length }}</span>
  179. <span>课后任务</span>
  180. </div>
  181. <div class="item-task-after-list item-task-list">
  182. <el-card v-for="(item, i) in itemInfoBox.after_task_list" :key="item.id">
  183. <el-collapse>
  184. <el-collapse-item>
  185. <template slot="title">
  186. <div class="card-title">
  187. <div class="name">
  188. {{
  189. itemInfoBox.pre_task_list.length +
  190. itemInfoBox.mid_task_list.length +
  191. i +
  192. 1
  193. }}. {{ item.name }}
  194. </div>
  195. <div class="info">
  196. {{ item.time_space_view_txt }}
  197. </div>
  198. </div>
  199. </template>
  200. <div class="task-info">
  201. <div>
  202. <span class="label">要求</span>
  203. <div>{{ item.content }}</div>
  204. </div>
  205. <div>
  206. <span class="label">课件</span>
  207. <div>
  208. <el-tag
  209. v-for="li in item.courseware_list"
  210. :key="li.courseware_id"
  211. color="#fff"
  212. >
  213. {{ li.courseware_name }}
  214. </el-tag>
  215. </div>
  216. </div>
  217. <div>
  218. <span class="label">其他文件</span>
  219. <div>
  220. <el-tag v-for="li in item.accessory_list" :key="li.file_id" color="#fff">
  221. <a target="_blank" :href="li.file_url">
  222. {{ li.file_name }} {{ li.file_url }}
  223. </a>
  224. </el-tag>
  225. </div>
  226. </div>
  227. </div>
  228. </el-collapse-item>
  229. </el-collapse>
  230. </el-card>
  231. <el-button @click="newTask(2)"><i class="el-icon-plus" /> 新建任务</el-button>
  232. </div>
  233. </div>
  234. </div>
  235. <div class="learning-materials">
  236. <div class="title">学习资料</div>
  237. <div>
  238. <el-button><svg-icon icon-class="upload" /> 上传文件</el-button>
  239. </div>
  240. </div>
  241. </div>
  242. </div>
  243. <!--添加课节弹出页-->
  244. <el-dialog
  245. v-loading="loading"
  246. :visible.sync="dialogVisible"
  247. title="课节信息"
  248. width="525px"
  249. top="25vh"
  250. :close-on-click-modal="false"
  251. :show-close="false"
  252. >
  253. <el-form
  254. ref="itemForm"
  255. :model="itemForm"
  256. :rules="itemRules"
  257. label-width="90px"
  258. label-position="left"
  259. >
  260. <el-form-item label="课节名称" prop="name">
  261. <el-input v-model="itemForm.name" class="item-name" />
  262. </el-form-item>
  263. <el-form-item label="课节周期" prop="date">
  264. <el-date-picker
  265. v-model="itemForm.date"
  266. type="datetimerange"
  267. range-separator="~"
  268. value-format="yyyy-MM-dd HH:mm:ss"
  269. unlink-panels
  270. />
  271. </el-form-item>
  272. <el-form-item>
  273. <el-button class="cancel" @click="dialogVisible = false">取消</el-button>
  274. <el-button type="primary" @click="addCSItem">确定</el-button>
  275. </el-form-item>
  276. </el-form>
  277. </el-dialog>
  278. </div>
  279. </template>
  280. <script>
  281. import StepBar from '@/components/StepBar';
  282. import {
  283. GetCourseInfo_ContainCSItem,
  284. AddCSItemToCourse,
  285. GetCSItemInfoBox,
  286. DeleteCSItem
  287. } from '@/api/course';
  288. export default {
  289. name: 'CreateTask',
  290. components: {
  291. StepBar
  292. },
  293. data() {
  294. return {
  295. id: this.$route.params.id,
  296. name: '',
  297. picture_url: '',
  298. begin_date: '',
  299. end_date: '',
  300. cs_item_list: [],
  301. curItemID: '',
  302. dialogVisible: false,
  303. itemForm: {
  304. name: '',
  305. date: []
  306. },
  307. itemRules: {
  308. name: { required: true, message: '课节名称不能为空', trigger: 'blur' },
  309. date: { required: true, message: '课节周期不能为空', trigger: 'blur' }
  310. },
  311. itemInfoBox: {
  312. name: '',
  313. date: [],
  314. pre_task_list: [],
  315. mid_task_list: [],
  316. after_task_list: [],
  317. learning_material_list: []
  318. },
  319. loading: false
  320. };
  321. },
  322. computed: {
  323. taskLength: function () {
  324. return (
  325. this.itemInfoBox.pre_task_list.length +
  326. this.itemInfoBox.mid_task_list.length +
  327. this.itemInfoBox.after_task_list.length
  328. );
  329. }
  330. },
  331. watch: {
  332. curItemID: function () {
  333. this.getCSItemInfoBox();
  334. }
  335. },
  336. created() {
  337. this.getCourseInfo();
  338. },
  339. methods: {
  340. getCourseInfo() {
  341. GetCourseInfo_ContainCSItem({ id: this.id }).then(
  342. ({ name, picture_url, begin_date, end_date, cs_item_list }) => {
  343. this.name = name;
  344. this.picture_url = picture_url;
  345. this.begin_date = begin_date;
  346. this.end_date = end_date;
  347. this.cs_item_list = cs_item_list;
  348. if (cs_item_list.length > 0) {
  349. this.curItemID = cs_item_list[cs_item_list.length - 1].id;
  350. }
  351. }
  352. );
  353. },
  354. preStep() {
  355. this.$router.push({ path: `/create_course_step_table/select_book/${this.id}` });
  356. },
  357. addCSItem() {
  358. this.$refs.itemForm.validate(valid => {
  359. if (valid) {
  360. let data = {
  361. course_id: this.id,
  362. name: this.itemForm.name,
  363. begin_time: this.itemForm.date[0],
  364. end_time: this.itemForm.date[1]
  365. };
  366. this.loading = true;
  367. AddCSItemToCourse(data)
  368. .then(() => {
  369. this.dialogVisible = false;
  370. this.loading = false;
  371. this.getCourseInfo();
  372. // 重置itemForm
  373. this.itemForm = { name: '', date: [] };
  374. })
  375. .catch(() => {
  376. this.loading = false;
  377. });
  378. } else {
  379. return false;
  380. }
  381. });
  382. },
  383. getCSItemInfoBox() {
  384. GetCSItemInfoBox({ id: this.curItemID }).then(
  385. ({ name, begin_time, end_time, pre_task_list, mid_task_list, after_task_list }) => {
  386. this.itemInfoBox.name = name;
  387. this.itemInfoBox.date = [begin_time, end_time];
  388. this.itemInfoBox.pre_task_list = pre_task_list;
  389. this.itemInfoBox.mid_task_list = mid_task_list;
  390. this.itemInfoBox.after_task_list = after_task_list;
  391. }
  392. );
  393. },
  394. deleteCSItem(id) {
  395. this.$confirm('您确定要删除该课节吗?', '提示', {
  396. confirmButtonText: '确定',
  397. cancelButtonText: '取消',
  398. type: 'warning'
  399. }).then(() => {
  400. DeleteCSItem({ id }).then(() => {
  401. this.$message.success('删除课节成功!');
  402. this.getCourseInfo();
  403. });
  404. });
  405. },
  406. newTask(time_type) {
  407. this.$router.push({
  408. path: `/create_course_step_table/new_task/${time_type}/${this.id}/${this.curItemID}`
  409. });
  410. }
  411. }
  412. };
  413. </script>
  414. <style lang="scss">
  415. @import '~@/styles/mixin.scss';
  416. .task {
  417. @include container;
  418. margin-top: $step-h;
  419. // 上部的课程信息
  420. &-course-info {
  421. display: flex;
  422. width: 100%;
  423. height: 120px;
  424. background-color: #fff;
  425. border-radius: 8px;
  426. .cover {
  427. width: 192px;
  428. height: 100%;
  429. border-right: 1px solid #e5e5e5;
  430. .el-image {
  431. width: 100%;
  432. height: 100%;
  433. }
  434. }
  435. .info {
  436. padding: 26px 32px;
  437. .name {
  438. font-size: 24px;
  439. }
  440. .date {
  441. color: #6b6b6b;
  442. font-size: 14px;
  443. margin-top: 16px;
  444. span {
  445. margin: 0 24px;
  446. }
  447. }
  448. }
  449. }
  450. // 中间的按钮
  451. &-button {
  452. margin: 16px 0;
  453. display: flex;
  454. justify-content: flex-end;
  455. .el-button + .el-button {
  456. margin-left: 16px;
  457. }
  458. .prev-step .el-icon-back {
  459. margin-right: 12px;
  460. }
  461. .preserve .svg-icon {
  462. margin-right: 8px;
  463. }
  464. }
  465. // 下部的课节
  466. &-item {
  467. display: flex;
  468. align-items: stretch;
  469. border-radius: 8px;
  470. &-list {
  471. flex: 3;
  472. background-color: #eee;
  473. &-title {
  474. display: flex;
  475. justify-content: space-between;
  476. padding: 16px 24px;
  477. height: 56px;
  478. line-height: 24px;
  479. background-color: #eee;
  480. cursor: pointer;
  481. &.selected {
  482. background-color: #fff;
  483. }
  484. }
  485. .create-item {
  486. margin: 24px;
  487. font-size: 16px;
  488. padding: 11px 20px;
  489. width: calc(100% - 48px);
  490. }
  491. }
  492. &-container {
  493. flex: 7;
  494. background-color: #fff;
  495. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
  496. .learning-materials {
  497. padding: 24px 32px;
  498. .title {
  499. font-size: 18px;
  500. font-weight: 700;
  501. margin-bottom: 24px;
  502. }
  503. }
  504. .item-info {
  505. @extend .learning-materials;
  506. border-bottom: 1px solid #d9d9d9;
  507. &-name,
  508. &-date {
  509. display: flex;
  510. margin-top: 16px;
  511. > :first-child {
  512. width: 110px;
  513. min-width: 120px;
  514. line-height: 40px;
  515. }
  516. .el-input {
  517. width: 600px;
  518. }
  519. }
  520. }
  521. // 课节任务
  522. .item-task {
  523. @extend .learning-materials;
  524. border-bottom: 1px solid #d9d9d9;
  525. .title {
  526. margin-bottom: 24px;
  527. }
  528. .number-tag {
  529. display: inline-block;
  530. vertical-align: bottom;
  531. line-height: 0;
  532. padding: 12px 9px;
  533. margin-right: 8px;
  534. font-size: 12px;
  535. background-color: #000;
  536. color: #fff;
  537. border-radius: 50%;
  538. }
  539. .task-container {
  540. .number-tag {
  541. padding: 10px 7px;
  542. }
  543. .item-task-list {
  544. .el-card {
  545. border-radius: 8px;
  546. margin-bottom: 16px;
  547. .card-title {
  548. display: flex;
  549. justify-content: space-between;
  550. width: calc(100% - 36px);
  551. .name {
  552. font-weight: 600;
  553. }
  554. .info {
  555. color: #929292;
  556. }
  557. }
  558. }
  559. .el-card,
  560. .el-collapse-item__wrap {
  561. background-color: #f7f7f7;
  562. .el-collapse-item__content {
  563. padding: 15px 24px 9px;
  564. background-color: #fff;
  565. color: #000;
  566. .task-info > div {
  567. display: flex;
  568. align-items: center;
  569. padding: 8px 0;
  570. span.label {
  571. width: 80px;
  572. margin-right: 16px;
  573. }
  574. .el-tag {
  575. border-color: #dbdbdb;
  576. margin-right: 16px;
  577. color: #000;
  578. }
  579. }
  580. }
  581. }
  582. .el-card.is-always-shadow,
  583. .el-card.is-hover-shadow:focus,
  584. .el-card.is-hover-shadow:hover {
  585. box-shadow: 0 0;
  586. }
  587. .el-card__body {
  588. padding: 0;
  589. background-color: #f7f7f7;
  590. .el-collapse-item__header {
  591. height: 22px;
  592. line-height: 22px;
  593. background-color: #f9f9f9;
  594. border-bottom-width: 0;
  595. &.focusing:focus:not(:hover) {
  596. color: #000;
  597. }
  598. }
  599. .el-collapse-item > div:first-child {
  600. background-color: #f9f9f9;
  601. border-bottom: 1px solid #e7e7e7;
  602. padding: 10px 20px;
  603. }
  604. }
  605. }
  606. }
  607. // 课前任务
  608. &-pre {
  609. &-title {
  610. .pre {
  611. background-color: #4a99ea;
  612. }
  613. }
  614. &-list {
  615. margin: 16px 9px;
  616. border-left: 2px solid #4a99ea;
  617. padding-left: 19px;
  618. }
  619. }
  620. // 课中任务
  621. &-mid {
  622. &-title {
  623. .mid {
  624. background-color: $basicColor;
  625. }
  626. }
  627. &-list {
  628. margin: 16px 9px;
  629. border-left: 2px solid $basicColor;
  630. padding-left: 19px;
  631. }
  632. }
  633. // 课后任务
  634. &-after {
  635. &-title {
  636. .after {
  637. background-color: #2ece5b;
  638. }
  639. }
  640. &-list {
  641. margin: 16px 9px;
  642. border-left: 2px solid #2ece5b;
  643. padding-left: 19px;
  644. }
  645. }
  646. }
  647. }
  648. }
  649. .el-dialog {
  650. .item-name {
  651. width: 400px;
  652. }
  653. }
  654. }
  655. .el-dropdown-menu {
  656. padding: 1px;
  657. .delete-menu {
  658. width: 128px;
  659. display: flex;
  660. justify-content: space-between;
  661. align-items: center;
  662. }
  663. }
  664. </style>