<template>
    <PageTable ref="connectionTable" :resource="dataList" :columnsFn="allColumns">
    </PageTable>
</template>

<script>
export default {
  props: {
    ipAddress: {
      type: String,
      default() {
        return "";
      }
    },
    jmxPort: {
      type: Number,
      default() {
        return -1;
      }
    },
    Identity: {
      type: Number,
      default() {
        return -1;
      }
    }
  },

  data() {
    return {
      dataList: [],

			dataSourceInfo: {
				ipAddress: this.ipAddress,
        jmxPort: this.jmxPort,
        dataSourceId: this.Identity
			}
    }
  },

  mounted: function() {
    this.search();
	},
	
  methods: {
    allColumns() {
      return [
        {
          title: this.$t('module.datasource.id'),
          key: "id",
          align: 'center',
          width: 120
        },
        {
          title: this.$t('module.datasource.connectionId'),
          key: "connectionId",
          align: 'center',
          width: 120
        },
        {
          title: this.$t('module.datasource.userCount'),
          key: "useCount",
          align: 'center',
					width: 100
        },
        {
					title: this.$t('module.datasource.lastActiveTime'),
          key: "lastActiveTime",
          align: "center",
          width: 150
        },
        {
					title: this.$t('module.datasource.lastActiveTime'),
          key: "connectTime",
          align: "center",
					width: 150
				},
        {
					title: "holdability",
          key: "holdability",
          align: 'center',
          width: 110
        },
        {
					title: "transactionIsolation",
          key: "transactionIsolation",
          align: 'center',
          width: 180
        },
        {
					title: "autoCommit",
          key: "autoCommit",
          align: "center",
          width: 110
        },
        {
					title: "readoOnly",
          key: "readoOnly",
          align: "center",
          width: 110
        },
        {
					title: "keepAliveCheckCount",
          key: "keepAliveCheckCount",
          align: 'center',
          width: 180
        }
      ]
    },
		search() {
      $store.dispatch("QueryConnectionList", this.dataSourceInfo).then(response => {

        if (response.statusCode == "0") {
          this.dataList = response.dataResult;
          this.$refs["connectionTable"].refresh();
        } else {
          this.$Message.error(response.msg);
        }
      });
    }
  }
};
</script>