Blame view

wenjuan/src/components/dajuanTongji/index.vue 13.6 KB
e5b57447   杨鑫   '分包问卷'
1
2
  <template>
    <div style="margin-bottom:20px;border: 1px solid #dddfe5;padding:20px;">
d64cd58f   wesley88   上传验收小程序
3
      <div style="font-size:16px;margin-bottom:20px;">({{ tixingtype }}){{ title }}</div>
e5b57447   杨鑫   '分包问卷'
4
5
      <div style="display: flex;">
        <div style="width: 45%;display: flex;justify-content: space-evenly;">
d64cd58f   wesley88   上传验收小程序
6
          <div ref="chart" style="width:500px; height:400px;" />
e5b57447   杨鑫   '分包问卷'
7
8
        </div>
        <div style="width: 55%;">
d64cd58f   wesley88   上传验收小程序
9
10
11
12
          <el-table
            :data="tiList"
            :header-cell-style="{fontSize: '14px',color:'#0009',fontWeight: 'normal',backgroundColor:'#F2F3F5'}"
          >
e5b57447   杨鑫   '分包问卷'
13
14
            <el-table-column label="选项" min-width="50%" prop="title">
              <template slot-scope="scope">
d64cd58f   wesley88   上传验收小程序
15
                {{ scope.row.title }}
e5b57447   杨鑫   '分包问卷'
16
17
18
19
              </template>
            </el-table-column>
            <el-table-column label="选择次数" min-width="20%">
              <template slot-scope="scope">
d64cd58f   wesley88   上传验收小程序
20
                <span v-if="scope.row.numci!=0"> {{ scope.row.numci.countAnswer }}</span>
e5b57447   杨鑫   '分包问卷'
21
22
23
24
25
                <span v-else>0</span>
              </template>
            </el-table-column>
            <el-table-column prop="percentage" label="百分比" min-width="20%">
              <template slot-scope="scope">
d64cd58f   wesley88   上传验收小程序
26
                <span v-if="scope.row.numci !=0"> {{ scope.row.numci.percentage }}%</span>
e5b57447   杨鑫   '分包问卷'
27
28
29
30
31
32
33
34
35
36
37
                <span v-else> 0%</span>
                <!-- {{scope.row.numci.percentage==''?0:scope.row.numci.percentage}}% -->
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
  </template>
  
  <script>
