<template>
 <div>
      <el-table :data="gridData" max-height="350">
        <el-table-column property="app_code" label="appCode" width="150"></el-table-column>
        <el-table-column property="page_name" label="pageName" width="200"></el-table-column>
        <el-table-column property="control_name" label="controlName"></el-table-column>
        <el-table-column property="query_sql" label="querySql" :show-overflow-tooltip='true'></el-table-column>
        <el-table-column property="version" label="version"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              @click="revertVersion(scope.$index, scope.row)">回滚</el-button>
              <el-button
              type="success"
              size="mini"
              @click="showView(scope.$index, scope.row)">查看效果</el-button>
          </template>
        </el-table-column>
      </el-table>
</div>
</template>
<script>
export default {
  name: 'lookPageLog',
  props: {
    elInfo: {
      type: Object,
      default() {
        return {
          dialogVisible: false
        }
      }
    },
    isrequest: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      pageTitle: '',
      dialogVisible: false,
      gridData: []
    }
  },
  watch: {
    isrequest(value) {
      this.dialogOpen()
    }
  },
  mounted() {
    this.dialogOpen()
  },
  methods: {
    revertVersion(index, item) {
      const parm = {
        sAppCode: item.app_code,
        sPage: item.page_name,
        sControl: item.control_name,
        version: item.version
      }
      this.$confirm('是否确定回滚到此版本!', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$emit('revertVersion', parm)
        })
        .catch((e) => {
          console.log(e)
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    dialogOpen() {
      const parm = {
        sPage: this.elInfo.page,
        sControl: this.elInfo.position
      }
      this.$API.getPageLog(parm).then(res => {
        this.gridData = res
      })
    },
    showView(index, item) {
      const data = {
        config: JSON.parse(item.json_config),
        sourceData: JSON.parse(item.json_data),
        sql: item.query_sql
      }
      this.$emit('showView', data)
    }
  }
}
</script>
