Blame view

src/views/oa/printQuestionAnswerList.vue 5.38 KB
0bf7e6a5   wuxw   加入问卷功能代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
  <template>
    <div class="print-question-answer-container">
      <el-card>
        <div class="text-center">
          <h1>{{ printQuestionAnswerInfo.qaName }}</h1>
        </div>
        <div v-html="printQuestionAnswerInfo.content"></div>
  
        <el-table :data="printQuestionAnswerInfo.questionTitles" border style="width: 100%" class="margin-top">
          <el-table-column prop="qaTitle" :label="$t('printQuestionAnswer.table.name')" width="300" align="center">
            <template slot-scope="{row}">
              <div style="max-width: 300px;">
                {{ row.qaTitle }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="titleType" :label="$t('printQuestionAnswer.table.type')" width="300" align="center">
            <template slot-scope="{row}">
              {{ _getTitleTypeName(row.titleType) }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('printQuestionAnswer.table.options')" align="center">
            <template slot-scope="{row}">
              <div v-for="(item, index) in row.titleValues" :key="index">
                {{ item.seq }}、{{ item.qaValue }}
              </div>
            </template>
          </el-table-column>
          <el-table-column :label="$t('printQuestionAnswer.table.selectCount')" align="center">
            <template slot-scope="{row}">
              <div v-for="(item, index) in row.titleValues" :key="index">
                {{ item.personCount }} {{ $t('printQuestionAnswer.unit.person') }}
              </div>
            </template>
          </el-table-column>
        </el-table>
  
        <div class="margin-top">
          <span>{{ $t('printQuestionAnswer.label.total') }}:{{ printQuestionAnswerInfo.voteCount }}</span>;
          <span>{{ $t('printQuestionAnswer.label.submitted') }}:{{ printQuestionAnswerInfo.votedCount }}</span>;
          <span v-for="(item, tIndex) in printQuestionAnswerInfo.titleValues" :key="tIndex">
            {{ item.qaValue }}: {{ item.personCount }}{{ $t('printQuestionAnswer.unit.person') }};
          </span>
        </div>
  
        <div class="text-right margin-top margin-right">
          {{ currentCommunity.name }}
        </div>
        <div class="text-right margin-top-sm margin-right">
          {{ dateFormat(new Date()) }}
        </div>
  
        <div id="print-btn" class="text-right margin-top">
          <el-button type="primary" @click="_printPurchaseApplyDiv">
            <i class="el-icon-printer"></i>&nbsp;{{ $t('common.print') }}
          </el-button>
          <el-button type="warning" style="margin-left: 20px;" @click="_closePage">
            <i class="el-icon-close"></i>
            {{ $t('common.cancel') }}
          </el-button>
        </div>
      </el-card>
    </div>
  </template>
  
  <script>
  import { getCommunityId } from '@/api/community/communityApi'
  import {
    listQuestionAnswer,
    listQuestionTitle
  } from '@/api/oa/printQuestionAnswerApi'
  import { dateFormat } from '@/utils/dateUtil'
  
  export default {
    name: 'PrintQuestionAnswerList',
    data() {
      return {
        printQuestionAnswerInfo: {
          qaName: '',
          startTime: '',
          endTime: '',
          communityId: '',
          content: '',
          titleType: '',
          questionTitles: [],
          updateRoomIds: false,
          voteCount: 0,
          qaId: '',
          votedCount: 0
        },
        currentCommunity: {
          name: '',
          communityId: ''
        }
      }
    },
    created() {
      this.printQuestionAnswerInfo.qaId = this.$route.query.qaId
      this.currentCommunity.communityId = getCommunityId()
      this._listQuestionAnswers()
      this._loadQuestionTitles()
    },
    methods: {
      async _listQuestionAnswers() {
        try {
          const params = {
            page: 1,
            row: 1,
            communityId: this.currentCommunity.communityId,
            qaId: this.printQuestionAnswerInfo.qaId
          }
          const { data } = await listQuestionAnswer(params)
          this.printQuestionAnswerInfo = Object.assign(
            this.printQuestionAnswerInfo,
            data[0]
          )
        } catch (error) {
          console.error('Failed to load question answers:', error)
        }
      },
      async _loadQuestionTitles() {
        try {
          const params = {
            page: 1,
            row: 100,
            communityId: this.currentCommunity.communityId,
            qaId: this.printQuestionAnswerInfo.qaId
          }
          const { data } = await listQuestionTitle(params)
          this.printQuestionAnswerInfo.questionTitles = data
        } catch (error) {
          console.error('Failed to load question titles:', error)
        }
      },
      _printPurchaseApplyDiv() {
        this.printFlag = '1'
        document.getElementById("print-btn").style.display = "none"
        window.print()
        window.opener = null
        window.close()
      },
      _closePage() {
        window.opener = null
        window.close()
      },
      _getTitleTypeName(_titleType) {
        if (_titleType == '1001') {
          return this.$t('printQuestionAnswer.type.single')
        } else if (_titleType == '2002') {
          return this.$t('printQuestionAnswer.type.multiple')
        } else {
          return this.$t('printQuestionAnswer.type.shortAnswer')
        }
      },
      dateFormat
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .print-question-answer-container {
    padding: 20px;
  
    .margin-top {
      margin-top: 20px;
    }
  
    .margin-top-sm {
      margin-top: 10px;
    }
  
    .margin-right {
      margin-right: 20px;
    }
  
    .text-center {
      text-align: center;
    }
  
    .text-right {
      text-align: right;
    }
  }
  </style>