123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <template>
- <div class="body">
- <div class="noshadowCard">
- <el-card class="box-card">
- 问题名称:<el-input
- v-model="title"
- size="mini"
- style="width: 150px; margin-right: 20px"
- />
- 创建时间:
- <el-date-picker
- v-model="daterange"
- size="mini"
- type="daterange"
- range-separator="至"
- start-placeholder="开始日期"
- end-placeholder="结束日期"
- value-format="yyyy-MM-dd"
- style="width:220px; margin-right: 20px"
- @change="dateChange"
- />
-
- <el-button type="primary" size="mini" @click="onSearch">查询</el-button>
- <el-button size="mini" @click="onReset">重置</el-button>
- <el-button type="primary" size="mini" @click="handleAdd">添加问题</el-button>
- </el-card>
- </div>
- <el-table stripe :data="tableData" border style="width: 100%">
- <el-table-column prop="title" label="问题名称" />
- <el-table-column prop="optType" label="答案类型" />
- <el-table-column prop="createDate" label="创建时间">
- <template slot-scope="scope">{{
- scope.row.createDate.substr(0, 10)
- }}</template>
- </el-table-column>
- <el-table-column fixed="right" label="操作">
- <template slot-scope="scope">
- <el-button type="text" @click="handleEdit(scope.row)">编辑</el-button>
- <el-popconfirm
- icon="el-icon-info"
- icon-color="red"
- title="确定删除这个问题吗?"
- @onConfirm="handleDelete(scope.row)"
- >
- <el-button slot="reference" type="text">删除</el-button>
- </el-popconfirm>
- </template>
- </el-table-column>
- </el-table>
- <el-pagination
- v-show="questionTotal!==0"
- style="float:right; margin:20px 0"
- :total="questionTotal"
- :current-page="currentPage"
- :page-size="pageSize"
- layout="total, prev, pager, next, sizes"
- @size-change="handleSizeChange"
- @current-change="handleCurrentChange"
- />
- </div>
- </template>
- <script>
- import { getQuestionList, deleteQuestion } from '@/api/question'
-
- export default {
- props: {
- gameId: String
- },
- data() {
- return {
- // 问题名称
- title: undefined,
- daterange: '',
- tableData: [],
- endDate: undefined,
- startDate: undefined,
- pageSize: 10,
- currentPage: 1,
- questionTotal: 0// 条目总数
- }
- },
- watch: {
- gameId() {
- if (this.gameId) {
- this.onSearch()
- }
- }
- },
- methods: {
- handleSizeChange(val) {
- this.pageSize = val
- this.changePagination()
- },
- handleCurrentChange(val) {
- this.currentPage = val
- this.changePagination()
- },
- changePagination() {
- getQuestionList({ gameId: this.gameId, title: this.title, startDate: this.startDate, endDate: this.endDate, pageSize: this.pageSize, pageNum: this.currentPage }).then(
- (res) => {
- this.tableData = res.data.records
- }
- )
- },
- // 添加问题
- handleAdd() {
- this.$emit('handleAddQuestion', true)
- },
- handleEdit(row) {
- // 向外传送数据row.questionId
- this.$emit('handleEditQuestion', row.questionId)
- },
- handleDelete(row) {
- deleteQuestion(row.questionId).then(() => {
- this.$message('删除问题成功')
- this.onSearch()
- // 关闭编辑问题页面防止编辑页面还没关闭就删除当前问题了
- this.$emit('handleCloseQuestion', true)
- })
- },
- onSearch() {
- getQuestionList({ gameId: this.gameId, title: this.title, startDate: this.startDate, endDate: this.endDate, pageSize: this.pageSize }).then(
- (res) => {
- this.tableData = res.data.records
- this.questionTotal = res.data.total
- this.pageSize = res.data.size
- }
- )
- },
- onReset() {
- this.title = ''
- this.daterange = ''
- this.startDate = ''
- this.endDate = ''
- this.pageSize = 10
- this.pageNum = 1
- this.onSearch()
- },
- dateChange(val) {
- this.startDate = this.daterange[0]
- this.endDate = this.daterange[1]
- }
- }
- }
- </script>
- <style>
- .noshadowCard > .box-card {
- box-shadow: none;
- }
- </style>
|