index.vue 4.58 KB
<template>
  <div class="app-container">
    <el-header height>
      <el-button type="primary" @click="createPublic">创建</el-button>
    </el-header>
    <el-main>
      <el-table
        :data="publicList"
        style="width: 100%"
        stripe
        highlight-current-row
        v-loading="loading"
      >
        <el-table-column label="活动标题" prop="title"></el-table-column>
        <el-table-column label="地点" prop="city">
        </el-table-column>
        <el-table-column label="报名" prop="enroll"></el-table-column>
        <el-table-column label="开始时间">
          <template slot-scope="scope">
            {{scope.row.startDate}} &nbsp; {{scope.row.startTime}}
          </template>
        </el-table-column>
        <el-table-column label="结束时间">
          <template slot-scope="scope">
            {{scope.row.endDate}} &nbsp; {{scope.row.endTime}}
          </template>
        </el-table-column>
        <el-table-column label="直播内容" prop="content"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-link type="primary" @click="editPublic(scope.row)">编辑&nbsp;</el-link>
            <el-link type="primary" @click="deletePublic(scope.row.publicCode)">删除</el-link>
          </template>
        </el-table-column>
      </el-table>
    </el-main>
    <el-footer height>
      <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>

    <public-save-dialog
      v-if="dialogVisible"
      :dialog-visible="dialogVisible"
      :public-temp="publicTemp"
      @closedialog="closedialog"
      @initPublic="initPublic">
    </public-save-dialog>
  </div>
</template>

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

  let urls = {
    publicListUrl: '/tianbao_edu_api/admin/public/list',
    publicSaveUrl: '/tianbao_edu_api/admin/public/save',
    publicDelUrl: '/tianbao_edu_api/admin/public/delete'
  }
  export default {
    components: {publicSaveDialog},
    data() {
      return {
        publicList: [],
        total: 0,
        loading: false,
        queryForm: {
          page: 1,
          size: 10
        },
        dialogVisible: false,
        publicTemp: {},
      }
    },
    methods: {
      initPublic() {
        this.loading = true
        request.get(urls.publicListUrl, this.queryForm).then(data => {
          this.loading = false
          this.publicList = data.content.list
          this.total = data.content.total
        }).catch(() => {

        })
      },
      editPublic(row) {
        this.publicTemp = row
        this.dialogVisible = true
      },
      createPublic() {
        this.publicTemp = null
        this.dialogVisible = true
      },
      closedialog() {
        this.dialogVisible = false
      },
      deletePublic(code) {

        this.$confirm('是否永远删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          request.post(urls.publicDelUrl, {publicCode: code}).then(data => {
            this.$message.success("删除成")
            this.initPublic()
          }).catch(() => {

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

        })
      },
      timestampToTime(row) {
        if (row === 0) {
          return ''
        }
        var date = new Date(row)
        var Y = date.getFullYear() + '-'
        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
        var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
        var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
        var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
        var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
        return Y + M + D + h + m + s
      },
      /*分页*/
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`)
        this.queryForm.size = val
        this.queryForm.page = 1
        this.initPublic()
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`)
        this.queryForm.page = val
        this.initPublic()
      },
    },
    created() {
      this.initPublic()
    }
  }
</script>

<style scoped>

</style>