fuliqi
2024-07-11 8269775d78f974a266c848ea15e73a85dafec2a5
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
<!-- 答卷管理 -->
<template>
  <div class="c">
    <div class="bg">
      <div class="main">
        <!-- 待返回的标题 -->
        <TitleIndex title="答卷管理"/>
        <div class="content">
          <!-- 搜索 -->
          <div>
            <el-form :inline="true" :model="queryParam" class="demo-form-inline" label-width="80px">
              <el-form-item>
                <el-input v-model="queryParam.examName" placeholder="请输入考试名称" clearable></el-input>
              </el-form-item>
              <el-form-item>
                <el-input v-model="queryParam.userName" placeholder="请输入用户名称" clearable></el-input>
              </el-form-item>
              <el-form-item>
                <el-button style="width:100px;" type="primary" size="small" @click="search()">查询</el-button>
                <el-button style="width:100px;" type="danger" size="small" @click="handleExport()">导出</el-button>
              </el-form-item>
            </el-form>
          </div>
          <!-- 表格 -->
          <el-table v-loading="listLoading" :data="tableData" border fit highlight-current-row>
            <el-table-column prop="examName" label="考试名称" align="center"/>
            <el-table-column prop="paperName" label="试卷名称" align="center"/>
            <el-table-column prop="userName" width="150" label="参考人" align="center"/>
            <el-table-column label="得分" width="150px" align="center">
              <template slot-scope="{row}">
                {{ row.score }} / {{ row.totalScore }}
              </template>
            </el-table-column>
            <el-table-column label="题目对错" width="100px" align="center">
              <template slot-scope="{row}">
                {{ row.questionCorrect }} / {{ row.questionCount }}
              </template>
            </el-table-column>
            <el-table-column prop="doTime" label="耗时" width="100px" align="center">
              <template slot-scope="{row}">
                {{ formattedDoTime(row) }}
              </template>
            </el-table-column>
            <el-table-column prop="submitTime" label="提交时间" width="240px" align="center">
              <template slot-scope="{row}">
                <span :style="row.status === 0 ? '' : 'color: red'">
                  {{ row.status === 0 ? row.submitTime : '缺考' }}
                </span>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="120px" align="center">
              <template slot-scope="{row}">
                <el-button size="mini" @click="view(row)">详情</el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination v-show="total > 0" :total="total" :page.sync="queryParam.pageIndex"
                      :limit.sync="queryParam.pageSize" @pagination="search"/>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
// 引入彈出窗口組件
import examPaperAnswerApi from '@/api/examPaperAnswer'
import Pagination from '@/components/Pagination'
 
export default {
  // 注册
  components: {
    Pagination
  },
  data () {
    return {
      listLoading: true,
      queryParam: {
        examId: '',
        userId: '',
        userName: '',
        pageIndex: 1,
        pageSize: 10
      },
      formLoading: false,
      total: 0,
      tableData: [],
      visible: false,
      subjects: []
    }
  },
  created () {
    this.queryParam.examId = this.$route.query.id
    this.queryParam.userId = this.$route.query.userId
    this.search()
  },
  methods: {
    formattedDoTime (row) {
      const totalSeconds = row.doTime
      const minutes = Math.floor(totalSeconds / 60)
      const seconds = totalSeconds % 60
      return `${minutes}分${seconds < 10 ? '0' + seconds : seconds}秒`
    },
    // 获取列表
    search () {
      this.listLoading = true
      examPaperAnswerApi.page(this.queryParam).then(re => {
        this.tableData = re.data.list
        this.total = re.data.total
        this.queryParam.pageSize = re.data.pageSize
        this.queryParam.pageIndex = re.data.pageNum
        this.listLoading = false
      })
    },
    view (row) {
      this.$router.push({ path: '/answer/answer-detail', query: { id: row.id } })
    },
    handleExport () {
      let that = this
      let url = '/api/admin/examPaperAnswer/exportExcel?userName=' + this.queryParam.userName
      if (this.queryParam.userId) url += '&userId=' + this.queryParam.userId
      if (this.queryParam.examId) url += '&examId=' + this.queryParam.examId
      var x = new XMLHttpRequest()
      x.open('POST', url, true)
      x.responseType = 'blob'
      x.onload = function () {
        var url = window.URL.createObjectURL(x.response)
        var a = document.createElement('a')
        a.href = url
        if (that.queryParam.examId) a.download = that.tableData[0].examName + '.xlsx'
        if (that.queryParam.userId) a.download = that.tableData[0].userName + '.xlsx'
        a.click()
      }
      x.send()
    }
  }
}
</script>
<style scoped lang="scss">
.flex {
  display: flex;
}
 
// 内容
.content {
  margin-bottom: 80px;
  background-color: #fff;
  padding: 20px 40px;
  border-radius: 10px;
}
</style>