master
lion 1 day ago
parent 6445a02d59
commit 95630f1507

@ -70,7 +70,7 @@
<SurveyStatsField
v-else
:field="q"
@texts="(kind) => openTexts(q, kind)"
@texts="(kind, key) => openTexts(q, kind, key)"
/>
</section>
</template>
@ -163,6 +163,7 @@
>
<div v-loading="textsLoading">
<div v-for="item in texts" :key="item.id" class="text-answer">
<div><strong>{{ (item.respondent && item.respondent.name) || '未填写姓名' }}</strong><span v-if="item.respondent && item.respondent.company_name"> · {{ item.respondent.company_name }}</span></div>
<small>{{ item.created_at }}</small>
<SurveyAttachments
v-if="item.files && item.files.length"
@ -232,15 +233,16 @@ export default {
textTotal: 0,
textQuestion: null,
textKind: 'value',
textOptionKey: '',
epoch: 0
}
},
computed: {
textTitle() {
return this.textQuestion
? this.textQuestion.name +
(this.textKind === 'other' ? ' · 补充内容' : ' · 回答')
: '回答'
if (!this.textQuestion) return '回答'
const option = (this.textQuestion.select_item || []).find(o => String(o.key) === String(this.textOptionKey))
const suffix = this.textKind === 'option' ? ' · ' + (option ? option.value : '选项') + ' · 补充内容' : this.textKind === 'other' ? ' · 补充内容' : ' · 回答'
return this.textQuestion.name + suffix
}
},
watch: {
@ -345,9 +347,11 @@ export default {
this.replyVisible = true
}
},
openTexts(q, kind) {
openTexts(q, kind, optionKey = '') {
this.textQuestion = q
this.textKind = kind
this.textOptionKey = optionKey
this.textTotal = 0
this.textPage = 1
this.texts = []
this.textsVisible = true
@ -356,16 +360,19 @@ export default {
async loadTexts() {
const epoch = this.epoch
const questionId = this.textQuestion.id
const kind = this.textKind
const optionKey = this.textOptionKey
this.textsLoading = true
try {
const res = await textAnswers({
course_content_evaluation_id: this.surveyData.id,
question_id: questionId,
kind: this.textKind,
kind,
option_key: optionKey,
page: this.textPage,
page_size: 20
})
if (epoch === this.epoch && questionId === this.textQuestion.id) {
if (epoch === this.epoch && this.textQuestion && questionId === this.textQuestion.id && kind === this.textKind && optionKey === this.textOptionKey) {
this.texts = res.data || []
this.textTotal = Number(res.total || 0)
}

@ -25,7 +25,11 @@
width="170"
><template
slot-scope="scope"
>{{ scope.row.percentage }}%</template></el-table-column></el-table>
>{{ scope.row.percentage }}%</template></el-table-column>
<el-table-column v-if="field.stats.options.some(option => option.note_count > 0)" label="补充内容" width="170">
<template slot-scope="scope"><el-button v-if="scope.row.note_count" type="text" size="small" @click="$emit('texts', 'option', scope.row.key)">查看补充内容({{ scope.row.note_count }})</el-button><span v-else>—</span></template>
</el-table-column>
</el-table>
<el-button
v-if="
['text', 'textarea', 'date', 'datetime', 'file'].includes(

@ -547,3 +547,4 @@ describe('Survey editing and results', () => {
wrapper.destroy()
})
})

@ -0,0 +1,30 @@
import { mount, createLocalVue } from '@vue/test-utils'
import ElementUI from 'element-ui'
import StatsField from '@/views/survey/components/SurveyStatsField.vue'
import Results from '@/views/survey/components/SurveyResultsDialog.vue'
import { textAnswers } from '@/api/survey/evaluationForm'
jest.mock('@/api/survey/evaluationForm', () => ({ statistics: jest.fn(), index: jest.fn(), show: jest.fn(), destroy: jest.fn(), textAnswers: jest.fn() }))
const localVue = createLocalVue()
localVue.use(ElementUI)
const flush = () => new Promise(resolve => setTimeout(resolve, 0))
describe('Option supplement results', () => {
it('opens the selected option supplement rather than a generic text list', async() => {
const field = { edit_input: 'checkbox', stats: { valid_count: 2, average: null, other_count: 0, options: [{ key: 'tax', label: '财税会场', count: 2, percentage: 100, note_count: 1 }, { key: 'legal', label: '法律会场', count: 1, percentage: 50, note_count: 0 }] } }
const wrapper = mount(StatsField, { localVue, propsData: { field } })
await flush()
const button = wrapper.findAll('button').wrappers.find(item => item.text().includes('查看补充内容'))
expect(button).toBeTruthy()
button.trigger('click')
expect(wrapper.emitted('texts')[0]).toEqual(['option', 'tax'])
wrapper.destroy()
})
it('sends the option key and keeps each respondent identity in the result', async() => {
textAnswers.mockResolvedValue({ data: [{ id: 7, text: '税务咨询', respondent: { name: '甲学员', company_name: '甲公司' } }], total: 1 })
const state = { epoch: 1, surveyData: { id: 10 }, textQuestion: { id: 66, name: '会场', select_item: [{ key: 'tax', value: '财税会场' }] }, textKind: 'option', textOptionKey: 'tax', textPage: 1 }
await Results.methods.loadTexts.call(state)
expect(textAnswers).toHaveBeenLastCalledWith({ course_content_evaluation_id: 10, question_id: 66, kind: 'option', option_key: 'tax', page: 1, page_size: 20 })
expect(state.texts[0].respondent.name).toBe('甲学员')
expect(Results.computed.textTitle.call(state)).toBe('会场 · 财税会场 · 补充内容')
})
})
Loading…
Cancel
Save