<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="top-right-btn">
        <el-tooltip class="item" effect="dark" content="刷新" placement="top">
          <el-button size="mini" circle icon="el-icon-refresh" @click="getScriptInfo" />
        </el-tooltip>
      </div>
    </div>
    <el-table
      :data="tableData"
      v-loading="listLoading"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      default-expand-all>
      <el-table-column
        prop="businessName"
        label="业务名称">
      </el-table-column>
     <el-table-column
        label="业务代码"
        prop="businessCode"
      ></el-table-column>
      <el-table-column label="操作" fixed="left" align="center" width="230" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button @click="invalidate(row,true)" type="primary" size="mini">
            重载
          </el-button>
          <el-button @click="invalidate(row,false)" type="danger" size="mini">
            清除
          </el-button>
        </template>
      </el-table-column>

    </el-table>
    <pagination v-show="listData.total>0" :total="listData.total" :page.sync="listData.page" :limit.sync="listData.pageSize" @pagination="getScriptInfo" />
     <cancledialog @tableRefresh="tableRefresh" ref="confirmDialog"></cancledialog>
  </div>
</template>

<script>
import { getLoadedScriptList } from '@/api/system/loadedScript'
import Cancledialog from '@/components/Dialog/Cancledialog.vue'

const form = {
  businessName: '',
  businessCode: '',
  businessModule: ''
}
export default {
  components: {
    Cancledialog
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        1: 'success',
        0: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      dialogStatus: 1, // 1增加，2修改
      dialogTitle: '',
      dialogVisible: false,
      search: {
        keyWord: ''
      },
      form: Object.assign({}, form),
      listData: {
        total: 0,
        page: 1,
        pageSize: 10
      },
      options: [],
      moduleOptions: [],

      confirmdialog: false,
      listLoading: false,
      tableData: [],
      menuId: ''
    }
  },
  mounted() {
    this.getScriptInfo()
  },
  methods: {
    // 获取列表
    getScriptInfo() {
      const _that = this
      _that.listLoading = true
      var data = {
      }
      // console.log(data);
      getLoadedScriptList(data).then(response => {
        console.log(response)
        const data = response.data
        // //  组合表单数据
        _that.tableData = data

        _that.listData.total = response.total
        // console.log(_that.tableData)
        _that.listLoading = false
      }).catch(err => {
        _that.listLoading = false
      })
    },
    // 刷新变革
    tableRefresh() {
      this.getScriptInfo()
    },
    // 启用禁用
    invalidate(row, reload) {
      var _that = this
      var params = {
        'businessCode': row.businessCode,
        'businessModule': row.businessModule,
        'reload': reload
      }

      var url = '/admin/v1/invalidateScriptCache'
      _that.$refs.confirmDialog.updataClick(params, url)
    }
  }
}
</script>

<style lang="scss" scoped>
  .filter-container {
    margin-bottom: 15px;
  }
</style>
