<!--
  @description: 报表管理-报表列表
  @Modifier: 肖文龙
  @routerPath: /report/reportConfig-list
  @date: 2020/12/23
-->
<template>
  <section>
    <table-crud
      ref="tableCrud"
      :search-form="searchForm"
      search-label-width="100px"
      @on-load="loadData"
    >
      <template v-slot:header>
        报表列表
      </template>
      <template v-slot:search="search">
        <el-form-item label="文件名">
          <el-input
            v-model.trim="searchForm.name"
            placeholder="文件名"
            @keyup.enter.native="search.onSearch"
          />
        </el-form-item>
      </template>
      <template v-slot:GXTable>
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
        >
          <el-table-column
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <el-table-column
            prop="name"
            header-align="center"
            label="文件名"
            min-width="300"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                @click.stop="reportAdd(scope.row)"
              >
                {{ scope.row.name }}
              </el-link>
            </template>
          </el-table-column>
          <el-table-column
            label="创建时间"
            prop="createTime"
            align="center"
            min-width="160"
          />
          <el-table-column
            label="更新时间"
            prop="updateTime"
            align="center"
            min-width="160"
          />
          <el-table-column
            align="center"
            label="操作"
            width="150"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                @click.stop="reportAdd(scope.row)"
              >
                [设计]
              </el-link>
              <el-link
                type="primary"
                @click.stop="reportPreve(scope.row)"
              >
                [预览]
              </el-link>
              <el-link
                type="primary"
                @click.stop="reportDelete(scope.row)"
              >
                [删除]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </table-crud>
  </section>
</template>
<script>
/* 接口*/
import { queryReportList, removeReport } from '@/api/statisticalAnalysis/report.js'
export default {
  name: 'ReportConfigList',
  data() {
    return {
      loading: false,
      // 搜索
      searchForm: {
        name: '' // 文件名
      },
      tableData: []
    }
  },
  created() {
  },
  methods: {
    // 获取数据
    loadData(params, callback) {
      queryReportList(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        callback(response.data.total)
      }).catch(() => {
        this.loading = false
      })
    },
    // 删除
    reportDelete(row) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const data = {
          ids: row.id // 报表id
        }
        removeReport(data).then(() => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.$refs.tableCrud.onSearchChange()
        })
      }).catch(() => {
      })
    },
    // 报表设计
    reportAdd(row) {
      this.$router.push({
        name: 'reportConfig-add',
        params: {
          name: row.name // 报表文件名称
        }
      })
    },
    // 预览
    reportPreve(row) {
      this.$router.push({
        name: 'reportConfig-detail',
        params: {
          name: row.name // 报表文件名称
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>

</style>
