fuliqi
2024-06-06 94da5161fcc39a88e0337e67573a3dd96691b39c
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
185
186
187
188
189
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
237
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<!-- 试卷管理 -->
<template>
  <div class="c">
    <div class="bg">
      <div class="main">
        <!-- 带返回的标题 -->
        <TitleIndex title='试卷管理' />
        <div class="content">
          <!-- 试卷生成按钮 -->
          <div style="padding-bottom:20px; border-bottom: 3px solid #409EFF;margin-bottom: 20px;display: flex; align-items: center;">
            <el-page-header @back="goBack()"/>
            <el-button
              type="primary"
              @click="getCreate"
            >试卷生成</el-button>
            <el-button
              type="primary"
              @click="toTemplate"
            >随机试卷模板</el-button>
          </div>
          <!-- 搜索 -->
          <div>
            <el-form
              :inline="true"
              :model="queryParam"
              label-width="80px"
            >
              <el-form-item>
                <el-input v-model="queryParam.id" placeholder="试卷编号" style="width: 120px" clearable></el-input>
              </el-form-item>
              <el-form-item>
                <el-input v-model="queryParam.name" placeholder="试卷名" clearable></el-input>
              </el-form-item>
              <el-form-item>
                <el-select
                  v-model="queryParam.subjectId"
                  placeholder="全部科目"
                  clearable
                >
                  <el-option v-for="item in subjects" :key="item.id" :label="item.name" :value="item.id"/>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-select
                  v-model="queryParam.paperType"
                  placeholder="试卷类型"
                  clearable
                >
                  <el-option label="固定试卷" value="1" />
                  <el-option label="随机试卷" value="2" />
                  <el-option label="随序试卷" value="3" />
                </el-select>
              </el-form-item>
 
              <el-form-item label="">
                <el-button
                  style="width:100px;"
                  type="primary"
                  size="small"
                  @click="getPage"
                >查询</el-button>
              </el-form-item>
            </el-form>
          </div>
          <!-- 表格 -->
          <el-table
            :header-cell-style="getRowClass"
            :data="tableData"
            border
            style="width: 100%;"
            :row-style="{height:'40px'}"
            :cell-style="{padding: '0'}"
          >
            <el-table-column
              align="center"
              prop="id"
              label="试卷编号"
            >
            </el-table-column>
            <el-table-column
              align="center"
              prop="name"
              label="试卷名"
            >
            </el-table-column>
            <el-table-column
              align="center"
              prop="subjectId"
              label="科目"
            >
              <template slot-scope="scope">
                {{ translate(scope.row.subjectId) }}
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              prop="paperType"
              label="试卷类型"
            >
              <template slot-scope="scope">
                <div v-if="scope.row.paperType === 1">固定试卷</div>
                <div v-else-if="scope.row.paperType === 2">随机试卷</div>
                <div v-else-if="scope.row.paperType === 3">随序试卷</div>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              prop="suggestTime"
              label="建议时长(分钟)"
            >
            </el-table-column>
            <el-table-column
              align="center"
              prop="score"
              label="分值"
            >
            </el-table-column>
            <el-table-column
              label="操作"
              align="center"
            >
              <template slot-scope="scope">
              <el-button type="text">预览</el-button>
              <el-button type="text">编辑</el-button>
              <el-button type="text" @click="deletePaper(scope.row)" class="link-left">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
 
          <div
            class="flex"
            style="justify-content:center;margin-top:20px;"
          >
            <pagination v-show="total>0" :total="total" :page.sync="queryParam.pageIndex" :limit.sync="queryParam.pageSize"
                        @pagination="getPage"/>
          </div>
        </div>
 
        <!-- 添加试卷对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body >
          <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-form-item label="试卷名称" prop="name" >
              <el-input v-model="form.name" placeholder="请输入试卷名称" style="width: 300px"/>
            </el-form-item>
            <el-form-item label="科目" prop="subjectId">
              <el-select v-model="form.subjectId" placeholder="请选择科目" style="width: 200px">
                <el-option
                  v-for="item in subjects"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="试卷类型" prop="paperType">
              <el-select v-model="form.paperType" placeholder="请选择试卷类型" style="width: 200px">
                <el-option label="固定试卷" value="1" />
                <el-option label="随序试卷" value="3" />
              </el-select>
            </el-form-item>
            <el-form-item label="考试时长(分钟)" prop="suggestTime">
              <el-input-number v-model="form.suggestTime" placeholder="请输入考试时长"/>
            </el-form-item>
            <el-button type="primary" @click="toCreate">编辑题目</el-button>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>
 
 
        </div>
      </div>
    </div>
 
