<template>
  <div class="th-table-properties">
    <CommonProperties :data="data" :isprivate="isprivate" @on-change="propertyChange"/>
    <div class="item" v-if="data.source">
      <div class="name inline">数据库id：</div>
      <div class="value inline" :title="data.source.databaseId">{{data.source.databaseId}}</div>
    </div>
    <div class="item" v-if="data.source">
      <div class="name inline">数据表：</div>
      <div class="value inline" :title="`${data.source.schema}.${data.source.table}`">{{data.source.schema}}.{{data.source.table}}</div>
    </div>
    <div class="developer">
      <div class="text">调用接口：</div>
      <TextCopy :text="getInterface()"/>
    </div>
  </div>
</template>

<script>
import util from '../../libs/util'
import CommonProperties from './CommonProperties.vue'
import TextCopy from '../text-copy'
import {catalogUpdate, tableUpdate} from '../../libs/request'
export default {
  props: ['node', 'data', 'isprivate'],
  components: {CommonProperties, TextCopy},
  methods: {
    propertyChange(data) {
      let {property, value} = data
      let updateData = {}
      if (property === 'id') {
        property = 'tableId'
        catalogUpdate(this.data.owner, this.node.catalogId, {resId: value}).then(res => {
          this.node.resId = res.data.resId
        })
      }
      updateData[property] = value
      tableUpdate(this.data.owner, this.data.tableId, updateData)
      this.data[property] = value
    },
    getInterface() {
      return `${util.getAPI('tables')}/${this.data.owner}/${this.data.tableId}/data`
    }
  },
  data() {
    return {
      editmode: false
    }
  }
}  
</script>
