index.vue 5.36 KB
<template>
  <div class="app-container">
    <el-header height>
      <el-button type="primary" @click="playbackTypeCreate">创建</el-button>
    </el-header>
    <el-main>
      <el-table
        :data="playbackTypeList"
        style="width: 100%"
        stripe
        highlight-current-row
        v-loading="loading"
      >
        <el-table-column label="名称" prop="typeName"></el-table-column>
        <el-table-column label="图片" prop="typeImage">
          <template slot-scope="scope">
            <a :href="scope.row.typeImage" target="_blank">
              <div style="width: 100px;">
                <el-image :src="scope.row.typeImage"></el-image>
              </div>
            </a>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-link type="primary" @click="playbackTypeEdit(scope.row)">编辑 &nbsp;</el-link>
            <el-link type="primary" @click="playbackTypeDelete(scope.row.playbackTypeCode)">删除 &nbsp;</el-link>
          </template>
        </el-table-column>
      </el-table>
    </el-main>
    <el-footer>
      <div style="text-align:right;">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryForm.page"
          :page-size="queryForm.size"
          layout="total, prev, pager, next"
          :total="total">
        </el-pagination>
      </div>
    </el-footer>

    <el-dialog
      width="60%"
      :title="title"
      :visible.sync="dialogVisible">
      <el-form :model="playbackTypeForm" ref="playbakcForm" :rules="playbackTypeRules" label-width="180px">
        <el-form-item label="名称:" prop="typeName">
          <el-input v-model="playbackTypeForm.typeName" maxlength="100" show-word-limit></el-input>
        </el-form-item>
        <el-form-item label="图片:" prop="typeImage">
          <upload-item
            v-model="playbackTypeForm.typeImage"
            v-on:before-upload="loading=true"
            v-on:after-upload="loading=false"
          ></upload-item>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('playbakcForm')">提交</el-button>
        <el-button @click="cancelCreate">取消</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
  import {request} from '@/api/fetch-api'
  import UploadItem from '@/components/UploadItem'

  let urls = {
    playbackTypeListUrl: '/tianbao_edu_api/admin/playbackType/list',
    playbackTypeSaveUrl: '/tianbao_edu_api/admin/playbackType/save',
    playbackTypeDelUrl: '/tianbao_edu_api/admin/playbackType/delete',
  }

  export default {
    components: {UploadItem},
    data() {
      return {
        playbackTypeList: [],
        total: 0,
        loading: false,
        queryForm: {
          page: 1,
          size: 10
        },
        dialogVisible: false,
        title: '',
        playbackTypeForm: {},
        playbackTypeRules: {
          typeName: [{required: true, message: '请输入名称', trigger: 'blur'}],
          typeImage: [{required: true, message: '上传缩略图', trigger: 'blur'}]
        }
      }
    },
    methods: {
      initPlayBackType() {
        this.loading = true
        request.get(urls.playbackTypeListUrl, this.queryForm).then(data => {
          this.loading = false
          this.playbackTypeList = data.content.list
          this.total = data.content.total
        }).catch(() => {

        })
      },
      playbackTypeEdit(row) {
        this.title = '编辑'
        this.dialogVisible = true
        this.playbackTypeForm = JSON.parse(JSON.stringify(row))
      },
      playbackTypeDelete(code) {
        this.$confirm('是否永远删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let form = {
            playbackTypeCode: code
          }
          request.post(urls.playbackTypeDelUrl, form).then(data => {
            this.initPlayBackType()
            this.$message.success("删除成功")
          }).catch(() => {

          })
        }).catch(() => {

        })

      },
      cancelCreate() {
        this.dialogVisible = false
        this.playbackTypeForm = {}
      },
      playbackTypeCreate() {
        this.playbackTypeForm = {}
        this.dialogVisible = true
        this.title = '创建'
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            request.post(urls.playbackTypeSaveUrl, this.playbackTypeForm).then(response => {
              this.dialogVisible = false
              this.$message.success("保存成功")
              this.initPlayBackType()
            }).catch(() => {

            })
          } else {
            console.log('error submit!!')
            return false
          }
        })

      },
      /*分页*/
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`)
        this.queryForm.size = val
        this.queryForm.page = 1
        this.initPlayBackType()
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`)
        this.queryForm.page = val
        this.initPlayBackType()
      },

    },
    created() {
      this.initPlayBackType()
    }
  }
</script>

<style scoped>

</style>