<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-group>
          <el-button @click="back()">返回</el-button>
        </el-button-group>
      </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="类型" />
        <ht-table-column label="操作">
          <template v-slot="{row}">
            <el-button size="small" @click="rest(row)">还原</el-button>
          </template>
        </ht-table-column>
      </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
      console.log(this.rows, '1')
    })
  },
  methods: {
    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: response.total,
            }
          })
          .finally(() => cb())
      }, 1000)
    },
    rowClick(row, column, event) {
      this.$refs.htTable.$refs.htTable.toggleRowSelection(row)
    },
    back() {
      this.$bus.emit('comback', 1)
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
    },
    rest(row) {
      console.log(row)
      let data = this.qs.stringify({
        id: row.systemConfigId,
      })
      portal.Reduction(data).then((res) => {
        if (res.state == true) {
          this.$message({
            message: res.message,
            type: 'success',
          })
        }
      })
    },
  },
  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>