You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
5.9 KiB
Vue

<template>
<div class="app-container">
<div class="tz-line">
<el-input placeholder="输入课程名称" />
<el-button type="primary" icon="el-icon-search">查找</el-button>
</div>
<el-table
v-loading="listLoading"
:data="list"
element-loading-text="Loading"
border
fit
highlight-current-row
>
<el-table-column label="课程名称" align="center">
<template slot-scope="scope">
<span>{{ scope.row.name }}</span>
</template>
</el-table-column>
<el-table-column label="课程类别">
<template slot-scope="scope">
{{ catIdToName(scope.row.catId) }}
</template>
</el-table-column>
<el-table-column label="标签" align="center">
<template slot-scope="scope">
<span>{{ tagIdToName(scope.row.tagId) }}</span>
</template>
</el-table-column>
<el-table-column label="创建人" align="center">
<template slot-scope="scope">
<span>{{ scope.row.creator }}</span>
</template>
</el-table-column>
<el-table-column label="创建时间" align="center">
<template slot-scope="scope">
<span>{{ new Date(scope.row.createTime).Format("yyyy-MM-dd") }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="操作" width="300" class-name="small-padding fixed-width">
<template slot-scope="{row,$index}">
<el-button type="primary" size="mini" @click="gotoEdit(row)">
编辑
</el-button>
<el-button v-if="row.status!='deleted'" size="mini" type="danger" @click="handleDelete(row,$index)">
删除
</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
:current-page="listQuery.pageNo"
:page-sizes="[10,15,20]"
:page-size="limit"
layout="total,prev,pager,next,jumper,sizes"
:total="total"
/>
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
<el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="100px" style="width: 400px; margin-left:50px;">
<el-form-item label="课程名称" prop="type">
<el-input v-model="temp.name" />
</el-form-item>
<el-form-item label="课程类别" prop="timestamp">
<el-select v-model="temp.catId" class="filter-item" placeholder="请选择">
<el-option v-for="item in catOptions" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item label="课程ID" prop="title">
<el-input v-model="temp.id" />
</el-form-item>
<el-form-item label="创建人">
<el-input v-model="temp.creator" />
</el-form-item>
<el-form-item label="创建时间">
<el-date-picker v-model="temp.createTime" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">
取消
</el-button>
<el-button type="primary">
</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { getList ,del } from '@/api/course'
import * as tag from '@/api/courseTag'
import * as cat from '@/api/courseCat'
export default {
filters: {
statusFilter(status) {
const statusMap = {
published: 'success',
draft: 'info',
deleted: 'danger'
}
return statusMap[status]
}
},
data() {
return {
list: null,
listLoading: true,
listQuery: {
pageNo: 0
},
total: 0,
limit: 20,
textMap: {
update: 'Edit',
create: 'Create'
},
dialogFormVisible: false,
tagOptions: [],
catOptions: [],
dialogStatus: '',
statusOptions: ['published', 'draft', 'deleted'],
temp: {
id: undefined,
importance: 1,
remark: '',
timestamp: new Date(),
title: '',
type: '',
status: 'published'
},
rules: {
type: [{ required: true, message: 'type is required', trigger: 'change' }],
timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
title: [{ required: true, message: 'title is required', trigger: 'blur' }]
}
}
},
created() {
this.fetchData()
},
methods: {
fetchData() {
this.listLoading = true
tag.getList().then(res=>{
this.tagOptions = res.data.list
})
cat.getList().then(res=>{
this.catOptions = res.data.list
this.listLoading = false
})
getList(this.listQuery).then(response => {
const onePage = response.data.page
this.list = onePage.content
this.total = onePage.totalElements
this.listLoading = false
})
},
handleUpdate(row) {
this.temp = Object.assign({}, row) // copy obj
this.temp.timestamp = new Date(this.temp.timestamp)
this.dialogStatus = 'update'
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs['dataForm'].clearValidate()
})
},
handleDelete(item,index){
del(item).then(response => {
if(response.code === 200){
this.list.splice(index,1)
}
})
},
catIdToName(catId){
return this.catOptions.find(cat=>cat.id == catId).name
},
tagIdToName(tagId){
let tag = this.tagOptions.find(tag=>tag.id === tagId)
if(tag){
return tag.name
}
return '未知'
},
gotoEdit(row){
this.$router.push({
path: '/resource/course/add',
query: {id: row.id}
})
}
}
}
</script>
<style scoped>
.tz-line{
display: flex;
width: 100%;
margin-bottom: 20px;
}
.tz-line button{
margin-left: 10px;
}
</style>