d64cd58f   wesley88   上传验收小程序
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  import * as echarts from 'echarts';
  import {
    Table,
    TableColumn
  } from 'element-ui';
  
  export default {
    name: 'DynamicChartTable',
    components: {
      'el-table': Table,
      'el-table-column': TableColumn
    },
    props: {
      title: {
        type: String,
        required: true
e5b57447   杨鑫   '分包问卷'
54
      },
d64cd58f   wesley88   上传验收小程序
55
56
57
58
59
60
61
62
63
64
65
      tixingtype: {
        type: String,
        required: true
      },
      tableData: {
        type: Object,
        required: true
      },
      index: {
        type: String,
        required: true
e5b57447   杨鑫   '分包问卷'
66
      },
d64cd58f   wesley88   上传验收小程序
67
68
69
70
71
72
73
74
75
76
    },
    data () {
      return {
        dataList: [],
        tiList: [],
        selectedQuestion: [],
        obj: {
          'code': '200',
          'data': {
            'genderStatistics': [
ab818baa   杨鑫   '1'
77
              {
d64cd58f   wesley88   上传验收小程序
78
79
                'gender': '男',
                'genderNumber': 11
ab818baa   杨鑫   '1'
80
              }
d64cd58f   wesley88   上传验收小程序
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
            ],
            'maleNumber': 11,
            'femaleNumber': 0,
            'unknownGenderNumber': 0,
            'countNumber': 11,
            'sumResTime': 191.86,
            'todayNumber': 11,
            'averageDuration': 17,
            'groupKeys': '[GroupKey(questionNumber=1, answer=1, countAnswer=2, percentage=18.00), GroupKey(questionNumber=1, answer=2, countAnswer=4, percentage=36.00), GroupKey(questionNumber=1, answer=3, countAnswer=3, percentage=27.00), GroupKey(questionNumber=1, answer=4, countAnswer=2, percentage=18.00)]',
            'cereQuestionnaireTable': {
              'id': '141',
              'title': '1231',
              'startDate': '2024-11-22',
              'endDate': '2024-11-30',
              'publishPort': 'H5端',
              'questionnaireType': '社会调查问卷',
              'estimatedTime': '12',
              'remarks': '123',
              'filler': '公众',
              'fillingConditions': '可重复填写',
              'coverImage': 'https://jy.scjysm.asia:18086/mefile/file/2024/11/f883786057004b1596d569b212471a27_ac6e8eb7cc9e9be4f7f2e7351ddf872.jpg',
              'rewardForParticipation': '不设置奖励',
              'rewardContent': '',
              'questionId': '361',
              'responseStatus': '5',
              'reviewStatus': '3',
              'queryStatus': '',
              'reviewComments': '通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过和嘎尔uiorg和农村 通过',
              'opinionDelisting': '到期下架',
              'createTime': '2024-11-22 16:24',
              'createUser': '213',
              'updateTime': '2024-11-22 16:32',
              'cereQuestionManagements': [
                {
                  'id': '361',
                  'questionType': '单选',
                  'questionBank': '公共端题库',
                  'isRequired': '必填',
                  'questionDescription': '',
                  'optionSettings': '{"1":"123"}',
                  'tikuTitle': 'asdasdas',
                  'createDate': '2024-11-22 16:23',
                  'createUser': '',
                  'questionCode': '',
                  'score': '{"1":1}',
                  'pageSize': 0,
                  'pageNumber': 0
                }
ab818baa   杨鑫   '1'
129
              ],
d64cd58f   wesley88   上传验收小程序
130
131
132
133
134
135
136
137
              'countNumber': 0,
              'question': '{"1":{"choose":"","type":"单选","title":"asdasdas","required":"必填","options":[{"score":"1","answer":"123","disabled":false}]}}',
              'needName': '',
              'needPhone': '',
              'needGender': '',
              'needOpinion': '',
              'pageSize': 0,
              'pageNumber': 0
e5b57447   杨鑫   '分包问卷'
138
            }
e5b57447   杨鑫   '分包问卷'
139
          },
d64cd58f   wesley88   上传验收小程序
140
141
142
143
144
          'errorData': {},
          'message': '成功',
          'name': '',
          'describe': '',
          'json': ''
e5b57447   杨鑫   '分包问卷'
145
        }
d64cd58f   wesley88   上传验收小程序
146
147
148
149
150
151
152
153
      }
    },
    watch: {
      // 监听 tableData 的变化
      tableData: {
        handler (newVal, oldVal) {
          const obj = {
            timu: '',
e5b57447   杨鑫   '分包问卷'
154
  
d64cd58f   wesley88   上传验收小程序
155
          }
e5b57447   杨鑫   '分包问卷'
156
  
d64cd58f   wesley88   上传验收小程序
157
158
159
160
161
162
163
164
165
166
167
168
          // this.initChart();
        },
        deep: true // 开启深度监听,以便监听对象内部属性的变化
      }
    },
    mounted () {
      this.loadQuestionByIndex(this.index)
      this.tubiao()
      console.log(JSON.parse(this.obj))
      // this.processData()
    },
    onload () {
e5b57447   杨鑫   '分包问卷'
169
  
d64cd58f   wesley88   上传验收小程序
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
    },
    beforeDestroy () {
      if (this.$refs.chart) {
        const myChart = echarts.getInstanceByDom(this.$refs.chart);
        if (myChart) {
          window.removeEventListener('resize', myChart.resize);
          myChart.dispose();
        }
      }
      this.dataList = []
      this.tiList = []
      this.selectedQuestion = []
    },
    methods: {
      init (data) {
        this.tableData = data;
        // console.log('initdata',data);
e5b57447   杨鑫   '分包问卷'
187
188
        this.loadQuestionByIndex(this.index)
        this.tubiao()
e5b57447   杨鑫   '分包问卷'
189
      },
d64cd58f   wesley88   上传验收小程序
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
      loadQuestionByIndex (index) {
        var tiIndex = Number(index);
        const {
          groupKeys,
          cereQuestionnaireTable
        } = this.tableData;
  
        var list = []; // 用于存储结果
  
        var table = JSON.parse(cereQuestionnaireTable.question); // 解析问卷中的问题数据
  
        // 遍历 groupKeys 中的每个条目
        // for (let i = 0; i < groupKeys.length; i++) {
        //     for (var key in table) {
        //         if (groupKeys[i].questionNumber == key) {  // 匹配 questionNumber
        //             console.log(table[key]);  // 打印当前匹配的问题
  
        //             // 确保该问题有选项,并且 options 数组不为空
        //             if (table[key].options && table[key].options.length != 0) {
        //                 // 遍历每个选项
        //                 for (let j = 0; j < table[key].options.length; j++) {
        //                     // 如果当前选项索引和 groupKeys[i].answer 匹配
        //                     if (j + 1 == groupKeys[i].answer) {
        //                         var info1 = {};  // 创建一个新的 info1 对象,避免引用问题
        //                         info1.title = table[key].options[j].answer;  // 选项的答案
        //                         info1.numci = groupKeys[i].countAnswer;  // 统计该选项的回答次数
        //                         info1.baifenbi = groupKeys[i].percentage;  // 该选项的百分比
        //                         list.push(info1);  // 将 info1 添加到 list 数组
        //                     }
        //                 }
        //             }
        //         }
        //     }
        // }
  
        var list = [{}];
        for (const key in table) {
          var itemdata = {};
          var timu = table[parseInt(key)];
          var option = {};
          // if(timu.type =='文本') continue;
          for (const o in timu.options) {
            option[parseInt(o) + 1] = timu.options[o].answer;
          }
          // option.push({
          //   index: parseInt( o )+ 1,
          //   answer: timu.options[o].answer
e5b57447   杨鑫   '分包问卷'
237
          // });
d64cd58f   wesley88   上传验收小程序
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
          // itemdata[key] = {tikuTitle:timu.title,optionSettings: JSON.stringify(option)};
          list.push({ tikuTitle: timu.title, optionSettings: JSON.stringify(option) })
          // list.push(itemdata)
        }
  
        // var querytabel = Object.keys(table).map((key, index) => {
        //     const item = table[key];
  
        //     const optionSettings = item.options.map((acc, index) => {
        //       index = acc.answer;
        //       return acc;
        //     }, {});
        //     const score = item.options.reduce((acc, option) => {
        //       acc[option.score] = option.score;
        //       return acc;
        //     }, {});
  
        //   return {
        //     id: (index + 1).toString(),
        //     questionType: item.type,
        //     questionBank: index === 0 ? "用户端题库" : "公共端题库",
        //     isRequired: item.required,
        //     questionDescription: "",
        //     optionSettings: JSON.stringify(optionSettings),
        //     tikuTitle: item.title,
        //     createDate: new Date().toISOString().slice(0, 19).replace("T", " "),
        //     createUser: "",
        //     questionCode: "",
        //     score: JSON.stringify(score),
        //     pageSize: 0,
        //     pageNumber: 0
        //   };
        // });
e5b57447   杨鑫   '分包问卷'
271
272
273
274
275
276
277
278
279
280
281
  
        // const filteredQueryTable = Object.values(querytabel);
        // 假设 this.index 是从1开始的序号
        const arrayIndex = Number(this.index); // 将序号转换为数组索引
  
        const question = list[arrayIndex]; // 索引是从1开始的
  
        const optionStats = this.initOptionStats(question.optionSettings);
  
        // 统计选项选择次数
        groupKeys.forEach((group) => {
e5b57447   杨鑫   '分包问卷'
282
283
284
285
286
287
288
289
290
291
292
293
294
295
          if (group.questionNumber == tiIndex) {
            const optionId = group.answer;
            const countAnswer = group.countAnswer;
  
            // 如果选项存在,将选择次数累加,并计算百分比
            if (optionStats[optionId]) {
              optionStats[optionId].countAnswer += countAnswer;
            } else {
              optionStats[optionId] = {
                countAnswer,
                percentage: group.percentage
              };
            }
          }
e5b57447   杨鑫   '分包问卷'
296
297
298
299
300
301
302
303
304
305
306
        });
  
        // 设置为当前选择的问题
        this.selectedQuestion = {
          ...question,
          optionStats
        }
  
        const optionlist = []
        // this.selectedQuestion.optionStats
        for (var key in this.selectedQuestion.optionStats) {
e5b57447   杨鑫   '分包问卷'
307
308
309
310
311
312
313
314
315
316
317
318
          const info2 = {
            tihao: 0,
            title: '',
            numci: 0,
            baifenbi: 0
          }
          const optionSettings = {
            ...JSON.parse(this.selectedQuestion.optionSettings)
          }
          info2.tihao = key
          info2.title = optionSettings[key]
          info2.numci = this.selectedQuestion.optionStats[key]
ab818baa   杨鑫   '1'
319
  
e5b57447   杨鑫   '分包问卷'
320
          optionlist.push(info2);
e5b57447   杨鑫   '分包问卷'
321
322
323
324
        }
  
        this.tiList = [];
        this.tiList = optionlist
e5b57447   杨鑫   '分包问卷'
325
326
      },
      // 初始化选项统计,确保每个选项都有统计数据
d64cd58f   wesley88   上传验收小程序
327
      initOptionStats (optionSettings) {
e5b57447   杨鑫   '分包问卷'
328
329
330
331
332
333
334
335
        const options = JSON.parse(optionSettings); // 解析 JSON 字符串
  
        const optionStats = {};
        for (const key in options) {
          optionStats[key] = 0; // 初始值为0
        }
  
        return optionStats;
e5b57447   杨鑫   '分包问卷'
336
337
338
      },
  
      // 根据选项ID获取选项描述
d64cd58f   wesley88   上传验收小程序
339
      getOptionDescription (optionId) {
e5b57447   杨鑫   '分包问卷'
340
        const optionSettings = JSON.parse(this.selectedQuestion.optionSettings);
d64cd58f   wesley88   上传验收小程序
341
        return optionSettings[optionId] || '无描述'; // 如果没有描述,返回"无描述"
e5b57447   杨鑫   '分包问卷'
342
343
      },
  
d64cd58f   wesley88   上传验收小程序
344
345
      tubiao () {
        const res = this.tiList.map(function (item) {
e5b57447   杨鑫   '分包问卷'
346
347
          return {
            name: item.title,
d64cd58f   wesley88   上传验收小程序
348
            value: item.numci.countAnswer || 0 // ///
e5b57447   杨鑫   '分包问卷'
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
          }
        })
        const option = {
          tooltip: {
            trigger: 'item'
          },
          legend: {
            //  bottom: '30',
            // left: 'center',
            x: 'right', // 可设定图例在左、右、居中
            y: 'bottom', // 可设定图例在上、下、居中
            left: 'center'
          },
          series: [{
            type: 'pie',
ba37c587   杨鑫   '最新版本'
364
365
            radius: ['30%', '60%'],
            center: ['50%', '40%'], // 调整饼图位置
e5b57447   杨鑫   '分包问卷'
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: false,
              position: 'center',
  
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 20,
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            color: ['#3f9b6a', 'rgb(61,182,211)', 'rgb(126, 211, 146)', 'rgb(200, 40, 211)', 'rgb(171, 184, 211)',
              'rgb(211, 169, 150)', 'rgb(185, 211, 16)'
            ],
            data: res,
          }]
        }
        const chartDom = this.$refs.chart;
        const myChart = echarts.init(chartDom);
        option && myChart.setOption(option);
      }
e5b57447   杨鑫   '分包问卷'
397
    }
d64cd58f   wesley88   上传验收小程序
398
  };
e5b57447   杨鑫   '分包问卷'
399
400
401
402
403
  </script>
  
  <style scoped>
    /* 添加一些基本样式 */
  </style>