</template>
<script>
import examPaperApi from '@/api/examPaper'
import subjectApi from '@/api/subject'
import Pagination from "@/components/Pagination"
export default {
  components: {Pagination},
  data() {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 总条数
      total: 0,
      queryParam: {
        id: null,
        paperType: null,
        subjectId: null,
        pageIndex: 1,
        pageSize: 10
      },
      form: {},
      tableData: [],
      subjects: [],
      // 表单校验
      rules: {
        name: [
          { required: true, message: "试卷名称不能为空", trigger: "blur" }
        ],
        subjectId: [
          { required: true, message: "科目不能为空", trigger: "blur" }
        ],
        paperType: [
          { required: true, message: "试卷类型不能为空", trigger: "blur" }
        ],
        suggestTime: [
          { required: true, message: "考试时长不能为空", trigger: "blur" }
        ],
      }
    };
 
  },
  created () {
    this.getSubjects();
    this.getPage()
  },
  methods: {
    translate(subjectId) {
      const subject = this.subjects.find(subject => subject.id == subjectId);
      return subject ? subject.name : '未知';
    },
    // 返回上一个页面
    goBack() {
      this.$router.back();
    },
    cancel(){
      this.open = false;
    },
    // 表单重置
    reset() {
      this.form = {
        name: null,
        subjectId: null,
        paperType: null,
      };
    },
    // 修改表单头部的颜色
    getRowClass() {
      return "background:#d2d3d6";
    },
    /** 生成试卷对话框 */
    getCreate() {
      this.reset();
      this.open = true;
      this.title = "试卷配置";
    },
    // 配置试卷题目
    toCreate() {
      //跳转到对应的管理页面
      this.$router.push({
        path: "/manage/test-paper-generation",
      });
    },
    toTemplate() {
      //跳转到模板管理页面
      this.$router.push({
        path: "/manage/paper-template",
      });
    },
    deletePaper (row) {
      examPaperApi.deletePaper(row.id).then(re => {
        if (re.code === 1) {
          this.getPage()
          this.$message.success("删除成功")
        } else {
          this.$message.error(re.message)
        }
      })
    },
    getPage () {
      this.listLoading = true
      examPaperApi.pageList(this.queryParam).then(re => {
        const data = re.data
        this.tableData = data.list
        this.total = data.total
        this.queryParam.pageIndex = data.pageNum
        this.listLoading = false
      })
    },
    // 获取科目
    getSubjects() {
      subjectApi.list().then(re => {
        this.subjects = re.data
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.deptId && this.form.deptId.length > 0) {
            this.form.deptId = this.form.deptId[this.form.deptId.length - 1]
          }
          let temp = {
            ...this.form,
            category: parseInt(this.form.category)
          };
          if (temp.id != null) {
            updatePoint(temp).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPoint(temp).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.reset()
              this.getList();
            });
          }
        } else {
          console.log("error")
        }
      })
    },
  },
};
</script>
<style scoped lang="scss">
.flex {
  display: flex;
}
// 内容
.content {
  width: 1262px;
  margin-bottom: 80px;
  background-color: #fff;
  padding: 20px 40px;
  border-radius: 10px;
}
</style>