<template>
  <div class="fullheight">
    <ht-table
      @load="loadData"
      :data="data"
      :pageResult="pageResult"
      :selection="true"
      :default-sorter="[{direction: 'DESC', property: 'createTime'}]"
      :show-export="false"
      :show-custom-column="false"
      ref="htTable"
      @row-click="rowClick"
      class="backuptable"
    >
      <template v-slot:toolbar>
        <el-button @click="back()">返回</el-button>
      </template>
      <template>
        <ht-table-column prop="backupFile" label="文件路径" />
        <ht-table-column prop="createTime" label="备份时间" />
        <ht-table-column prop="systemResult" label="执行结果" />
        <ht-table-column prop="systemType" label="类型" />
      </template>
    </ht-table>
  </div>
</template>

<script>
import portal from '@/api/portal.js'
export default {
  name: 'backupTable',
  data() {
    return {
      data: [],
      saveUrl: `${window.context.portal}/sys/sysProperties/v1/save`,
      pageResult: {
        page: 1,
        pageSize: 50,
        total: 0,
      },
      currentProperty: {encrypt: 1},
      rows: {},
    }
  },
  created() {
    this.$bus.on('seerow', (row) => {
      this.rows = row
    })
  },
  methods: {
    rowClick(row, column, event) {
      this.$refs.htTable.$refs.htTable.toggleRowSelection(row)
    },
    loadData(param, cb) {
      //加载请求渲染表格
      setTimeout(() => {
        param.sorter=[
            {
              property: 'SYSTEM_CONFIG_ID_',
              value: this.rows,
              group: 'quick',
              relation: 'OR',
              operation: 'LIKE',
            },
          ],
        portal
          .QueryBase(param)
          .then((response) => {
            let arr = []
            for (let i in response.rows) {
              if (response.rows[i].systemType == '还原') {
                arr.push(response.rows[i])
              }
            }
            // console.log(arr)
            this.data = arr
            this.pageResult = {
              page: response.page,
              pageSize: response.pageSize,
              total: arr.length,
            }
          })
          .finally(() => cb())
      }, 1000)
    },
    back() {
      this.$bus.emit('comback')
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
    },
  },
  beforeDestroy() {
    this.$bus.off('seerow')
  },
}
</script>

<style lang="scss" scoped>
/deep/ .ht-table {
  height: 490px !important;
  max-height: 490px !important;
}
/deep/ .el-table__body-wrapper {
  max-height: 462px !important;
}
</style>