123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <template>
- <div class="body">
- <el-card class="box-card" shadow="never" body-style="padding:0">
- <div slot="header" class="clearfix">
- <h3 style="float:left">题库列表</h3>
- <h4 v-if="resultMode==='examination'" style="float:left;margin-left: 10px;">总分{{ totalScore }}</h4>
- <el-button
- type="primary"
- style="float: right"
- icon="el-icon-plus"
- @click="handleAdd"
- >添加题目</el-button>
- </div>
- <ul style="list-style-type: none;margin:24px 0 0 -40px">
- <li v-for="item,index in tableData" :key="index" class="questionli" @click="handleEdit(item)">
- <span style="width:45px">第{{ index+1 }}题</span>
- <span style="width:45px">{{ item.optType === 'single'?'单选题':item.optType==='many'?'多选题':'判断题' }}</span>
- <span style="flex:1">{{ item.title }}</span>
- <el-popconfirm
- style="width:30px"
- icon="el-icon-info"
- icon-color="red"
- title="确定删除这个问题吗?"
- @onConfirm="handleDelete(item)"
- >
- <el-button slot="reference" type="text" style="color:red">删除</el-button>
- </el-popconfirm>
- </li>
- </ul>
- <el-pagination
- v-show="questionTotal!==0"
- style="float:right; margin:24px 0"
- :total="questionTotal"
- :current-page="currentPage"
- :page-size="pageSize"
- layout="total, prev, pager, next, sizes"
- @size-change="handleSizeChange"
- @current-change="handleCurrentChange"
- />
- </el-card>
- </div>
- </template>
- <script>
- import { getQuestionList } from '@/api/question'
- import { deleteGameLeverQuestion } from '@/api/gamelevelquestion'
-
- export default {
- props: {
- gameId: {
- type: String,
- required: true
- },
- resultMode: String
- },
- data() {
- return {
- tableData: [],
- pageSize: 20,
- currentPage: 1,
- questionTotal: 0, // 条目总数
- totalScore: 0
- }
- },
- watch: {
- gameId: {
- handler(val) {
- if (val) {
- this.onSearch()
- }
- },
- immediate: true // 页面加载时就启动
- }
- },
- methods: {
- handleSizeChange(val) {
- this.pageSize = val
- this.changePagination()
- },
- handleCurrentChange(val) {
- this.currentPage = val
- this.changePagination()
- },
- changePagination() {
- getQuestionList({ gameId: this.gameId, pageSize: this.pageSize, pageNum: this.currentPage }).then(
- (res) => {
- this.tableData = res.data.records
- }
- )
- },
- // 添加问题
- handleAdd() {
- this.$emit('handleAddQuestion', true)
- },
- handleEdit(row) {
- // 向外传送数据row.gameQuestionMapId
- this.$emit('handleEditQuestion', row.gameQuestionMapId)
- },
- handleDelete(row) {
- deleteGameLeverQuestion(row.gameQuestionMapId).then(() => {
- this.$message('删除问题成功')
- this.onSearch()
- // 关闭编辑问题页面防止编辑页面还没关闭就删除当前问题了
- this.$emit('handleCloseQuestion', true)
- })
- },
- onSearch() {
- getQuestionList({ gameId: this.gameId, pageSize: this.pageSize }).then(
- (res) => {
- this.tableData = res.data.records
- this.questionTotal = res.data.total
- this.pageSize = res.data.size
- this.totalScore = 0
- res.data.records.map(item => {
- this.totalScore += item.score
- })
- }
- )
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .questionli {
- width: 100%;
- overflow: hidden;
- display: flex;
- line-height:40px;
- background-color: white;
- padding:0 8px;
- border: 1px solid #f0f2f5;
- }
- .questionli:nth-of-type(even) {
- background: #f0f2f5;
- }
- .questionli:hover {
- background-color: rgb(230, 247, 255);
- }
- </style>
|