index.vue 5.97 KB
<template>
  <div class="app-container">
    <el-header height>
      <el-button type="primary" @click="videoTypeCreate">创建</el-button>
    </el-header>
    <el-main>
      <el-table
        :data="videoTypeList"
        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">
              <el-image :src="scope.row.typeImage"></el-image>
            </a>
          </template>
        </el-table-column>
        <el-table-column label="软/硬件" prop="machine">
          <template slot-scope="scope">
            <span v-if="scope.row.machine===1">软件</span>
            <span v-if="scope.row.machine===0">硬件</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-link type="primary" @click="videoTypeEdit(scope.row)">编辑 &nbsp;</el-link>
            <el-link type="primary" @click="videoTypeDelete(scope.row.videoTypeCode)">删除 &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="videoTypeForm" ref="videoTypeForm" :rules="videoTypeRules" label-width="180px">
        <el-form-item label="名称:" prop="typeName">
          <el-input v-model="videoTypeForm.typeName" maxlength="100" show-word-limit></el-input>
        </el-form-item>
        <el-form-item label="图片:" prop="typeImage">
          <upload-item
            v-model="videoTypeForm.typeImage"
            v-on:before-upload="loading=true"
            v-on:after-upload="loading=false"
          ></upload-item>
        </el-form-item>
        <el-form-item label="软/硬件:" prop="machine">
          <el-select v-model="videoTypeForm.machine" placeholder="请选择">
            <el-option
              v-for="item in machineOption"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('videoTypeForm')">提交</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 = {
    videoTypeListUrl: '/tianbao_edu_api/admin/videoType/list',
    videoTypeSaveUrl: '/tianbao_edu_api/admin/videoType/save',
    videoTypeDelUrl: '/tianbao_edu_api/admin/videoType/delete',
  }

  export default {
    components: {UploadItem},
    data() {
      return {
        videoTypeList: [],
        total: 0,
        loading: false,
        queryForm: {
          page: 1,
          size: 10
        },
        dialogVisible: false,
        title: '',
        videoTypeForm: {},
        videoTypeRules: {
          typeName: [{required: true, message: '请输入名称', trigger: 'blur'}],
          typeImage: [{required: true, message: '上传缩略图', trigger: 'blur'}],
          machine: [{required: true, message: '请选择', trigger: 'blur'}]
        },
        machineOption:[
            {label:'软件',value:1},
            {label:'硬件',value:0},
        ]

      }
    },
    methods: {
      initVideoType() {
        this.loading = true
        request.get(urls.videoTypeListUrl, this.queryForm).then(data => {
          this.loading = false
          this.videoTypeList = data.content.list
          this.total = data.content.total
        }).catch(() => {

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

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

        })

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

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

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

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

<style scoped>

</style>