dir-quest.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div id="dir-quest">
  3. <template v-if="view == 'list'">
  4. <el-card style="margin:10px" v-for="(i, index) in questList" :key="index" @click.native="toDetail(i, 'detail')">
  5. <p>{{ i.name }}</p>
  6. <p>类型:{{ i.type == 0 ? '常用问卷' : '非常用问卷' }}</p>
  7. </el-card>
  8. </template>
  9. <template v-else>
  10. <el-row>
  11. <el-col :span="3" style="margin:5px 10px">
  12. <el-button type="text" size="mini" icon="el-icon-arrow-left" @click="view = 'list'">返回问卷列表</el-button>
  13. </el-col>
  14. </el-row>
  15. <van-panel title="进度" :status="`${student.answertotal || 0}/${student.alltotal || 0}`">
  16. <van-cell-group>
  17. <van-cell v-for="(i, index) in student.list" :key="index" :title="i.name" :value="i.completion" />
  18. </van-cell-group>
  19. </van-panel>
  20. </template>
  21. </div>
  22. </template>
  23. <script>
  24. import _ from 'lodash';
  25. import { mapState, createNamespacedHelpers } from 'vuex';
  26. const { mapActions: completion } = createNamespacedHelpers('completion');
  27. const { mapActions: classes } = createNamespacedHelpers('classes');
  28. const { mapActions: termquest } = createNamespacedHelpers('termquest');
  29. const { mapActions: questionnaire } = createNamespacedHelpers('questionnaire');
  30. const { mapActions: util } = createNamespacedHelpers('util');
  31. export default {
  32. name: 'dir-quest',
  33. props: {},
  34. components: {},
  35. data: function() {
  36. return {
  37. view: 'list', //detail
  38. questList: [],
  39. classInfo: {},
  40. student: {
  41. list: [],
  42. },
  43. };
  44. },
  45. created() {
  46. this.search();
  47. },
  48. methods: {
  49. ...completion({ getCompletion: 'query' }),
  50. ...classes({ getClass: 'fetch' }),
  51. ...termquest({ getTermQuestList: 'query' }),
  52. ...questionnaire({ getQuestionnaireList: 'query', allFetch: 'mergeRequest' }),
  53. ...util({ modelFetch: 'fetch' }),
  54. async search() {
  55. //查询班级信息,获得期,批次
  56. let res = await this.getClass(this.classid);
  57. if (!this.$checkRes(res)) {
  58. this.$notify({ type: 'danger', message: '没有查询到班级' });
  59. return;
  60. } else this.$set(this, `classInfo`, res.data);
  61. let ql = [];
  62. //查询所有问卷
  63. const quest = await this.getQuestionnaireList({ type: 0 });
  64. if (this.$checkRes(quest)) {
  65. ql = ql.concat(quest.data);
  66. }
  67. //查询这期的所有问卷,id=>数据
  68. let rql = await this.modelFetch({ model: 'termquest', termid: res.data.termid });
  69. if (this.$checkRes(rql)) {
  70. let ids = _.get(rql.data, `questionnaireid`);
  71. if (ids) {
  72. let questList = await this.allFetch({ method: 'fetch', data: ids });
  73. ql = ql.concat(questList.filter(f => f.status == 1));
  74. }
  75. }
  76. this.$set(this, `questList`, ql);
  77. },
  78. async toDetail(data, type) {
  79. this.view = type;
  80. let { id: questionnaireid } = data;
  81. let { id: batch } = this.classInfo;
  82. let res = await this.getCompletion({ type: '2', typeid: batch, questionnaireid });
  83. if (this.$checkRes(res)) {
  84. let { data: completion, answertotal, alltotal, completiontotal } = res;
  85. completion = completion.map(i => {
  86. i.completion.includes('NaN') ? (i.completion = '-') : '';
  87. return i;
  88. });
  89. this.$set(this, `student`, { list: completion, answertotal, alltotal, completiontotal });
  90. }
  91. },
  92. },
  93. computed: {
  94. ...mapState(['user', 'classid']),
  95. pageTitle() {
  96. return `${this.$route.meta.title}`;
  97. },
  98. },
  99. metaInfo() {
  100. return { title: this.$route.meta.title };
  101. },
  102. };
  103. </script>
  104. <style lang="less" scoped>
  105. p {
  106. padding: 0;
  107. margin: 0;
  108. }
  109. </style>