index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <div id="index">
  3. <list-frame title="问卷完成度查询" :total="total" :needFilter="false" :needAdd="false" :needPag="views === 'plan'">
  4. <transition name="el-fade-in-linear">
  5. <self-cards :title="planTitle" v-if="views === `plan`">
  6. <data-table :fields="fields" :data="list" :opera="opera" @view="data => toView(data, 'term')"></data-table>
  7. </self-cards>
  8. <self-cards :title="termTitle" v-if="views === `term`" :returns="toReturns">
  9. <data-table :fields="termFields" :data="termList" :opera="opera" @view="data => toView(data, 'pool')"></data-table>
  10. </self-cards>
  11. <self-cards title="问卷列表" v-if="views === `pool`" :returns="toReturns">
  12. <data-table :fields="quesFields" :data="quesList" :opera="opera" @view="data => toView(data, 'batch')"></data-table>
  13. </self-cards>
  14. <self-cards :title="batchTitle" v-if="views === `batch`" :returns="toReturns">
  15. <el-alert :title="`进度:${batch.answertotal || 0}/${batch.alltotal || 0}`" :closable="false"></el-alert>
  16. <data-table :fields="batchFields" :data="batch.list" :opera="opera" @view="data => toView(data, 'class')"></data-table>
  17. </self-cards>
  18. <self-cards :title="classTitle" v-if="views === `class`" :returns="toReturns">
  19. <el-alert :title="`进度:${classes.answertotal || 0}/${classes.alltotal || 0}`" :closable="false"></el-alert>
  20. <data-table :fields="classFields" :data="classes.list" :opera="opera" @view="data => toView(data, 'student')"></data-table>
  21. </self-cards>
  22. <self-cards :title="studentTitle" v-if="views === `student`" :returns="toReturns">
  23. <el-alert :title="`进度:${student.answertotal || 0}/${student.alltotal || 0}`" :closable="false"></el-alert>
  24. <data-table :fields="studFields" :data="student.list" :opera="[]"></data-table>
  25. </self-cards>
  26. </transition>
  27. </list-frame>
  28. </div>
  29. </template>
  30. <script>
  31. import listFrame from '@frame/layout/admin/list-frame';
  32. import dataTable from '@frame/components/data-table';
  33. import selfCards from './parts/cards';
  34. import _ from 'lodash';
  35. import { createNamespacedHelpers } from 'vuex';
  36. const { mapActions: trainPlan } = createNamespacedHelpers('trainplan');
  37. const { mapActions: classes } = createNamespacedHelpers('classes');
  38. const { mapActions: student } = createNamespacedHelpers('student');
  39. const { mapActions: completion } = createNamespacedHelpers('completion');
  40. const { mapActions: questionnaire } = createNamespacedHelpers('questionnaire');
  41. const { mapActions: termquest } = createNamespacedHelpers('termquest');
  42. export default {
  43. name: 'index',
  44. metaInfo: { title: '问卷完成度查询' },
  45. props: {},
  46. components: {
  47. listFrame,
  48. dataTable,
  49. selfCards,
  50. },
  51. data: () => ({
  52. views: 'plan', // term, batch, class
  53. planTitle: '全年计划',
  54. termTitle: '',
  55. batchTitle: '',
  56. classTitle: '',
  57. studentTitle: '',
  58. planid: undefined,
  59. opera: [
  60. {
  61. label: '查看',
  62. icon: 'el-icon-view',
  63. method: 'view',
  64. },
  65. ],
  66. fields: [
  67. { label: '计划标题', prop: 'title' },
  68. { label: '年度', prop: 'year' },
  69. {
  70. label: '状态',
  71. prop: 'status',
  72. format: i => {
  73. return i === '0' ? '筹备中' : i === '1' ? '发布中' : '已结束';
  74. },
  75. },
  76. ],
  77. list: [],
  78. termFields: [{ label: '期数', prop: 'term' }],
  79. termList: [],
  80. quesFields: [{ label: '标题', prop: 'name' }],
  81. quesList: [],
  82. quest: [],
  83. batchFields: [
  84. { label: '批次', prop: 'name' },
  85. { label: '进度', prop: 'completion' },
  86. ],
  87. batch: {
  88. list: [],
  89. },
  90. classFields: [
  91. { label: '班级', prop: 'name' },
  92. { label: '进度', prop: 'completion' },
  93. ],
  94. classes: {
  95. list: [],
  96. },
  97. total: 0,
  98. studFields: [
  99. { label: '姓名', prop: 'name' },
  100. { label: '进度', prop: 'completion' },
  101. ],
  102. student: {
  103. list: [],
  104. },
  105. classid: '',
  106. studTotal: 0,
  107. }),
  108. created() {
  109. this.search();
  110. },
  111. computed: {},
  112. methods: {
  113. ...trainPlan(['query', 'delete', 'update']),
  114. ...completion({ getCompletion: 'query' }),
  115. ...classes({ getClassesList: 'query' }),
  116. ...student({ getStudentList: 'query' }),
  117. ...termquest({ getTermQuestList: 'query' }),
  118. ...questionnaire({ getQuestionnaireList: 'query' }),
  119. async search({ skip = 0, limit = 10, ...info } = {}) {
  120. const res = await this.query({ skip, limit, status: '1', ...info });
  121. if (this.$checkRes(res)) {
  122. this.$set(this, `list`, res.data);
  123. this.$set(this, `total`, res.total);
  124. }
  125. const quest = await this.getQuestionnaireList();
  126. if (this.$checkRes(res)) {
  127. this.$set(this, `quest`, quest.data);
  128. }
  129. },
  130. async toView({ data }, type) {
  131. this.views = type;
  132. if (type === 'term') {
  133. let planid = data._id;
  134. this.planid = planid;
  135. this.$set(this, `termTitle`, data.title);
  136. this.$set(this, `termList`, data.termnum);
  137. }
  138. if (type === 'pool') {
  139. let termid = data._id;
  140. let res = await this.getTermQuestList({ termid: termid });
  141. if (this.$checkRes(res)) {
  142. let { term } = data;
  143. let { questionnaireid, termid, ...othrers } = res.data[0];
  144. let newArr = this.quest.filter(q => (_.find(questionnaireid, sq => sq === q.id) ? q : ''));
  145. newArr = newArr.map(q => {
  146. q.term = term;
  147. q.termid = termid;
  148. return q;
  149. });
  150. this.$set(this, `quesList`, newArr);
  151. }
  152. }
  153. if (type === 'batch') {
  154. let termid = data.termid;
  155. let questionnaireid = data.id;
  156. let res = await this.getCompletion({ type: '0', typeid: termid, trainplanid: this.planid, questionnaireid });
  157. if (this.$checkRes(res)) {
  158. let { data: completion, answertotal, alltotal, completiontotal } = res;
  159. completion = completion.map(i => {
  160. i.completion.includes('NaN') ? (i.completion = '-') : '';
  161. i.questname = data.name;
  162. i.term = data.term;
  163. i.questionnaireid = questionnaireid;
  164. return i;
  165. });
  166. this.$set(this, `batch`, { list: completion, answertotal, alltotal, completiontotal });
  167. }
  168. this.$set(this, `batchTitle`, `第${data.term}期 问卷${data.name}进度`);
  169. }
  170. if (type === 'class') {
  171. let { id: batch, questname, term, questionnaireid } = data;
  172. let res = await this.getCompletion({ type: '1', typeid: batch, questionnaireid });
  173. if (this.$checkRes(res)) {
  174. let { data: completion, answertotal, alltotal, completiontotal } = res;
  175. completion = completion.map(i => {
  176. i.completion.includes('NaN') ? (i.completion = '-') : '';
  177. i.questname = data.questname;
  178. i.questionnaireid = questionnaireid;
  179. return i;
  180. });
  181. this.$set(this, `classes`, { list: completion, answertotal, alltotal, completiontotal });
  182. }
  183. this.$set(this, `classTitle`, `${data.name} 问卷${questname}进度`);
  184. }
  185. if (type === 'student') {
  186. let { id, questname, questionnaireid } = data;
  187. let res = await this.getCompletion({ type: '2', typeid: data.id, questionnaireid });
  188. if (this.$checkRes(res)) {
  189. let { data: completion, answertotal, alltotal, completiontotal } = res;
  190. completion = completion.map(i => {
  191. i.completion.includes('NaN') ? (i.completion = '-') : '';
  192. return i;
  193. });
  194. this.$set(this, `student`, { list: completion, answertotal, alltotal, completiontotal });
  195. }
  196. this.$set(this, `studentTitle`, `${data.name} 问卷${questname}进度`);
  197. }
  198. },
  199. toReturns() {
  200. if (this.views === 'term') this.views = 'plan';
  201. else if (this.views === 'pool') this.views = 'term';
  202. else if (this.views === 'batch') this.views = 'pool';
  203. else if (this.views === 'class') this.views = 'batch';
  204. else if (this.views === 'student') this.views = 'class';
  205. },
  206. },
  207. watch: {
  208. views: {
  209. handler(val) {
  210. if (val === 'plan') this.planid = undefined;
  211. },
  212. },
  213. },
  214. };
  215. </script>
  216. <style lang="less" scoped></style>