stutask.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <div id="stutask">
  3. <van-row>
  4. <van-col class="style">
  5. <van-col :span="24" class="top">
  6. <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
  7. </van-col>
  8. <van-col class="main" :span="24" v-if="display === 'list'">
  9. <van-col :span="24" class="taskList" v-for="(item, index) in taskList" :key="index">
  10. <van-cell is-link @click="toDetail(item)">
  11. <!-- 使用 title 插槽来自定义标题 -->
  12. <template #title>
  13. <span class="custom-title">{{ item.stuname }}</span>
  14. <span v-if="item.score" style="margin-left:20px" class="custom-title">分数:{{ item.score }}</span>
  15. </template>
  16. </van-cell>
  17. </van-col>
  18. </van-col>
  19. <van-col :span="24" v-else-if="display === 'detail'">
  20. <van-col :span="12" style="margin:5px 10px">
  21. <van-button plain icon="arrow-left" size="small" @click="display = 'list'">返回学生列表</van-button>
  22. </van-col>
  23. <template v-if="tasktype === 'task'">
  24. <van-col :span="24" class="title">
  25. {{ task.title }}
  26. </van-col>
  27. <van-col :span="24" class="question" v-for="(item, index) in task.question" :key="index">
  28. <p>
  29. {{ index + 1 }}、(<template>{{ item.type === '0' ? '单选' : item.type === '1' ? '多选' : item.type === '2' ? '简答' : '' }}</template
  30. >)({{ item.score }}分)
  31. </p>
  32. <p>{{ item.topic }}({{ item.stuanswer }})</p>
  33. <p v-for="i in item.option" :key="i._id">{{ i.number }}、{{ i.opname }}</p>
  34. <p v-if="item.answer">正确答案:{{ item.answer }}</p>
  35. </van-col>
  36. </template>
  37. <template v-else-if="tasktype === 'pic'">
  38. <van-image :src="picrul"></van-image>
  39. </template>
  40. <van-field v-model="score" type="number" label="作业成绩:" placeholder="请输入学生成绩" />
  41. <van-button round type="info" @click="onSubmit">提交成绩</van-button>
  42. </van-col>
  43. </van-col>
  44. </van-row>
  45. </div>
  46. </template>
  47. <script>
  48. import NavBar from '@/layout/common/topInfo.vue';
  49. import { mapState, createNamespacedHelpers, mapGetters } from 'vuex';
  50. const { mapActions: uploadtask } = createNamespacedHelpers('uploadtask');
  51. const { mapActions: task } = createNamespacedHelpers('task');
  52. export default {
  53. name: 'stutask',
  54. props: {},
  55. components: { NavBar },
  56. data: () => ({
  57. title: '',
  58. isleftarrow: '',
  59. navShow: true,
  60. taskList: [],
  61. display: 'list',
  62. task: {},
  63. tasktype: '',
  64. picrul: '',
  65. score: '',
  66. uploadtask: {},
  67. }),
  68. created() {
  69. this.search();
  70. },
  71. computed: {
  72. id() {
  73. return this.$route.query.id;
  74. },
  75. },
  76. methods: {
  77. ...uploadtask(['fetch', 'query', 'update']),
  78. ...task({ taskInfo: 'fetch' }),
  79. async search() {
  80. const stutasks = await this.query({ lessonid: this.id });
  81. this.$set(this, `taskList`, stutasks.data);
  82. },
  83. async toDetail(item) {
  84. this.$set(this, `uploadtask`, item);
  85. this.display = 'detail';
  86. if (item.taskid) {
  87. this.tasktype = 'task';
  88. const task = await this.taskInfo(item.taskid);
  89. for (const question of task.data.question) {
  90. const answer = item.answers.find(item => item.questionid === question._id);
  91. question.stuanswer = answer.answer;
  92. }
  93. this.$set(this, `task`, task.data);
  94. console.log(task.data);
  95. } else if (item.picrul) {
  96. this.tasktype = 'pic';
  97. this.picrul = item.picrul;
  98. }
  99. if (item.score) {
  100. this.score = item.score;
  101. }
  102. },
  103. async onSubmit() {
  104. this.uploadtask.score = this.score;
  105. const res = await this.update(this.uploadtask);
  106. if (res.errcode === 0) {
  107. this.$toast('提交学生成绩成功');
  108. this.display = 'list';
  109. }
  110. console.log(this.uploadtask);
  111. },
  112. },
  113. mounted() {
  114. this.title = this.$route.meta.title;
  115. this.isleftarrow = this.$route.meta.isleftarrow;
  116. },
  117. watch: {
  118. $route(to, from) {
  119. this.title = to.meta.title;
  120. this.isleftarrow = to.meta.isleftarrow;
  121. },
  122. },
  123. };
  124. </script>
  125. <style lang="less" scoped>
  126. .style {
  127. width: 100%;
  128. min-height: 667px;
  129. position: relative;
  130. background-color: #f9fafc;
  131. }
  132. .top {
  133. height: 46px;
  134. overflow: hidden;
  135. }
  136. .title {
  137. text-align: center;
  138. font-weight: bold;
  139. font-size: 20px;
  140. }
  141. /deep/.van-field {
  142. width: 70%;
  143. border: 1px solid #f5f5f5;
  144. display: -webkit-inline-box;
  145. margin-right: 10px;
  146. }
  147. </style>