123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- /* eslint-disable no-duplicate-case */
- <template>
- <div class="school-container">
- <div class="topic">
- <el-form :inline="true" :model="formInline" class="demo-form-inline">
- <el-form-item label="code">
- <el-input v-model="formInline.code" placeholder="code" clearable />
- </el-form-item>
- <el-form-item label="状态">
- <el-select v-model="formInline.status" placeholder="请选择状态">
- <el-option label="未上架" value="NOT_ON_STOCK" />
- <el-option label="上架" value="HAS_ON_STOCK" />
- </el-select>
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click="onSubmit">查询</el-button>
- </el-form-item>
- </el-form>
- <el-button
- type="primary"
- style="position: absolute;right: 20px; top: 15px;"
- @click="addTopic"
- >添加</el-button>
- <el-table
- :data="getTopicData.list"
- style="width: 100%"
- >
- <el-table-column
- label="id"
- width="180"
- prop="id"
- />
- <el-table-column
- label="code"
- width="180"
- prop="code"
- />
- <el-table-column
- label="背景图"
- width="140"
- >
- <template slot-scope="scope">
- <img :src="scope.row.bgImg" width="128">
- </template>
- </el-table-column>
- <el-table-column
- label="标题"
- width="200"
- prop="title"
- />
- <el-table-column
- label="状态"
- width="100"
- >
- <template slot-scope="scope">
- <span style="margin-left: 10px">{{ scope.row.status === 'NOT_ON_STOCK' ? '未上架' : '已上架' }}</span>
- </template>
- </el-table-column>
- <el-table-column
- label="创建时间"
- width="200"
- >
- <template slot-scope="scope">
- <i class="el-icon-time" />
- <span style="margin-left: 10px">{{ scope.row.gmtCreated }}</span>
- </template>
- </el-table-column>
- <el-table-column
- label="修改时间"
- width="200"
- >
- <template slot-scope="scope">
- <i class="el-icon-time" />
- <span style="margin-left: 10px">{{ scope.row.gmtModified }}</span>
- </template>
- </el-table-column>
- <el-table-column label="操作">
- <template slot-scope="scope">
- <el-button
- size="mini"
- @click="handleDel(scope.$index, scope.row)"
- >{{ scope.row.status === 'NOT_ON_STOCK' ? '上架' : '下架' }}</el-button>
- <el-button
- size="mini"
- @click="handleDetail(scope.$index, scope.row)"
- >课件</el-button>
- </template>
- </el-table-column>
- </el-table>
- <el-dialog title="专题" :visible.sync="dialogFormVisible">
- <el-form ref="ruleForm" :model="form" :rules="rules">
- <el-form-item label="code" :label-width="formLabelWidth" prop="code">
- <el-input v-model="form.code" autocomplete="off" clearable />
- </el-form-item>
- <el-form-item label="背景图" :label-width="formLabelWidth" prop="bgImg">
- <el-input v-model="form.bgImg" autocomplete="off" clearable />
- </el-form-item>
- <el-form-item label="标题" :label-width="formLabelWidth" prop="title">
- <el-input v-model="form.title" autocomplete="off" clearable />
- </el-form-item>
- <el-form-item label="状态" :label-width="formLabelWidth" prop="status">
- <el-select v-model="form.status" placeholder="请选择状态">
- <el-option label="未上架" value="NOT_ON_STOCK" />
- <el-option label="上架" value="HAS_ON_STOCK" />
- </el-select>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button @click="dialogFormVisible = false">取 消</el-button>
- <el-button type="primary" @click="handOk('ruleForm')">确 定</el-button>
- </div>
- </el-dialog>
- <el-pagination
- background
- layout="prev, pager, next"
- :total="getTopicData.totalSize"
- @current-change="handleCurrentChange"
- />
- </div>
- </div>
- </template>
- <script>
- import { mapGetters } from 'vuex'
- export default {
- data() {
- return {
- dialogFormVisible: false,
- formInline: {
- code: '',
- status: ''
- },
- form: {
- code: '',
- title: '',
- bgImg: '',
- status: ''
- },
- formLabelWidth: '120px',
- rules: {
- code: [{ required: true, message: '请输入code', trigger: 'blur' }],
- title: [{ required: true, message: '请输入名称', trigger: 'blur' }],
- bgImg: [{ required: true, message: '请输入背景图', trigger: 'blur' }],
- status: [{ required: true, message: '请选择状态', trigger: 'change' }]
- },
- page: 1
- }
- },
- created() {
- this.$store.dispatch('topicList/getTopicLists', {
- page: this.page
- })
- },
- // eslint-disable-next-line vue/order-in-components
- computed: {
- ...mapGetters([
- 'getTopicData'
- ])
- },
- methods: {
- onSubmit() {
- this.$store.dispatch('topicList/getTopicLists', this.formInline)
- },
- handleDel(index, row) {
- const id = row.id
- const status = row.status === 'NOT_ON_STOCK' ? 'HAS_ON_STOCK' : 'NOT_ON_STOCK'
- this.$store.dispatch('topicList/setTopicLists', {
- id,
- status
- }).then(() => {
- this.dialogFormVisible = false
- this.$store.dispatch('topicList/getTopicLists', {
- page: this.page
- })
- })
- },
- handleDetail(index, row) {
- console.log(index, row)
- this.$router.push({
- path: '/topicRelation/topicRelation',
- query: {
- topicId: row.id
- }
- })
- },
- handOk(formName) {
- this.$refs[formName].validate((valid) => {
- if (valid) {
- this.$store.dispatch('topicList/addTopicLists', this.form).then(() => {
- this.dialogFormVisible = false
- this.$store.dispatch('topicList/getTopicLists', {
- page: this.page
- })
- })
- } else {
- console.log('error submit!!')
- return false
- }
- })
- },
- addTopic() {
- this.dialogFormVisible = true
- },
- handleCurrentChange(val) {
- console.log(val)
- this.page = val
- this.$store.dispatch('topicList/getTopicLists', {
- page: this.page
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .topic {
- margin-top: 20px;
- }
- .el-form {
- width: 50%;
- }
- .el-input {
- width: 300px;
- }
- .el-select>.el-input {
- width: 300px;
- }
- .el-pagination {
- text-align: center;
- margin-top: 20px;
- }
- </style>
|