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

<script>
import lang from '../../../vuex/modules/system/datasource/lang.json';

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.name'),
          key: "name",
          fixed: 'left',
          width: 300
        },
        {
          title: this.$t('module.datasource.value'),
          key: "value",
          width: 1250
        }
        // {
				// 	title: "备注",
        //   key: "desc",
        //   fixed: 'right',
        //   width: 250
        // }
      ]
    },
		search() {
      $store.dispatch("QueryDataSourceInfo", this.dataSourceInfo).then(response => {

        if (response.statusCode == "0") {
          var arr = [];
          for (var item in response.dataResult) {
            var strName = "name:'" + ((lang[item]==null) ? item : lang[item]) + "'";
            var strValue = "value:'" + response.dataResult[item] + "'";
            var obj = eval('({' + strName + "," + strValue + '})');;
            arr.push(obj);
          }
          this.dataList = arr;
          this.$refs["dataSourceDetailTable"].refresh();
        } else {
          this.$Message.error(response.msg);
        }
      });
    }
  }
};
</script>
