FinishCourseware.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <el-dialog
  3. class="finish-courseware"
  4. :visible="dialogVisible"
  5. :width="dialogWidth"
  6. :title="$t('Key332')"
  7. :close-on-click-modal="false"
  8. @close="dialogClose"
  9. >
  10. <bookquestion
  11. v-if="category === 'OC' || category.length === 0"
  12. ref="courseware"
  13. :context="context"
  14. @handleBookUserAnswer="handleBookUserAnswer"
  15. />
  16. <bookailp
  17. v-else-if="category === 'AILP'"
  18. :context="context"
  19. :ui-type="ui_type"
  20. :preview-width="820"
  21. :preview-height="461"
  22. @handleBookUserAnswer="handleBookUserAnswer"
  23. />
  24. <template v-else-if="category === 'NPC'">
  25. <booknpc
  26. v-if="context"
  27. ref="booknpc"
  28. :is-show-save="true"
  29. task-model=""
  30. :context="context"
  31. :theme-color="themeColor"
  32. @finishTaskMaterial="saveNPCAnswer"
  33. />
  34. </template>
  35. <template v-if="category == 'NNPE'">
  36. <booknnpe v-if="context" :context="context" :theme-color="themeColor" />
  37. </template>
  38. <div v-if="category !== 'NPC'" slot="footer">
  39. <el-button type="primary" @click="finishTaskMaterial">
  40. {{ $t('Key82') }}
  41. </el-button>
  42. </div>
  43. </el-dialog>
  44. </template>
  45. <script>
  46. import { GetCoursewareContent_View, FinishMyTaskMaterial_Student } from '@/api/course';
  47. export default {
  48. props: {
  49. dialogVisible: {
  50. default: false,
  51. type: Boolean
  52. },
  53. id: {
  54. default: '',
  55. type: String
  56. },
  57. coursewareId: {
  58. default: '',
  59. type: String
  60. }
  61. },
  62. data() {
  63. return {
  64. context: null,
  65. ui_type: '',
  66. exam_answer: '',
  67. category: '',
  68. dialogWidth: '860px',
  69. themeColor: ''
  70. };
  71. },
  72. watch: {
  73. coursewareId(val) {
  74. if (!val) {
  75. this.context = null;
  76. this.exam_answer = '';
  77. return;
  78. }
  79. GetCoursewareContent_View({ id: this.coursewareId }).then(({ content, category, book_theme_color }) => {
  80. if (!content) {
  81. this.context = null;
  82. return;
  83. }
  84. this.category = category;
  85. if (category === 'OC' || category.length === 0) {
  86. this.dialogWidth = '860px';
  87. this.context = {
  88. id: this.coursewareId,
  89. ui_type: JSON.parse(content).question.ui_type,
  90. content: JSON.parse(content)
  91. };
  92. this.$nextTick(() => {
  93. this.$refs.courseware.handleAnswerTimeStart();
  94. });
  95. }
  96. if (category === 'AILP') {
  97. this.dialogWidth = '860px';
  98. const contents = JSON.parse(content);
  99. if (contents.question && contents.question.length > 0) {
  100. this.context = JSON.parse(contents.question);
  101. this.ui_type = contents.ui_type ? contents.ui_type : '';
  102. }
  103. }
  104. if (category === 'NPC') {
  105. this.themeColor = book_theme_color;
  106. this.dialogWidth = '900px';
  107. this.context = JSON.parse(content);
  108. this.$nextTick(() => {
  109. this.$refs.booknpc.handleAnswerTimeStart();
  110. });
  111. return;
  112. }
  113. if (category === 'NNPE') {
  114. this.dialogWidth = '900px';
  115. this.themeColor = book_theme_color;
  116. this.context = JSON.parse(content);
  117. }
  118. });
  119. }
  120. },
  121. created() {
  122. this.updateWordPack({
  123. word_key_list: ['Key332', 'Key82', 'Key333', 'Key334']
  124. });
  125. },
  126. methods: {
  127. saveNPCAnswer(content, duration) {
  128. const loading = this.$loading();
  129. FinishMyTaskMaterial_Student({
  130. task_id: this.id,
  131. material_type: 'COURSEWARE',
  132. material_id: this.coursewareId,
  133. exam_answer: {
  134. duration,
  135. content
  136. }
  137. })
  138. .then(() => {
  139. this.$message.success(this.$i18n.t('Key334'));
  140. this.dialogClose();
  141. this.$router.go(0);
  142. })
  143. .finally(() => {
  144. loading.close();
  145. this.exam_answer = '';
  146. });
  147. },
  148. finishTaskMaterial() {
  149. if (this.exam_answer.length === 0 && this.category === 'GCLS') {
  150. this.$message.warning(this.$i18n.t('Key333'));
  151. return;
  152. }
  153. const loading = this.$loading();
  154. FinishMyTaskMaterial_Student({
  155. task_id: this.id,
  156. material_type: 'COURSEWARE',
  157. material_id: this.coursewareId,
  158. exam_answer: this.exam_answer
  159. })
  160. .then(() => {
  161. this.$message.success(this.$i18n.t('Key334'));
  162. this.dialogClose();
  163. this.$router.go(0);
  164. })
  165. .finally(() => {
  166. loading.close();
  167. this.exam_answer = '';
  168. });
  169. },
  170. handleBookUserAnswer(data) {
  171. this.exam_answer = data;
  172. },
  173. dialogClose() {
  174. this.$emit('dialogClose');
  175. }
  176. }
  177. };
  178. </script>
  179. <style lang="scss">
  180. @import '~@/styles/mixin';
  181. .finish-courseware {
  182. @include dialog;
  183. }
  184. </style>