stutask.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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="picurl"></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. picurl: '',
  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. if (answer) {
  92. question.stuanswer = answer.answer;
  93. }
  94. }
  95. this.$set(this, `task`, task.data);
  96. console.log(task.data);
  97. } else if (item.picurl) {
  98. this.tasktype = 'pic';
  99. this.picurl = item.picurl;
  100. }
  101. if (item.score) {
  102. this.score = item.score;
  103. }
  104. },
  105. async onSubmit() {
  106. this.uploadtask.score = this.score;
  107. const res = await this.update(this.uploadtask);
  108. if (res.errcode === 0) {
  109. this.$toast('提交学生成绩成功');
  110. this.display = 'list';
  111. }
  112. },
  113. },
  114. mounted() {
  115. this.title = this.$route.meta.title;
  116. this.isleftarrow = this.$route.meta.isleftarrow;
  117. },
  118. watch: {
  119. $route(to, from) {
  120. this.title = to.meta.title;
  121. this.isleftarrow = to.meta.isleftarrow;
  122. },
  123. },
  124. };
  125. </script>
  126. <style lang="less" scoped>
  127. .style {
  128. width: 100%;
  129. min-height: 667px;
  130. position: relative;
  131. background-color: #f9fafc;
  132. }
  133. .top {
  134. height: 46px;
  135. overflow: hidden;
  136. }
  137. .title {
  138. text-align: center;
  139. font-weight: bold;
  140. font-size: 20px;
  141. }
  142. /deep/.van-field {
  143. width: 70%;
  144. border: 1px solid #f5f5f5;
  145. display: -webkit-inline-box;
  146. margin-right: 10px;
  147. }
  148. </style>