|
@@ -48,6 +48,8 @@ import detailFrame from '@frame/layout/admin/detail-frame';
|
|
|
import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
const { mapActions: questionnaire } = createNamespacedHelpers('questionnaire');
|
|
|
const { mapActions: questionanswer } = createNamespacedHelpers('questionanswer');
|
|
|
+const { mapActions: setting } = createNamespacedHelpers('setting');
|
|
|
+const { mapActions: student } = createNamespacedHelpers('student');
|
|
|
|
|
|
export default {
|
|
|
name: 'detail',
|
|
@@ -69,6 +71,8 @@ export default {
|
|
|
methods: {
|
|
|
...questionnaire(['fetch']),
|
|
|
...questionanswer(['query']),
|
|
|
+ ...setting({ getSetting: 'fetch' }),
|
|
|
+ ...student(['findList']),
|
|
|
async search() {
|
|
|
let res = await this.fetch(this.querys.questionnaireid);
|
|
|
if (!this.$checkRes(res)) return;
|
|
@@ -151,25 +155,62 @@ export default {
|
|
|
window.history.go(-1);
|
|
|
},
|
|
|
//导出excel数据
|
|
|
- toExcel() {
|
|
|
+ async toExcel() {
|
|
|
+ let msg = this.$message({ message: '正在导出...', duration: 0 });
|
|
|
const { export_json_to_excel } = require('@frame/excel/Export2Excel');
|
|
|
let duplicate = _.cloneDeep(this.cdata);
|
|
|
- let data = [];
|
|
|
- for (const dup of duplicate) {
|
|
|
- const elm = { studentname: dup.studentname };
|
|
|
- for (const answer of dup.answers) {
|
|
|
- elm[answer.questionid] = answer.answer;
|
|
|
+ try {
|
|
|
+ let studsi = await this.findList(duplicate.map(i => i.studentid));
|
|
|
+ if (!this.$checkRes(studsi)) {
|
|
|
+ msg.close();
|
|
|
+ this.$message.error('学生信息有误,请检查学生信息');
|
|
|
+ return;
|
|
|
}
|
|
|
- data.push(elm);
|
|
|
+ let studs = studsi.data;
|
|
|
+ //获取导出问卷选择导出的字段
|
|
|
+ let setr = await this.getSetting();
|
|
|
+ if (!setr) {
|
|
|
+ this.$message.error('没有找到默认设置信息,请查看是否填写默认设置');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let obj = _.get(setr.data, 'ques_setting', []);
|
|
|
+ let arrzh = obj.map(i => i.zh);
|
|
|
+ let arr = obj.map(i => i.key);
|
|
|
+ let nd = duplicate.map(i => {
|
|
|
+ let sr = studs.find(f => f._id == i.studentid);
|
|
|
+ if (sr) {
|
|
|
+ let obj = _.pick(sr, arr);
|
|
|
+ i = { ...i, ...obj };
|
|
|
+ }
|
|
|
+ return i;
|
|
|
+ });
|
|
|
+ let data = [];
|
|
|
+ for (const dup of nd) {
|
|
|
+ const elm = { studentname: dup.studentname };
|
|
|
+ for (const key of arr) {
|
|
|
+ elm[key] = dup[key];
|
|
|
+ }
|
|
|
+ for (const answer of dup.answers) {
|
|
|
+ elm[answer.questionid] = answer.answer;
|
|
|
+ }
|
|
|
+ data.push(elm);
|
|
|
+ }
|
|
|
+ let dquest = _.cloneDeep(this.quest.question);
|
|
|
+ let qarr = dquest.map(i => ({ questionid: i._id, topic: i.topic }));
|
|
|
+ let tHeader = qarr.map(i => i.topic);
|
|
|
+ tHeader = arrzh.concat(tHeader);
|
|
|
+ tHeader.unshift('学生姓名');
|
|
|
+ let filterVal = qarr.map(i => i.questionid);
|
|
|
+ filterVal = arr.concat(filterVal);
|
|
|
+ filterVal.unshift('studentname');
|
|
|
+ data = data.map(v => filterVal.map(j => v[j]));
|
|
|
+ export_json_to_excel(tHeader, data, this.quest.name);
|
|
|
+ msg.close();
|
|
|
+ this.$message.success('导出成功');
|
|
|
+ } catch (error) {
|
|
|
+ msg.close();
|
|
|
+ this.$message.error('导出失败');
|
|
|
}
|
|
|
- let dquest = _.cloneDeep(this.quest.question);
|
|
|
- let qarr = dquest.map(i => ({ questionid: i._id, topic: i.topic }));
|
|
|
- let tHeader = qarr.map(i => i.topic);
|
|
|
- tHeader.unshift('学生姓名');
|
|
|
- let filterVal = qarr.map(i => i.questionid);
|
|
|
- filterVal.unshift('studentname');
|
|
|
- data = data.map(v => filterVal.map(j => v[j]));
|
|
|
- export_json_to_excel(tHeader, data, this.quest.name);
|
|
|
},
|
|
|
},
|
|
|
computed: {
|