<template>
    <div>
        <PageTable ref="valueSetTable" :resource="searchResult" :columns="columns" :isPage="false">
        </PageTable>
    </div>
</template>
<script>
export default {
  components: {},
  props: {
    sqlSentence: {
      type: String,
      default() {
        return "";
      }
    }
  },
  data() {
    return {
      searchResult: [],
      columns: [
        {
          title: "id",
          align: "center",
          key: "vsiId"
        },
        {
          title: this.$t("module.valueSet.key"),
          align: "center",
          key: "vsiKey"
        },
        {
          title: this.$t("module.valueSet.value"),
          align: "center",
          key: "vsiValue"
        }
      ]
    };
  },
  computed: {},
  created: function() {
    $store
      .dispatch("PreviewSearchResult", { vsiSql: this.sqlSentence })
      .then(response => {
        if(!response.statusCode == "0"){
          this.$Message.warning({
            content: response.msg,
            duration: 6
          })
        }
        response.dataResult.map(res => {
          this.searchResult.push(res);
        });
        this.$refs['valueSetTable'].refresh();
      });
    this.$emit("SetTitle", this.$t("module.valueSet.sqlPreview"));
    this.$emit("SetPageSize", 900);
    this.$emit("SetPageActions", [
      {
        text: this.$t("common.close"),
        theme: "primary",
        icon: "close",
        handle: this.cancel
      }
    ]);
  },
  beforeMount: function() {},
  mounted: function() {},
  beforeDestroy: function() {},
  destroyed: function() {},
  methods: {
    cancel() {
      this.$emit("Close");
    }
  },
  watch: {},
  directives: {}
};
</script>
